|
|
|
|
|
|
|
|
#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 |