You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

XMLReader.inline.hpp 33KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621
  1. // XMLReader.inline.hpp
  2. //
  3. // (C) 2006-2009 MicroNeil Research Corporation.
  4. //
  5. // This program is part of the MicroNeil Research Open Library Project. For
  6. // more information go to http://www.microneil.com/OpenLibrary/index.html
  7. //
  8. // This program is free software; you can redistribute it and/or modify it
  9. // under the terms of the GNU General Public License as published by the
  10. // Free Software Foundation; either version 2 of the License, or (at your
  11. // option) any later version.
  12. //
  13. // This program is distributed in the hope that it will be useful, but WITHOUT
  14. // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  15. // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  16. // more details.
  17. //
  18. // You should have received a copy of the GNU General Public License along with
  19. // this program; if not, write to the Free Software Foundation, Inc., 59 Temple
  20. // Place, Suite 330, Boston, MA 02111-1307 USA
  21. // See XMLReader.hpp for details
  22. //// XMLReader Element /////////////////////////////////////////////////////
  23. inline XMLReaderElement::XMLReaderElement(const char* Name) : // Construct with a cstring.
  24. myName(std::string(Name)),
  25. myParent(NULL),
  26. myLine(0),
  27. myIndex(0),
  28. myLength(0),
  29. myCleanFlag(true),
  30. myInitOnInterpretFlag(false),
  31. myWasProcessed(false),
  32. wasProcessed(&myWasProcessed) {
  33. }
  34. inline XMLReaderElement::XMLReaderElement(const std::string Name) : // Construct with a c++ string.
  35. myName(Name),
  36. myParent(NULL),
  37. myLine(0),
  38. myIndex(0),
  39. myLength(0),
  40. myCleanFlag(true),
  41. myInitOnInterpretFlag(false),
  42. myWasProcessed(false),
  43. wasProcessed(&myWasProcessed) {
  44. }
  45. inline XMLReaderElement::XMLReaderElement( // Construct sub element w/ cstring.
  46. const char* Name,
  47. XMLReaderElement& Parent) :
  48. myName(std::string(Name)),
  49. myParent(&Parent),
  50. myLine(0),
  51. myIndex(0),
  52. myLength(0),
  53. myCleanFlag(true),
  54. myInitOnInterpretFlag(false),
  55. myWasProcessed(false),
  56. wasProcessed(&myWasProcessed) {
  57. }
  58. inline XMLReaderElement::XMLReaderElement( // Construct sub element w/ string.
  59. const std::string Name,
  60. XMLReaderElement& Parent) :
  61. myName(Name),
  62. myParent(&Parent),
  63. myLine(0),
  64. myIndex(0),
  65. myLength(0),
  66. myCleanFlag(true),
  67. myInitOnInterpretFlag(false),
  68. myWasProcessed(false),
  69. wasProcessed(&myWasProcessed) {
  70. }
  71. inline std::string XMLReaderElement::Name() { return myName; } // Get the name of this element.
  72. inline XMLReaderElement& XMLReaderElement::Parent() { // Get the parrent of this element.
  73. if(NULL != myParent) { // If I have a parent
  74. return (*myParent); // then I dereference and return it.
  75. } // If I don't have a parent
  76. return (*this); // then I return myself.
  77. }
  78. inline XMLReaderElement& XMLReaderElement::Parent( // Set the parrent of this element.
  79. XMLReaderElement& Parent) { // Given this parent
  80. myParent = &Parent; // I take and store it's address
  81. return (*myParent); // then dereference and return it.
  82. }
  83. inline int XMLReaderElement::Line() { return myLine; } // Get the last line number.
  84. inline int XMLReaderElement::Index() { return myIndex; } // Get the last data position.
  85. inline int XMLReaderElement::Length() { return myLength; } // Get the last length.
  86. inline void XMLReaderElement::notifyDirty() { myCleanFlag = false; } // Attributes do this when they change.
  87. inline XMLReaderElement& XMLReaderElement::Element(const char* Name) { // Add a new sub element by c string name.
  88. return Element(std::string(Name)); // Use the string name version
  89. }
  90. inline XMLReaderElement& XMLReaderElement::Element(const std::string Name) { // Add a new sub element by c++ string name.
  91. XMLReaderElement* N = new XMLReaderElement( // Create a new Element with the
  92. Name, // name provided and
  93. (*this)); // myself as the parent.
  94. myElements.push_back(N); // Add it to the list.
  95. return (*N); // Return the new element.
  96. }
  97. inline XMLReaderElement& XMLReaderElement::Element( // Mapping factory for convenience,
  98. const char* Name, // requires a name, of course,
  99. XMLReaderTranslator& newTranslator) { // Add a Translator to this element.
  100. return Element(std::string(Name), newTranslator); // Use the string name version
  101. }
  102. inline XMLReaderElement& XMLReaderElement::Element( // Mapping factory for convenience,
  103. const char* Name, // requires a name, of course,
  104. std::string& x, std::string init) { // Map to a string.
  105. return Element(std::string(Name), x, init); // Use the string name version
  106. }
  107. inline XMLReaderElement& XMLReaderElement::Element( // Mapping factory for convenience,
  108. const char* Name, // requires a name, of course,
  109. int& x, int init, int radix) { // Map to an int.
  110. return Element(std::string(Name), x, init, radix); // Use the string name version
  111. }
  112. inline XMLReaderElement& XMLReaderElement::Element( // Mapping factory for convenience,
  113. const char* Name, // requires a name, of course,
  114. double& x, double init) { // Map to a double.
  115. return Element(std::string(Name), x, init); // Use the string name version
  116. }
  117. inline XMLReaderElement& XMLReaderElement::Element( // Mapping factory for convenience,
  118. const char* Name, // requires a name, of course,
  119. bool& x, bool init) { // Map to a boolean.
  120. return Element(std::string(Name), x, init); // Use the string name version
  121. }
  122. inline XMLReaderElement& XMLReaderElement::indicator(bool& x) {
  123. wasProcessed = &x;
  124. return *this;
  125. }
  126. inline XMLReaderElement& XMLReaderElement::End() { // Return this element's parent.
  127. return Parent(); // Borrow Parent()
  128. }
  129. inline XMLReaderElement& XMLReaderElement::End(const char* Name) { // Check the name and return the parent
  130. return End(std::string(Name)); // Borrow End(string)
  131. }
  132. inline XMLReaderElement& XMLReaderElement::End(const std::string Name) { // if the name is correct - or throw!
  133. if(0 != Name.compare(myName)) { // If Name is not myName
  134. throw EndNameDoesNotMatch(); // throw an exception!
  135. } // If the names match then
  136. return Parent(); // return the parent.
  137. }
  138. inline XMLReaderAttribute& XMLReaderElement::Attribute( // Add an attribute using a cstring.
  139. const char* Name) { // Given this cstring name
  140. return Attribute(std::string(Name)); // Convert it to a string and borrow
  141. } // Attribute(string)
  142. inline XMLReaderAttribute& XMLReaderElement::Attribute( // Mapping factory for convenience,
  143. const char* Name, // requires a name, of course,
  144. XMLReaderTranslator& newTranslator) { // Add a Translator to this element.
  145. return Attribute(std::string(Name), newTranslator); // Borrow the string name version
  146. }
  147. inline XMLReaderAttribute& XMLReaderElement::Attribute( // Mapping factory for convenience,
  148. const char* Name, // requires a name, of course,
  149. std::string& x, std::string init) { // Map to a string.
  150. return Attribute(std::string(Name), x, init); // Borrow the string name version
  151. }
  152. inline XMLReaderAttribute& XMLReaderElement::Attribute( // Mapping factory for convenience,
  153. const char* Name, // requires a name, of course,
  154. int& x, int init, int radix) { // Map to an int.
  155. return Attribute(std::string(Name), x, init); // Borrow the string name version
  156. }
  157. inline XMLReaderAttribute& XMLReaderElement::Attribute( // Mapping factory for convenience,
  158. const char* Name, // requires a name, of course,
  159. double& x, double init) { // Map to a double.
  160. return Attribute(std::string(Name), x, init); // Borrow the string name version
  161. }
  162. inline XMLReaderAttribute& XMLReaderElement::Attribute( // Mapping factory for convenience,
  163. const char* Name, // requires a name, of course,
  164. bool& x, bool init) { // Map to a boolean.
  165. return Attribute(std::string(Name), x, init); // Borrow the string name version
  166. }
  167. inline XMLReaderElement& XMLReaderElement::setInitOnInterpret() { // Set the init on interpret flag.
  168. myInitOnInterpretFlag = true; // Set the flag.
  169. return(*this); // Dereference and return self.
  170. }
  171. inline XMLReaderElement& XMLReaderElement::atStartCall( // Add an atStart call-back.
  172. XMLerator& Functor) { // Given this Functor,
  173. myStartXMLerators.push_back(&Functor); // add it to my atStart list then
  174. return(*this); // dereference and return myself.
  175. }
  176. inline XMLReaderElement& XMLReaderElement::atEndCall( // Add an atEnd call-back.
  177. XMLerator& Functor) { // Given this Functor,
  178. myEndXMLerators.push_back(&Functor); // add it to my atEnd list then
  179. return(*this); // dereference and return myself.
  180. }
  181. inline XMLReaderElement& XMLReaderElement::Mnemonic( // Add a mnemonic using c strings.
  182. const char* name, const char* value) { // Given char* and char*
  183. return Mnemonic(std::string(name), std::string(value)); // make strings and borrow that method.
  184. }
  185. inline XMLReaderElement& XMLReaderElement::Mnemonic( // Add a mnemonic using mixed strings.
  186. const char* name, const std::string value) { // Given char* and string
  187. return Mnemonic(std::string(name), value); // make strings and borrow that method.
  188. }
  189. inline XMLReaderElement& XMLReaderElement::Mnemonic( // Add a mnemonic using mixed strings.
  190. const std::string name, const char* value) { // Given string and char*
  191. return Mnemonic(name, std::string(value)); // make strings and borrow that method.
  192. }
  193. inline XMLReaderElement& XMLReaderElement::Mnemonic( // Add a mnemonic using c++ strings.
  194. const std::string name, const std::string value) { // Givent string and string
  195. XMLReaderMnemonic* N = // Create a new Mnemonic
  196. new XMLReaderMnemonic(name, value); // using the values provided,
  197. myMnemonics.push_back(N); // add it to my list, then
  198. return(*this); // dereference and return myself.
  199. }
  200. //// XMLReader Attribute ///////////////////////////////////////////////////
  201. inline XMLReaderAttribute::XMLReaderAttribute( // Attributes are constructed with a
  202. const char* Name, XMLReaderElement& Parent) : // Name and a Parent.
  203. myName(std::string(Name)), // We convert the name to a string.
  204. myParent(Parent), // We just grab the parent.
  205. myLine(0), // Everything else gets zeroed.
  206. myIndex(0),
  207. myLength(0),
  208. myWasProcessed(false),
  209. wasProcessed(&myWasProcessed),
  210. attrFunc(nullptr) {
  211. }
  212. inline XMLReaderAttribute::XMLReaderAttribute( // Attributes are constrictued with a
  213. const std::string Name, XMLReaderElement& Parent) : // Name and a Parent.
  214. myName(Name), // We grab them and zero the rest.
  215. myParent(Parent),
  216. myLine(0),
  217. myIndex(0),
  218. myLength(0),
  219. myWasProcessed(false),
  220. wasProcessed(&myWasProcessed),
  221. attrFunc(nullptr) {
  222. }
  223. inline std::string XMLReaderAttribute::Name() { // Get the name of this attribute.
  224. return myName;
  225. }
  226. inline XMLReaderElement& XMLReaderAttribute::Parent() { // Get the parent of this attribute.
  227. return myParent;
  228. }
  229. inline int XMLReaderAttribute::Line() { // Get the last line number.
  230. return myLine;
  231. }
  232. inline int XMLReaderAttribute::Index() { // Get the last data position.
  233. return myIndex;
  234. }
  235. inline int XMLReaderAttribute::Length() { // Get the last length.
  236. return myLength;
  237. }
  238. inline XMLReaderElement& XMLReaderAttribute::Element( // Add a new sub element by c string name.
  239. const char* Name) {
  240. return myParent.Element(Name);
  241. }
  242. inline XMLReaderElement& XMLReaderAttribute::Element( // Add a new sub element by c++ string name.
  243. const std::string Name) {
  244. return myParent.Element(Name);
  245. }
  246. inline XMLReaderElement& XMLReaderAttribute::Element( // Mapping factory for convenience,
  247. const char* Name, // requires a name, of course,
  248. XMLReaderTranslator& newTranslator) { // Add a Translator to this element.
  249. return myParent.Element(Name, newTranslator);
  250. }
  251. inline XMLReaderElement& XMLReaderAttribute::Element( // Mapping factory for convenience,
  252. const char* Name, // requires a name, of course,
  253. std::string& x, std::string init) { // Map to a string.
  254. return myParent.Element(Name, x, init);
  255. }
  256. inline XMLReaderElement& XMLReaderAttribute::Element( // Mapping factory for convenience,
  257. const char* Name, // requires a name, of course,
  258. int& x, int init, int radix) { // Map to an int.
  259. return myParent.Element(Name, x, init, radix);
  260. }
  261. inline XMLReaderElement& XMLReaderAttribute::Element( // Mapping factory for convenience,
  262. const char* Name, // requires a name, of course,
  263. double& x, double init) { // Map to a double.
  264. return myParent.Element(Name, x, init);
  265. }
  266. inline XMLReaderElement& XMLReaderAttribute::Element( // Mapping factory for convenience,
  267. const char* Name, // requires a name, of course,
  268. bool& x, bool init) { // Map to a boolean.
  269. return myParent.Element(Name, x, init);
  270. }
  271. inline XMLReaderElement& XMLReaderAttribute::Element( // Mapping factory for convenience,
  272. const std::string Name, // requires a name, of course,
  273. XMLReaderTranslator& newTranslator) { // Add a Translator to this element.
  274. return myParent.Element(Name, newTranslator);
  275. }
  276. inline XMLReaderElement& XMLReaderAttribute::Element( // Mapping factory for convenience,
  277. const std::string Name, // requires a name, of course,
  278. std::string& x, std::string init) { // Map to a string.
  279. return myParent.Element(Name, x, init);
  280. }
  281. inline XMLReaderElement& XMLReaderAttribute::Element( // Mapping factory for convenience,
  282. const std::string Name, // requires a name, of course,
  283. int& x, int init, int radix) { // Map to an int.
  284. return myParent.Element(Name, x, init, radix);
  285. }
  286. inline XMLReaderElement& XMLReaderAttribute::Element( // Mapping factory for convenience,
  287. const std::string Name, // requires a name, of course,
  288. double& x, double init) { // Map to a double.
  289. return myParent.Element(Name, x, init);
  290. }
  291. inline XMLReaderElement& XMLReaderAttribute::Element( // Mapping factory for convenience,
  292. const std::string Name, // requires a name, of course,
  293. bool& x, bool init) { // Map to a boolean.
  294. return myParent.Element(Name, x, init);
  295. }
  296. inline XMLReaderElement& XMLReaderAttribute::End() { // Return this element's parent.
  297. return myParent.End();
  298. }
  299. inline XMLReaderElement& XMLReaderAttribute::End(const char* Name) { // Check the name and return the parent
  300. return myParent.End(Name);
  301. }
  302. inline XMLReaderElement& XMLReaderAttribute::End(const std::string Name) { // if the name is correct - or throw!
  303. return myParent.End(Name);
  304. }
  305. inline XMLReaderAttribute& XMLReaderAttribute::Attribute( // Add an attribute using a cstring.
  306. const char* Name) {
  307. return myParent.Attribute(Name);
  308. }
  309. inline XMLReaderAttribute& XMLReaderAttribute::Attribute( // Add an attribute using a c++ string.
  310. const std::string Name) {
  311. return myParent.Attribute(Name);
  312. }
  313. inline XMLReaderAttribute& XMLReaderAttribute::Attribute( // Mapping factory for convenience,
  314. const char* Name, // requires a name, of course,
  315. XMLReaderTranslator& newTranslator) { // Add a Translator to this element.
  316. return myParent.Attribute(Name, newTranslator);
  317. }
  318. inline XMLReaderAttribute& XMLReaderAttribute::Attribute( // Mapping factory for convenience,
  319. const char* Name, // requires a name, of course,
  320. std::string& x, std::string init) { // Map to a string.
  321. return myParent.Attribute(Name, x, init);
  322. }
  323. inline XMLReaderAttribute& XMLReaderAttribute::Attribute( // Mapping factory for convenience,
  324. const char* Name, // requires a name, of course,
  325. int& x, int init, int radix) { // Map to an int.
  326. return myParent.Attribute(Name, x, init, radix);
  327. }
  328. inline XMLReaderAttribute& XMLReaderAttribute::Attribute( // Mapping factory for convenience,
  329. const char* Name, // requires a name, of course,
  330. double& x, double init) { // Map to a double.
  331. return myParent.Attribute(Name, x, init);
  332. }
  333. inline XMLReaderAttribute& XMLReaderAttribute::Attribute( // Mapping factory for convenience,
  334. const char* Name, // requires a name, of course,
  335. bool& x, bool init) { // Map to a boolean.
  336. return myParent.Attribute(Name, x, init);
  337. }
  338. inline XMLReaderAttribute& XMLReaderAttribute::Attribute( // Mapping factory for convenience,
  339. const std::string Name, // requires a name, of course,
  340. XMLReaderTranslator& newTranslator) { // Add a Translator to this element.
  341. return myParent.Attribute(Name, newTranslator);
  342. }
  343. inline XMLReaderAttribute& XMLReaderAttribute::Attribute( // Mapping factory for convenience,
  344. const std::string Name, // requires a name, of course,
  345. std::string& x, std::string init) { // Map to a string.
  346. return myParent.Attribute(Name, x, init);
  347. }
  348. inline XMLReaderAttribute& XMLReaderAttribute::Attribute( // Mapping factory for convenience,
  349. const std::string Name, // requires a name, of course,
  350. int& x, int init, int radix) { // Map to an int.
  351. return myParent.Attribute(Name, x, init, radix);
  352. }
  353. inline XMLReaderAttribute& XMLReaderAttribute::Attribute( // Mapping factory for convenience,
  354. const std::string Name, // requires a name, of course,
  355. double& x, double init) { // Map to a double.
  356. return myParent.Attribute(Name, x, init);
  357. }
  358. inline XMLReaderAttribute& XMLReaderAttribute::Attribute( // Mapping factory for convenience,
  359. const std::string Name, // requires a name, of course,
  360. bool& x, bool init) { // Map to a boolean.
  361. return myParent.Attribute(Name, x, init);
  362. }
  363. inline XMLReaderAttribute& XMLReaderAttribute::indicator(bool& x) {
  364. wasProcessed = &x;
  365. return *this;
  366. }
  367. inline XMLReaderAttribute& XMLReaderAttribute::indicator(bool& x, AttributeFunctor& f) {
  368. wasProcessed = &x;
  369. attrFunc = &f;
  370. return *this;
  371. }
  372. inline XMLReaderElement& XMLReaderAttribute::setInitOnInterpret() { // Set the init on interpret flag.
  373. return myParent.setInitOnInterpret();
  374. }
  375. inline XMLReaderElement& XMLReaderAttribute::atStartCall( // Add an atStart call-back to this element.
  376. XMLerator& Functor) {
  377. return myParent.atStartCall(Functor);
  378. }
  379. inline XMLReaderElement& XMLReaderAttribute::atEndCall( // Add an atEnd call-back to this element.
  380. XMLerator& Functor) {
  381. return myParent.atEndCall(Functor);
  382. }
  383. inline XMLReaderAttribute& XMLReaderAttribute::Mnemonic( // Add a mnemonic using c strings.
  384. const char* name, const char* value) { // Given char* and char*
  385. return Mnemonic(std::string(name), std::string(value)); // make strings and borrow that method.
  386. }
  387. inline XMLReaderAttribute& XMLReaderAttribute::Mnemonic( // Add a mnemonic using mixed strings.
  388. const char* name, const std::string value) { // Given char* and string
  389. return Mnemonic(std::string(name), value); // make strings and borrow that method.
  390. }
  391. inline XMLReaderAttribute& XMLReaderAttribute::Mnemonic( // Add a mnemonic using mixed strings.
  392. const std::string name, const char* value) { // Given string and char*
  393. return Mnemonic(name, std::string(value)); // make strings and borrow that method.
  394. }
  395. inline XMLReaderAttribute& XMLReaderAttribute::Mnemonic( // Add a mnemonic using c++ strings.
  396. const std::string name, const std::string value) { // Givent string and string
  397. XMLReaderMnemonic* N = // Create a new Mnemonic
  398. new XMLReaderMnemonic(name, value); // using the values provided,
  399. myMnemonics.push_back(N); // add it to my list, then
  400. return(*this); // dereference and return myself.
  401. }
  402. //// XMLReader Data ////////////////////////////////////////////////////////
  403. inline char XMLReaderData::Data(int Index) { // Returns char from Data[Index]
  404. if(0 > Index || Index >= myBufferSize) { // Check that index is in range
  405. return 0; // and return 0 if it is not.
  406. } // If Index is within range then
  407. return myDataBuffer[Index]; // return the byte requested.
  408. }
  409. inline int XMLReaderData::Index() { // Reads the current Index.
  410. return myIndex;
  411. }
  412. inline int XMLReaderData::Index(int i) { // Changes the current Index.
  413. if(0 > i || i >= myBufferSize) { // If i is out of range then
  414. return myIndex; // return the current Index unchanged.
  415. } // If i is within range then
  416. myIndex = i; // change the Index to i and
  417. return myIndex; // return the changed Index.
  418. }
  419. inline int XMLReaderData::Line() { // Reads the current Line number.
  420. return myLine;
  421. }
  422. inline int XMLReaderData::addNewLines(int Count) { // Increments the Line number.
  423. myLine += Count; // Add the number of new lines.
  424. return myLine; // Return the current Line number.
  425. }
  426. //// XMLReader Translator //////////////////////////////////////////////////
  427. inline StringTranslator::StringTranslator( // Construct this with
  428. std::string& Variable, // the variable to map,
  429. std::string Initializer) : // and the default value.
  430. myVariable(Variable),
  431. myInitializer(Initializer) {
  432. }
  433. inline void StringTranslator::translate(const char* Value) { // Provide a translation method.
  434. myVariable = std::string(Value); // String to String = simple copy.
  435. }
  436. inline void StringTranslator::initialize() { // Provide an initialization method.
  437. myVariable = myInitializer; // Revert to the initializer value.
  438. }
  439. inline IntegerTranslator::IntegerTranslator( // Construct this with
  440. int& Variable, // the variable to map,
  441. int Initializer, // and the default value.
  442. int Radix) : // For this one we also need a Radix.
  443. myVariable(Variable),
  444. myInitializer(Initializer),
  445. myRadix(Radix) {
  446. }
  447. inline void IntegerTranslator::translate(const char* Value) { // Provide a translation method.
  448. char* dummy; // Throw away ptr for strtol().
  449. myVariable = strtol(Value, &dummy, myRadix); // Convert the string w/ strtol().
  450. }
  451. inline void IntegerTranslator::initialize() { // Provide an initialization method.
  452. myVariable = myInitializer; // Revert to the initializer value.
  453. }
  454. inline DoubleTranslator::DoubleTranslator( // Construct this with
  455. double& Variable, // the variable to map,
  456. double Initializer) : // and the default value.
  457. myVariable(Variable),
  458. myInitializer(Initializer) {
  459. }
  460. inline void DoubleTranslator::translate(const char* Value) { // Provide a translation method.
  461. char* dummy; // Throw away ptr for strtod().
  462. myVariable = strtod(Value, &dummy); // Convert the string w/ strtod().
  463. }
  464. inline void DoubleTranslator::initialize() { // Provide an initialization method.
  465. myVariable = myInitializer; // Revert to the initializer value.
  466. }
  467. inline BoolTranslator::BoolTranslator( // Construct this with
  468. bool& Variable, // the variable to map,
  469. bool Initializer) : // and the default value.
  470. myVariable(Variable),
  471. myInitializer(Initializer) {
  472. }
  473. inline void BoolTranslator::translate(const char* Value) { // Provide a translation method.
  474. if(
  475. (0 == strcmp(Value,"on")) ||
  476. (0 == strcmp(Value,"true")) || // on, true, yes, and 1 are
  477. (0 == strcmp(Value, "yes")) || // interpreted as a boolean true.
  478. (0 == strcmp(Value, "1"))
  479. ) {
  480. myVariable = true;
  481. } else { // Anything else is interpreted as
  482. myVariable = false; // boolean false.
  483. }
  484. }
  485. inline void BoolTranslator::initialize() { // Provide an initialization method.
  486. myVariable = myInitializer; // Revert to the initializer value.
  487. }
  488. inline void RawTranslator::setRawDataAssignment(std::string &RawData) {
  489. RawDataAssignment = &RawData;
  490. }
  491. inline void RawTranslator::setIndexAssignment(int &Index, int &Endex) {
  492. IndexAssignment = &Index;
  493. EndexAssignment = &Endex;
  494. }
  495. inline void RawTranslator::translate(int Index, int Endex, XMLReaderData &Data) {
  496. if (0 != RawDataAssignment) *RawDataAssignment = Data.extract(Index, Endex);
  497. if (0 != IndexAssignment) *IndexAssignment = Index;
  498. if (0 != EndexAssignment) *EndexAssignment = Endex;
  499. }
  500. //// XMLReader Mnemonic ////////////////////////////////////////////////////
  501. inline XMLReaderMnemonic::XMLReaderMnemonic( // To make one, provide both parts.
  502. std::string Name, std::string Value) :
  503. myName(Name),
  504. myValue(Value) {
  505. }
  506. inline bool XMLReaderMnemonic::test(std::string Name) { // Test to see if this Mnemonic matches.
  507. return (0 == Name.compare(myName)); // Return true if Name and myName match.
  508. }
  509. inline std::string XMLReaderMnemonic::Value() { // If it does then we will need it's value.
  510. return myValue;
  511. }