MeVisLab Toolbox Reference
mlParserBase.h
Go to the documentation of this file.
1/*************************************************************************************
2**
3** Copyright 2007, MeVis Medical Solutions AG
4**
5** The user may use this file in accordance with the license agreement provided with
6** the Software or, alternatively, in accordance with the terms contained in a
7** written agreement between the user and MeVis Medical Solutions AG.
8**
9** For further information use the contact form at https://www.mevislab.de/contact
10**
11**************************************************************************************/
12
13#ifndef ML_PARSER_BASE_H
14#define ML_PARSER_BASE_H
15
16
21
22// ML-includes
23#include "mlBaseInit.h"
24#include "mlModuleIncludes.h"
25
26
28
29
30// ------------------------------------------------------------------
31// Class ParserBase
32// ------------------------------------------------------------------
33
37{
38public:
39
41 ParserBase () : _source(nullptr), _pNext(nullptr), _eos(true) {}
42
44 virtual ~ParserBase() {}
45
48 virtual int init (const char *source);
49
51 const char *getCurrentPos () { return _pNext; }
52
54 bool endOfSource () { return _eos; }
55
57 virtual const char *getErrorMessage (int errorCode);
58
60 enum {
61 kNoError = 0,
64 kEndOfSource = -1
65 };
66
67
71 static char *newString (const std::string &str);
72
74 static void deleteString (char *str);
75
76
77protected:
78
81
82
84 const char *_source;
86 const char *_pNext;
88 bool _eos;
89
90};
91
92
94
95#endif // __mlParserBase_H
Basic parser class from which special parser classes can be derived for parsing persistent state stri...
const char * _pNext
Pointer to current parser position.
@ kNumBaseErrorCodes
Highest error code +1.
@ kEmptyString
Source string null or empty.
static char * newString(const std::string &str)
Convenience method to create a copy of the string str allocated on the heap.
const char * getCurrentPos()
Get current parser position.
virtual const char * getErrorMessage(int errorCode)
Get error string for errorCode.
static void deleteString(char *str)
Dispose a string allocated with newString()
ParserBase()
Constructor.
bool _eos
End-of-string flag.
bool endOfSource()
Return end-of-source flag.
const char * _source
Source string.
virtual int init(const char *source)
Initialize parser and proceed to first non-whitespace character.
virtual ~ParserBase()
Make destructor virtual to avoid warnings.
void skipWhitespace()
Proceed to next non-whitespace character.
#define MLBASEEXPORT
defined Header file mlBaseInit.h
Definition mlBaseInit.h:22
Target mlrange_cast(Source arg)
Generic version of checked ML casts.