git-svn-id: https://svn.microneil.com/svn/CodeDweller/branches/adeniz_1@52 d34b734f-a00e-4b39-a726-e4eeb87269abadeniz_1
using namespace std; | using namespace std; | ||||
namespace CodeDweller { | |||||
//// Helper functions ////////////////////////////////////////////////////////// | //// Helper functions ////////////////////////////////////////////////////////// | ||||
// isNameChar(const char x) | // isNameChar(const char x) | ||||
} // true. | } // true. | ||||
} | } | ||||
} |
#include <cstdlib> | #include <cstdlib> | ||||
#include <list> | #include <list> | ||||
using namespace std; | |||||
namespace CodeDweller { | |||||
class ConfigurationElement; // Elements exist | class ConfigurationElement; // Elements exist | ||||
class ConfigurationAttribute; // Attributes exist | class ConfigurationAttribute; // Attributes exist | ||||
private: | private: | ||||
string myName; // Elements have a name. | |||||
std::string myName; // Elements have a name. | |||||
// External important things I remember but don't touch... | // External important things I remember but don't touch... | ||||
ConfigurationElement* myParent; // They may have a parrent. | 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... | // 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... | // During Interpret() operations we keep track of where we are seen... | ||||
public: | public: | ||||
ConfigurationElement(const char* Name); // Must be constructed with a name | 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 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: | // Upon desctruction an element will delete all subordinate objects: | ||||
// * All sub element objects. | // * All sub element objects. | ||||
// Elements can be probed for some simple, useful things. | // 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(); // Get the parent of this element. | ||||
ConfigurationElement& Parent(ConfigurationElement& newParent); // Set the parent of this element. | ConfigurationElement& Parent(ConfigurationElement& newParent); // Set the parent of this element. | ||||
// Elements can contain either data or sub-elements. | // 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 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. | //// Mapping element factory methods for convenience. | ||||
//// Root-Node elements are _usually_ empty and without attributes in xml | //// Root-Node elements are _usually_ empty and without attributes in xml | ||||
ConfigurationElement& Element( // Mapping factory for convenience, | ConfigurationElement& Element( // Mapping factory for convenience, | ||||
const char* Name, // requires a name, of course, | 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, | ConfigurationElement& Element( // Mapping factory for convenience, | ||||
const char* Name, // requires a name, of course, | const char* Name, // requires a name, of course, | ||||
// string versions | // string versions | ||||
ConfigurationElement& Element( // Mapping factory for convenience, | 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. | ConfigurationTranslator& newTranslator); // Add a Translator to this element. | ||||
ConfigurationElement& Element( // Mapping factory for convenience, | 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, | 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. | int& x, int init = 0, int radix = 0); // Map to an int. | ||||
ConfigurationElement& Element( // Mapping factory for convenience, | 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. | double& x, double init = 0.0); // Map to a double. | ||||
ConfigurationElement& Element( // Mapping factory for convenience, | 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. | bool& x, bool init = false); // Map to a boolean. | ||||
// 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. | ||||
ConfigurationElement& End(); // Return this element's parent. | ConfigurationElement& End(); // Return this element's parent. | ||||
ConfigurationElement& End(const char* Name); // Check the name and return the 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. | // Elements can have attributes. | ||||
ConfigurationAttribute& Attribute(const char* Name); // Add an attribute using a cstring. | 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. | //// Mapping Attribute factory methods for convenience. | ||||
ConfigurationAttribute& Attribute( // Mapping factory for convenience, | ConfigurationAttribute& Attribute( // Mapping factory for convenience, | ||||
const char* Name, // requires a name, of course, | 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, | ConfigurationAttribute& Attribute( // Mapping factory for convenience, | ||||
const char* Name, // requires a name, of course, | const char* Name, // requires a name, of course, | ||||
// string versions | // string versions | ||||
ConfigurationAttribute& Attribute( // Mapping factory for convenience, | 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. | ConfigurationTranslator& newTranslator); // Add a Translator to this element. | ||||
ConfigurationAttribute& Attribute( // Mapping factory for convenience, | 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, | 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. | int& x, int init = 0, int radix = 0); // Map to an int. | ||||
ConfigurationAttribute& Attribute( // Mapping factory for convenience, | 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. | double& x, double init = 0.0); // Map to a double. | ||||
ConfigurationAttribute& Attribute( // Mapping factory for convenience, | 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. | bool& x, bool init = false); // Map to a boolean. | ||||
// Elements can Initialize() at each Interpret() call. | // Elements can Initialize() at each Interpret() call. | ||||
// to the converted value. Usually - just one variable. | // to the converted value. Usually - just one variable. | ||||
ConfigurationElement& mapTo(ConfigurationTranslator& newTranslator); // Add a Translator to this element. | ConfigurationElement& mapTo(ConfigurationTranslator& newTranslator); // Add a Translator to this element. | ||||
ConfigurationElement& mapTo(string& x, string init = string("")); // Map to a string. | |||||
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(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(double& x, double init = 0.0); // Map to a double. | ||||
ConfigurationElement& mapTo(bool& x, bool init = false); // Map to a boolean. | ConfigurationElement& mapTo(bool& x, bool init = false); // Map to a boolean. | ||||
// passed to the Translators instead of the raw contents. | // 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 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 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 | // The way data gets into an element tree is that it is Interpret()ed | ||||
// recursively. The data is loaded into a ConfigurationData object which | // recursively. The data is loaded into a ConfigurationData object which | ||||
private: | private: | ||||
string myName; // Elements have a name. | |||||
std::string myName; // Elements have a name. | |||||
ConfigurationElement& myParent; // They may have a parrent. | 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 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. | ||||
public: | public: | ||||
ConfigurationAttribute(const char* Name, ConfigurationElement& Parent); // Sub-elements are constructed with a | ConfigurationAttribute(const char* Name, ConfigurationElement& Parent); // Sub-elements are constructed with a | ||||
ConfigurationAttribute(const string Name, ConfigurationElement& Parent); // parrent. | |||||
ConfigurationAttribute(const std::string Name, ConfigurationElement& Parent); // parrent. | |||||
// Attributes delete their Mnemonics and Translators when they go. | // Attributes delete their Mnemonics and Translators when they go. | ||||
// See Elements for similar warnings about objects provided to | // See Elements for similar warnings about objects provided to | ||||
// Attributes can be probed for some simple, useful things. | // 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. | ConfigurationElement& Parent(); // Get the parent of this attribute. | ||||
int Line(); // Get the last line number. | int Line(); // Get the last line number. | ||||
int Index(); // Get the last data position. | int Index(); // Get the last data position. | ||||
//// For switching back to the parent element and adding new sub-elements. | //// 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 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. | //// Mapping element factory methods for convenience. | ||||
//// Root-Node elements are _usually_ empty and without attributes in xml | //// Root-Node elements are _usually_ empty and without attributes in xml | ||||
ConfigurationElement& Element( // Mapping factory for convenience, | ConfigurationElement& Element( // Mapping factory for convenience, | ||||
const char* Name, // requires a name, of course, | 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, | ConfigurationElement& Element( // Mapping factory for convenience, | ||||
const char* Name, // requires a name, of course, | const char* Name, // requires a name, of course, | ||||
// string versions | // string versions | ||||
ConfigurationElement& Element( // Mapping factory for convenience, | 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. | ConfigurationTranslator& newTranslator); // Add a Translator to this element. | ||||
ConfigurationElement& Element( // Mapping factory for convenience, | 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, | 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. | int& x, int init = 0, int radix = 0); // Map to an int. | ||||
ConfigurationElement& Element( // Mapping factory for convenience, | 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. | double& x, double init = 0.0); // Map to a double. | ||||
ConfigurationElement& Element( // Mapping factory for convenience, | 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. | bool& x, bool init = false); // Map to a boolean. | ||||
// 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. | ||||
ConfigurationElement& End(); // Return this element's parent. | ConfigurationElement& End(); // Return this element's parent. | ||||
ConfigurationElement& End(const char* Name); // Check the name and return the 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. | //// For adding new attributes to the parent element. | ||||
ConfigurationAttribute& Attribute(const char* Name); // Add an attribute using a cstring. | 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. | //// Mapping Attribute factory methods for convenience. | ||||
ConfigurationAttribute& Attribute( // Mapping factory for convenience, | ConfigurationAttribute& Attribute( // Mapping factory for convenience, | ||||
const char* Name, // requires a name, of course, | 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, | ConfigurationAttribute& Attribute( // Mapping factory for convenience, | ||||
const char* Name, // requires a name, of course, | const char* Name, // requires a name, of course, | ||||
// string versions | // string versions | ||||
ConfigurationAttribute& Attribute( // Mapping factory for convenience, | 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. | ConfigurationTranslator& newTranslator); // Add a Translator to this element. | ||||
ConfigurationAttribute& Attribute( // Mapping factory for convenience, | 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, | 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. | int& x, int init = 0, int radix = 0); // Map to an int. | ||||
ConfigurationAttribute& Attribute( // Mapping factory for convenience, | 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. | double& x, double init = 0.0); // Map to a double. | ||||
ConfigurationAttribute& Attribute( // Mapping factory for convenience, | 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. | bool& x, bool init = false); // Map to a boolean. | ||||
//// Set Init On Interprete for the parent element. | //// Set Init On Interprete for the parent element. | ||||
// attribute. | // attribute. | ||||
ConfigurationAttribute& mapTo(ConfigurationTranslator& newTranslator); // Add a Translator to 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(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(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(double& x, double init = 0.0); // Map to a double. | ||||
ConfigurationAttribute& mapTo(bool& x, bool init = false); // Map to a boolean. | ConfigurationAttribute& mapTo(bool& x, bool init = false); // Map to a boolean. | ||||
// Attributes can have mnemonics just like elements. | // 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 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 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. | // Attributes participate in the Interprete() task just like elements. | ||||
public: | public: | ||||
ConfigurationData(const char* FileName); // Constructor from c string file name. | 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(const char* Data, int Length); // Raw constructor from text buffer. | ||||
~ConfigurationData(); // Destroys the internal buffer etc. | ~ConfigurationData(); // Destroys the internal buffer etc. | ||||
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. | ||||
stringstream Log; // Convenient Interpret log. | |||||
std::stringstream Log; // Convenient Interpret log. | |||||
}; | }; | ||||
class StringTranslator : public ConfigurationTranslator { | class StringTranslator : public ConfigurationTranslator { | ||||
private: | private: | ||||
string& myVariable; // Variable to map. | |||||
string myInitializer; // Initial/Default value. | |||||
std::string& myVariable; // Variable to map. | |||||
std::string myInitializer; // Initial/Default value. | |||||
public: | public: | ||||
StringTranslator( // Construct this with | 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 translate(const char* Value); // Provide a translation method. | ||||
void initialize(); // Provide an initialization method. | void initialize(); // Provide an initialization method. | ||||
class ConfigurationMnemonic { // Mnemonics | class ConfigurationMnemonic { // Mnemonics | ||||
private: | 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: | 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 ////////////////////////////////////////////////////////////// | //// Configurator ////////////////////////////////////////////////////////////// | ||||
void operator()(ConfigurationElement& E, ConfigurationData& D); // Handle the operation. | void operator()(ConfigurationElement& E, ConfigurationData& D); // Handle the operation. | ||||
}; | }; | ||||
} | |||||
#endif | #endif | ||||
// End Of Include Only Once | // End Of Include Only Once |
//// Configuration Element ///////////////////////////////////////////////////// | //// Configuration Element ///////////////////////////////////////////////////// | ||||
inline ConfigurationElement::ConfigurationElement(const char* Name) : // Construct with a cstring. | inline ConfigurationElement::ConfigurationElement(const char* Name) : // Construct with a cstring. | ||||
myName(string(Name)), | |||||
myName(std::string(Name)), | |||||
myParent(NULL), | myParent(NULL), | ||||
myLine(0), | myLine(0), | ||||
myIndex(0), | myIndex(0), | ||||
myInitOnInterpretFlag(false) { | myInitOnInterpretFlag(false) { | ||||
} | } | ||||
inline ConfigurationElement::ConfigurationElement(const string Name) : // Construct with a c++ string. | |||||
inline ConfigurationElement::ConfigurationElement(const std::string Name) : // Construct with a c++ string. | |||||
myName(Name), | myName(Name), | ||||
myParent(NULL), | myParent(NULL), | ||||
myLine(0), | myLine(0), | ||||
const char* Name, | const char* Name, | ||||
ConfigurationElement& Parent) : | ConfigurationElement& Parent) : | ||||
myName(string(Name)), | |||||
myName(std::string(Name)), | |||||
myParent(&Parent), | myParent(&Parent), | ||||
myLine(0), | myLine(0), | ||||
myIndex(0), | myIndex(0), | ||||
} | } | ||||
inline ConfigurationElement::ConfigurationElement( // Construct sub element w/ string. | inline ConfigurationElement::ConfigurationElement( // Construct sub element w/ string. | ||||
const string Name, | |||||
const std::string Name, | |||||
ConfigurationElement& Parent) : | ConfigurationElement& Parent) : | ||||
myName(Name), | myName(Name), | ||||
myInitOnInterpretFlag(false) { | myInitOnInterpretFlag(false) { | ||||
} | } | ||||
inline string ConfigurationElement::Name() { return myName; } // Get the name of this element. | |||||
inline std::string ConfigurationElement::Name() { return myName; } // Get the name of this element. | |||||
inline ConfigurationElement& ConfigurationElement::Parent() { // Get the parrent of this element. | inline ConfigurationElement& ConfigurationElement::Parent() { // Get the parrent of this element. | ||||
if(NULL != myParent) { // If I have a parent | if(NULL != myParent) { // If I have a parent | ||||
inline void ConfigurationElement::notifyDirty() { myCleanFlag = false; } // Attributes do this when they change. | 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. | 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 | |||||
return Element(std::string(Name)); // Use the string name version | |||||
} | } | ||||
inline ConfigurationElement& ConfigurationElement::Element(const string Name) { // Add a new sub element by c++ string name. | |||||
inline 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 | ConfigurationElement* N = new ConfigurationElement( // Create a new Element with the | ||||
Name, // name provided and | Name, // name provided and | ||||
(*this)); // myself as the parent. | (*this)); // myself as the parent. | ||||
inline ConfigurationElement& ConfigurationElement::Element( // Mapping factory for convenience, | inline ConfigurationElement& ConfigurationElement::Element( // Mapping factory for convenience, | ||||
const char* Name, // requires a name, of course, | const char* Name, // requires a name, of course, | ||||
ConfigurationTranslator& newTranslator) { // Add a Translator to this element. | ConfigurationTranslator& newTranslator) { // Add a Translator to this element. | ||||
return Element(string(Name), newTranslator); // Use the string name version | |||||
return Element(std::string(Name), newTranslator); // Use the string name version | |||||
} | } | ||||
inline ConfigurationElement& ConfigurationElement::Element( // Mapping factory for convenience, | inline ConfigurationElement& ConfigurationElement::Element( // Mapping factory for convenience, | ||||
const char* Name, // requires a name, of course, | 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 | |||||
std::string& x, std::string init) { // Map to a string. | |||||
return Element(std::string(Name), x, init); // Use the string name version | |||||
} | } | ||||
inline ConfigurationElement& ConfigurationElement::Element( // Mapping factory for convenience, | inline ConfigurationElement& ConfigurationElement::Element( // Mapping factory for convenience, | ||||
const char* Name, // requires a name, of course, | const char* Name, // requires a name, of course, | ||||
int& x, int init, int radix) { // Map to an int. | int& x, int init, int radix) { // Map to an int. | ||||
return Element(string(Name), x, init, radix); // Use the string name version | |||||
return Element(std::string(Name), x, init, radix); // Use the string name version | |||||
} | } | ||||
inline ConfigurationElement& ConfigurationElement::Element( // Mapping factory for convenience, | inline ConfigurationElement& ConfigurationElement::Element( // Mapping factory for convenience, | ||||
const char* Name, // requires a name, of course, | const char* Name, // requires a name, of course, | ||||
double& x, double init) { // Map to a double. | double& x, double init) { // Map to a double. | ||||
return Element(string(Name), x, init); // Use the string name version | |||||
return Element(std::string(Name), x, init); // Use the string name version | |||||
} | } | ||||
inline ConfigurationElement& ConfigurationElement::Element( // Mapping factory for convenience, | inline ConfigurationElement& ConfigurationElement::Element( // Mapping factory for convenience, | ||||
const char* Name, // requires a name, of course, | const char* Name, // requires a name, of course, | ||||
bool& x, bool init) { // Map to a boolean. | bool& x, bool init) { // Map to a boolean. | ||||
return Element(string(Name), x, init); // Use the string name version | |||||
return Element(std::string(Name), x, init); // Use the string name version | |||||
} | } | ||||
inline ConfigurationElement& ConfigurationElement::End() { // Return this element's parent. | inline ConfigurationElement& ConfigurationElement::End() { // Return this element's parent. | ||||
} | } | ||||
inline ConfigurationElement& ConfigurationElement::End(const char* Name) { // Check the name and return the parent | inline ConfigurationElement& ConfigurationElement::End(const char* Name) { // Check the name and return the parent | ||||
return End(string(Name)); // Borrow End(string) | |||||
return End(std::string(Name)); // Borrow End(string) | |||||
} | } | ||||
inline ConfigurationElement& ConfigurationElement::End(const string Name) { // if the name is correct - or throw! | |||||
inline ConfigurationElement& ConfigurationElement::End(const std::string Name) {// if the name is correct - or throw! | |||||
if(0 != Name.compare(myName)) { // If Name is not myName | if(0 != Name.compare(myName)) { // If Name is not myName | ||||
throw EndNameDoesNotMatch(); // throw an exception! | throw EndNameDoesNotMatch(); // throw an exception! | ||||
} // If the names match then | } // If the names match then | ||||
inline ConfigurationAttribute& ConfigurationElement::Attribute( // Add an attribute using a cstring. | inline ConfigurationAttribute& ConfigurationElement::Attribute( // Add an attribute using a cstring. | ||||
const char* Name) { // Given this cstring name | const char* Name) { // Given this cstring name | ||||
return Attribute(string(Name)); // Convert it to a string and borrow | |||||
return Attribute(std::string(Name)); // Convert it to a string and borrow | |||||
} // Attribute(string) | } // Attribute(string) | ||||
inline ConfigurationAttribute& ConfigurationElement::Attribute( // Mapping factory for convenience, | inline ConfigurationAttribute& ConfigurationElement::Attribute( // Mapping factory for convenience, | ||||
const char* Name, // requires a name, of course, | const char* Name, // requires a name, of course, | ||||
ConfigurationTranslator& newTranslator) { // Add a Translator to this element. | ConfigurationTranslator& newTranslator) { // Add a Translator to this element. | ||||
return Attribute(string(Name), newTranslator); // Borrow the string name version | |||||
return Attribute(std::string(Name), newTranslator); // Borrow the string name version | |||||
} | } | ||||
inline ConfigurationAttribute& ConfigurationElement::Attribute( // Mapping factory for convenience, | inline ConfigurationAttribute& ConfigurationElement::Attribute( // Mapping factory for convenience, | ||||
const char* Name, // requires a name, of course, | 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 | |||||
std::string& x, std::string init) { // Map to a string. | |||||
return Attribute(std::string(Name), x, init); // Borrow the string name version | |||||
} | } | ||||
inline ConfigurationAttribute& ConfigurationElement::Attribute( // Mapping factory for convenience, | inline ConfigurationAttribute& ConfigurationElement::Attribute( // Mapping factory for convenience, | ||||
const char* Name, // requires a name, of course, | const char* Name, // requires a name, of course, | ||||
int& x, int init, int radix) { // Map to an int. | int& x, int init, int radix) { // Map to an int. | ||||
return Attribute(string(Name), x, init); // Borrow the string name version | |||||
return Attribute(std::string(Name), x, init); // Borrow the string name version | |||||
} | } | ||||
inline ConfigurationAttribute& ConfigurationElement::Attribute( // Mapping factory for convenience, | inline ConfigurationAttribute& ConfigurationElement::Attribute( // Mapping factory for convenience, | ||||
const char* Name, // requires a name, of course, | const char* Name, // requires a name, of course, | ||||
double& x, double init) { // Map to a double. | double& x, double init) { // Map to a double. | ||||
return Attribute(string(Name), x, init); // Borrow the string name version | |||||
return Attribute(std::string(Name), x, init); // Borrow the string name version | |||||
} | } | ||||
inline ConfigurationAttribute& ConfigurationElement::Attribute( // Mapping factory for convenience, | inline ConfigurationAttribute& ConfigurationElement::Attribute( // Mapping factory for convenience, | ||||
const char* Name, // requires a name, of course, | const char* Name, // requires a name, of course, | ||||
bool& x, bool init) { // Map to a boolean. | bool& x, bool init) { // Map to a boolean. | ||||
return Attribute(string(Name), x, init); // Borrow the string name version | |||||
return Attribute(std::string(Name), x, init); // Borrow the string name version | |||||
} | } | ||||
inline ConfigurationElement& ConfigurationElement::setInitOnInterpret() { // Set the init on interpret flag. | inline ConfigurationElement& ConfigurationElement::setInitOnInterpret() { // Set the init on interpret flag. | ||||
inline ConfigurationElement& ConfigurationElement::Mnemonic( // Add a mnemonic using c strings. | inline ConfigurationElement& ConfigurationElement::Mnemonic( // Add a mnemonic using c strings. | ||||
const char* name, const char* value) { // Given char* and char* | const char* name, const char* value) { // Given char* and char* | ||||
return Mnemonic(string(name), string(value)); // make strings and borrow that method. | |||||
return Mnemonic(std::string(name), std::string(value)); // make strings and borrow that method. | |||||
} | } | ||||
inline ConfigurationElement& ConfigurationElement::Mnemonic( // Add a mnemonic using mixed strings. | 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. | |||||
const char* name, const std::string value) { // Given char* and string | |||||
return Mnemonic(std::string(name), value); // make strings and borrow that method. | |||||
} | } | ||||
inline ConfigurationElement& ConfigurationElement::Mnemonic( // Add a mnemonic using mixed strings. | 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. | |||||
const std::string name, const char* value) { // Given string and char* | |||||
return Mnemonic(name, std::string(value)); // make strings and borrow that method. | |||||
} | } | ||||
inline ConfigurationElement& ConfigurationElement::Mnemonic( // Add a mnemonic using c++ strings. | inline ConfigurationElement& ConfigurationElement::Mnemonic( // Add a mnemonic using c++ strings. | ||||
const string name, const string value) { // Givent string and string | |||||
const std::string name, const std::string value) { // Givent string and string | |||||
ConfigurationMnemonic* N = // Create a new Mnemonic | ConfigurationMnemonic* N = // Create a new Mnemonic | ||||
new ConfigurationMnemonic(name, value); // using the values provided, | new ConfigurationMnemonic(name, value); // using the values provided, | ||||
myMnemonics.push_back(N); // add it to my list, then | myMnemonics.push_back(N); // add it to my list, then | ||||
inline ConfigurationAttribute::ConfigurationAttribute( // Attributes are constructed with a | inline ConfigurationAttribute::ConfigurationAttribute( // Attributes are constructed with a | ||||
const char* Name, ConfigurationElement& Parent) : // Name and a Parent. | const char* Name, ConfigurationElement& Parent) : // Name and a Parent. | ||||
myName(string(Name)), // We convert the name to a string. | |||||
myName(std::string(Name)), // We convert the name to a string. | |||||
myParent(Parent), // We just grab the parent. | myParent(Parent), // We just grab the parent. | ||||
myLine(0), // Everything else gets zeroed. | myLine(0), // Everything else gets zeroed. | ||||
myIndex(0), | myIndex(0), | ||||
} | } | ||||
inline ConfigurationAttribute::ConfigurationAttribute( // Attributes are constrictued with a | inline ConfigurationAttribute::ConfigurationAttribute( // Attributes are constrictued with a | ||||
const string Name, ConfigurationElement& Parent) : // Name and a Parent. | |||||
const std::string Name, ConfigurationElement& Parent) : // Name and a Parent. | |||||
myName(Name), // We grab them and zero the rest. | myName(Name), // We grab them and zero the rest. | ||||
myParent(Parent), | myParent(Parent), | ||||
myLine(0), | myLine(0), | ||||
myLength(0) { | myLength(0) { | ||||
} | } | ||||
inline string ConfigurationAttribute::Name() { // Get the name of this attribute. | |||||
inline std::string ConfigurationAttribute::Name() { // Get the name of this attribute. | |||||
return myName; | return myName; | ||||
} | } | ||||
} | } | ||||
inline ConfigurationElement& ConfigurationAttribute::Element( // Add a new sub element by c++ string name. | inline ConfigurationElement& ConfigurationAttribute::Element( // Add a new sub element by c++ string name. | ||||
const string Name) { | |||||
const std::string Name) { | |||||
return myParent.Element(Name); | return myParent.Element(Name); | ||||
} | } | ||||
inline ConfigurationElement& ConfigurationAttribute::Element( // Mapping factory for convenience, | inline ConfigurationElement& ConfigurationAttribute::Element( // Mapping factory for convenience, | ||||
const char* Name, // requires a name, of course, | const char* Name, // requires a name, of course, | ||||
string& x, string init) { // Map to a string. | |||||
std::string& x, std::string init) { // Map to a string. | |||||
return myParent.Element(Name, x, init); | return myParent.Element(Name, x, init); | ||||
} | } | ||||
} | } | ||||
inline ConfigurationElement& ConfigurationAttribute::Element( // Mapping factory for convenience, | inline ConfigurationElement& ConfigurationAttribute::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. | ConfigurationTranslator& newTranslator) { // Add a Translator to this element. | ||||
return myParent.Element(Name, newTranslator); | return myParent.Element(Name, newTranslator); | ||||
} | } | ||||
inline ConfigurationElement& ConfigurationAttribute::Element( // Mapping factory for convenience, | inline ConfigurationElement& ConfigurationAttribute::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. | |||||
return myParent.Element(Name, x, init); | return myParent.Element(Name, x, init); | ||||
} | } | ||||
inline ConfigurationElement& ConfigurationAttribute::Element( // Mapping factory for convenience, | inline ConfigurationElement& ConfigurationAttribute::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. | int& x, int init, int radix) { // Map to an int. | ||||
return myParent.Element(Name, x, init, radix); | return myParent.Element(Name, x, init, radix); | ||||
} | } | ||||
inline ConfigurationElement& ConfigurationAttribute::Element( // Mapping factory for convenience, | inline ConfigurationElement& ConfigurationAttribute::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. | double& x, double init) { // Map to a double. | ||||
return myParent.Element(Name, x, init); | return myParent.Element(Name, x, init); | ||||
} | } | ||||
inline ConfigurationElement& ConfigurationAttribute::Element( // Mapping factory for convenience, | inline ConfigurationElement& ConfigurationAttribute::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. | bool& x, bool init) { // Map to a boolean. | ||||
return myParent.Element(Name, x, init); | return myParent.Element(Name, x, init); | ||||
} | } | ||||
return myParent.End(Name); | return myParent.End(Name); | ||||
} | } | ||||
inline ConfigurationElement& ConfigurationAttribute::End(const string Name) { // if the name is correct - or throw! | |||||
inline ConfigurationElement& ConfigurationAttribute::End(const std::string Name) { // if the name is correct - or throw! | |||||
return myParent.End(Name); | return myParent.End(Name); | ||||
} | } | ||||
} | } | ||||
inline ConfigurationAttribute& ConfigurationAttribute::Attribute( // Add an attribute using a c++ string. | inline ConfigurationAttribute& ConfigurationAttribute::Attribute( // Add an attribute using a c++ string. | ||||
const string Name) { | |||||
const std::string Name) { | |||||
return myParent.Attribute(Name); | return myParent.Attribute(Name); | ||||
} | } | ||||
inline ConfigurationAttribute& ConfigurationAttribute::Attribute( // Mapping factory for convenience, | inline ConfigurationAttribute& ConfigurationAttribute::Attribute( // Mapping factory for convenience, | ||||
const char* Name, // requires a name, of course, | const char* Name, // requires a name, of course, | ||||
string& x, string init) { // Map to a string. | |||||
std::string& x, std::string init) { // Map to a string. | |||||
return myParent.Attribute(Name, x, init); | return myParent.Attribute(Name, x, init); | ||||
} | } | ||||
} | } | ||||
inline ConfigurationAttribute& ConfigurationAttribute::Attribute( // Mapping factory for convenience, | inline ConfigurationAttribute& 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. | ConfigurationTranslator& newTranslator) { // Add a Translator to this element. | ||||
return myParent.Attribute(Name, newTranslator); | return myParent.Attribute(Name, newTranslator); | ||||
} | } | ||||
inline ConfigurationAttribute& ConfigurationAttribute::Attribute( // Mapping factory for convenience, | inline ConfigurationAttribute& ConfigurationAttribute::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. | |||||
return myParent.Attribute(Name, x, init); | return myParent.Attribute(Name, x, init); | ||||
} | } | ||||
inline ConfigurationAttribute& ConfigurationAttribute::Attribute( // Mapping factory for convenience, | inline ConfigurationAttribute& 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, int radix) { // Map to an int. | int& x, int init, int radix) { // Map to an int. | ||||
return myParent.Attribute(Name, x, init, radix); | return myParent.Attribute(Name, x, init, radix); | ||||
} | } | ||||
inline ConfigurationAttribute& ConfigurationAttribute::Attribute( // Mapping factory for convenience, | inline ConfigurationAttribute& 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) { // Map to a double. | double& x, double init) { // Map to a double. | ||||
return myParent.Attribute(Name, x, init); | return myParent.Attribute(Name, x, init); | ||||
} | } | ||||
inline ConfigurationAttribute& ConfigurationAttribute::Attribute( // Mapping factory for convenience, | inline ConfigurationAttribute& 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) { // Map to a boolean. | bool& x, bool init) { // Map to a boolean. | ||||
return myParent.Attribute(Name, x, init); | return myParent.Attribute(Name, x, init); | ||||
} | } | ||||
inline ConfigurationAttribute& ConfigurationAttribute::Mnemonic( // Add a mnemonic using c strings. | inline ConfigurationAttribute& ConfigurationAttribute::Mnemonic( // Add a mnemonic using c strings. | ||||
const char* name, const char* value) { // Given char* and char* | const char* name, const char* value) { // Given char* and char* | ||||
return Mnemonic(string(name), string(value)); // make strings and borrow that method. | |||||
return Mnemonic(std::string(name), std::string(value)); // make strings and borrow that method. | |||||
} | } | ||||
inline ConfigurationAttribute& ConfigurationAttribute::Mnemonic( // Add a mnemonic using mixed strings. | 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. | |||||
const char* name, const std::string value) { // Given char* and string | |||||
return Mnemonic(std::string(name), value); // make strings and borrow that method. | |||||
} | } | ||||
inline ConfigurationAttribute& ConfigurationAttribute::Mnemonic( // Add a mnemonic using mixed strings. | 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. | |||||
const std::string name, const char* value) { // Given string and char* | |||||
return Mnemonic(name, std::string(value)); // make strings and borrow that method. | |||||
} | } | ||||
inline ConfigurationAttribute& ConfigurationAttribute::Mnemonic( // Add a mnemonic using c++ strings. | inline ConfigurationAttribute& ConfigurationAttribute::Mnemonic( // Add a mnemonic using c++ strings. | ||||
const string name, const string value) { // Givent string and string | |||||
const std::string name, const std::string value) { // Givent string and string | |||||
ConfigurationMnemonic* N = // Create a new Mnemonic | ConfigurationMnemonic* N = // Create a new Mnemonic | ||||
new ConfigurationMnemonic(name, value); // using the values provided, | new ConfigurationMnemonic(name, value); // using the values provided, | ||||
myMnemonics.push_back(N); // add it to my list, then | myMnemonics.push_back(N); // add it to my list, then | ||||
//// Configuration Translator ////////////////////////////////////////////////// | //// Configuration Translator ////////////////////////////////////////////////// | ||||
inline StringTranslator::StringTranslator( // Construct this with | inline StringTranslator::StringTranslator( // Construct this with | ||||
string& Variable, // the variable to map, | |||||
string Initializer) : // and the default value. | |||||
std::string& Variable, // the variable to map, | |||||
std::string Initializer) : // and the default value. | |||||
myVariable(Variable), | myVariable(Variable), | ||||
myInitializer(Initializer) { | myInitializer(Initializer) { | ||||
} | } | ||||
inline void StringTranslator::translate(const char* Value) { // Provide a translation method. | inline void StringTranslator::translate(const char* Value) { // Provide a translation method. | ||||
myVariable = string(Value); // String to String = simple copy. | |||||
myVariable = std::string(Value); // String to String = simple copy. | |||||
} | } | ||||
inline void StringTranslator::initialize() { // Provide an initialization method. | inline void StringTranslator::initialize() { // Provide an initialization method. | ||||
//// Configuration Mnemonic //////////////////////////////////////////////////// | //// Configuration Mnemonic //////////////////////////////////////////////////// | ||||
inline ConfigurationMnemonic::ConfigurationMnemonic( // To make one, provide both parts. | inline ConfigurationMnemonic::ConfigurationMnemonic( // To make one, provide both parts. | ||||
string Name, string Value) : | |||||
std::string Name, std::string Value) : | |||||
myName(Name), | myName(Name), | ||||
myValue(Value) { | myValue(Value) { | ||||
} | } | ||||
inline bool ConfigurationMnemonic::test(string Name) { // Test to see if this Mnemonic matches. | |||||
inline 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. | 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. | |||||
inline std::string ConfigurationMnemonic::Value() { // If it does then we will need it's value. | |||||
return myValue; | return myValue; | ||||
} | } |