Browse Source

cleaned up namespace & inline in configuration

master
Pete McNeil 4 years ago
parent
commit
a2632c78e3
3 changed files with 684 additions and 713 deletions
  1. 600
    45
      configuration.cpp
  2. 84
    92
      configuration.hpp
  3. 0
    576
      configuration.inline.hpp

+ 600
- 45
configuration.cpp View File

@@ -23,7 +23,561 @@

#include "configuration.hpp"

using namespace std;
namespace codedweller {

//// Configuration Element /////////////////////////////////////////////////////

ConfigurationElement::ConfigurationElement(const char* Name) : // Construct with a cstring.
myName(std::string(Name)),
myParent(NULL),
myLine(0),
myIndex(0),
myLength(0),
myCleanFlag(true),
myInitOnInterpretFlag(false) {
}

ConfigurationElement::ConfigurationElement(const std::string Name) : // Construct with a c++ string.
myName(Name),
myParent(NULL),
myLine(0),
myIndex(0),
myLength(0),
myCleanFlag(true),
myInitOnInterpretFlag(false) {
}

ConfigurationElement::ConfigurationElement( // Construct sub element w/ cstring.
const char* Name,
ConfigurationElement& Parent) :

myName(std::string(Name)),
myParent(&Parent),
myLine(0),
myIndex(0),
myLength(0),
myCleanFlag(true),
myInitOnInterpretFlag(false) {
}

ConfigurationElement::ConfigurationElement( // Construct sub element w/ string.
const std::string Name,
ConfigurationElement& Parent) :

myName(Name),
myParent(&Parent),
myLine(0),
myIndex(0),
myLength(0),
myCleanFlag(true),
myInitOnInterpretFlag(false) {
}

std::string ConfigurationElement::Name() { return myName; } // Get the name of this element.

ConfigurationElement& ConfigurationElement::Parent() { // Get the parrent of this element.
if(NULL != myParent) { // If I have a parent
return (*myParent); // then I dereference and return it.
} // If I don't have a parent
return (*this); // then I return myself.
}

ConfigurationElement& ConfigurationElement::Parent( // Set the parrent of this element.
ConfigurationElement& Parent) { // Given this parent
myParent = &Parent; // I take and store it's address
return (*myParent); // then dereference and return it.
}

int ConfigurationElement::Line() { return myLine; } // Get the last line number.

int ConfigurationElement::Index() { return myIndex; } // Get the last data position.

int ConfigurationElement::Length() { return myLength; } // Get the last length.

void ConfigurationElement::notifyDirty() { myCleanFlag = false; } // Attributes do this when they change.

ConfigurationElement& ConfigurationElement::Element(const char* Name) { // Add a new sub element by c string name.
return Element(std::string(Name)); // Use the string name version
}

ConfigurationElement& ConfigurationElement::Element(const std::string Name) { // Add a new sub element by c++ string name.
ConfigurationElement* N = new ConfigurationElement( // Create a new Element with the
Name, // name provided and
(*this)); // myself as the parent.

myElements.push_back(N); // Add it to the list.
return (*N); // Return the new element.
}

ConfigurationElement& ConfigurationElement::Element( // Mapping factory for convenience,
const char* Name, // requires a name, of course,
ConfigurationTranslator& newTranslator) { // Add a Translator to this element.
return Element(std::string(Name), newTranslator); // Use the string name version
}

ConfigurationElement& ConfigurationElement::Element( // Mapping factory for convenience,
const char* Name, // requires a name, of course,
std::string& x, std::string init) { // Map to a string.
return Element(std::string(Name), x, init); // Use the string name version
}

ConfigurationElement& ConfigurationElement::Element( // Mapping factory for convenience,
const char* Name, // requires a name, of course,
int& x, int init, int radix) { // Map to an int.
return Element(std::string(Name), x, init, radix); // Use the string name version
}

ConfigurationElement& ConfigurationElement::Element( // Mapping factory for convenience,
const char* Name, // requires a name, of course,
double& x, double init) { // Map to a double.
return Element(std::string(Name), x, init); // Use the string name version
}

ConfigurationElement& ConfigurationElement::Element( // Mapping factory for convenience,
const char* Name, // requires a name, of course,
bool& x, bool init) { // Map to a boolean.
return Element(std::string(Name), x, init); // Use the string name version
}

ConfigurationElement& ConfigurationElement::End() { // Return this element's parent.
return Parent(); // Borrow Parent()
}

ConfigurationElement& ConfigurationElement::End(const char* Name) { // Check the name and return the parent
return End(std::string(Name)); // Borrow End(string)
}

ConfigurationElement& ConfigurationElement::End(const std::string Name) { // if the name is correct - or throw!
if(0 != Name.compare(myName)) { // If Name is not myName
throw EndNameDoesNotMatch(); // throw an exception!
} // If the names match then
return Parent(); // return the parent.
}

ConfigurationAttribute& ConfigurationElement::Attribute( // Add an attribute using a cstring.
const char* Name) { // Given this cstring name
return Attribute(std::string(Name)); // Convert it to a string and borrow
} // Attribute(string)

ConfigurationAttribute& ConfigurationElement::Attribute( // Mapping factory for convenience,
const char* Name, // requires a name, of course,
ConfigurationTranslator& newTranslator) { // Add a Translator to this element.
return Attribute(std::string(Name), newTranslator); // Borrow the string name version
}

ConfigurationAttribute& ConfigurationElement::Attribute( // Mapping factory for convenience,
const char* Name, // requires a name, of course,
std::string& x, std::string init) { // Map to a string.
return Attribute(std::string(Name), x, init); // Borrow the string name version
}

ConfigurationAttribute& ConfigurationElement::Attribute( // Mapping factory for convenience,
const char* Name, // requires a name, of course,
int& x, int init, int radix) { // Map to an int.
return Attribute(std::string(Name), x, init); // Borrow the string name version
}

ConfigurationAttribute& ConfigurationElement::Attribute( // Mapping factory for convenience,
const char* Name, // requires a name, of course,
double& x, double init) { // Map to a double.
return Attribute(std::string(Name), x, init); // Borrow the string name version
}

ConfigurationAttribute& ConfigurationElement::Attribute( // Mapping factory for convenience,
const char* Name, // requires a name, of course,
bool& x, bool init) { // Map to a boolean.
return Attribute(std::string(Name), x, init); // Borrow the string name version
}

ConfigurationElement& ConfigurationElement::setInitOnInterpret() { // Set the init on interpret flag.
myInitOnInterpretFlag = true; // Set the flag.
return(*this); // Dereference and return self.
}

ConfigurationElement& ConfigurationElement::atStartCall( // Add an atStart call-back.
Configurator& Functor) { // Given this Functor,
myStartConfigurators.push_back(&Functor); // add it to my atStart list then
return(*this); // dereference and return myself.
}

ConfigurationElement& ConfigurationElement::atEndCall( // Add an atEnd call-back.
Configurator& Functor) { // Given this Functor,
myEndConfigurators.push_back(&Functor); // add it to my atEnd list then
return(*this); // dereference and return myself.
}

ConfigurationElement& ConfigurationElement::Mnemonic( // Add a mnemonic using c strings.
const char* name, const char* value) { // Given char* and char*
return Mnemonic(std::string(name), std::string(value)); // make strings and borrow that method.
}

ConfigurationElement& ConfigurationElement::Mnemonic( // Add a mnemonic using mixed strings.
const char* name, const std::string value) { // Given char* and string
return Mnemonic(std::string(name), value); // make strings and borrow that method.
}

ConfigurationElement& ConfigurationElement::Mnemonic( // Add a mnemonic using mixed strings.
const std::string name, const char* value) { // Given string and char*
return Mnemonic(name, std::string(value)); // make strings and borrow that method.
}

ConfigurationElement& ConfigurationElement::Mnemonic( // Add a mnemonic using c++ strings.
const std::string name, const std::string value) { // Givent string and string
ConfigurationMnemonic* N = // Create a new Mnemonic
new ConfigurationMnemonic(name, value); // using the values provided,
myMnemonics.push_back(N); // add it to my list, then
return(*this); // dereference and return myself.
}

//// Configuration Attribute ///////////////////////////////////////////////////

ConfigurationAttribute::ConfigurationAttribute( // Attributes are constructed with a
const char* Name, ConfigurationElement& Parent) : // Name and a Parent.
myName(std::string(Name)), // We convert the name to a string.
myParent(Parent), // We just grab the parent.
myLine(0), // Everything else gets zeroed.
myIndex(0),
myLength(0) {
}

ConfigurationAttribute::ConfigurationAttribute( // Attributes are constrictued with a
const std::string Name, ConfigurationElement& Parent) : // Name and a Parent.
myName(Name), // We grab them and zero the rest.
myParent(Parent),
myLine(0),
myIndex(0),
myLength(0) {
}

std::string ConfigurationAttribute::Name() { // Get the name of this attribute.
return myName;
}

ConfigurationElement& ConfigurationAttribute::Parent() { // Get the parent of this attribute.
return myParent;
}

int ConfigurationAttribute::Line() { // Get the last line number.
return myLine;
}

int ConfigurationAttribute::Index() { // Get the last data position.
return myIndex;
}

int ConfigurationAttribute::Length() { // Get the last length.
return myLength;
}

ConfigurationElement& ConfigurationAttribute::Element( // Add a new sub element by c string name.
const char* Name) {
return myParent.Element(Name);
}

ConfigurationElement& ConfigurationAttribute::Element( // Add a new sub element by c++ string name.
const std::string Name) {
return myParent.Element(Name);
}

ConfigurationElement& ConfigurationAttribute::Element( // Mapping factory for convenience,
const char* Name, // requires a name, of course,
ConfigurationTranslator& newTranslator) { // Add a Translator to this element.
return myParent.Element(Name, newTranslator);
}

ConfigurationElement& ConfigurationAttribute::Element( // Mapping factory for convenience,
const char* Name, // requires a name, of course,
std::string& x, std::string init) { // Map to a string.
return myParent.Element(Name, x, init);
}

ConfigurationElement& ConfigurationAttribute::Element( // Mapping factory for convenience,
const char* Name, // requires a name, of course,
int& x, int init, int radix) { // Map to an int.
return myParent.Element(Name, x, init, radix);
}

ConfigurationElement& ConfigurationAttribute::Element( // Mapping factory for convenience,
const char* Name, // requires a name, of course,
double& x, double init) { // Map to a double.
return myParent.Element(Name, x, init);
}

ConfigurationElement& ConfigurationAttribute::Element( // Mapping factory for convenience,
const char* Name, // requires a name, of course,
bool& x, bool init) { // Map to a boolean.
return myParent.Element(Name, x, init);
}

ConfigurationElement& ConfigurationAttribute::Element( // Mapping factory for convenience,
const std::string Name, // requires a name, of course,
ConfigurationTranslator& newTranslator) { // Add a Translator to this element.
return myParent.Element(Name, newTranslator);
}

ConfigurationElement& ConfigurationAttribute::Element( // Mapping factory for convenience,
const std::string Name, // requires a name, of course,
std::string& x, std::string init) { // Map to a string.
return myParent.Element(Name, x, init);
}

ConfigurationElement& ConfigurationAttribute::Element( // Mapping factory for convenience,
const std::string Name, // requires a name, of course,
int& x, int init, int radix) { // Map to an int.
return myParent.Element(Name, x, init, radix);
}

ConfigurationElement& ConfigurationAttribute::Element( // Mapping factory for convenience,
const std::string Name, // requires a name, of course,
double& x, double init) { // Map to a double.
return myParent.Element(Name, x, init);
}

ConfigurationElement& ConfigurationAttribute::Element( // Mapping factory for convenience,
const std::string Name, // requires a name, of course,
bool& x, bool init) { // Map to a boolean.
return myParent.Element(Name, x, init);
}

ConfigurationElement& ConfigurationAttribute::End() { // Return this element's parent.
return myParent.End();
}

ConfigurationElement& ConfigurationAttribute::End(const char* Name) { // Check the name and return the parent
return myParent.End(Name);
}

ConfigurationElement& ConfigurationAttribute::End(const std::string Name) { // if the name is correct - or throw!
return myParent.End(Name);
}

ConfigurationAttribute& ConfigurationAttribute::Attribute( // Add an attribute using a cstring.
const char* Name) {
return myParent.Attribute(Name);
}

ConfigurationAttribute& ConfigurationAttribute::Attribute( // Add an attribute using a c++ string.
const std::string Name) {
return myParent.Attribute(Name);
}

ConfigurationAttribute& ConfigurationAttribute::Attribute( // Mapping factory for convenience,
const char* Name, // requires a name, of course,
ConfigurationTranslator& newTranslator) { // Add a Translator to this element.
return myParent.Attribute(Name, newTranslator);
}

ConfigurationAttribute& ConfigurationAttribute::Attribute( // Mapping factory for convenience,
const char* Name, // requires a name, of course,
std::string& x, std::string init) { // Map to a string.
return myParent.Attribute(Name, x, init);
}

ConfigurationAttribute& ConfigurationAttribute::Attribute( // Mapping factory for convenience,
const char* Name, // requires a name, of course,
int& x, int init, int radix) { // Map to an int.
return myParent.Attribute(Name, x, init, radix);
}

ConfigurationAttribute& ConfigurationAttribute::Attribute( // Mapping factory for convenience,
const char* Name, // requires a name, of course,
double& x, double init) { // Map to a double.
return myParent.Attribute(Name, x, init);
}

ConfigurationAttribute& ConfigurationAttribute::Attribute( // Mapping factory for convenience,
const char* Name, // requires a name, of course,
bool& x, bool init) { // Map to a boolean.
return myParent.Attribute(Name, x, init);
}

ConfigurationAttribute& ConfigurationAttribute::Attribute( // Mapping factory for convenience,
const std::string Name, // requires a name, of course,
ConfigurationTranslator& newTranslator) { // Add a Translator to this element.
return myParent.Attribute(Name, newTranslator);
}

ConfigurationAttribute& ConfigurationAttribute::Attribute( // Mapping factory for convenience,
const std::string Name, // requires a name, of course,
std::string& x, std::string init) { // Map to a string.
return myParent.Attribute(Name, x, init);
}

ConfigurationAttribute& ConfigurationAttribute::Attribute( // Mapping factory for convenience,
const std::string Name, // requires a name, of course,
int& x, int init, int radix) { // Map to an int.
return myParent.Attribute(Name, x, init, radix);
}

ConfigurationAttribute& ConfigurationAttribute::Attribute( // Mapping factory for convenience,
const std::string Name, // requires a name, of course,
double& x, double init) { // Map to a double.
return myParent.Attribute(Name, x, init);
}

ConfigurationAttribute& ConfigurationAttribute::Attribute( // Mapping factory for convenience,
const std::string Name, // requires a name, of course,
bool& x, bool init) { // Map to a boolean.
return myParent.Attribute(Name, x, init);
}

ConfigurationElement& ConfigurationAttribute::setInitOnInterpret() { // Set the init on interpret flag.
return myParent.setInitOnInterpret();
}

ConfigurationElement& ConfigurationAttribute::atStartCall( // Add an atStart call-back to this element.
Configurator& Functor) {
return myParent.atStartCall(Functor);
}

ConfigurationElement& ConfigurationAttribute::atEndCall( // Add an atEnd call-back to this element.
Configurator& Functor) {
return myParent.atEndCall(Functor);
}

ConfigurationAttribute& ConfigurationAttribute::Mnemonic( // Add a mnemonic using c strings.
const char* name, const char* value) { // Given char* and char*
return Mnemonic(std::string(name), std::string(value)); // make strings and borrow that method.
}

ConfigurationAttribute& ConfigurationAttribute::Mnemonic( // Add a mnemonic using mixed strings.
const char* name, const std::string value) { // Given char* and string
return Mnemonic(std::string(name), value); // make strings and borrow that method.
}

ConfigurationAttribute& ConfigurationAttribute::Mnemonic( // Add a mnemonic using mixed strings.
const std::string name, const char* value) { // Given string and char*
return Mnemonic(name, std::string(value)); // make strings and borrow that method.
}

ConfigurationAttribute& ConfigurationAttribute::Mnemonic( // Add a mnemonic using c++ strings.
const std::string name, const std::string value) { // Givent string and string
ConfigurationMnemonic* N = // Create a new Mnemonic
new ConfigurationMnemonic(name, value); // using the values provided,
myMnemonics.push_back(N); // add it to my list, then
return(*this); // dereference and return myself.
}

//// Configuration Data ////////////////////////////////////////////////////////

char ConfigurationData::Data(int Index) { // Returns char from Data[Index]
if(0 > Index || Index >= myBufferSize) { // Check that index is in range
return 0; // and return 0 if it is not.
} // If Index is within range then
return myDataBuffer[Index]; // return the byte requested.
}

int ConfigurationData::Index() { // Reads the current Index.
return myIndex;
}

int ConfigurationData::Index(int i) { // Changes the current Index.
if(0 > i || i >= myBufferSize) { // If i is out of range then
return myIndex; // return the current Index unchanged.
} // If i is within range then
myIndex = i; // change the Index to i and
return myIndex; // return the changed Index.
}

int ConfigurationData::Line() { // Reads the current Line number.
return myLine;
}

int ConfigurationData::addNewLines(int Count) { // Increments the Line number.
myLine += Count; // Add the number of new lines.
return myLine; // Return the current Line number.
}

//// Configuration Translator //////////////////////////////////////////////////

StringTranslator::StringTranslator( // Construct this with
std::string& Variable, // the variable to map,
std::string Initializer) : // and the default value.
myVariable(Variable),
myInitializer(Initializer) {
}

void StringTranslator::translate(const char* Value) { // Provide a translation method.
myVariable = std::string(Value); // String to String = simple copy.
}

void StringTranslator::initialize() { // Provide an initialization method.
myVariable = myInitializer; // Revert to the initializer value.
}

IntegerTranslator::IntegerTranslator( // Construct this with
int& Variable, // the variable to map,
int Initializer, // and the default value.
int Radix) : // For this one we also need a Radix.
myVariable(Variable),
myInitializer(Initializer),
myRadix(Radix) {
}

void IntegerTranslator::translate(const char* Value) { // Provide a translation method.
char* dummy; // Throw away ptr for strtol().
myVariable = strtol(Value, &dummy, myRadix); // Convert the string w/ strtol().
}

void IntegerTranslator::initialize() { // Provide an initialization method.
myVariable = myInitializer; // Revert to the initializer value.
}

DoubleTranslator::DoubleTranslator( // Construct this with
double& Variable, // the variable to map,
double Initializer) : // and the default value.
myVariable(Variable),
myInitializer(Initializer) {
}

void DoubleTranslator::translate(const char* Value) { // Provide a translation method.
char* dummy; // Throw away ptr for strtod().
myVariable = strtod(Value, &dummy); // Convert the string w/ strtod().
}

void DoubleTranslator::initialize() { // Provide an initialization method.
myVariable = myInitializer; // Revert to the initializer value.
}

BoolTranslator::BoolTranslator( // Construct this with
bool& Variable, // the variable to map,
bool Initializer) : // and the default value.
myVariable(Variable),
myInitializer(Initializer) {
}

void BoolTranslator::translate(const char* Value) { // Provide a translation method.
if(
(0 == strcmp(Value,"on")) ||
(0 == strcmp(Value,"true")) || // on, true, yes, and 1 are
(0 == strcmp(Value, "yes")) || // interpreted as a boolean true.
(0 == strcmp(Value, "1"))
) {
myVariable = true;
} else { // Anything else is interpreted as
myVariable = false; // boolean false.
}
}

void BoolTranslator::initialize() { // Provide an initialization method.
myVariable = myInitializer; // Revert to the initializer value.
}

//// Configuration Mnemonic ////////////////////////////////////////////////////

ConfigurationMnemonic::ConfigurationMnemonic( // To make one, provide both parts.
std::string Name, std::string Value) :
myName(Name),
myValue(Value) {
}

bool ConfigurationMnemonic::test(std::string Name) { // Test to see if this Mnemonic matches.
return (0 == Name.compare(myName)); // Return true if Name and myName match.
}

std::string ConfigurationMnemonic::Value() { // If it does then we will need it's value.
return myValue;
}

//// Helper functions //////////////////////////////////////////////////////////

@@ -354,7 +908,7 @@ ConfigurationElement::~ConfigurationElement() {
// Delete my attributes

if(0 < myAttributes.size()) { // If we have attributes...
list<ConfigurationAttribute*>::iterator iAttribute; // Iterate through our attributes list.
std::list<ConfigurationAttribute*>::iterator iAttribute; // Iterate through our attributes list.
iAttribute = myAttributes.begin(); // Start at the beginning and
while(iAttribute != myAttributes.end()) { // loop through the whole list.
delete (*iAttribute); // Delete each attribute
@@ -366,7 +920,7 @@ ConfigurationElement::~ConfigurationElement() {
// Delete my sub-elements

if(0 < myElements.size()) { // If we have elements...
list<ConfigurationElement*>::iterator iElement; // Iterate through our elements list.
std::list<ConfigurationElement*>::iterator iElement; // Iterate through our elements list.
iElement = myElements.begin(); // Start at the beginning and
while(iElement != myElements.end()) { // loop through the whole list.
delete (*iElement); // Delete each element
@@ -378,7 +932,7 @@ ConfigurationElement::~ConfigurationElement() {
// Delete my mnemonics

if(0 < myMnemonics.size()) { // If we have mnemonics...
list<ConfigurationMnemonic*>::iterator iMnemonic; // Iterate through our mnemonics list.
std::list<ConfigurationMnemonic*>::iterator iMnemonic; // Iterate through our mnemonics list.
iMnemonic = myMnemonics.begin(); // Start at the beginning and
while(iMnemonic != myMnemonics.end()) { // loop through the whole list.
delete (*iMnemonic); // Delete each mnemonic
@@ -390,7 +944,7 @@ ConfigurationElement::~ConfigurationElement() {
// Delete my translators

if(0 < myTranslators.size()) { // If we have translators...
list<ConfigurationTranslator*>::iterator iTranslator; // Iterate through our translators list.
std::list<ConfigurationTranslator*>::iterator iTranslator; // Iterate through our translators list.
iTranslator = myTranslators.begin(); // Start at the beginning and
while(iTranslator != myTranslators.end()) { // loop through the whole list.
delete (*iTranslator); // Delete each translator
@@ -409,7 +963,7 @@ ConfigurationElement::~ConfigurationElement() {
}

ConfigurationElement& ConfigurationElement::Element( // Mapping factory for convenience,
const string Name, // requires a name, of course,
const std::string Name, // requires a name, of course,
ConfigurationTranslator& newTranslator) { // Add a Translator to this element.

ConfigurationElement* N = new ConfigurationElement( // Create a new Element with the
@@ -422,8 +976,8 @@ ConfigurationElement& ConfigurationElement::Element(
}

ConfigurationElement& ConfigurationElement::Element( // Mapping factory for convenience,
const string Name, // requires a name, of course,
string& x, string init) { // Map to a string.
const std::string Name, // requires a name, of course,
std::string& x, std::string init) { // Map to a string.

ConfigurationElement* N = new ConfigurationElement( // Create a new Element with the
Name, // name provided and
@@ -435,7 +989,7 @@ ConfigurationElement& ConfigurationElement::Element(
}

ConfigurationElement& ConfigurationElement::Element( // Mapping factory for convenience,
const string Name, // requires a name, of course,
const std::string Name, // requires a name, of course,
int& x, int init, int radix) { // Map to an int.

ConfigurationElement* N = new ConfigurationElement( // Create a new Element with the
@@ -448,7 +1002,7 @@ ConfigurationElement& ConfigurationElement::Element(
}

ConfigurationElement& ConfigurationElement::Element( // Mapping factory for convenience,
const string Name, // requires a name, of course,
const std::string Name, // requires a name, of course,
double& x, double init) { // Map to a double.

ConfigurationElement* N = new ConfigurationElement( // Create a new Element with the
@@ -461,7 +1015,7 @@ ConfigurationElement& ConfigurationElement::Element(
}

ConfigurationElement& ConfigurationElement::Element( // Mapping factory for convenience,
const string Name, // requires a name, of course,
const std::string Name, // requires a name, of course,
bool& x, bool init) { // Map to a boolean.

ConfigurationElement* N = new ConfigurationElement( // Create a new Element with the
@@ -473,9 +1027,9 @@ ConfigurationElement& ConfigurationElement::Element(
return (*N); // Return the new element.
}

ConfigurationAttribute& ConfigurationElement::Attribute(const string Name) { // Add an attribute using a c++ string.
ConfigurationAttribute* N = // Create a new attribute by name and
new ConfigurationAttribute(Name, (*this)); // provide myself as the parent.
ConfigurationAttribute& ConfigurationElement::Attribute(const std::string Name) { // Add an attribute using a c++ string.
ConfigurationAttribute* N = // Create a new attribute by name and
new ConfigurationAttribute(Name, (*this)); // provide myself as the parent.

myCleanFlag = false; // New attributes make us dirty.

@@ -484,7 +1038,7 @@ ConfigurationAttribute& ConfigurationElement::Attribute(const string Name) {
}

ConfigurationAttribute& ConfigurationElement::Attribute( // Mapping factory for convenience,
const string Name, // requires a name, of course,
const std::string Name, // requires a name, of course,
ConfigurationTranslator& newTranslator) { // Add a Translator to this element.

myCleanFlag = false; // New attributes make us dirty.
@@ -498,8 +1052,8 @@ ConfigurationAttribute& ConfigurationElement::Attribute(
}

ConfigurationAttribute& ConfigurationElement::Attribute( // Mapping factory for convenience,
const string Name, // requires a name, of course,
string& x, string init) { // Map to a string.
const std::string Name, // requires a name, of course,
std::string& x, std::string init) { // Map to a string.

myCleanFlag = false; // New attributes make us dirty.

@@ -512,7 +1066,7 @@ ConfigurationAttribute& ConfigurationElement::Attribute(
}

ConfigurationAttribute& ConfigurationElement::Attribute( // Mapping factory for convenience,
const string Name, // requires a name, of course,
const std::string Name, // requires a name, of course,
int& x, int init, int radix) { // Map to an int.

myCleanFlag = false; // New attributes make us dirty.
@@ -526,7 +1080,7 @@ ConfigurationAttribute& ConfigurationElement::Attribute(
}

ConfigurationAttribute& ConfigurationElement::Attribute( // Mapping factory for convenience,
const string Name, // requires a name, of course,
const std::string Name, // requires a name, of course,
double& x, double init) { // Map to a double.

myCleanFlag = false; // New attributes make us dirty.
@@ -540,7 +1094,7 @@ ConfigurationAttribute& ConfigurationElement::Attribute(
}

ConfigurationAttribute& ConfigurationElement::Attribute( // Mapping factory for convenience,
const string Name, // requires a name, of course,
const std::string Name, // requires a name, of course,
bool& x, bool init) { // Map to a boolean.

myCleanFlag = false; // New attributes make us dirty.
@@ -561,7 +1115,7 @@ ConfigurationElement& ConfigurationElement::mapTo(
}

ConfigurationElement& ConfigurationElement::mapTo( // Map to a string.
string& x, string init) { // Given a string and init value,
std::string& x, std::string init) { // Given a string and init value,
ConfigurationTranslator* N = // create a new translator for it
new StringTranslator(x, init); // with the values i'm given,
myTranslators.push_back(N); // push it onto my list, then
@@ -601,7 +1155,7 @@ void ConfigurationElement::initialize() {
// Initialize the elements below me

if(0 < myElements.size()) { // If we have elements...
list<ConfigurationElement*>::iterator iElement; // Iterate through our elements list.
std::list<ConfigurationElement*>::iterator iElement; // Iterate through our elements list.
iElement = myElements.begin(); // Start at the beginning and
while(iElement != myElements.end()) { // loop through the whole list.
(*iElement)->initialize(); // Initialize each element
@@ -616,7 +1170,7 @@ void ConfigurationElement::initialize() {
// Initialize my own translators

if(0 < myTranslators.size()) { // If we have translators...
list<ConfigurationTranslator*>::iterator iTranslator; // Iterate through our translators list.
std::list<ConfigurationTranslator*>::iterator iTranslator; // Iterate through our translators list.
iTranslator = myTranslators.begin(); // Start at the beginning and
while(iTranslator != myTranslators.end()) { // loop through the whole list.
(*iTranslator)->initialize(); // Initialize each translator
@@ -627,7 +1181,7 @@ void ConfigurationElement::initialize() {
// Initialize my own attributes

if(0 < myAttributes.size()) { // If we have attributes...
list<ConfigurationAttribute*>::iterator iAttribute; // Iterate through our attributes list.
std::list<ConfigurationAttribute*>::iterator iAttribute; // Iterate through our attributes list.
iAttribute = myAttributes.begin(); // Start at the beginning and
while(iAttribute != myAttributes.end()) { // loop through the whole list.
(*iAttribute)->initialize(); // Initialize each attribute
@@ -648,7 +1202,7 @@ void ConfigurationElement::initialize() {
}

void ConfigurationElement::runStartConfigurators(ConfigurationData& D) { // Does what it says ;-)
list<Configurator*>::iterator iConfigurator; // Iterate through our Configurators list.
std::list<Configurator*>::iterator iConfigurator; // Iterate through our Configurators list.
iConfigurator = myStartConfigurators.begin(); // Start at the beginning and
while(iConfigurator != myStartConfigurators.end()) { // loop through the whole list.
(** iConfigurator)(*this, D); // Launch each configurator with self.
@@ -657,7 +1211,7 @@ void ConfigurationElement::runStartConfigurators(ConfigurationData& D) {
}

void ConfigurationElement::runEndConfigurators(ConfigurationData& D) { // Does what it says ;-)
list<Configurator*>::iterator iConfigurator; // Iterate through our Configurators list.
std::list<Configurator*>::iterator iConfigurator; // Iterate through our Configurators list.
iConfigurator = myEndConfigurators.begin(); // Start at the beginning and
while(iConfigurator != myEndConfigurators.end()) { // loop through the whole list.
(** iConfigurator)(*this, D); // Launch each configurator with self.
@@ -744,7 +1298,7 @@ bool ConfigurationElement::interpret(ConfigurationData& Data) {

if(isalpha(Data.Data(Index))) { // If it looks like an attribute...
bool ParseHappened = false; // Start pessimistically at each pass.
list<ConfigurationAttribute*>::iterator iAttribute; // Iterate through our attributes list.
std::list<ConfigurationAttribute*>::iterator iAttribute; // Iterate through our attributes list.
iAttribute = myAttributes.begin(); // Start at the beginning and
while(iAttribute != myAttributes.end()) { // loop through the whole list.
ParseHappened = (* iAttribute)->interpret(Data); // Have each attribute interpret(Data)
@@ -848,7 +1402,7 @@ bool ConfigurationElement::interpret(ConfigurationData& Data) {
NewLines = 0; // Reset our new lines count.
if(0 < myElements.size()) { // If we have elements check them.

list<ConfigurationElement*>::iterator iElement; // Iterate through our elements list.
std::list<ConfigurationElement*>::iterator iElement; // Iterate through our elements list.
iElement = myElements.begin(); // Start at the beginning and
while(iElement != myElements.end()) { // loop through the whole list.
ConfigurationElement& doNode = **iElement; // Grab the element we're on.
@@ -906,7 +1460,7 @@ bool ConfigurationElement::interpret(ConfigurationData& Data) {
// Create the Content buffer...

int BfrSize = Stopdex - Startdex +1; // How big a buffer do we need?
vector<char> heapBfr(BfrSize,0); // Make one that size.
std::vector<char> heapBfr(BfrSize,0); // Make one that size.
char* Bfr = &heapBfr[0];

copyDataCountLines(Bfr, Data, Startdex, Stopdex); // Get our data and ignore our lines.
@@ -918,7 +1472,7 @@ bool ConfigurationElement::interpret(ConfigurationData& Data) {
// Translate our data by Mnemonic

if(0 < myMnemonics.size()) { // If we have mnemonics...
list<ConfigurationMnemonic*>::iterator iMnemonic; // Iterate through our mnemonics list.
std::list<ConfigurationMnemonic*>::iterator iMnemonic; // Iterate through our mnemonics list.
iMnemonic = myMnemonics.begin(); // Start at the beginning and
while(iMnemonic != myMnemonics.end()) { // loop through the whole list.
if(true == ((*iMnemonic)->test(TranslationData))) { // Check to see if the mnemonic matches.
@@ -933,7 +1487,7 @@ bool ConfigurationElement::interpret(ConfigurationData& Data) {

// Put our TranslationData through each Translator.

list<ConfigurationTranslator*>::iterator iTranslator; // Iterate through our translators list.
std::list<ConfigurationTranslator*>::iterator iTranslator; // Iterate through our translators list.
iTranslator = myTranslators.begin(); // Start at the beginning and
while(iTranslator != myTranslators.end()) { // loop through the whole list.
(*iTranslator)->translate(TranslationData); // Pass the data to each one then
@@ -954,7 +1508,7 @@ ConfigurationAttribute::~ConfigurationAttribute() {
// Delete my mnemonics

if(0 < myMnemonics.size()) { // If we have mnemonics...
list<ConfigurationMnemonic*>::iterator iMnemonic; // Iterate through our mnemonics list.
std::list<ConfigurationMnemonic*>::iterator iMnemonic; // Iterate through our mnemonics list.
iMnemonic = myMnemonics.begin(); // Start at the beginning and
while(iMnemonic != myMnemonics.end()) { // loop through the whole list.
delete (*iMnemonic); // Delete each mnemonic
@@ -966,7 +1520,7 @@ ConfigurationAttribute::~ConfigurationAttribute() {
// Delete my translators

if(0 < myTranslators.size()) { // If we have translators...
list<ConfigurationTranslator*>::iterator iTranslator; // Iterate through our translators list.
std::list<ConfigurationTranslator*>::iterator iTranslator; // Iterate through our translators list.
iTranslator = myTranslators.begin(); // Start at the beginning and
while(iTranslator != myTranslators.end()) { // loop through the whole list.
delete (*iTranslator); // Delete each translator
@@ -990,7 +1544,7 @@ ConfigurationAttribute& ConfigurationAttribute::mapTo(
}

ConfigurationAttribute& ConfigurationAttribute::mapTo( // Map to a string.
string& x, string init) { // Given a string and init value,
std::string& x, std::string init) { // Given a string and init value,
ConfigurationTranslator* N = // create a new translator for it
new StringTranslator(x, init); // with the values i'm given,
myTranslators.push_back(N); // push it onto my list, then
@@ -1028,7 +1582,7 @@ ConfigurationAttribute& ConfigurationAttribute::mapTo(
void ConfigurationAttribute::initialize() { // Reset all translators to defaults.

if(0 < myTranslators.size()) { // If we have translators...
list<ConfigurationTranslator*>::iterator iTranslator; // Iterate through our translators list.
std::list<ConfigurationTranslator*>::iterator iTranslator; // Iterate through our translators list.
iTranslator = myTranslators.begin(); // Start at the beginning and
while(iTranslator != myTranslators.end()) { // loop through the whole list.
(*iTranslator)->initialize(); // initialize each translator
@@ -1099,7 +1653,7 @@ bool ConfigurationAttribute::interpret(ConfigurationData& Data) {
// Read our data.

int BfrSize = Stopdex - Startdex +1; // How big a buffer do we need?
vector<char> heapBfr(BfrSize,0); // Make one that size.
std::vector<char> heapBfr(BfrSize,0); // Make one that size.
char* Bfr = &heapBfr[0];

NewLines += copyDataCountLines(Bfr, Data, Startdex, Stopdex); // Get our data and count our lines.
@@ -1111,7 +1665,7 @@ bool ConfigurationAttribute::interpret(ConfigurationData& Data) {
// Translate our data by Mnemonic

if(0 < myMnemonics.size()) { // If we have mnemonics...
list<ConfigurationMnemonic*>::iterator iMnemonic; // Iterate through our mnemonics list.
std::list<ConfigurationMnemonic*>::iterator iMnemonic; // Iterate through our mnemonics list.
iMnemonic = myMnemonics.begin(); // Start at the beginning and
while(iMnemonic != myMnemonics.end()) { // loop through the whole list.
if(true == ((*iMnemonic)->test(TranslationData))){ // Check to see if the mnemonic matches.
@@ -1127,7 +1681,7 @@ bool ConfigurationAttribute::interpret(ConfigurationData& Data) {
// Put our TranslationData through each Translator.

if(0 < myTranslators.size()) { // We'd better have translators!
list<ConfigurationTranslator*>::iterator iTranslator; // Iterate through our translators list.
std::list<ConfigurationTranslator*>::iterator iTranslator; // Iterate through our translators list.
iTranslator = myTranslators.begin(); // Start at the beginning and
while(iTranslator != myTranslators.end()) { // loop through the whole list.
(*iTranslator)->translate(TranslationData); // Pass the data to each one and
@@ -1173,11 +1727,11 @@ ConfigurationData::ConfigurationData(const char* FileName) :
myIndex(0), // Our Index is zero
myLine(1) { // We start on line 1
try { // Capture any throws.
ifstream CFGFile(FileName); // Open the file.
CFGFile.seekg(0,ios::end); // Seek to the end
std::ifstream CFGFile(FileName); // Open the file.
CFGFile.seekg(0,std::ios::end); // Seek to the end
myBufferSize = CFGFile.tellg(); // to find out what size it is.
myDataBuffer = newCStringBuffer(myBufferSize); // Make a new buffer the right size.
CFGFile.seekg(0,ios::beg); // Seek to the beginning and
CFGFile.seekg(0,std::ios::beg); // Seek to the beginning and
CFGFile.read(myDataBuffer, myBufferSize); // read the file into the buffer.
if(CFGFile.bad()) { // If the read failed, we're unusable!
delete[] myDataBuffer; // Delete the buffer
@@ -1194,17 +1748,17 @@ ConfigurationData::ConfigurationData(const char* FileName) :
} // indicating there is no Data.
}

ConfigurationData::ConfigurationData(const string FileName) : // Raw constructor from file.
ConfigurationData::ConfigurationData(const std::string FileName) : // Raw constructor from file.
myDataBuffer(NULL), // No data buffer yet.
myBufferSize(0), // No length yet.
myIndex(0), // Our Index is zero
myLine(1) { // We start on line 1
try { // Capture any throws.
ifstream CFGFile(FileName.c_str()); // Open the file.
CFGFile.seekg(0,ios::end); // Seek to the end
std::ifstream CFGFile(FileName.c_str()); // Open the file.
CFGFile.seekg(0,std::ios::end); // Seek to the end
myBufferSize = CFGFile.tellg(); // to find out what size it is.
myDataBuffer = newCStringBuffer(myBufferSize); // Make a new buffer the right size.
CFGFile.seekg(0,ios::beg); // Seek to the beginning and
CFGFile.seekg(0,std::ios::beg); // Seek to the beginning and
CFGFile.read(myDataBuffer, myBufferSize); // read the file into the buffer.
if(CFGFile.bad()) { // If the read failed, we're unusable!
delete[] myDataBuffer; // Delete the buffer
@@ -1250,3 +1804,4 @@ void ConfiguratorSetTrueOnComplete::operator()(
} // true.
}

} // End namespace codedweller

+ 84
- 92
configuration.hpp View File

@@ -105,8 +105,7 @@

// Include This Header Once Only ===============================================

#ifndef configuration_included
#define configuration_included
#pragma once

#include <string>
#include <vector>
@@ -116,7 +115,7 @@
#include <cstdlib>
#include <list>

using namespace std;
namespace codedweller {

class ConfigurationElement; // Elements exist
class ConfigurationAttribute; // Attributes exist
@@ -135,21 +134,21 @@ class ConfigurationElement {

private:

string myName; // Elements have a name.
std::string myName; // Elements have a name.

// External important things I remember but don't touch...

ConfigurationElement* myParent; // They may have a parrent.

list<Configurator*> myStartConfigurators; // Call these when we start Interpret()
list<Configurator*> myEndConfigurators; // Call these when we finish Interpret()
std::list<Configurator*> myStartConfigurators; // Call these when we start Interpret()
std::list<Configurator*> myEndConfigurators; // Call these when we finish Interpret()

// Internal / subordinate things I own and kill...

list<ConfigurationAttribute*> myAttributes; // They may have a list of attributes.
list<ConfigurationElement*> myElements; // They may have a list of sub-elements.
list<ConfigurationMnemonic*> myMnemonics; // They may have a list of mnemonics.
list<ConfigurationTranslator*> myTranslators; // They may have a list of translators.
std::list<ConfigurationAttribute*> myAttributes; // They may have a list of attributes.
std::list<ConfigurationElement*> myElements; // They may have a list of sub-elements.
std::list<ConfigurationMnemonic*> myMnemonics; // They may have a list of mnemonics.
std::list<ConfigurationTranslator*> myTranslators; // They may have a list of translators.

// During Interpret() operations we keep track of where we are seen...

@@ -167,10 +166,10 @@ class ConfigurationElement {
public:

ConfigurationElement(const char* Name); // Must be constructed with a name
ConfigurationElement(const string Name); // either c string or c++ string.
ConfigurationElement(const std::string Name); // either c string or c++ string.

ConfigurationElement(const char* Name, ConfigurationElement& Parent); // Sub-elements are constructed with a
ConfigurationElement(const string Name, ConfigurationElement& Parent); // parrent.
ConfigurationElement(const std::string Name, ConfigurationElement& Parent); // parrent.

// Upon desctruction an element will delete all subordinate objects:
// * All sub element objects.
@@ -189,7 +188,7 @@ class ConfigurationElement {

// Elements can be probed for some simple, useful things.

string Name(); // Get the name of this element.
std::string Name(); // Get the name of this element.
ConfigurationElement& Parent(); // Get the parent of this element.
ConfigurationElement& Parent(ConfigurationElement& newParent); // Set the parent of this element.

@@ -203,7 +202,7 @@ class ConfigurationElement {
// Elements can contain either data or sub-elements.

ConfigurationElement& Element(const char* Name); // Add a new sub element by c string name.
ConfigurationElement& Element(const string Name); // Add a new sub element by c++ string name.
ConfigurationElement& Element(const std::string Name); // Add a new sub element by c++ string name.

//// Mapping element factory methods for convenience.
//// Root-Node elements are _usually_ empty and without attributes in xml
@@ -217,7 +216,7 @@ class ConfigurationElement {

ConfigurationElement& Element( // Mapping factory for convenience,
const char* Name, // requires a name, of course,
string& x, string init = string("")); // Map to a string.
std::string& x, std::string init = std::string("")); // Map to a string.

ConfigurationElement& Element( // Mapping factory for convenience,
const char* Name, // requires a name, of course,
@@ -234,23 +233,23 @@ class ConfigurationElement {
// string versions

ConfigurationElement& Element( // Mapping factory for convenience,
const string Name, // requires a name, of course,
const std::string Name, // requires a name, of course,
ConfigurationTranslator& newTranslator); // Add a Translator to this element.

ConfigurationElement& Element( // Mapping factory for convenience,
const string Name, // requires a name, of course,
string& x, string init = string("")); // Map to a string.
const std::string Name, // requires a name, of course,
std::string& x, std::string init = std::string("")); // Map to a string.

ConfigurationElement& Element( // Mapping factory for convenience,
const string Name, // requires a name, of course,
const std::string Name, // requires a name, of course,
int& x, int init = 0, int radix = 0); // Map to an int.

ConfigurationElement& Element( // Mapping factory for convenience,
const string Name, // requires a name, of course,
const std::string Name, // requires a name, of course,
double& x, double init = 0.0); // Map to a double.

ConfigurationElement& Element( // Mapping factory for convenience,
const 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.

// End methods for heading back up the tree at the end of an element.
@@ -259,12 +258,12 @@ class ConfigurationElement {

ConfigurationElement& End(); // Return this element's parent.
ConfigurationElement& End(const char* Name); // Check the name and return the parent
ConfigurationElement& End(const string Name); // if the name is correct - or throw!
ConfigurationElement& End(const std::string Name); // if the name is correct - or throw!

// Elements can have attributes.

ConfigurationAttribute& Attribute(const char* Name); // Add an attribute using a cstring.
ConfigurationAttribute& Attribute(const string Name); // Add an attribute using a c++ string.
ConfigurationAttribute& Attribute(const std::string Name); // Add an attribute using a c++ string.

//// Mapping Attribute factory methods for convenience.

@@ -276,7 +275,7 @@ class ConfigurationElement {

ConfigurationAttribute& Attribute( // Mapping factory for convenience,
const char* Name, // requires a name, of course,
string& x, string init = string("")); // Map to a string.
std::string& x, std::string init = std::string("")); // Map to a string.

ConfigurationAttribute& Attribute( // Mapping factory for convenience,
const char* Name, // requires a name, of course,
@@ -293,23 +292,23 @@ class ConfigurationElement {
// string versions

ConfigurationAttribute& Attribute( // Mapping factory for convenience,
const string Name, // requires a name, of course,
const std::string Name, // requires a name, of course,
ConfigurationTranslator& newTranslator); // Add a Translator to this element.

ConfigurationAttribute& Attribute( // Mapping factory for convenience,
const string Name, // requires a name, of course,
string& x, string init = string("")); // Map to a string.
const std::string Name, // requires a name, of course,
std::string& x, std::string init = std::string("")); // Map to a string.

ConfigurationAttribute& Attribute( // Mapping factory for convenience,
const string Name, // requires a name, of course,
const std::string Name, // requires a name, of course,
int& x, int init = 0, int radix = 0); // Map to an int.

ConfigurationAttribute& Attribute( // Mapping factory for convenience,
const string Name, // requires a name, of course,
const std::string Name, // requires a name, of course,
double& x, double init = 0.0); // Map to a double.

ConfigurationAttribute& Attribute( // Mapping factory for convenience,
const 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.

// Elements can Initialize() at each Interpret() call.
@@ -330,21 +329,21 @@ class ConfigurationElement {
// converts it into the expected type, and sets one or more variables
// to the converted value. Usually - just one variable.

ConfigurationElement& mapTo(ConfigurationTranslator& newTranslator); // Add a Translator to this element.
ConfigurationElement& mapTo(string& x, string init = string("")); // Map to a string.
ConfigurationElement& mapTo(int& x, int init = 0, int radix = 0); // Map to an int.
ConfigurationElement& mapTo(double& x, double init = 0.0); // Map to a double.
ConfigurationElement& mapTo(bool& x, bool init = false); // Map to a boolean.
ConfigurationElement& mapTo(ConfigurationTranslator& newTranslator); // Add a Translator to this element.
ConfigurationElement& mapTo(std::string& x, std::string init = std::string("")); // Map to a string.
ConfigurationElement& mapTo(int& x, int init = 0, int radix = 0); // Map to an int.
ConfigurationElement& mapTo(double& x, double init = 0.0); // Map to a double.
ConfigurationElement& mapTo(bool& x, bool init = false); // Map to a boolean.

// An Element's contents may use some special mnemonics to make a
// configuration easier to understand and less error prone. When the
// contents match a mnemnoic then the translation of the mnemonic is
// passed to the Translators instead of the raw contents.

ConfigurationElement& Mnemonic(const char* name, const char* value); // Add a mnemonic using c strings.
ConfigurationElement& Mnemonic(const char* name, const string value); // Add a mnemonic using c & c++ strings.
ConfigurationElement& Mnemonic(const string name, const char* value); // Add a mnemonic using c++ & c strings.
ConfigurationElement& Mnemonic(const string name, const string value); // Add a mnemonic using c++ strings.
ConfigurationElement& Mnemonic(const char* name, const char* value); // Add a mnemonic using c strings.
ConfigurationElement& Mnemonic(const char* name, const std::string value); // Add a mnemonic using c & c++ strings.
ConfigurationElement& Mnemonic(const std::string name, const char* value); // Add a mnemonic using c++ & c strings.
ConfigurationElement& Mnemonic(const std::string name, const std::string value); // Add a mnemonic using c++ strings.

// The way data gets into an element tree is that it is Interpret()ed
// recursively. The data is loaded into a ConfigurationData object which
@@ -388,11 +387,11 @@ class ConfigurationAttribute {

private:

string myName; // Elements have a name.
std::string myName; // Elements have a name.
ConfigurationElement& myParent; // They may have a parrent.

list<ConfigurationMnemonic*> myMnemonics; // They may have a list of mnemonics.
list<ConfigurationTranslator*> myTranslators; // They may have a list of translators.
std::list<ConfigurationMnemonic*> myMnemonics; // They may have a list of mnemonics.
std::list<ConfigurationTranslator*> myTranslators; // They may have a list of translators.

int myLine; // Last line number I was seen on.
int myIndex; // Last char position I was seen on.
@@ -400,8 +399,8 @@ class ConfigurationAttribute {

public:

ConfigurationAttribute(const char* Name, ConfigurationElement& Parent); // Sub-elements are constructed with a
ConfigurationAttribute(const string Name, ConfigurationElement& Parent); // parrent.
ConfigurationAttribute(const char* Name, ConfigurationElement& Parent); // Sub-elements are constructed with a
ConfigurationAttribute(const std::string Name, ConfigurationElement& Parent); // parrent.

// Attributes delete their Mnemonics and Translators when they go.
// See Elements for similar warnings about objects provided to
@@ -412,7 +411,7 @@ class ConfigurationAttribute {

// Attributes can be probed for some simple, useful things.

string Name(); // Get the name of this attribute.
std::string Name(); // Get the name of this attribute.
ConfigurationElement& Parent(); // Get the parent of this attribute.
int Line(); // Get the last line number.
int Index(); // Get the last data position.
@@ -428,7 +427,7 @@ class ConfigurationAttribute {
//// For switching back to the parent element and adding new sub-elements.

ConfigurationElement& Element(const char* Name); // Add a new sub element by c string name.
ConfigurationElement& Element(const string Name); // Add a new sub element by c++ string name.
ConfigurationElement& Element(const std::string Name); // Add a new sub element by c++ string name.

//// Mapping element factory methods for convenience.
//// Root-Node elements are _usually_ empty and without attributes in xml
@@ -442,7 +441,7 @@ class ConfigurationAttribute {

ConfigurationElement& Element( // Mapping factory for convenience,
const char* Name, // requires a name, of course,
string& x, string init = string("")); // Map to a string.
std::string& x, std::string init = std::string("")); // Map to a string.

ConfigurationElement& Element( // Mapping factory for convenience,
const char* Name, // requires a name, of course,
@@ -459,35 +458,35 @@ class ConfigurationAttribute {
// string versions

ConfigurationElement& Element( // Mapping factory for convenience,
const string Name, // requires a name, of course,
const std::string Name, // requires a name, of course,
ConfigurationTranslator& newTranslator); // Add a Translator to this element.

ConfigurationElement& Element( // Mapping factory for convenience,
const string Name, // requires a name, of course,
string& x, string init = string("")); // Map to a string.
const std::string Name, // requires a name, of course,
std::string& x, std::string init = std::string("")); // Map to a string.

ConfigurationElement& Element( // Mapping factory for convenience,
const string Name, // requires a name, of course,
const std::string Name, // requires a name, of course,
int& x, int init = 0, int radix = 0); // Map to an int.

ConfigurationElement& Element( // Mapping factory for convenience,
const string Name, // requires a name, of course,
const std::string Name, // requires a name, of course,
double& x, double init = 0.0); // Map to a double.

ConfigurationElement& Element( // Mapping factory for convenience,
const 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.

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

ConfigurationElement& End(); // Return this element's parent.
ConfigurationElement& End(const char* Name); // Check the name and return the parent
ConfigurationElement& End(const string Name); // if the name is correct - or throw!
ConfigurationElement& End(const std::string Name); // if the name is correct - or throw!

//// For adding new attributes to the parent element.

ConfigurationAttribute& Attribute(const char* Name); // Add an attribute using a cstring.
ConfigurationAttribute& Attribute(const string Name); // Add an attribute using a c++ string.
ConfigurationAttribute& Attribute(const std::string Name); // Add an attribute using a c++ string.

//// Mapping Attribute factory methods for convenience.

@@ -499,7 +498,7 @@ class ConfigurationAttribute {

ConfigurationAttribute& Attribute( // Mapping factory for convenience,
const char* Name, // requires a name, of course,
string& x, string init = string("")); // Map to a string.
std::string& x, std::string init = std::string("")); // Map to a string.

ConfigurationAttribute& Attribute( // Mapping factory for convenience,
const char* Name, // requires a name, of course,
@@ -516,23 +515,23 @@ class ConfigurationAttribute {
// string versions

ConfigurationAttribute& Attribute( // Mapping factory for convenience,
const string Name, // requires a name, of course,
const std::string Name, // requires a name, of course,
ConfigurationTranslator& newTranslator); // Add a Translator to this element.

ConfigurationAttribute& Attribute( // Mapping factory for convenience,
const string Name, // requires a name, of course,
string& x, string init = string("")); // Map to a string.
const std::string Name, // requires a name, of course,
std::string& x, std::string init = std::string("")); // Map to a string.

ConfigurationAttribute& Attribute( // Mapping factory for convenience,
const string Name, // requires a name, of course,
const std::string Name, // requires a name, of course,
int& x, int init = 0, int radix = 0); // Map to an int.

ConfigurationAttribute& Attribute( // Mapping factory for convenience,
const string Name, // requires a name, of course,
const std::string Name, // requires a name, of course,
double& x, double init = 0.0); // Map to a double.

ConfigurationAttribute& Attribute( // Mapping factory for convenience,
const 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.

//// Set Init On Interprete for the parent element.
@@ -549,18 +548,18 @@ class ConfigurationAttribute {
// apply to the parent element's contents. Here they are for use on this
// attribute.

ConfigurationAttribute& mapTo(ConfigurationTranslator& newTranslator); // Add a Translator to this attribute.
ConfigurationAttribute& mapTo(string& x, string init = string("")); // Map to a string.
ConfigurationAttribute& mapTo(int& x, int init, int radix = 0); // Map to an int.
ConfigurationAttribute& mapTo(double& x, double init = 0.0); // Map to a double.
ConfigurationAttribute& mapTo(bool& x, bool init = false); // Map to a boolean.
ConfigurationAttribute& mapTo(ConfigurationTranslator& newTranslator); // Add a Translator to this attribute.
ConfigurationAttribute& mapTo(std::string& x, std::string init = std::string("")); // Map to a string.
ConfigurationAttribute& mapTo(int& x, int init, int radix = 0); // Map to an int.
ConfigurationAttribute& mapTo(double& x, double init = 0.0); // Map to a double.
ConfigurationAttribute& mapTo(bool& x, bool init = false); // Map to a boolean.

// Attributes can have mnemonics just like elements.

ConfigurationAttribute& Mnemonic(const char* name, const char* value); // Add a mnemonic using a c string.
ConfigurationAttribute& Mnemonic(const char* name, const string value); // Add a mnemonic using c & c++ strings.
ConfigurationAttribute& Mnemonic(const string name, const char* value); // Add a mnemonic using c++ & c strings.
ConfigurationAttribute& Mnemonic(const string name, const string value); // Add a mnemonic using a c++ string.
ConfigurationAttribute& Mnemonic(const char* name, const char* value); // Add a mnemonic using a c string.
ConfigurationAttribute& Mnemonic(const char* name, const std::string value); // Add a mnemonic using c & c++ strings.
ConfigurationAttribute& Mnemonic(const std::string name, const char* value); // Add a mnemonic using c++ & c strings.
ConfigurationAttribute& Mnemonic(const std::string name, const std::string value); // Add a mnemonic using a c++ string.

// Attributes participate in the Interprete() task just like elements.

@@ -588,7 +587,7 @@ class ConfigurationData {
public:

ConfigurationData(const char* FileName); // Constructor from c string file name.
ConfigurationData(const string FileName); // Constructor from c++ string file name.
ConfigurationData(const std::string FileName); // Constructor from c++ string file name.
ConfigurationData(const char* Data, int Length); // Raw constructor from text buffer.

~ConfigurationData(); // Destroys the internal buffer etc.
@@ -599,7 +598,7 @@ class ConfigurationData {
int Line(); // Reads the current Line number.
int addNewLines(int Count); // Increments the Line number.

stringstream Log; // Convenient Interpret log.
std::stringstream Log; // Convenient Interpret log.

};

@@ -610,7 +609,7 @@ class ConfigurationData {
// collection of the basic translators used for built-in mapTo()s.

class ConfigurationTranslator { // Translators exist
public:
public:
virtual ~ConfigurationTranslator(){}; // Stop No Virt Dtor warnings.
virtual void translate(const char* Value) = 0; // Pure virtual translator.
virtual void initialize() = 0; // Pure virtual initializer.
@@ -618,13 +617,13 @@ class ConfigurationTranslator {

class StringTranslator : public ConfigurationTranslator {
private:
string& myVariable; // Variable to map.
string myInitializer; // Initial/Default value.
std::string& myVariable; // Variable to map.
std::string myInitializer; // Initial/Default value.

public:
StringTranslator( // Construct this with
string& Variable, // the variable to map,
string Inititializer); // and the default value.
std::string& Variable, // the variable to map,
std::string Inititializer); // and the default value.

void translate(const char* Value); // Provide a translation method.
void initialize(); // Provide an initialization method.
@@ -685,13 +684,13 @@ class BoolTranslator : public ConfigurationTranslator {

class ConfigurationMnemonic { // Mnemonics
private:
string myName; // What is the Mnemonic?
string myValue; // What is the translation?
std::string myName; // What is the Mnemonic?
std::string myValue; // What is the translation?

public:
ConfigurationMnemonic(string Name, string Value); // To make one, provide both parts.
bool test(string Name); // Test to see if this Mnemonic matches.
string Value(); // If it does then we will need it's value.
ConfigurationMnemonic(std::string Name, std::string Value); // To make one, provide both parts.
bool test(std::string Name); // Test to see if this Mnemonic matches.
std::string Value(); // If it does then we will need it's value.
};

//// Configurator //////////////////////////////////////////////////////////////
@@ -707,14 +706,10 @@ class ConfigurationMnemonic {

class Configurator { // Configurators exist
public:
virtual void operator()(ConfigurationElement& E, ConfigurationData& D) = 0; // Pure virtual configurator.
virtual void operator()(ConfigurationElement& E, ConfigurationData& D) = 0; // Pure virtual configurator.
virtual ~Configurator() {} // Virtual dtor keeps warnings away.
};

//// Include our inline methods ////////////////////////////////////////////////

#include "configuration.inline.hpp"

//// Utilities /////////////////////////////////////////////////////////////////

// SetTrueOnComplete Configurator //////////////////////////////////////////////
@@ -729,7 +724,4 @@ class ConfiguratorSetTrueOnComplete : public Configurator {
void operator()(ConfigurationElement& E, ConfigurationData& D); // Handle the operation.
};

#endif

// End Of Include Only Once

} // End namespace codedweller

+ 0
- 576
configuration.inline.hpp View File

@@ -1,576 +0,0 @@
// configuration.inline.hpp
//
// (C) 2006-2009 MicroNeil Research Corporation.
//
// This program is part of the MicroNeil Research Open Library Project. For
// more information go to http://www.microneil.com/OpenLibrary/index.html
//
// This program is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2 of the License, or (at your
// option) any later version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
// more details.
//
// You should have received a copy of the GNU General Public License along with
// this program; if not, write to the Free Software Foundation, Inc., 59 Temple
// Place, Suite 330, Boston, MA 02111-1307 USA

// See configuration.hpp for details

//// Configuration Element /////////////////////////////////////////////////////

inline ConfigurationElement::ConfigurationElement(const char* Name) : // Construct with a cstring.
myName(string(Name)),
myParent(NULL),
myLine(0),
myIndex(0),
myLength(0),
myCleanFlag(true),
myInitOnInterpretFlag(false) {
}

inline ConfigurationElement::ConfigurationElement(const string Name) : // Construct with a c++ string.
myName(Name),
myParent(NULL),
myLine(0),
myIndex(0),
myLength(0),
myCleanFlag(true),
myInitOnInterpretFlag(false) {
}

inline ConfigurationElement::ConfigurationElement( // Construct sub element w/ cstring.
const char* Name,
ConfigurationElement& Parent) :

myName(string(Name)),
myParent(&Parent),
myLine(0),
myIndex(0),
myLength(0),
myCleanFlag(true),
myInitOnInterpretFlag(false) {
}

inline ConfigurationElement::ConfigurationElement( // Construct sub element w/ string.
const string Name,
ConfigurationElement& Parent) :

myName(Name),
myParent(&Parent),
myLine(0),
myIndex(0),
myLength(0),
myCleanFlag(true),
myInitOnInterpretFlag(false) {
}

inline string ConfigurationElement::Name() { return myName; } // Get the name of this element.

inline ConfigurationElement& ConfigurationElement::Parent() { // Get the parrent of this element.
if(NULL != myParent) { // If I have a parent
return (*myParent); // then I dereference and return it.
} // If I don't have a parent
return (*this); // then I return myself.
}

inline ConfigurationElement& ConfigurationElement::Parent( // Set the parrent of this element.
ConfigurationElement& Parent) { // Given this parent
myParent = &Parent; // I take and store it's address
return (*myParent); // then dereference and return it.
}

inline int ConfigurationElement::Line() { return myLine; } // Get the last line number.

inline int ConfigurationElement::Index() { return myIndex; } // Get the last data position.

inline int ConfigurationElement::Length() { return myLength; } // Get the last length.

inline void ConfigurationElement::notifyDirty() { myCleanFlag = false; } // Attributes do this when they change.

inline ConfigurationElement& ConfigurationElement::Element(const char* Name) { // Add a new sub element by c string name.
return Element(string(Name)); // Use the string name version
}

inline ConfigurationElement& ConfigurationElement::Element(const string Name) { // Add a new sub element by c++ string name.
ConfigurationElement* N = new ConfigurationElement( // Create a new Element with the
Name, // name provided and
(*this)); // myself as the parent.

myElements.push_back(N); // Add it to the list.
return (*N); // Return the new element.
}

inline ConfigurationElement& ConfigurationElement::Element( // Mapping factory for convenience,
const char* Name, // requires a name, of course,
ConfigurationTranslator& newTranslator) { // Add a Translator to this element.
return Element(string(Name), newTranslator); // Use the string name version
}

inline ConfigurationElement& ConfigurationElement::Element( // Mapping factory for convenience,
const char* Name, // requires a name, of course,
string& x, string init) { // Map to a string.
return Element(string(Name), x, init); // Use the string name version
}

inline ConfigurationElement& ConfigurationElement::Element( // Mapping factory for convenience,
const char* Name, // requires a name, of course,
int& x, int init, int radix) { // Map to an int.
return Element(string(Name), x, init, radix); // Use the string name version
}

inline ConfigurationElement& ConfigurationElement::Element( // Mapping factory for convenience,
const char* Name, // requires a name, of course,
double& x, double init) { // Map to a double.
return Element(string(Name), x, init); // Use the string name version
}

inline ConfigurationElement& ConfigurationElement::Element( // Mapping factory for convenience,
const char* Name, // requires a name, of course,
bool& x, bool init) { // Map to a boolean.
return Element(string(Name), x, init); // Use the string name version
}

inline ConfigurationElement& ConfigurationElement::End() { // Return this element's parent.
return Parent(); // Borrow Parent()
}

inline ConfigurationElement& ConfigurationElement::End(const char* Name) { // Check the name and return the parent
return End(string(Name)); // Borrow End(string)
}

inline ConfigurationElement& ConfigurationElement::End(const string Name) { // if the name is correct - or throw!
if(0 != Name.compare(myName)) { // If Name is not myName
throw EndNameDoesNotMatch(); // throw an exception!
} // If the names match then
return Parent(); // return the parent.
}

inline ConfigurationAttribute& ConfigurationElement::Attribute( // Add an attribute using a cstring.
const char* Name) { // Given this cstring name
return Attribute(string(Name)); // Convert it to a string and borrow
} // Attribute(string)

inline ConfigurationAttribute& ConfigurationElement::Attribute( // Mapping factory for convenience,
const char* Name, // requires a name, of course,
ConfigurationTranslator& newTranslator) { // Add a Translator to this element.
return Attribute(string(Name), newTranslator); // Borrow the string name version
}

inline ConfigurationAttribute& ConfigurationElement::Attribute( // Mapping factory for convenience,
const char* Name, // requires a name, of course,
string& x, string init) { // Map to a string.
return Attribute(string(Name), x, init); // Borrow the string name version
}

inline ConfigurationAttribute& ConfigurationElement::Attribute( // Mapping factory for convenience,
const char* Name, // requires a name, of course,
int& x, int init, int radix) { // Map to an int.
return Attribute(string(Name), x, init); // Borrow the string name version
}

inline ConfigurationAttribute& ConfigurationElement::Attribute( // Mapping factory for convenience,
const char* Name, // requires a name, of course,
double& x, double init) { // Map to a double.
return Attribute(string(Name), x, init); // Borrow the string name version
}

inline ConfigurationAttribute& ConfigurationElement::Attribute( // Mapping factory for convenience,
const char* Name, // requires a name, of course,
bool& x, bool init) { // Map to a boolean.
return Attribute(string(Name), x, init); // Borrow the string name version
}

inline ConfigurationElement& ConfigurationElement::setInitOnInterpret() { // Set the init on interpret flag.
myInitOnInterpretFlag = true; // Set the flag.
return(*this); // Dereference and return self.
}

inline ConfigurationElement& ConfigurationElement::atStartCall( // Add an atStart call-back.
Configurator& Functor) { // Given this Functor,
myStartConfigurators.push_back(&Functor); // add it to my atStart list then
return(*this); // dereference and return myself.
}

inline ConfigurationElement& ConfigurationElement::atEndCall( // Add an atEnd call-back.
Configurator& Functor) { // Given this Functor,
myEndConfigurators.push_back(&Functor); // add it to my atEnd list then
return(*this); // dereference and return myself.
}

inline ConfigurationElement& ConfigurationElement::Mnemonic( // Add a mnemonic using c strings.
const char* name, const char* value) { // Given char* and char*
return Mnemonic(string(name), string(value)); // make strings and borrow that method.
}

inline ConfigurationElement& ConfigurationElement::Mnemonic( // Add a mnemonic using mixed strings.
const char* name, const string value) { // Given char* and string
return Mnemonic(string(name), value); // make strings and borrow that method.
}

inline ConfigurationElement& ConfigurationElement::Mnemonic( // Add a mnemonic using mixed strings.
const string name, const char* value) { // Given string and char*
return Mnemonic(name, string(value)); // make strings and borrow that method.
}

inline ConfigurationElement& ConfigurationElement::Mnemonic( // Add a mnemonic using c++ strings.
const string name, const string value) { // Givent string and string
ConfigurationMnemonic* N = // Create a new Mnemonic
new ConfigurationMnemonic(name, value); // using the values provided,
myMnemonics.push_back(N); // add it to my list, then
return(*this); // dereference and return myself.
}

//// Configuration Attribute ///////////////////////////////////////////////////

inline ConfigurationAttribute::ConfigurationAttribute( // Attributes are constructed with a
const char* Name, ConfigurationElement& Parent) : // Name and a Parent.
myName(string(Name)), // We convert the name to a string.
myParent(Parent), // We just grab the parent.
myLine(0), // Everything else gets zeroed.
myIndex(0),
myLength(0) {
}

inline ConfigurationAttribute::ConfigurationAttribute( // Attributes are constrictued with a
const string Name, ConfigurationElement& Parent) : // Name and a Parent.
myName(Name), // We grab them and zero the rest.
myParent(Parent),
myLine(0),
myIndex(0),
myLength(0) {
}

inline string ConfigurationAttribute::Name() { // Get the name of this attribute.
return myName;
}

inline ConfigurationElement& ConfigurationAttribute::Parent() { // Get the parent of this attribute.
return myParent;
}

inline int ConfigurationAttribute::Line() { // Get the last line number.
return myLine;
}

inline int ConfigurationAttribute::Index() { // Get the last data position.
return myIndex;
}

inline int ConfigurationAttribute::Length() { // Get the last length.
return myLength;
}

inline ConfigurationElement& ConfigurationAttribute::Element( // Add a new sub element by c string name.
const char* Name) {
return myParent.Element(Name);
}

inline ConfigurationElement& ConfigurationAttribute::Element( // Add a new sub element by c++ string name.
const string Name) {
return myParent.Element(Name);
}

inline ConfigurationElement& ConfigurationAttribute::Element( // Mapping factory for convenience,
const char* Name, // requires a name, of course,
ConfigurationTranslator& newTranslator) { // Add a Translator to this element.
return myParent.Element(Name, newTranslator);
}

inline ConfigurationElement& ConfigurationAttribute::Element( // Mapping factory for convenience,
const char* Name, // requires a name, of course,
string& x, string init) { // Map to a string.
return myParent.Element(Name, x, init);
}

inline ConfigurationElement& ConfigurationAttribute::Element( // Mapping factory for convenience,
const char* Name, // requires a name, of course,
int& x, int init, int radix) { // Map to an int.
return myParent.Element(Name, x, init, radix);
}

inline ConfigurationElement& ConfigurationAttribute::Element( // Mapping factory for convenience,
const char* Name, // requires a name, of course,
double& x, double init) { // Map to a double.
return myParent.Element(Name, x, init);
}

inline ConfigurationElement& ConfigurationAttribute::Element( // Mapping factory for convenience,
const char* Name, // requires a name, of course,
bool& x, bool init) { // Map to a boolean.
return myParent.Element(Name, x, init);
}

inline ConfigurationElement& ConfigurationAttribute::Element( // Mapping factory for convenience,
const string Name, // requires a name, of course,
ConfigurationTranslator& newTranslator) { // Add a Translator to this element.
return myParent.Element(Name, newTranslator);
}

inline ConfigurationElement& ConfigurationAttribute::Element( // Mapping factory for convenience,
const string Name, // requires a name, of course,
string& x, string init) { // Map to a string.
return myParent.Element(Name, x, init);
}

inline ConfigurationElement& ConfigurationAttribute::Element( // Mapping factory for convenience,
const string Name, // requires a name, of course,
int& x, int init, int radix) { // Map to an int.
return myParent.Element(Name, x, init, radix);
}

inline ConfigurationElement& ConfigurationAttribute::Element( // Mapping factory for convenience,
const string Name, // requires a name, of course,
double& x, double init) { // Map to a double.
return myParent.Element(Name, x, init);
}

inline ConfigurationElement& ConfigurationAttribute::Element( // Mapping factory for convenience,
const string Name, // requires a name, of course,
bool& x, bool init) { // Map to a boolean.
return myParent.Element(Name, x, init);
}

inline ConfigurationElement& ConfigurationAttribute::End() { // Return this element's parent.
return myParent.End();
}

inline ConfigurationElement& ConfigurationAttribute::End(const char* Name) { // Check the name and return the parent
return myParent.End(Name);
}

inline ConfigurationElement& ConfigurationAttribute::End(const string Name) { // if the name is correct - or throw!
return myParent.End(Name);
}

inline ConfigurationAttribute& ConfigurationAttribute::Attribute( // Add an attribute using a cstring.
const char* Name) {
return myParent.Attribute(Name);
}

inline ConfigurationAttribute& ConfigurationAttribute::Attribute( // Add an attribute using a c++ string.
const string Name) {
return myParent.Attribute(Name);
}

inline ConfigurationAttribute& ConfigurationAttribute::Attribute( // Mapping factory for convenience,
const char* Name, // requires a name, of course,
ConfigurationTranslator& newTranslator) { // Add a Translator to this element.
return myParent.Attribute(Name, newTranslator);
}

inline ConfigurationAttribute& ConfigurationAttribute::Attribute( // Mapping factory for convenience,
const char* Name, // requires a name, of course,
string& x, string init) { // Map to a string.
return myParent.Attribute(Name, x, init);
}

inline ConfigurationAttribute& ConfigurationAttribute::Attribute( // Mapping factory for convenience,
const char* Name, // requires a name, of course,
int& x, int init, int radix) { // Map to an int.
return myParent.Attribute(Name, x, init, radix);
}

inline ConfigurationAttribute& ConfigurationAttribute::Attribute( // Mapping factory for convenience,
const char* Name, // requires a name, of course,
double& x, double init) { // Map to a double.
return myParent.Attribute(Name, x, init);
}

inline ConfigurationAttribute& ConfigurationAttribute::Attribute( // Mapping factory for convenience,
const char* Name, // requires a name, of course,
bool& x, bool init) { // Map to a boolean.
return myParent.Attribute(Name, x, init);
}

inline ConfigurationAttribute& ConfigurationAttribute::Attribute( // Mapping factory for convenience,
const string Name, // requires a name, of course,
ConfigurationTranslator& newTranslator) { // Add a Translator to this element.
return myParent.Attribute(Name, newTranslator);
}

inline ConfigurationAttribute& ConfigurationAttribute::Attribute( // Mapping factory for convenience,
const string Name, // requires a name, of course,
string& x, string init) { // Map to a string.
return myParent.Attribute(Name, x, init);
}

inline ConfigurationAttribute& ConfigurationAttribute::Attribute( // Mapping factory for convenience,
const string Name, // requires a name, of course,
int& x, int init, int radix) { // Map to an int.
return myParent.Attribute(Name, x, init, radix);
}

inline ConfigurationAttribute& ConfigurationAttribute::Attribute( // Mapping factory for convenience,
const string Name, // requires a name, of course,
double& x, double init) { // Map to a double.
return myParent.Attribute(Name, x, init);
}

inline ConfigurationAttribute& ConfigurationAttribute::Attribute( // Mapping factory for convenience,
const string Name, // requires a name, of course,
bool& x, bool init) { // Map to a boolean.
return myParent.Attribute(Name, x, init);
}

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

inline ConfigurationElement& ConfigurationAttribute::atStartCall( // Add an atStart call-back to this element.
Configurator& Functor) {
return myParent.atStartCall(Functor);
}

inline ConfigurationElement& ConfigurationAttribute::atEndCall( // Add an atEnd call-back to this element.
Configurator& Functor) {
return myParent.atEndCall(Functor);
}

inline ConfigurationAttribute& ConfigurationAttribute::Mnemonic( // Add a mnemonic using c strings.
const char* name, const char* value) { // Given char* and char*
return Mnemonic(string(name), string(value)); // make strings and borrow that method.
}

inline ConfigurationAttribute& ConfigurationAttribute::Mnemonic( // Add a mnemonic using mixed strings.
const char* name, const string value) { // Given char* and string
return Mnemonic(string(name), value); // make strings and borrow that method.
}

inline ConfigurationAttribute& ConfigurationAttribute::Mnemonic( // Add a mnemonic using mixed strings.
const string name, const char* value) { // Given string and char*
return Mnemonic(name, string(value)); // make strings and borrow that method.
}

inline ConfigurationAttribute& ConfigurationAttribute::Mnemonic( // Add a mnemonic using c++ strings.
const string name, const string value) { // Givent string and string
ConfigurationMnemonic* N = // Create a new Mnemonic
new ConfigurationMnemonic(name, value); // using the values provided,
myMnemonics.push_back(N); // add it to my list, then
return(*this); // dereference and return myself.
}

//// Configuration Data ////////////////////////////////////////////////////////

inline char ConfigurationData::Data(int Index) { // Returns char from Data[Index]
if(0 > Index || Index >= myBufferSize) { // Check that index is in range
return 0; // and return 0 if it is not.
} // If Index is within range then
return myDataBuffer[Index]; // return the byte requested.
}

inline int ConfigurationData::Index() { // Reads the current Index.
return myIndex;
}

inline int ConfigurationData::Index(int i) { // Changes the current Index.
if(0 > i || i >= myBufferSize) { // If i is out of range then
return myIndex; // return the current Index unchanged.
} // If i is within range then
myIndex = i; // change the Index to i and
return myIndex; // return the changed Index.
}

inline int ConfigurationData::Line() { // Reads the current Line number.
return myLine;
}

inline int ConfigurationData::addNewLines(int Count) { // Increments the Line number.
myLine += Count; // Add the number of new lines.
return myLine; // Return the current Line number.
}

//// Configuration Translator //////////////////////////////////////////////////

inline StringTranslator::StringTranslator( // Construct this with
string& Variable, // the variable to map,
string Initializer) : // and the default value.
myVariable(Variable),
myInitializer(Initializer) {
}

inline void StringTranslator::translate(const char* Value) { // Provide a translation method.
myVariable = string(Value); // String to String = simple copy.
}

inline void StringTranslator::initialize() { // Provide an initialization method.
myVariable = myInitializer; // Revert to the initializer value.
}

inline IntegerTranslator::IntegerTranslator( // Construct this with
int& Variable, // the variable to map,
int Initializer, // and the default value.
int Radix) : // For this one we also need a Radix.
myVariable(Variable),
myInitializer(Initializer),
myRadix(Radix) {
}

inline void IntegerTranslator::translate(const char* Value) { // Provide a translation method.
char* dummy; // Throw away ptr for strtol().
myVariable = strtol(Value, &dummy, myRadix); // Convert the string w/ strtol().
}

inline void IntegerTranslator::initialize() { // Provide an initialization method.
myVariable = myInitializer; // Revert to the initializer value.
}

inline DoubleTranslator::DoubleTranslator( // Construct this with
double& Variable, // the variable to map,
double Initializer) : // and the default value.
myVariable(Variable),
myInitializer(Initializer) {
}

inline void DoubleTranslator::translate(const char* Value) { // Provide a translation method.
char* dummy; // Throw away ptr for strtod().
myVariable = strtod(Value, &dummy); // Convert the string w/ strtod().
}

inline void DoubleTranslator::initialize() { // Provide an initialization method.
myVariable = myInitializer; // Revert to the initializer value.
}

inline BoolTranslator::BoolTranslator( // Construct this with
bool& Variable, // the variable to map,
bool Initializer) : // and the default value.
myVariable(Variable),
myInitializer(Initializer) {
}

inline void BoolTranslator::translate(const char* Value) { // Provide a translation method.
if(
(0 == strcmp(Value,"on")) ||
(0 == strcmp(Value,"true")) || // on, true, yes, and 1 are
(0 == strcmp(Value, "yes")) || // interpreted as a boolean true.
(0 == strcmp(Value, "1"))
) {
myVariable = true;
} else { // Anything else is interpreted as
myVariable = false; // boolean false.
}
}

inline void BoolTranslator::initialize() { // Provide an initialization method.
myVariable = myInitializer; // Revert to the initializer value.
}

//// Configuration Mnemonic ////////////////////////////////////////////////////

inline ConfigurationMnemonic::ConfigurationMnemonic( // To make one, provide both parts.
string Name, string Value) :
myName(Name),
myValue(Value) {
}

inline bool ConfigurationMnemonic::test(string Name) { // Test to see if this Mnemonic matches.
return (0 == Name.compare(myName)); // Return true if Name and myName match.
}

inline string ConfigurationMnemonic::Value() { // If it does then we will need it's value.
return myValue;
}

Loading…
Cancel
Save