Code:
class Parsing {
private:
int Length; //
int Ptr; //
List<ParseEl> Index; //
public:
Parsing(); //
Parsing( //
const int argc,
char* argv[]);
Parsing( //
istream& is);
void ParseFile( //
istream& is);
void ParseCmd( //
const int argc,
char* argv[]);
bool GetFloat( // Get a floating point number.
const String& Id,
float& f,
const int ord1,
const int ord2,
const int ord3);
bool GetReal( // Wrapper function for GetFloat.
const String& Id,
float& f,
const int ord1,
const int ord2,
const int ord3);
bool GetFloat( // Get a floating point number.
const char* Id,
float& f,
const int ord1,
const int ord2,
const int ord3);
bool GetReal( // Wrapper function for GetFloat.
const char* Id,
float& f,
const int ord1,
const int ord2,
const int ord3);
private:
bool GetFloat( // Get a floating point number.
const char* Id,
float& f,
const List<int>& ord);
bool GetReal( // Wrapper function for GetFloat.
const char* Id,
float& f,
const List<int>& ord);
};
////////////////////////////////////////////////////////////////////////////////////////////////////
inline bool Parsing::GetFloat(
const String& Id,
float& f,
const int ord1 = 0,
const int ord2 = 0,
const int ord3 = 0) {
return GetFloat( (char *)Id, f, ord1, ord2, ord3 );
}
////////////////////////////////////////////////////////////////////////////////////////////////////
inline bool Parsing::GetReal(
const String& Id,
float& f,
const int ord1 = 0,
const int ord2 = 0,
const int ord3 = 0) {
return GetFloat( (char *)Id, f, ord1, ord2, ord3 );
}
////////////////////////////////////////////////////////////////////////////////////////////////////
bool Parsing::GetFloat(
const char* Id,
float& f,
const int ord1 = 0,
const int ord2 = 0,
const int ord3 = 0 ) {
List<int> L;
if (ord1 != 0) {
L += ord1;
if (ord2 != 0) {
L += ord2;
if (ord3 != 0) { L += ord3; }
}
}
return GetFloat(Id, f, L);
}
////////////////////////////////////////////////////////////////////////////////////////////////////
bool Parsing::GetReal(
const char* Id,
float& f,
const int ord1 = 0,
const int ord2 = 0,
const int ord3 = 0 ) {
List<int> L;
if (ord1 != 0) {
L += ord1;
if (ord2 != 0) {
L += ord2;
if (ord3 != 0) { L += ord3; }
}
}
return GetFloat(Id, f, L);
}
////////////////////////////////////////////////////////////////////////////////////////////////////
bool Parsing::GetFloat(
const char* Id,
float& f,
const List<int>& ord) {
int j;
int found = -1;
int HId = Hash(Id);
j = Ptr;
if (Index.size() == 0) { return false; }
do {
if ( (Index[j].Hash == HId) && (Index[j].Type == PARAM)
&& (Index[j].Name == String(Id)) && (Index[j].Ord == ord) ) {
found = j;
}
j++;
if (j == Index.size()) { j = 0; }
} while ((found == -1) && (j != Ptr));
if (found == -1) { return false; }
Index[found].Str.Rewind();
Index[found].Str >> f;
Ptr = found;
if (Ptr == Index.size()) { Ptr = 0; }
return true;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
bool Parsing::GetReal(
const char* Id,
float& f,
const List<int>& ord) {
int j;
int found = -1;
int HId = Hash(Id);
j = Ptr;
if (Index.size() == 0) { return false; }
do {
if ( (Index[j].Hash == HId) && (Index[j].Type == PARAM)
&& (Index[j].Name == String(Id)) && (Index[j].Ord == ord) ) {
found = j;
}
j++;
if (j == Index.size()) { j = 0; }
} while ((found == -1) && (j != Ptr));
if (found == -1) { return false; }
Index[found].Str.Rewind();
Index[found].Str >> f;
Ptr = found;
if (Ptr == Index.size()) { Ptr = 0; }
return true;
}