Firmware for Arduino | PLEN Project Company Inc.
Parser.h
Go to the documentation of this file.
1 
8 #pragma once
9 
10 #ifndef UTILITY_PARSER_H
11 #define UTILITY_PARSER_H
12 
13 
14 #include <stdint.h>
15 
16 namespace Utility
17 {
18  class AbstractParser;
19  class NilParser;
20  class CharGroupParser;
21  class StringGroupParser;
22  class HexStringParser;
23 
24 
34  uint16_t hexbytes2uint16_impl(const char* bytes, uint8_t size);
35 
42  template<const int SIZE>
43  uint16_t hexbytes2uint16(const char* bytes)
44  {
45  typedef uint8_t SIZE_needs_to_be_4_and_under[(SIZE > 4)? -1 : 1];
46 
47  return hexbytes2uint16_impl(bytes, SIZE);
48  }
49 
50 
62  int16_t hexbytes2int16_impl(const char* bytes, uint8_t size);
63 
70  template<const int SIZE>
71  int16_t hexbytes2int16(const char* bytes)
72  {
73  typedef uint8_t SIZE_needs_to_be_4_and_under[(SIZE > 4)? -1 : 1];
74 
75  return hexbytes2int16_impl(bytes, SIZE);
76  }
77 }
78 
79 
84 {
85 protected:
86  int8_t m_index;
87 
94 
95 public:
99  virtual ~AbstractParser();
100 
108  virtual bool parse(const char* input) = 0;
109 
117  virtual const int8_t& index();
118 };
119 
120 
125 {
126 public:
130  NilParser();
131 
135  virtual ~NilParser();
136 
144  virtual bool parse(const char* input);
145 };
146 
147 
169 {
170 private:
171  const char* m_accept_chars;
172 
173 public:
183  CharGroupParser(const char* accept_chars);
184 
188  virtual ~CharGroupParser();
189 
203  virtual bool parse(const char* input);
204 };
205 
206 
235 {
236 private:
237  const char** m_accept_strs;
238  const uint8_t m_size;
239 
240 public:
251  StringGroupParser(const char* accept_strs[], uint8_t size);
252 
256  virtual ~StringGroupParser();
257 
265  virtual bool parse(const char* input);
266 };
267 
268 
273 {
274 public:
278  HexStringParser();
279 
283  virtual ~HexStringParser();
284 
292  virtual bool parse(const char* input);
293 };
294 
295 #endif // UTILITY_PARSER_H
virtual ~NilParser()
Destructor.
int16_t hexbytes2int16_impl(const char *bytes, uint8_t size)
Convert hex string to an int16_t.
virtual bool parse(const char *input)
Parse input string.
virtual ~HexStringParser()
Destructor.
CharGroupParser(const char *accept_chars)
Constructor.
virtual const int8_t & index()
Get matched index of after parsing.
virtual ~CharGroupParser()
Destructor.
Parser class that accepts only strings given.
Definition: Parser.h:234
Parser class that accepts only hex string.
Definition: Parser.h:272
virtual bool parse(const char *input)=0
Parser function interface.
Abstract parser interface.
Definition: Parser.h:83
int8_t m_index
Definition: Parser.h:86
virtual ~StringGroupParser()
Destructor.
Definition: Parser.h:16
NilParser()
Constructor.
int16_t hexbytes2int16(const char *bytes)
hexbytes2int16_impl with compile time assertion.
Definition: Parser.h:71
virtual bool parse(const char *input)
Do nothing.
Parser class that accepts only characters given.
Definition: Parser.h:168
HexStringParser()
Constructor.
virtual ~AbstractParser()
Destructor.
AbstractParser()
Constructor.
uint16_t hexbytes2uint16(const char *bytes)
hexbytes2uint16_impl with compile time assertion
Definition: Parser.h:43
StringGroupParser(const char *accept_strs[], uint8_t size)
Constructor.
virtual bool parse(const char *input)
Parse input string.
virtual bool parse(const char *input)
Parse input string.
uint16_t hexbytes2uint16_impl(const char *bytes, uint8_t size)
Convert hex string to an uint16_t.
Parser class that accepts all.
Definition: Parser.h:124