浏览代码

Backed out test code, and implemented ConfigurationElement::RawData.


git-svn-id: https://svn.microneil.com/svn/CodeDweller/branches/adeniz_1@68 d34b734f-a00e-4b39-a726-e4eeb87269ab
adeniz_1
adeniz 10 年前
父节点
当前提交
5ea6e7ba26
共有 3 个文件被更改,包括 64 次插入5 次删除
  1. 28
    2
      configuration.cpp
  2. 21
    3
      configuration.hpp
  3. 15
    0
      configuration.inline.hpp

+ 28
- 2
configuration.cpp 查看文件

@@ -598,6 +598,16 @@ ConfigurationElement& ConfigurationElement::mapTo(
return(*this); // then dereference and return myself.
}

ConfigurationElement& ConfigurationElement::RawData(std::string &RawData) {
myRawTranslator.setRawDataAssignment(RawData);
return(*this);
}

ConfigurationElement& ConfigurationElement::RawIndex(int &Index, int &Endex) {
myRawTranslator.setIndexAssignment(Index, Endex);
return(*this);
}

void ConfigurationElement::initialize() { // Reset all translators to defaults.

// Initialize the elements below me
@@ -702,8 +712,6 @@ bool ConfigurationElement::interpret(ConfigurationData& Data) {
++Index; // past it and scan for our name.
}

startOfElementIndex = Data.Index(); // AVD

for(unsigned int I = 0; I < myName.length(); I++) { // For the length of our name,
char x = Data.Data(Index + I); // get each corresponding Data byte
if(x != myName.at(I)) { // check it sudden death style.
@@ -790,6 +798,8 @@ bool ConfigurationElement::interpret(ConfigurationData& Data) {
// may have contained, and we are syncrhonized with Data.

if(ThisIsAnEmptyElement) { // If the element was self closing then
myEndex = Data.Index() - 1;
myRawTranslator.translate(myIndex, myEndex, Data);
runEndConfigurators(Data); // run the End Configurators and return
return true; // true to the caller.
}
@@ -945,7 +955,9 @@ bool ConfigurationElement::interpret(ConfigurationData& Data) {
}

// And finally, after all is done successfully...
myEndex = Data.Index() - 1;

myRawTranslator.translate(myIndex, myEndex, Data);
runEndConfigurators(Data); // Launch the End Configurators.
return true; // Return our success!
}
@@ -1225,6 +1237,20 @@ ConfigurationData::~ConfigurationData() {
myLine = 0;
}

std::string ConfigurationData::extract(int Index, int Endex) const {
int Start = Index, End = Endex;

if (0 == myBufferSize) return std::string("");

if (Start < 0) Start = 0;
if (Start >= myBufferSize) Start = myBufferSize - 1;

if (Start > End) End = Start;
if (End >= myBufferSize) End = myBufferSize - 1;

return std::string(myDataBuffer, Start, End - Start + 1);
}

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

// SetTrueOnComplete Configurator //////////////////////////////////////////////

+ 21
- 3
configuration.hpp 查看文件

@@ -124,6 +124,17 @@ class ConfigurationTranslator;
class ConfigurationMnemonic; // Mnemonics exist
class Configurator; // Configurators exist

class RawTranslator {
private:
int *IndexAssignment = 0;
int *EndexAssignment = 0;
std::string *RawDataAssignment = 0;
public:
void setRawDataAssignment(std::string &RawData);
void setIndexAssignment(int &Index, int &Endex);
void translate(int Index, int Endex, ConfigurationData &Data);
};

//// Configuration Element /////////////////////////////////////////////////////
//
// Elements make up the core of a configuration. That is, a configuration is a
@@ -150,10 +161,13 @@ class ConfigurationElement {
std::list<ConfigurationMnemonic*> myMnemonics; // They may have a list of mnemonics.
std::list<ConfigurationTranslator*> myTranslators; // They may have a list of translators.

RawTranslator myRawTranslator; // Provides entire element.

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

int myLine; // Last line number I was seen on.
int myIndex; // Last char position I was seen on.
int myEndex; // Last char of element.
int myLength; // Last segment length.

bool myCleanFlag; // Keep track of initialization.
@@ -252,6 +266,12 @@ class ConfigurationElement {
const std::string Name, // requires a name, of course,
bool& x, bool init = false); // Map to a boolean.

ConfigurationElement& RawData( // Copy entire element to
std::string &Element); // a string.

ConfigurationElement& RawIndex( // Copy indices of the entire
int &Index, int &Endex); // element.

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

class EndNameDoesNotMatch {}; // Throw when End(name) doesn't match.
@@ -376,8 +396,6 @@ class ConfigurationElement {

bool interpret(ConfigurationData& Data); // (re) Interpret this data.

int startOfElementIndex; // AVD

};

//// Configuration Attribute ///////////////////////////////////////////////////
@@ -599,7 +617,7 @@ class ConfigurationData {
int Index(int i); // Changes the current Index.
int Line(); // Reads the current Line number.
int addNewLines(int Count); // Increments the Line number.
char const *Buffer() const { return myDataBuffer; } // AVD
std::string extract(int Index, int Endex) const ; // Return substring of buffer.

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


+ 15
- 0
configuration.inline.hpp 查看文件

@@ -559,6 +559,21 @@ inline void BoolTranslator::initialize() {
myVariable = myInitializer; // Revert to the initializer value.
}

inline void RawTranslator::setRawDataAssignment(std::string &RawData) {
RawDataAssignment = &RawData;
}

inline void RawTranslator::setIndexAssignment(int &Index, int &Endex) {
IndexAssignment = &Index;
EndexAssignment = &Endex;
}

inline void RawTranslator::translate(int Index, int Endex, ConfigurationData &Data) {
if (0 != RawDataAssignment) *RawDataAssignment = Data.extract(Index, Endex);
if (0 != IndexAssignment) *IndexAssignment = Index;
if (0 != EndexAssignment) *EndexAssignment = Endex;
}

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

inline ConfigurationMnemonic::ConfigurationMnemonic( // To make one, provide both parts.

正在加载...
取消
保存