git-svn-id: https://svn.microneil.com/svn/CodeDweller/branches/adeniz_1@68 d34b734f-a00e-4b39-a726-e4eeb87269abadeniz_1
return(*this); // then dereference and return myself. | return(*this); // then dereference and return myself. | ||||
} | } | ||||
ConfigurationElement& ConfigurationElement::RawData(std::string &RawData) { | |||||
myRawTranslator.setRawDataAssignment(RawData); | |||||
return(*this); | |||||
} | |||||
ConfigurationElement& ConfigurationElement::RawIndex(int &Index, int &Endex) { | |||||
myRawTranslator.setIndexAssignment(Index, Endex); | |||||
return(*this); | |||||
} | |||||
void ConfigurationElement::initialize() { // Reset all translators to defaults. | void ConfigurationElement::initialize() { // Reset all translators to defaults. | ||||
// Initialize the elements below me | // Initialize the elements below me | ||||
++Index; // past it and scan for our name. | ++Index; // past it and scan for our name. | ||||
} | } | ||||
startOfElementIndex = Data.Index(); // AVD | |||||
for(unsigned int I = 0; I < myName.length(); I++) { // For the length of our name, | for(unsigned int I = 0; I < myName.length(); I++) { // For the length of our name, | ||||
char x = Data.Data(Index + I); // get each corresponding Data byte | char x = Data.Data(Index + I); // get each corresponding Data byte | ||||
if(x != myName.at(I)) { // check it sudden death style. | if(x != myName.at(I)) { // check it sudden death style. | ||||
// may have contained, and we are syncrhonized with Data. | // may have contained, and we are syncrhonized with Data. | ||||
if(ThisIsAnEmptyElement) { // If the element was self closing then | if(ThisIsAnEmptyElement) { // If the element was self closing then | ||||
myEndex = Data.Index() - 1; | |||||
myRawTranslator.translate(myIndex, myEndex, Data); | |||||
runEndConfigurators(Data); // run the End Configurators and return | runEndConfigurators(Data); // run the End Configurators and return | ||||
return true; // true to the caller. | return true; // true to the caller. | ||||
} | } | ||||
} | } | ||||
// And finally, after all is done successfully... | // And finally, after all is done successfully... | ||||
myEndex = Data.Index() - 1; | |||||
myRawTranslator.translate(myIndex, myEndex, Data); | |||||
runEndConfigurators(Data); // Launch the End Configurators. | runEndConfigurators(Data); // Launch the End Configurators. | ||||
return true; // Return our success! | return true; // Return our success! | ||||
} | } | ||||
myLine = 0; | myLine = 0; | ||||
} | } | ||||
std::string ConfigurationData::extract(int Index, int Endex) const { | |||||
int Start = Index, End = Endex; | |||||
if (0 == myBufferSize) return std::string(""); | |||||
if (Start < 0) Start = 0; | |||||
if (Start >= myBufferSize) Start = myBufferSize - 1; | |||||
if (Start > End) End = Start; | |||||
if (End >= myBufferSize) End = myBufferSize - 1; | |||||
return std::string(myDataBuffer, Start, End - Start + 1); | |||||
} | |||||
//// Utilities ///////////////////////////////////////////////////////////////// | //// Utilities ///////////////////////////////////////////////////////////////// | ||||
// SetTrueOnComplete Configurator ////////////////////////////////////////////// | // SetTrueOnComplete Configurator ////////////////////////////////////////////// |
class ConfigurationMnemonic; // Mnemonics exist | class ConfigurationMnemonic; // Mnemonics exist | ||||
class Configurator; // Configurators exist | class Configurator; // Configurators exist | ||||
class RawTranslator { | |||||
private: | |||||
int *IndexAssignment = 0; | |||||
int *EndexAssignment = 0; | |||||
std::string *RawDataAssignment = 0; | |||||
public: | |||||
void setRawDataAssignment(std::string &RawData); | |||||
void setIndexAssignment(int &Index, int &Endex); | |||||
void translate(int Index, int Endex, ConfigurationData &Data); | |||||
}; | |||||
//// Configuration Element ///////////////////////////////////////////////////// | //// Configuration Element ///////////////////////////////////////////////////// | ||||
// | // | ||||
// Elements make up the core of a configuration. That is, a configuration is a | // Elements make up the core of a configuration. That is, a configuration is a | ||||
std::list<ConfigurationMnemonic*> myMnemonics; // They may have a list of mnemonics. | std::list<ConfigurationMnemonic*> myMnemonics; // They may have a list of mnemonics. | ||||
std::list<ConfigurationTranslator*> myTranslators; // They may have a list of translators. | std::list<ConfigurationTranslator*> myTranslators; // They may have a list of translators. | ||||
RawTranslator myRawTranslator; // Provides entire element. | |||||
// During Interpret() operations we keep track of where we are seen... | // During Interpret() operations we keep track of where we are seen... | ||||
int myLine; // Last line number I was seen on. | int myLine; // Last line number I was seen on. | ||||
int myIndex; // Last char position I was seen on. | int myIndex; // Last char position I was seen on. | ||||
int myEndex; // Last char of element. | |||||
int myLength; // Last segment length. | int myLength; // Last segment length. | ||||
bool myCleanFlag; // Keep track of initialization. | bool myCleanFlag; // Keep track of initialization. | ||||
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. | ||||
ConfigurationElement& RawData( // Copy entire element to | |||||
std::string &Element); // a string. | |||||
ConfigurationElement& RawIndex( // Copy indices of the entire | |||||
int &Index, int &Endex); // element. | |||||
// 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. | ||||
bool interpret(ConfigurationData& Data); // (re) Interpret this data. | bool interpret(ConfigurationData& Data); // (re) Interpret this data. | ||||
int startOfElementIndex; // AVD | |||||
}; | }; | ||||
//// Configuration Attribute /////////////////////////////////////////////////// | //// Configuration Attribute /////////////////////////////////////////////////// | ||||
int Index(int i); // Changes the current Index. | int Index(int i); // Changes the current Index. | ||||
int Line(); // Reads the current Line number. | int Line(); // Reads the current Line number. | ||||
int addNewLines(int Count); // Increments the Line number. | int addNewLines(int Count); // Increments the Line number. | ||||
char const *Buffer() const { return myDataBuffer; } // AVD | |||||
std::string extract(int Index, int Endex) const ; // Return substring of buffer. | |||||
std::stringstream Log; // Convenient Interpret log. | std::stringstream Log; // Convenient Interpret log. | ||||
myVariable = myInitializer; // Revert to the initializer value. | myVariable = myInitializer; // Revert to the initializer value. | ||||
} | } | ||||
inline void RawTranslator::setRawDataAssignment(std::string &RawData) { | |||||
RawDataAssignment = &RawData; | |||||
} | |||||
inline void RawTranslator::setIndexAssignment(int &Index, int &Endex) { | |||||
IndexAssignment = &Index; | |||||
EndexAssignment = &Endex; | |||||
} | |||||
inline void RawTranslator::translate(int Index, int Endex, ConfigurationData &Data) { | |||||
if (0 != RawDataAssignment) *RawDataAssignment = Data.extract(Index, Endex); | |||||
if (0 != IndexAssignment) *IndexAssignment = Index; | |||||
if (0 != EndexAssignment) *EndexAssignment = Endex; | |||||
} | |||||
//// Configuration Mnemonic //////////////////////////////////////////////////// | //// Configuration Mnemonic //////////////////////////////////////////////////// | ||||
inline ConfigurationMnemonic::ConfigurationMnemonic( // To make one, provide both parts. | inline ConfigurationMnemonic::ConfigurationMnemonic( // To make one, provide both parts. |