Selaa lähdekoodia

Implemented XMLReaderElement::indicator() and

XMLReaderAttribute::indicator().


git-svn-id: https://svn.microneil.com/svn/CodeDweller/branches/adeniz_1@105 d34b734f-a00e-4b39-a726-e4eeb87269ab
adeniz_1
adeniz 8 vuotta sitten
vanhempi
commit
9f230f4e5d
3 muutettua tiedostoa jossa 76 lisäystä ja 7 poistoa
  1. 9
    1
      XMLReader.cpp
  2. 31
    0
      XMLReader.hpp
  3. 36
    6
      XMLReader.inline.hpp

+ 9
- 1
XMLReader.cpp Näytä tiedosto

@@ -21,6 +21,9 @@

// See XMLReader.hpp for details

//debug
#include <iostream>
//end of debug
#include "CodeDweller/XMLReader.hpp"

using namespace std;
@@ -653,6 +656,8 @@ void XMLReaderElement::initialize() {
myIndex = 0; // no interpet() call has been made.
myLength = 0;

*wasProcessed = false;

// At this point we know we are clean

myCleanFlag = true; // Clean as a whistle!
@@ -678,7 +683,6 @@ void XMLReaderElement::runEndXMLerators(XMLReaderData& D) {
}

bool XMLReaderElement::interpret(XMLReaderData& Data) { // (re) Interpret this data.

int Index = Data.Index(); // Our working index.
int Startdex = 0; // Where our data starts.
int Stopdex = 0; // Where our data stops.
@@ -806,6 +810,7 @@ bool XMLReaderElement::interpret(XMLReaderData& Data) {
myEndex = Data.Index() - 1;
myRawTranslator.translate(myIndex, myEndex, Data);
runEndXMLerators(Data); // run the End XMLerators and return
*wasProcessed = true;
return true; // true to the caller.
}

@@ -964,6 +969,7 @@ bool XMLReaderElement::interpret(XMLReaderData& Data) {

myRawTranslator.translate(myIndex, myEndex, Data);
runEndXMLerators(Data); // Launch the End XMLerators.
*wasProcessed = true;
return true; // Return our success!
}

@@ -1061,6 +1067,7 @@ void XMLReaderAttribute::initialize() {
myLine = 0; // Initialized means to be as if
myIndex = 0; // no interpet() call has been made.
myLength = 0;
*wasProcessed = false;
}

bool XMLReaderAttribute::interpret(XMLReaderData& Data) { // (re) Interpret this data.
@@ -1165,6 +1172,7 @@ bool XMLReaderAttribute::interpret(XMLReaderData& Data) {

Data.Index(Stopdex + 1); // Move the Index.
Data.addNewLines(NewLines); // Update the Line Number.
*wasProcessed = true;

return true; // If we got here, we succeeded!
}

+ 31
- 0
XMLReader.hpp Näytä tiedosto

@@ -183,6 +183,9 @@ class XMLReaderElement {

bool myInitOnInterpretFlag; // Initialize() at each Interpret()?

bool myWasProcessed; // true iff the element was processed.
bool *wasProcessed; // Points to caller's variable.

void runStartXMLerators(XMLReaderData& D); // Does what it says ;-)
void runEndXMLerators(XMLReaderData& D); // Does what it says ;-)

@@ -281,6 +284,8 @@ class XMLReaderElement {
XMLReaderElement& RawIndex( // Copy indices of the entire
int &Index, int &Endex); // element.

XMLReaderElement& indicator(bool& x); // Set x to true iff element is found.

// End methods for heading back up the tree at the end of an element.

class EndNameDoesNotMatch {}; // Throw when End(name) doesn't match.
@@ -407,6 +412,23 @@ class XMLReaderElement {

};

//// Function object to call after /////////////////////////////////////////////////////
//
// Elements make up the core of a configuration. That is, a configuration is a
// tree of elements. Elements translate directly to well formed xml elements in
// a configuration file or string.

//// Attribute Functor //////////////////////////////////////////////////////////////
//
// This functor is passed to XMLReaderAttribute::indicator() as an
// optional parameter, and is called if the attribute is processed.

class AttributeFunctor {
public:
virtual void operator()(XMLReaderAttribute& A, XMLReaderData& D) = 0;
virtual ~AttributeFunctor() {}
};

//// XMLReader Attribute ///////////////////////////////////////////////////
//
// Attributes translate directly to well formed xml attributes (within the
@@ -426,6 +448,11 @@ class XMLReaderAttribute {
int myIndex; // Last char position I was seen on.
int myLength; // Last segment length.

bool myWasProcessed; // true iff the attribute was processed.
bool *wasProcessed; // Points to caller's variable.

AttributeFunctor *attrFunc; // Call if attribute was processed.

public:

XMLReaderAttribute(const char* Name, XMLReaderElement& Parent); // Sub-elements are constructed with a
@@ -563,6 +590,10 @@ class XMLReaderAttribute {
const std::string Name, // requires a name, of course,
bool& x, bool init = false); // Map to a boolean.

XMLReaderAttribute& indicator(bool& x); // Set x to true iff attribute is found.
XMLReaderAttribute& indicator(bool& x, AttributeFunctor &f); // Set x to true and invoke f() iff
// attribute is found.

//// Set Init On Interprete for the parent element.

XMLReaderElement& setInitOnInterpret(); // Set the init on interpret flag.

+ 36
- 6
XMLReader.inline.hpp Näytä tiedosto

@@ -30,7 +30,9 @@ inline XMLReaderElement::XMLReaderElement(const char* Name) :
myIndex(0),
myLength(0),
myCleanFlag(true),
myInitOnInterpretFlag(false) {
myInitOnInterpretFlag(false),
myWasProcessed(false),
wasProcessed(&myWasProcessed) {
}

inline XMLReaderElement::XMLReaderElement(const std::string Name) : // Construct with a c++ string.
@@ -40,7 +42,9 @@ inline XMLReaderElement::XMLReaderElement(const std::string Name) :
myIndex(0),
myLength(0),
myCleanFlag(true),
myInitOnInterpretFlag(false) {
myInitOnInterpretFlag(false),
myWasProcessed(false),
wasProcessed(&myWasProcessed) {
}

inline XMLReaderElement::XMLReaderElement( // Construct sub element w/ cstring.
@@ -53,7 +57,9 @@ inline XMLReaderElement::XMLReaderElement(
myIndex(0),
myLength(0),
myCleanFlag(true),
myInitOnInterpretFlag(false) {
myInitOnInterpretFlag(false),
myWasProcessed(false),
wasProcessed(&myWasProcessed) {
}

inline XMLReaderElement::XMLReaderElement( // Construct sub element w/ string.
@@ -66,7 +72,9 @@ inline XMLReaderElement::XMLReaderElement(
myIndex(0),
myLength(0),
myCleanFlag(true),
myInitOnInterpretFlag(false) {
myInitOnInterpretFlag(false),
myWasProcessed(false),
wasProcessed(&myWasProcessed) {
}

inline std::string XMLReaderElement::Name() { return myName; } // Get the name of this element.
@@ -135,6 +143,11 @@ inline XMLReaderElement& XMLReaderElement::Element(
return Element(std::string(Name), x, init); // Use the string name version
}

inline XMLReaderElement& XMLReaderElement::indicator(bool& x) {
wasProcessed = &x;
return *this;
}

inline XMLReaderElement& XMLReaderElement::End() { // Return this element's parent.
return Parent(); // Borrow Parent()
}
@@ -233,7 +246,10 @@ inline XMLReaderAttribute::XMLReaderAttribute(
myParent(Parent), // We just grab the parent.
myLine(0), // Everything else gets zeroed.
myIndex(0),
myLength(0) {
myLength(0),
myWasProcessed(false),
wasProcessed(&myWasProcessed),
attrFunc(nullptr) {
}

inline XMLReaderAttribute::XMLReaderAttribute( // Attributes are constrictued with a
@@ -242,7 +258,10 @@ inline XMLReaderAttribute::XMLReaderAttribute(
myParent(Parent),
myLine(0),
myIndex(0),
myLength(0) {
myLength(0),
myWasProcessed(false),
wasProcessed(&myWasProcessed),
attrFunc(nullptr) {
}

inline std::string XMLReaderAttribute::Name() { // Get the name of this attribute.
@@ -417,6 +436,17 @@ inline XMLReaderAttribute& XMLReaderAttribute::Attribute(
return myParent.Attribute(Name, x, init);
}

inline XMLReaderAttribute& XMLReaderAttribute::indicator(bool& x) {
wasProcessed = &x;
return *this;
}

inline XMLReaderAttribute& XMLReaderAttribute::indicator(bool& x, AttributeFunctor& f) {
wasProcessed = &x;
attrFunc = &f;
return *this;
}

inline XMLReaderElement& XMLReaderAttribute::setInitOnInterpret() { // Set the init on interpret flag.
return myParent.setInitOnInterpret();
}

Loading…
Peruuta
Tallenna