2 * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 * @file abstract_input_tokenizer.h
18 * @author Tomasz Iwanek (t.iwanek@samsung.com)
19 * @brief Simple tokenizer abstraction
22 #ifndef ABSTRACT_INPUT_TOKENIZER_H
23 #define ABSTRACT_INPUT_TOKENIZER_H
28 #include <dpl/abstract_input.h>
29 #include <dpl/exception.h>
34 * Tokenizer abstract base class
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
40 template<class Token> class AbstractInputTokenizer
46 DECLARE_EXCEPTION_TYPE(DPL::Exception, Base)
47 DECLARE_EXCEPTION_TYPE(Base, TokenizerError)
50 typedef Token TokenType;
52 AbstractInputTokenizer() {}
53 virtual ~AbstractInputTokenizer() {}
56 * @brief Reset resets data source
57 * @param wia AbstractWaitableInputAdapter instance
59 virtual void Reset(std::shared_ptr<AbstractInput> wia)
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
73 * @param token token to be set
76 virtual std::unique_ptr<Token> GetNextToken() = 0;
77 virtual bool IsStateValid() = 0;
80 std::shared_ptr<AbstractInput> m_input;