Browse Source

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 9 years ago
parent
commit
9f230f4e5d
3 changed files with 76 additions and 7 deletions
  1. 9
    1
      XMLReader.cpp
  2. 31
    0
      XMLReader.hpp
  3. 36
    6
      XMLReader.inline.hpp

+ 9
- 1
XMLReader.cpp View File



// See XMLReader.hpp for details // See XMLReader.hpp for details


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


using namespace std; using namespace std;
myIndex = 0; // no interpet() call has been made. myIndex = 0; // no interpet() call has been made.
myLength = 0; myLength = 0;


*wasProcessed = false;

// At this point we know we are clean // At this point we know we are clean


myCleanFlag = true; // Clean as a whistle! myCleanFlag = true; // Clean as a whistle!
} }


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

int Index = Data.Index(); // Our working index. int Index = Data.Index(); // Our working index.
int Startdex = 0; // Where our data starts. int Startdex = 0; // Where our data starts.
int Stopdex = 0; // Where our data stops. int Stopdex = 0; // Where our data stops.
myEndex = Data.Index() - 1; myEndex = Data.Index() - 1;
myRawTranslator.translate(myIndex, myEndex, Data); myRawTranslator.translate(myIndex, myEndex, Data);
runEndXMLerators(Data); // run the End XMLerators and return runEndXMLerators(Data); // run the End XMLerators and return
*wasProcessed = true;
return true; // true to the caller. return true; // true to the caller.
} }




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


myLine = 0; // Initialized means to be as if myLine = 0; // Initialized means to be as if
myIndex = 0; // no interpet() call has been made. myIndex = 0; // no interpet() call has been made.
myLength = 0; myLength = 0;
*wasProcessed = false;
} }


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


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


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

+ 31
- 0
XMLReader.hpp View File



bool myInitOnInterpretFlag; // Initialize() at each Interpret()? 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 runStartXMLerators(XMLReaderData& D); // Does what it says ;-)
void runEndXMLerators(XMLReaderData& D); // Does what it says ;-) void runEndXMLerators(XMLReaderData& D); // Does what it says ;-)


XMLReaderElement& RawIndex( // Copy indices of the entire XMLReaderElement& RawIndex( // Copy indices of the entire
int &Index, int &Endex); // element. 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. // End methods for heading back up the tree at the end of an element.


class EndNameDoesNotMatch {}; // Throw when End(name) doesn't match. class EndNameDoesNotMatch {}; // Throw when End(name) doesn't match.


}; };


//// 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 /////////////////////////////////////////////////// //// XMLReader Attribute ///////////////////////////////////////////////////
// //
// Attributes translate directly to well formed xml attributes (within the // Attributes translate directly to well formed xml attributes (within the
int myIndex; // Last char position I was seen on. int myIndex; // Last char position I was seen on.
int myLength; // Last segment length. 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: public:


XMLReaderAttribute(const char* Name, XMLReaderElement& Parent); // Sub-elements are constructed with a XMLReaderAttribute(const char* Name, XMLReaderElement& Parent); // Sub-elements are constructed with a
const std::string Name, // requires a name, of course, const std::string Name, // requires a name, of course,
bool& x, bool init = false); // Map to a boolean. 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. //// Set Init On Interprete for the parent element.


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

+ 36
- 6
XMLReader.inline.hpp View File

myIndex(0), myIndex(0),
myLength(0), myLength(0),
myCleanFlag(true), myCleanFlag(true),
myInitOnInterpretFlag(false) {
myInitOnInterpretFlag(false),
myWasProcessed(false),
wasProcessed(&myWasProcessed) {
} }


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


inline XMLReaderElement::XMLReaderElement( // Construct sub element w/ cstring. inline XMLReaderElement::XMLReaderElement( // Construct sub element w/ cstring.
myIndex(0), myIndex(0),
myLength(0), myLength(0),
myCleanFlag(true), myCleanFlag(true),
myInitOnInterpretFlag(false) {
myInitOnInterpretFlag(false),
myWasProcessed(false),
wasProcessed(&myWasProcessed) {
} }


inline XMLReaderElement::XMLReaderElement( // Construct sub element w/ string. inline XMLReaderElement::XMLReaderElement( // Construct sub element w/ string.
myIndex(0), myIndex(0),
myLength(0), myLength(0),
myCleanFlag(true), myCleanFlag(true),
myInitOnInterpretFlag(false) {
myInitOnInterpretFlag(false),
myWasProcessed(false),
wasProcessed(&myWasProcessed) {
} }


inline std::string XMLReaderElement::Name() { return myName; } // Get the name of this element. inline std::string XMLReaderElement::Name() { return myName; } // Get the name of this element.
return Element(std::string(Name), x, init); // Use the string name version 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. inline XMLReaderElement& XMLReaderElement::End() { // Return this element's parent.
return Parent(); // Borrow Parent() return Parent(); // Borrow Parent()
} }
myParent(Parent), // We just grab the parent. myParent(Parent), // We just grab the parent.
myLine(0), // Everything else gets zeroed. myLine(0), // Everything else gets zeroed.
myIndex(0), myIndex(0),
myLength(0) {
myLength(0),
myWasProcessed(false),
wasProcessed(&myWasProcessed),
attrFunc(nullptr) {
} }


inline XMLReaderAttribute::XMLReaderAttribute( // Attributes are constrictued with a inline XMLReaderAttribute::XMLReaderAttribute( // Attributes are constrictued with a
myParent(Parent), myParent(Parent),
myLine(0), myLine(0),
myIndex(0), myIndex(0),
myLength(0) {
myLength(0),
myWasProcessed(false),
wasProcessed(&myWasProcessed),
attrFunc(nullptr) {
} }


inline std::string XMLReaderAttribute::Name() { // Get the name of this attribute. inline std::string XMLReaderAttribute::Name() { // Get the name of this attribute.
return myParent.Attribute(Name, x, init); 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. inline XMLReaderElement& XMLReaderAttribute::setInitOnInterpret() { // Set the init on interpret flag.
return myParent.setInitOnInterpret(); return myParent.setInitOnInterpret();
} }

Loading…
Cancel
Save