Initialize Tizen 2.3
[framework/web/wrt-commons.git] / modules / 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/exception.h>
30
31 namespace DPL {
32
33 /**
34  * Tokenizer abstract base class
35  *
36  * This class is supposed to accept AbstractInput in constructor
37  * and produce tokens until end of source. If parsing ends in invalid state
38  * then IsStateValid() should return false
39  */
40 template<class Token> class AbstractInputTokenizer
41 {
42 public:
43     class Exception
44     {
45     public:
46         DECLARE_EXCEPTION_TYPE(DPL::Exception, Base)
47         DECLARE_EXCEPTION_TYPE(Base, TokenizerError)
48     };
49
50     typedef Token TokenType;
51
52     AbstractInputTokenizer() {}
53     virtual ~AbstractInputTokenizer() {}
54
55     /**
56      * @brief Reset resets data source
57      * @param wia AbstractWaitableInputAdapter instance
58      */
59     virtual void Reset(std::shared_ptr<AbstractInput> wia)
60     {
61         m_input = wia;
62     }
63
64     /**
65      * @brief GetNextToken
66      *
67      * Parses next token.
68      * Returns pointer to token
69      * @throw TokenizerError in condition of input source error
70      * If returned empty pointer IsStateValid() == true -> end of input
71      *                           IsStateValid() == false -> error
72      *
73      * @param token token to be set
74      * @return
75      */
76     virtual std::unique_ptr<Token> GetNextToken() = 0;
77     virtual bool IsStateValid() = 0;
78
79 protected:
80     std::shared_ptr<AbstractInput> m_input;
81 };
82
83 }
84
85 #endif