Simpatico  v1.10
XmlBase.cpp
1 /*
2 * Util Package - C++ Utilities for Scientific Computation
3 *
4 * Copyright 2010 - 2017, The Regents of the University of Minnesota
5 * Distributed under the terms of the GNU General Public License.
6 */
7 
8 #include "XmlBase.h"
9 
10 namespace Util
11 {
12 
13  /*
14  * Constructor.
15  */
17  : stringPtr_(0),
18  end_(0),
19  cursor_(0),
20  c_('\0')
21  {}
22 
23  /*
24  * Destructor.
25  */
27  {}
28 
29  /*
30  * Initialize string and cursor.
31  */
32  void XmlBase::setString(const std::string& string, int cursor)
33  {
34  stringPtr_ = &string;
35  end_ = string.length();
36  setCursor(cursor);
37  }
38 
39  /*
40  * Set cursor. String must already be set.
41  */
43  {
44  if (!stringPtr_) {
45  UTIL_THROW("No string");
46  }
47  if (cursor > end_) {
48  UTIL_THROW("Error: cursor > end_");
49  }
50  if (cursor < 0) {
51  UTIL_THROW("Error: cursor < 0");
52  }
53  cursor_ = cursor;
54  if (cursor < end_) {
55  c_ = (*stringPtr_)[cursor];
56  } else {
57  c_ = '\0';
58  }
59  }
60 
61 }
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
void setCursor(int cursor)
Set cursor.
Definition: XmlBase.cpp:42
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
Definition: global.h:51
~XmlBase()
Destructor.
Definition: XmlBase.cpp:26
Utility classes for scientific computation.
Definition: accumulators.mod:1
XmlBase()
Constructor.
Definition: XmlBase.cpp:16
const std::string & string() const
Return the associated string.
Definition: XmlBase.h:118