|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242 |
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- #include "configuration.hpp"
-
- using namespace std;
-
-
-
-
-
-
- bool isNameChar(const char x) {
- return (
- isalnum(x) ||
- ('.' == x) ||
- ('-' == x) ||
- ('_' == x) ||
- (':' == x)
- );
- }
-
-
-
-
-
-
-
- int eatSpacesCountLines(ConfigurationData& Data, int& Index) {
- int LineCount = 0;
- char C = 0;
-
- for(;;) {
- C = Data.Data(Index);
- if(0 == C) {
- break;
- }
- if(isspace(C)) {
- if('\n' == C) {
- ++LineCount;
- }
- ++Index;
- } else {
- break;
- }
- }
- return LineCount;
- }
-
-
-
-
-
-
-
-
- int eatNonTagTextCountLines(ConfigurationData& Data, int& Index) {
- int LineCount = 0;
- char C = 0;
-
- for(;;) {
- C = Data.Data(Index);
- if(0 == C) {
- break;
- }
- if('\n' == C) {
- ++LineCount;
- } else
- if('<' == C) {
- break;
- }
- ++Index;
- }
- return LineCount;
- }
-
-
-
-
-
- int eatCommentsCountLines(ConfigurationData& Data, int& Index) {
- int LineCount = 0;
- char C = 0;
-
-
-
- if(
- Data.Data(Index) != '<' ||
- Data.Data(Index + 1) != '!' ||
- Data.Data(Index + 2) != '-' ||
- Data.Data(Index + 3) != '-'
- ) {
- return 0;
- }
-
-
-
- Index += 4;
-
- for(;;) {
- C = Data.Data(Index);
- if(0 == C) {
- break;
- }
- if('\n' == C) {
- ++LineCount;
- } else
- if('-' == C) {
- if(
- '-' == Data.Data(Index + 1) &&
- '>' == Data.Data(Index + 2)
- ) {
- Index += 3;
- break;
- }
- }
- ++Index;
- }
- return LineCount;
- }
-
-
-
-
- int eatDocSpecsCountLines(ConfigurationData& Data, int& Index) {
- int LineCount = 0;
- char C = 0;
-
-
-
- if(
- Data.Data(Index) != '<' ||
- Data.Data(Index + 1) != '?'
- ) {
- return 0;
- }
-
-
-
- for(;;) {
- C = Data.Data(Index);
- if(0 == C) {
- break;
- }
- if('\n' == C) {
- ++LineCount;
- } else
- if('?' == C) {
- if('>' == Data.Data(Index + 1)) {
- Index += 2;
- break;
- }
- }
- ++Index;
- }
- return LineCount;
- }
-
-
-
-
- int eatAttributeCountLines(ConfigurationData& Data, int& Index) {
- int LineCount = 0;
- char C = 0;
-
- while(isNameChar(Data.Data(Index))) ++Index;
-
- LineCount += eatSpacesCountLines(Data, Index);
-
- if('=' != Data.Data(Index)) {
- return LineCount;
- } else {
- ++Index;
- }
-
- LineCount += eatSpacesCountLines(Data, Index);
-
- C = Data.Data(Index);
- if(
- '\'' != Data.Data(Index) &&
- '\"' != Data.Data(Index)
- ) {
- return LineCount;
- } else {
- ++Index;
- }
-
- while(Data.Data(Index) != C) {
- if(0 == Data.Data(Index)) {
- return LineCount;
- } else
- if('\n' == Data.Data(Index)) {
- ++LineCount;
- }
- ++Index;
- }
- ++Index;
- return LineCount;
- }
-
-
-
-
- int eatElementCountLines(ConfigurationData& Data, int& Index) {
- int LineCount = 0;
-
-
-
- if(
- '<' != Data.Data(Index) ||
- false == isNameChar(Data.Data(Index + 1))
- ) {
- return 0;
- }
-
-
-
- ++Index;
- int NameIndex = Index;
-
- while(isNameChar(Data.Data(Index))) ++Index;
-
- int NameEndex = Index;
-
-
-
- for(;;) {
- if(0 == Data.Data(Index)) {
- return LineCount;
- }
-
- LineCount += eatSpacesCountLines(Data, Index);
-
- if(
- '/' == Data.Data(Index) &&
- '>' == Data.Data(Index + 1)
- ) {
- Index += 2;
- return LineCount;
- }
-
- if('>' == Data.Data(Index)) {
- ++Index;
- break;
- }
-
- ++Index;
- }
-
-
-
-
-
-
-
-
- while(
- '<' != Data.Data(Index) ||
- '/' != Data.Data(Index + 1)
- ) {
-
- int CheckIndex = Index;
-
- LineCount += eatNonTagTextCountLines(Data, Index);
- LineCount += eatElementCountLines(Data, Index);
- LineCount += eatCommentsCountLines(Data, Index);
- LineCount += eatDocSpecsCountLines(Data, Index);
-
-
-
- if(CheckIndex == Index) {
- break;
- }
- };
-
- if(
- '<' != Data.Data(Index) ||
- '/' != Data.Data(Index + 1)
- ) {
- return LineCount;
- }
-
-
-
-
-
-
- int t = 0;
- for(t = 0; (NameIndex + t) < NameEndex; t++) {
- if(Data.Data(NameIndex + t) != Data.Data(Index + 2 + t)) {
- return LineCount;
- }
- }
-
- if('>' == Data.Data(Index + 2 + t)) {
- Index += (3 + t);
- }
-
- return LineCount;
- }
-
-
-
-
-
-
-
- int copyDataCountLines(char* Bfr, ConfigurationData& Data, int Start, int End) {
- int Lines = 0;
- int DataIndex = Start;
- int BfrIndex = 0;
- char C = 0;
- while(DataIndex < End) {
- C = Data.Data(DataIndex);
- Bfr[BfrIndex] = C;
- if('\n' == C) {
- ++Lines;
- }
- ++BfrIndex;
- ++DataIndex;
- }
- Bfr[BfrIndex] = 0;
- return Lines;
- }
-
-
-
- ConfigurationElement::~ConfigurationElement() {
-
-
-
-
-
-
-
- if(0 < myAttributes.size()) {
- list<ConfigurationAttribute*>::iterator iAttribute;
- iAttribute = myAttributes.begin();
- while(iAttribute != myAttributes.end()) {
- delete (*iAttribute);
- iAttribute++;
- }
- myAttributes.clear();
- }
-
-
-
- if(0 < myElements.size()) {
- list<ConfigurationElement*>::iterator iElement;
- iElement = myElements.begin();
- while(iElement != myElements.end()) {
- delete (*iElement);
- iElement++;
- }
- myElements.clear();
- }
-
-
-
- if(0 < myMnemonics.size()) {
- list<ConfigurationMnemonic*>::iterator iMnemonic;
- iMnemonic = myMnemonics.begin();
- while(iMnemonic != myMnemonics.end()) {
- delete (*iMnemonic);
- iMnemonic++;
- }
- myMnemonics.clear();
- }
-
-
-
- if(0 < myTranslators.size()) {
- list<ConfigurationTranslator*>::iterator iTranslator;
- iTranslator = myTranslators.begin();
- while(iTranslator != myTranslators.end()) {
- delete (*iTranslator);
- iTranslator++;
- }
- myTranslators.clear();
- }
-
-
-
- myLine = 0;
- myIndex = 0;
- myLength = 0;
- myCleanFlag = true;
-
- }
-
- ConfigurationElement& ConfigurationElement::Element(
- const string Name,
- ConfigurationTranslator& newTranslator) {
-
- ConfigurationElement* N = new ConfigurationElement(
- Name,
- (*this));
-
- myElements.push_back(N);
- N->mapTo(newTranslator);
- return (*N);
- }
-
- ConfigurationElement& ConfigurationElement::Element(
- const string Name,
- string& x, string init) {
-
- ConfigurationElement* N = new ConfigurationElement(
- Name,
- (*this));
-
- myElements.push_back(N);
- N->mapTo(x, init);
- return (*N);
- }
-
- ConfigurationElement& ConfigurationElement::Element(
- const string Name,
- int& x, int init, int radix) {
-
- ConfigurationElement* N = new ConfigurationElement(
- Name,
- (*this));
-
- myElements.push_back(N);
- N->mapTo(x, init, radix);
- return (*N);
- }
-
- ConfigurationElement& ConfigurationElement::Element(
- const string Name,
- double& x, double init) {
-
- ConfigurationElement* N = new ConfigurationElement(
- Name,
- (*this));
-
- myElements.push_back(N);
- N->mapTo(x, init);
- return (*N);
- }
-
- ConfigurationElement& ConfigurationElement::Element(
- const string Name,
- bool& x, bool init) {
-
- ConfigurationElement* N = new ConfigurationElement(
- Name,
- (*this));
-
- myElements.push_back(N);
- N->mapTo(x, init);
- return (*N);
- }
-
- ConfigurationAttribute& ConfigurationElement::Attribute(const string Name) {
- ConfigurationAttribute* N =
- new ConfigurationAttribute(Name, (*this));
-
- myCleanFlag = false;
-
- myAttributes.push_back(N);
- return (*N);
- }
-
- ConfigurationAttribute& ConfigurationElement::Attribute(
- const string Name,
- ConfigurationTranslator& newTranslator) {
-
- myCleanFlag = false;
-
- ConfigurationAttribute* N =
- new ConfigurationAttribute(Name, (*this));
-
- myAttributes.push_back(N);
- N->mapTo(newTranslator);
- return(*N);
- }
-
- ConfigurationAttribute& ConfigurationElement::Attribute(
- const string Name,
- string& x, string init) {
-
- myCleanFlag = false;
-
- ConfigurationAttribute* N =
- new ConfigurationAttribute(Name, (*this));
-
- myAttributes.push_back(N);
- N->mapTo(x, init);
- return(*N);
- }
-
- ConfigurationAttribute& ConfigurationElement::Attribute(
- const string Name,
- int& x, int init, int radix) {
-
- myCleanFlag = false;
-
- ConfigurationAttribute* N =
- new ConfigurationAttribute(Name, (*this));
-
- myAttributes.push_back(N);
- N->mapTo(x, init, radix);
- return(*N);
- }
-
- ConfigurationAttribute& ConfigurationElement::Attribute(
- const string Name,
- double& x, double init) {
-
- myCleanFlag = false;
-
- ConfigurationAttribute* N =
- new ConfigurationAttribute(Name, (*this));
-
- myAttributes.push_back(N);
- N->mapTo(x, init);
- return(*N);
- }
-
- ConfigurationAttribute& ConfigurationElement::Attribute(
- const string Name,
- bool& x, bool init) {
-
- myCleanFlag = false;
-
- ConfigurationAttribute* N =
- new ConfigurationAttribute(Name, (*this));
-
- myAttributes.push_back(N);
- N->mapTo(x, init);
- return(*N);
- }
-
- ConfigurationElement& ConfigurationElement::mapTo(
- ConfigurationTranslator& newTranslator) {
- myTranslators.push_back(&newTranslator);
- myCleanFlag = false;
- return(*this);
- }
-
- ConfigurationElement& ConfigurationElement::mapTo(
- string& x, string init) {
- ConfigurationTranslator* N =
- new StringTranslator(x, init);
- myTranslators.push_back(N);
- myCleanFlag = false;
- return(*this);
- }
-
- ConfigurationElement& ConfigurationElement::mapTo(
- int& x, int init, int radix) {
- ConfigurationTranslator* N =
- new IntegerTranslator(x, init, radix);
- myTranslators.push_back(N);
- myCleanFlag = false;
- return(*this);
- }
-
- ConfigurationElement& ConfigurationElement::mapTo(
- double& x, double init) {
- ConfigurationTranslator* N =
- new DoubleTranslator(x, init);
- myTranslators.push_back(N);
- myCleanFlag = false;
- return(*this);
- }
-
- ConfigurationElement& ConfigurationElement::mapTo(
- bool& x, bool init) {
- ConfigurationTranslator* N =
- new BoolTranslator(x, init);
- myTranslators.push_back(N);
- myCleanFlag = false;
- return(*this);
- }
-
- void ConfigurationElement::initialize() {
-
-
-
- if(0 < myElements.size()) {
- list<ConfigurationElement*>::iterator iElement;
- iElement = myElements.begin();
- while(iElement != myElements.end()) {
- (*iElement)->initialize();
- iElement++;
- }
- }
-
-
-
- if(true == myCleanFlag) return;
-
-
-
- if(0 < myTranslators.size()) {
- list<ConfigurationTranslator*>::iterator iTranslator;
- iTranslator = myTranslators.begin();
- while(iTranslator != myTranslators.end()) {
- (*iTranslator)->initialize();
- iTranslator++;
- }
- }
-
-
-
- if(0 < myAttributes.size()) {
- list<ConfigurationAttribute*>::iterator iAttribute;
- iAttribute = myAttributes.begin();
- while(iAttribute != myAttributes.end()) {
- (*iAttribute)->initialize();
- ++iAttribute;
- }
- }
-
-
-
- myLine = 0;
- myIndex = 0;
- myLength = 0;
-
-
-
- myCleanFlag = true;
-
- }
-
- void ConfigurationElement::runStartConfigurators(ConfigurationData& D) {
- list<Configurator*>::iterator iConfigurator;
- iConfigurator = myStartConfigurators.begin();
- while(iConfigurator != myStartConfigurators.end()) {
- (** iConfigurator)(*this, D);
- ++iConfigurator;
- }
- }
-
- void ConfigurationElement::runEndConfigurators(ConfigurationData& D) {
- list<Configurator*>::iterator iConfigurator;
- iConfigurator = myEndConfigurators.begin();
- while(iConfigurator != myEndConfigurators.end()) {
- (** iConfigurator)(*this, D);
- ++iConfigurator;
- }
- }
-
- bool ConfigurationElement::interpret(ConfigurationData& Data) {
-
- int Index = Data.Index();
- int Startdex = 0;
- int Stopdex = 0;
- int NewLines = 0;
-
-
-
-
-
-
- for(;;) {
- int StartingPoint = Index;
- NewLines += eatNonTagTextCountLines(Data, Index);
- NewLines += eatCommentsCountLines(Data, Index);
- NewLines += eatDocSpecsCountLines(Data, Index);
- if(StartingPoint == Index) { break; }
- }
-
-
-
-
- Data.Index(Index);
- Data.addNewLines(NewLines);
- NewLines = 0;
-
-
-
- if(Data.Data(Index) != '<') {
- return false;
- } else {
- ++Index;
- }
-
- for(unsigned int I = 0; I < myName.length(); I++) {
- char x = Data.Data(Index + I);
- if(x != myName.at(I)) {
- return false;
- }
- }
- Index += myName.length();
-
-
-
-
- if(true == myInitOnInterpretFlag) {
- initialize();
- }
-
-
-
- myLine = Data.Line();
- myIndex = Data.Index();
- myLength = 0;
-
- runStartConfigurators(Data);
-
- myCleanFlag = false;
-
-
-
- bool ThisIsAnEmptyElement = false;
-
- for(;;) {
-
- NewLines += eatSpacesCountLines(Data, Index);
- Data.Index(Index);
- Data.addNewLines(NewLines);
- NewLines = 0;
-
-
-
-
-
-
-
- if(isalpha(Data.Data(Index))) {
- bool ParseHappened = false;
- list<ConfigurationAttribute*>::iterator iAttribute;
- iAttribute = myAttributes.begin();
- while(iAttribute != myAttributes.end()) {
- ParseHappened = (* iAttribute)->interpret(Data);
- ++iAttribute;
- if(ParseHappened) break;
- }
- if(false == ParseHappened) {
- NewLines += eatAttributeCountLines(Data, Index);
- Data.Index(Index);
- Data.addNewLines(NewLines);
- NewLines = 0;
- } else {
- Index = Data.Index();
- }
- } else
- if(0 == Data.Data(Index)) {
- break;
- } else
- if(
- '/' == Data.Data(Index) &&
- '>' == Data.Data(Index + 1)
- ) {
- ThisIsAnEmptyElement = true;
- Index += 2;
- break;
- } else
- if('>' == Data.Data(Index)) {
- Index += 1;
- break;
-
- } else {
- ++Index;
- }
- }
-
- Data.Index(Index);
-
-
-
-
- if(ThisIsAnEmptyElement) {
- runEndConfigurators(Data);
- return true;
- }
-
-
-
-
- Startdex = Index;
-
-
-
-
-
-
-
-
-
- for(;;) {
-
- int CheckPoint = Index;
-
-
-
- if(0 == Data.Data(Index)) {
- return false;
- } else
-
-
-
- if(
- '<' == Data.Data(Index) &&
- '/' == Data.Data(Index + 1)
- ) {
- Stopdex = Index;
- Index += 2;
- for(unsigned int I = 0; I < myName.length(); I++) {
- char x = Data.Data(Index + I);
- if(x != myName.at(I)) {
- return false;
- }
- }
- Index += myName.length();
- if('>' != Data.Data(Index)) {
- return false;
- } else {
- ++Index;
- break;
- }
- } else
-
-
-
- if(
- '<' == Data.Data(Index) &&
- isalpha(Data.Data(Index + 1))
- ) {
- bool ElementHappened = false;
- Data.Index(Index);
- Data.addNewLines(NewLines);
- NewLines = 0;
- if(0 < myElements.size()) {
-
- list<ConfigurationElement*>::iterator iElement;
- iElement = myElements.begin();
- while(iElement != myElements.end()) {
- ConfigurationElement& doNode = **iElement;
- ElementHappened = doNode.interpret(Data);
- Index = Data.Index();
- ++iElement;
- if(ElementHappened) break;
- }
- if(false == ElementHappened) {
- NewLines += eatElementCountLines(Data, Index);
- Data.Index(Index);
- Data.addNewLines(NewLines);
- NewLines = 0;
- }
- } else {
- NewLines += eatElementCountLines(Data, Index);
- }
-
-
-
- } else {
- NewLines += eatSpacesCountLines(Data, Index);
- NewLines += eatCommentsCountLines(Data, Index);
- NewLines += eatDocSpecsCountLines(Data, Index);
- NewLines += eatNonTagTextCountLines(Data, Index);
- Data.Index(Index);
- Data.addNewLines(NewLines);
- NewLines = 0;
- }
-
-
-
-
-
-
-
-
-
- if(CheckPoint == Index) return false;
- }
-
-
-
- Data.Index(Index);
- Data.addNewLines(NewLines);
- NewLines = 0;
-
-
-
-
- if(
- 0 < myTranslators.size() &&
- Stopdex > Startdex
- ) {
-
-
- int BfrSize = Stopdex - Startdex;
- char Bfr[BfrSize];
-
- copyDataCountLines(Bfr, Data, Startdex, Stopdex);
-
-
-
- char* TranslationData = Bfr;
-
-
-
- if(0 < myMnemonics.size()) {
- list<ConfigurationMnemonic*>::iterator iMnemonic;
- iMnemonic = myMnemonics.begin();
- while(iMnemonic != myMnemonics.end()) {
- if(true == ((*iMnemonic)->test(TranslationData))) {
- TranslationData = const_cast<char*>(
- (*iMnemonic)->Value().c_str());
- break;
- } else {
- ++iMnemonic;
- }
- }
- }
-
-
-
- list<ConfigurationTranslator*>::iterator iTranslator;
- iTranslator = myTranslators.begin();
- while(iTranslator != myTranslators.end()) {
- (*iTranslator)->translate(TranslationData);
- ++iTranslator;
- }
- }
-
-
-
- runEndConfigurators(Data);
- return true;
- }
-
-
-
- ConfigurationAttribute::~ConfigurationAttribute() {
-
-
-
- if(0 < myMnemonics.size()) {
- list<ConfigurationMnemonic*>::iterator iMnemonic;
- iMnemonic = myMnemonics.begin();
- while(iMnemonic != myMnemonics.end()) {
- delete (*iMnemonic);
- iMnemonic++;
- }
- myMnemonics.clear();
- }
-
-
-
- if(0 < myTranslators.size()) {
- list<ConfigurationTranslator*>::iterator iTranslator;
- iTranslator = myTranslators.begin();
- while(iTranslator != myTranslators.end()) {
- delete (*iTranslator);
- iTranslator++;
- }
- myTranslators.clear();
- }
-
-
-
- myLine = 0;
- myIndex = 0;
- myLength = 0;
- }
-
- ConfigurationAttribute& ConfigurationAttribute::mapTo(
- ConfigurationTranslator& newTranslator) {
- myTranslators.push_back(&newTranslator);
- myParent.notifyDirty();
- return(*this);
- }
-
- ConfigurationAttribute& ConfigurationAttribute::mapTo(
- string& x, string init) {
- ConfigurationTranslator* N =
- new StringTranslator(x, init);
- myTranslators.push_back(N);
- myParent.notifyDirty();
- return(*this);
- }
-
- ConfigurationAttribute& ConfigurationAttribute::mapTo(
- int& x, int init, int radix) {
- ConfigurationTranslator* N =
- new IntegerTranslator(x, init, radix);
- myTranslators.push_back(N);
- myParent.notifyDirty();
- return(*this);
- }
-
- ConfigurationAttribute& ConfigurationAttribute::mapTo(
- double& x, double init) {
- ConfigurationTranslator* N =
- new DoubleTranslator(x, init);
- myTranslators.push_back(N);
- myParent.notifyDirty();
- return(*this);
- }
-
- ConfigurationAttribute& ConfigurationAttribute::mapTo(
- bool& x, bool init) {
- ConfigurationTranslator* N =
- new BoolTranslator(x, init);
- myTranslators.push_back(N);
- myParent.notifyDirty();
- return(*this);
- }
-
- void ConfigurationAttribute::initialize() {
-
- if(0 < myTranslators.size()) {
- list<ConfigurationTranslator*>::iterator iTranslator;
- iTranslator = myTranslators.begin();
- while(iTranslator != myTranslators.end()) {
- (*iTranslator)->initialize();
- iTranslator++;
- }
- }
-
-
-
- myLine = 0;
- myIndex = 0;
- myLength = 0;
- }
-
- bool ConfigurationAttribute::interpret(ConfigurationData& Data) {
-
- int Index = Data.Index();
- int Startdex = 0;
- int Stopdex = 0;
- int NewLines = 0;
-
-
-
- for(unsigned int I = 0; I < myName.length(); I++) {
- char x = Data.Data(Index + I);
- if(x != myName.at(I)) {
- return false;
- }
- }
- Index += myName.length();
-
- NewLines += eatSpacesCountLines(Data, Index);
-
-
-
- if('=' != Data.Data(Index)) {
- return false;
- } else {
- ++Index;
- }
-
- NewLines += eatSpacesCountLines(Data, Index);
-
-
-
- char QuoteCharacter = 0;
- if('\'' == Data.Data(Index) || '\"' == Data.Data(Index)) {
- QuoteCharacter = Data.Data(Index);
- ++Index; Startdex = Index;
- } else {
- return false;
- }
-
-
-
- for(;;) {
- char C = Data.Data(Index);
- if(0 == C) {
- return false;
- }
- if(QuoteCharacter == C) {
- Stopdex = Index;
- break;
- }
- ++Index;
- }
-
-
-
- int BfrSize = Stopdex - Startdex;
- char Bfr[BfrSize];
-
- NewLines += copyDataCountLines(Bfr, Data, Startdex, Stopdex);
-
-
-
- char* TranslationData = Bfr;
-
-
-
- if(0 < myMnemonics.size()) {
- list<ConfigurationMnemonic*>::iterator iMnemonic;
- iMnemonic = myMnemonics.begin();
- while(iMnemonic != myMnemonics.end()) {
- if(true == ((*iMnemonic)->test(TranslationData))){
- TranslationData = const_cast<char*>(
- (*iMnemonic)->Value().c_str());
- break;
- } else {
- ++iMnemonic;
- }
- }
- }
-
-
-
- if(0 < myTranslators.size()) {
- list<ConfigurationTranslator*>::iterator iTranslator;
- iTranslator = myTranslators.begin();
- while(iTranslator != myTranslators.end()) {
- (*iTranslator)->translate(TranslationData);
- ++iTranslator;
- }
- }
-
-
-
- myLine = Data.Line();
- myIndex = Data.Index();
- myLength = Stopdex + 1 - myIndex;
-
-
-
- Data.Index(Stopdex + 1);
- Data.addNewLines(NewLines);
-
- return true;
- }
-
-
-
- ConfigurationData::ConfigurationData(const char* Data, int Length) :
- myBufferSize(Length),
- myIndex(0),
- myLine(1) {
- myDataBuffer = new char[myBufferSize];
- memcpy(myDataBuffer, Data, myBufferSize);
- }
-
- ConfigurationData::ConfigurationData(const char* FileName) :
- myDataBuffer(NULL),
- myBufferSize(0),
- myIndex(0),
- myLine(1) {
- try {
- ifstream CFGFile(FileName);
- CFGFile.seekg(0,ios::end);
- myBufferSize = CFGFile.tellg();
- myDataBuffer = new char[myBufferSize];
- CFGFile.seekg(0,ios::beg);
- CFGFile.read(myDataBuffer, myBufferSize);
- if(CFGFile.bad()) {
- delete[] myDataBuffer;
- myDataBuffer = NULL;
- myBufferSize = 0;
- }
- CFGFile.close();
- } catch (...) {
- if(NULL != myDataBuffer) {
- delete[] myDataBuffer;
- myDataBuffer = NULL;
- }
- myBufferSize = 0;
- }
- }
-
- ConfigurationData::ConfigurationData(const string FileName) :
- myDataBuffer(NULL),
- myBufferSize(0),
- myIndex(0),
- myLine(1) {
- try {
- ifstream CFGFile(FileName.c_str());
- CFGFile.seekg(0,ios::end);
- myBufferSize = CFGFile.tellg();
- myDataBuffer = new char[myBufferSize];
- CFGFile.seekg(0,ios::beg);
- CFGFile.read(myDataBuffer, myBufferSize);
- if(CFGFile.bad()) {
- delete[] myDataBuffer;
- myDataBuffer = NULL;
- myBufferSize = 0;
- }
- CFGFile.close();
- } catch (...) {
- if(NULL != myDataBuffer) {
- delete[] myDataBuffer;
- myDataBuffer = NULL;
- }
- myBufferSize = 0;
- }
- }
-
- ConfigurationData::~ConfigurationData() {
- if(NULL != myDataBuffer) {
- delete[] myDataBuffer;
- myDataBuffer = NULL;
- }
- myBufferSize = 0;
- myIndex = 0;
- myLine = 0;
- }
-
-
-
-
-
- ConfiguratorSetTrueOnComplete::ConfiguratorSetTrueOnComplete() :
- myBoolean(NULL) {
- }
-
- void ConfiguratorSetTrueOnComplete::setup(bool& Target) {
- myBoolean = &Target;
- }
-
- void ConfiguratorSetTrueOnComplete::operator()(
- ConfigurationElement& E, ConfigurationData& D) {
- if(NULL != myBoolean) {
- *myBoolean = true;
- }
- }
-
|