Initialize Tizen 2.3
[framework/web/wrt-commons.git] / modules_mobile / test / include / dpl / test / abstract_input_tokenizer.h
1 /*
2  * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *    Licensed under the Apache License, Version 2.0 (the "License");
5  *    you may not use this file except in compliance with the License.
6  *    You may obtain a copy of the License at
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *    Unless required by applicable law or agreed to in writing, software
11  *    distributed under the License is distributed on an "AS IS" BASIS,
12  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *    See the License for the specific language governing permissions and
14  *    limitations under the License.
15  */
16 /*
17  * @file        abstract_input_tokenizer.h
18  * @author      Tomasz Iwanek (t.iwanek@samsung.com)
19  * @brief       Simple tokenizer abstraction
20  */
21
22 #ifndef ABSTRACT_INPUT_TOKENIZER_H
23 #define ABSTRACT_INPUT_TOKENIZER_H
24
25 #include <memory>
26 #include <string>
27
28 #include <dpl/abstract_input.h>
29 #include <dpl/optional.h>
30 #include <dpl/exception.h>
31
32 namespace DPL {
33
34 /**
35  * Tokenizer abstract base class
36  *
37  * This class is supposed to accept AbstractInput in constructor
38  * and produce tokens until end of source. If parsing ends in invalid state
39  * then IsStateValid() should return false
40  */
41 template<class Token> class AbstractInputTokenizer
42 {
43 public:
44     class Exception
45     {
46     public:
47         DECLARE_EXCEPTION_TYPE(DPL::Exception, Base)
48         DECLARE_EXCEPTION_TYPE(Base, TokenizerError)
49     };
50
51     typedef Token TokenType;
52
53     AbstractInputTokenizer() {}
54     virtual ~AbstractInputTokenizer() {}
55
56     /**
57      * @brief Reset resets data source
58      * @param wia AbstractWaitableInputAdapter instance
59      */
60     virtual void Reset(std::shared_ptr<AbstractInput> wia)
61     {
62         m_input = wia;
63     }
64
65     /**
66      * @brief GetNextToken
67      *
68      * Parses next token.
69      * Returns pointer to token
70      * @throw TokenizerError in condition of input source error
71      * If returned empty pointer IsStateValid() == true -> end of input
72      *                           IsStateValid() == false -> error
73      *
74      * @param token token to be set
75      * @return
76      */
77     virtual std::unique_ptr<Token> GetNextToken() = 0;
78     virtual bool IsStateValid() = 0;
79
80 protected:
81     std::shared_ptr<AbstractInput> m_input;
82 };
83
84 }
85
86 #endif