LineParser.h
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2018 New Eagle
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of New Eagle nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *********************************************************************/
34 
35 #ifndef _NEW_EAGLE_LINEPARSER_H
36 #define _NEW_EAGLE_LINEPARSER_H
37 
38 #include <ros/ros.h>
39 
40 #include <string>
41 #include <exception>
42 #include <ctype.h>
43 
44 namespace NewEagle
45 {
46  class LineParserExceptionBase: public std::exception
47  {
48  };
49 
50  class LineParserAtEOLException: public LineParserExceptionBase
51  {
52  virtual const char* what() const throw()
53  {
54  return "Unexpected end of line.";
55  }
56  };
57 
58  class LineParserLenZeroException: public LineParserExceptionBase
59  {
60  virtual const char* what() const throw()
61  {
62  return "Nothing found in search space.";
63  }
64  };
65 
66  class LineParserInvalidCharException: public LineParserExceptionBase
67  {
68  virtual const char* what() const throw()
69  {
70  return "Invalid character(s) search space.";
71  }
72  };
73 
74  enum ReadDoubleState
75  {
77  READING_FRACTION = 1,
78  READ_E = 2,
79  READ_SIGN = 3,
80  READING_EXP = 4
81  };
82 
83  class LineParser
84  {
85  public:
86  LineParser(const std::string &line);
87  ~LineParser();
88 
89  int32_t GetPosition();
90  std::string ReadCIdentifier();
91  std::string ReadCIdentifier(std::string fieldName);
92  uint32_t ReadUInt();
93  uint32_t ReadUInt(std::string fieldName);
94  void SeekSeparator(char separator);
95  char ReadNextChar(std::string fieldName);
96  int32_t ReadInt();
97  double ReadDouble();
98  double ReadDouble(std::string fieldName);
99  std::string ReadQuotedString();
100  uint32_t PeekUInt();
101 
102  private:
103  int32_t _position;
104  std::string _line;
105 
107  bool AtEOL();
108  char ReadNextChar();
109  };
110 }
111 
112 #endif // _NEW_EAGLE_LINEPARSER_H
NewEagle::LineParser::AtEOL
bool AtEOL()
Definition: LineParser.cpp:135
NewEagle::LineParser::SkipWhitespace
void SkipWhitespace()
Definition: LineParser.cpp:127
NewEagle::ReadDoubleState
ReadDoubleState
Definition: LineParser.h:106
NewEagle::LineParser::ReadNextChar
char ReadNextChar()
Definition: LineParser.cpp:140
ros.h
NewEagle::LineParser::~LineParser
~LineParser()
Definition: LineParser.cpp:77
NewEagle::LineParser::ReadQuotedString
std::string ReadQuotedString()
Definition: LineParser.cpp:427
NewEagle
Definition: Dbc.h:45
NewEagle::READING_WHOLE_NUMBER
@ READING_WHOLE_NUMBER
Definition: LineParser.h:108
NewEagle::LineParser::ReadDouble
double ReadDouble()
Definition: LineParser.cpp:305
NewEagle::LineParser::PeekUInt
uint32_t PeekUInt()
Definition: LineParser.cpp:170
NewEagle::LineParser::ReadInt
int32_t ReadInt()
Definition: LineParser.cpp:261
NewEagle::LineParserAtEOLException::what
virtual const char * what() const
Definition: LineParser.h:84
NewEagle::LineParser::SeekSeparator
void SeekSeparator(char separator)
Definition: LineParser.cpp:417
NewEagle::READING_EXP
@ READING_EXP
Definition: LineParser.h:112
NewEagle::READ_E
@ READ_E
Definition: LineParser.h:110
NewEagle::LineParserLenZeroException::what
virtual const char * what() const
Definition: LineParser.h:92
NewEagle::LineParser::ReadUInt
uint32_t ReadUInt()
Definition: LineParser.cpp:210
NewEagle::LineParser
Definition: LineParser.h:115
NewEagle::LineParser::LineParser
LineParser(const std::string &line)
Definition: LineParser.cpp:71
NewEagle::LineParser::ReadCIdentifier
std::string ReadCIdentifier()
Definition: LineParser.cpp:86
NewEagle::LineParser::_line
std::string _line
Definition: LineParser.h:136
NewEagle::LineParser::_position
int32_t _position
Definition: LineParser.h:135
NewEagle::READING_FRACTION
@ READING_FRACTION
Definition: LineParser.h:109
NewEagle::LineParserInvalidCharException::what
virtual const char * what() const
Definition: LineParser.h:100
NewEagle::READ_SIGN
@ READ_SIGN
Definition: LineParser.h:111
NewEagle::LineParser::GetPosition
int32_t GetPosition()
Definition: LineParser.cpp:81


can_dbc_parser
Author(s): Ryan Borchert
autogenerated on Sat Apr 9 2022 02:34:32