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 value_separated_parser.h
18 * @author Tomasz Iwanek (t.iwanek@samsung.com)
19 * @brief Parser for some value seperated files/data
22 #ifndef VALUE_SEPARATED_PARSER_H
23 #define VALUE_SEPARATED_PARSER_H
29 #include<dpl/test/value_separated_tokens.h>
30 #include<dpl/test/abstract_input_parser.h>
34 typedef std::vector<std::string> VSLine;
35 typedef std::vector<VSLine> VSResult;
36 typedef std::shared_ptr<VSResult> VSResultPtr;
39 * Value Seperated parser
41 * Requires following policy class:
43 * template<VSResultPtr>
44 * struct CSVParserPolicy
46 * static bool SkipLine(VSLine & );
47 * static bool Validate(VSResultPtr& result);
50 template<class ParserPolicy>
51 class VSParser : public AbstractInputParser<VSResultPtr, VSToken>
54 VSParser() : m_switchLine(true), m_result(new VSResult()) {}
56 void ConsumeToken(std::unique_ptr<VSToken> && token)
60 m_result->push_back(VSLine());
63 if(token->isNewLine())
65 if(ParserPolicy::SkipLine(*m_result->rbegin()))
73 m_result->rbegin()->push_back(token->cell());
79 return ParserPolicy::Validate(m_result);
82 VSResultPtr GetResult() const