Minor tweaks to snf_engine.* to remove compiler warnings. Refactored Evaluator objects to use unsigned ints for positions. git-svn-id: https://svn.microneil.com/svn/SNFMulti/trunk@6 dc71a809-1921-45c4-985c-09c81d0142d9wx
} | } | ||||
GBUdbDataset::GBUdbDataset(GBUdbDataset& Original) : // Copy constructor. | GBUdbDataset::GBUdbDataset(GBUdbDataset& Original) : // Copy constructor. | ||||
MyFileName(Original.MyFileName), // Copy the name pointer. | |||||
DataArray(NULL), // The array pointer starts as NULL. | |||||
MyArraySize(Original.MyArraySize) { // We copy the ArraySize | |||||
DataArray = new GBUdbRecord[MyArraySize]; // then allocate a new Array that size. | |||||
memcpy(DataArray, Original.DataArray, sizeof(GBUdbRecord) * MyArraySize); // Then we copy the data wholesale. | |||||
DataArray(NULL), // The array pointer starts as NULL. | |||||
MyArraySize(Original.MyArraySize), // Copy the ArraySize | |||||
MyFileName(Original.MyFileName) { // Copy the name pointer. | |||||
DataArray = new GBUdbRecord[MyArraySize]; // Allocate a new Array. | |||||
memcpy(DataArray, Original.DataArray, sizeof(GBUdbRecord) * MyArraySize); // Copy the data wholesale. | |||||
} | } | ||||
const char* GBUdbDataset::FileName(const char* NewName) { // (Re) Set the file name. | const char* GBUdbDataset::FileName(const char* NewName) { // (Re) Set the file name. | ||||
time(&rawtime); // Grab the current time and | time(&rawtime); // Grab the current time and | ||||
gmt=gmtime(&rawtime); // convert it to GMT. | gmt=gmtime(&rawtime); // convert it to GMT. | ||||
sprintf(TimestampBfr,"%04d%02d%02d%02d%02d%02d\0", // Format yyyymmddhhmmss | |||||
sprintf(TimestampBfr,"%04d%02d%02d%02d%02d%02d", // Format yyyymmddhhmmss | |||||
gmt->tm_year+1900, | gmt->tm_year+1900, | ||||
gmt->tm_mon+1, | gmt->tm_mon+1, | ||||
gmt->tm_mday, | gmt->tm_mday, |
// Evaluator::Evaluator(position,evalmatrix) Constructor | // Evaluator::Evaluator(position,evalmatrix) Constructor | ||||
Evaluator::Evaluator(int s, EvaluationMatrix* m) { // Constructor... | |||||
Evaluator::Evaluator(unsigned int s, EvaluationMatrix* m) { // Constructor... | |||||
myEvaluationMatrix = m; // Capture the matrix I live in. | myEvaluationMatrix = m; // Capture the matrix I live in. | ||||
Matrix = myEvaluationMatrix->getTokens(); // Capture the token matrix I walk in. | Matrix = myEvaluationMatrix->getTokens(); // Capture the token matrix I walk in. | ||||
// and which has the only difference of putting the new evaluator after the current one | // and which has the only difference of putting the new evaluator after the current one | ||||
// in the chain in order to support branch-out operations for loop sequences in the matrix. | // in the chain in order to support branch-out operations for loop sequences in the matrix. | ||||
Evaluator* EvaluationMatrix::AddEvaluator(int s, int m) { // Adds a new evaluator at top. | |||||
Evaluator* EvaluationMatrix::AddEvaluator(int s, unsigned int m) { // Adds a new evaluator at top. | |||||
if(!isNoDuplicate(m)) return NULL; // If there is a duplicate do nothing. | if(!isNoDuplicate(m)) return NULL; // If there is a duplicate do nothing. | ||||
// EvaluationMatrix::InsEvaluator() | // EvaluationMatrix::InsEvaluator() | ||||
Evaluator* EvaluationMatrix::InsEvaluator(int s, int m) { // Inserts a new evaluator. | |||||
Evaluator* EvaluationMatrix::InsEvaluator(int s, unsigned int m) { // Inserts a new evaluator. | |||||
if(!isNoDuplicate(m)) return NULL; // If there is a duplicate do nothing. | if(!isNoDuplicate(m)) return NULL; // If there is a duplicate do nothing. | ||||
// Constructors... | // Constructors... | ||||
TokenMatrix() : | TokenMatrix() : | ||||
MatrixSize(0), | |||||
Matrix(NULL) { } | |||||
Matrix(NULL), | |||||
MatrixSize(0) { } | |||||
TokenMatrix(ifstream& F) : | TokenMatrix(ifstream& F) : | ||||
MatrixSize(0), | |||||
Matrix(NULL) { | |||||
Matrix(NULL), | |||||
MatrixSize(0) { | |||||
Load(F); | Load(F); | ||||
} | } | ||||
States Condition; // What state am I in? How's my health? | States Condition; // What state am I in? How's my health? | ||||
Evaluator* NextEvaluator; // Linked List Pointer. | Evaluator* NextEvaluator; // Linked List Pointer. | ||||
int StreamStartPosition; // Indexes the position where we started. | |||||
unsigned int StreamStartPosition; // Indexes the position where we started. | |||||
unsigned int CurrentPosition; // Indexes the node we are surfing. | unsigned int CurrentPosition; // Indexes the node we are surfing. | ||||
int WildRunLength; // Wildcard run length so far. | int WildRunLength; // Wildcard run length so far. | ||||
// key to creating buddies when working with wildcards. It prevents us from recursively | // key to creating buddies when working with wildcards. It prevents us from recursively | ||||
// proliferating evaluators at each new character when running in a wildcard loop. | // proliferating evaluators at each new character when running in a wildcard loop. | ||||
int isNoDuplicate(int Position) { // Returns false if there is a duplicate. | |||||
bool isNoDuplicate(unsigned int Position) { // Returns false if there is a duplicate. | |||||
if(CurrentPosition == Position) // Obviously, if I match, then there's a dup. | if(CurrentPosition == Position) // Obviously, if I match, then there's a dup. | ||||
return false; | return false; | ||||
// If I don't match and I'm the last one then | // If I don't match and I'm the last one then | ||||
return NextEvaluator->isNoDuplicate(Position); | return NextEvaluator->isNoDuplicate(Position); | ||||
} | } | ||||
Evaluator(int s, EvaluationMatrix* m); // Constructor... | |||||
Evaluator(unsigned int s, EvaluationMatrix* m); // Constructor... | |||||
~Evaluator(){ | ~Evaluator(){ | ||||
if(NextEvaluator!=NULL){ // If there's more to this list then | if(NextEvaluator!=NULL){ // If there's more to this list then | ||||
return myTokenMatrix->Size(); // for use when creating evaluators. | return myTokenMatrix->Size(); // for use when creating evaluators. | ||||
} | } | ||||
Evaluator* AddEvaluator(int s, int m); // Adds a new evaluator to the top. | |||||
Evaluator* AddEvaluator(int s, unsigned int m); // Adds a new evaluator to the top. | |||||
Evaluator* InsEvaluator(int s, int m); // Inserts a new evaluator after the | |||||
Evaluator* InsEvaluator(int s, unsigned int m); // Inserts a new evaluator after the | |||||
// current evaluator. (Only called by | // current evaluator. (Only called by | ||||
// an existing evaluator in process...) | // an existing evaluator in process...) | ||||
// isNoDuplicate(int p) checks for duplicate evaulators | // isNoDuplicate(int p) checks for duplicate evaulators | ||||
int isNoDuplicate(int p) { // If there's no list there can be no | |||||
bool isNoDuplicate(unsigned int p) { // If there's no list there can be no | |||||
if(EvaluatorList == NULL) // duplicates so we're true. If there is | if(EvaluatorList == NULL) // duplicates so we're true. If there is | ||||
return true; // a list then we'll let the list answer. | return true; // a list then we'll let the list answer. | ||||
else | else |