• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 The Android Open Source Project
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 #ifndef TEXT_PARSER_BASE_H
18 #define TEXT_PARSER_BASE_H
19 
20 #include <utils/Errors.h>
21 #include <utils/String8.h>
22 
23 using namespace android;
24 using namespace std;
25 
26 /**
27  * Base class for text parser
28  */
29 class TextParserBase {
30 public:
31     String8 name;
32 
TextParserBase(String8 name)33     explicit TextParserBase(String8 name) : name(name) {};
~TextParserBase()34     virtual ~TextParserBase() {};
35 
36     virtual status_t Parse(const int in, const int out) const = 0;
37 };
38 
39 /**
40  * No op parser returns what it reads
41  */
42 class NoopParser : public TextParserBase {
43 public:
NoopParser()44     NoopParser() : TextParserBase(String8("NoopParser")) {};
~NoopParser()45     ~NoopParser() {};
46 
47     virtual status_t Parse(const int in, const int out) const;
48 };
49 
50 /**
51  * This parser is used for testing only, results in timeout.
52  */
53 class TimeoutParser : public TextParserBase {
54 public:
TimeoutParser()55     TimeoutParser() : TextParserBase(String8("TimeoutParser")) {};
~TimeoutParser()56     ~TimeoutParser() {};
57 
Parse(const int,const int)58     virtual status_t Parse(const int /** in */, const int /** out */) const { while (true); };
59 };
60 
61 /**
62  * This parser is used for testing only, results in reversed input text.
63  */
64 class ReverseParser : public TextParserBase {
65 public:
ReverseParser()66     ReverseParser() : TextParserBase(String8("ReverseParser")) {};
~ReverseParser()67     ~ReverseParser() {};
68 
69     virtual status_t Parse(const int in, const int out) const;
70 };
71 
72 #endif // TEXT_PARSER_BASE_H
73