Simpatico  v1.10
XmlBase.h
1 #ifndef UTIL_XML_BASE_H
2 #define UTIL_XML_BASE_H
3 
4 /*
5 * Util Package - C++ Utilities for Scientific Computation
6 *
7 * Copyright 2010 - 2017, The Regents of the University of Minnesota
8 * Distributed under the terms of the GNU General Public License.
9 */
10 
11 #include <util/global.h>
12 #include <string>
13 
14 namespace Util
15 {
16 
22  class XmlBase
23  {
24  public:
25 
29  XmlBase();
30 
34  ~XmlBase();
35 
39  void setString(const std::string& string, int cursor = 0);
40 
44  void setCursor(int cursor);
45 
49  void skip();
50 
54  void next();
55 
59  const std::string& string() const;
60 
64  int cursor() const;
65 
69  int c() const;
70 
74  bool isEnd() const;
75 
76  private:
77 
78  std::string const * stringPtr_;
79  int end_;
80  int cursor_;
81  char c_;
82 
83  };
84 
85  /*
86  * Skip leading white space, if any.
87  */
88  inline void XmlBase::skip()
89  {
90  if (cursor_ == end_) return;
91  while (c_ == ' ') {
92  ++cursor_;
93  if (cursor_ == end_) {
94  c_ = '\0';
95  return;
96  }
97  c_ = (*stringPtr_)[cursor_];
98  }
99  }
100 
101  /*
102  * Advance to the next character.
103  */
104  inline void XmlBase::next()
105  {
106  if (cursor_ == end_) return;
107  ++cursor_;
108  if (cursor_ != end_) {
109  c_ = (*stringPtr_)[cursor_];
110  } else {
111  c_ = '\0';
112  }
113  }
114 
115  /*
116  * Return the associated string.
117  */
118  inline const std::string& XmlBase::string() const
119  { return (*stringPtr_); }
120 
124  inline int XmlBase::cursor() const
125  { return cursor_; }
126 
130  inline int XmlBase::c() const
131  { return c_; }
132 
136  inline bool XmlBase::isEnd() const
137  { return (cursor_ == end_); }
138 
139 }
140 #endif
Base class for classes that parse XML markup tags.
Definition: XmlBase.h:22
void setString(const std::string &string, int cursor=0)
Initialize string and cursor.
Definition: XmlBase.cpp:32
int cursor() const
Return the index of the current character.
Definition: XmlBase.h:124
File containing preprocessor macros for error handling.
void setCursor(int cursor)
Set cursor.
Definition: XmlBase.cpp:42
~XmlBase()
Destructor.
Definition: XmlBase.cpp:26
void next()
Advance to the next character.
Definition: XmlBase.h:104
Utility classes for scientific computation.
Definition: accumulators.mod:1
bool isEnd() const
Has the cursor reached the end of the string?
Definition: XmlBase.h:136
XmlBase()
Constructor.
Definition: XmlBase.cpp:16
const std::string & string() const
Return the associated string.
Definition: XmlBase.h:118
int c() const
Return the current character.
Definition: XmlBase.h:130
void skip()
Skip leading white space, if any.
Definition: XmlBase.h:88