-
Notifications
You must be signed in to change notification settings - Fork 1
Parsing
Data reading, setting, adding, and retrieval are prefixed with "read", "set", "add", and "get", respectively. The "read" prefix indicates a single valued data type returned. The "set" prefix indicates input of a single valued data type. The "add" prefix indicates a multi-valued data type that is appended. The "get" prefix indicates a pointer returned from a multi-valued data type.
The Script::read() member function include/fileFormats/scriptFormat.h just passes words or numbers one at a time to the Blob::input() member function (the reset and END_INPUT parts trigger the Blob object to start and stop receiving):
template <typename T, typename U>
void Script<T,U>::read()
{
std::string in("");
file.seekg(std::ios::beg);
file.clear();
(*b).reset();
while(!file.eof() && in!=END_INPUT)
{
file >> in;
if(!file.eof())
(*b).input(in);
}
//this actually checks for failure, otherwise, you would just guess
(*b).input(END_INPUT);
}
Once read() passes information to Blob::input(), this triggers one of two states (each with their own sub-states, this is a top-down leftmost parser): State A: Check if input is a recognized command (wP==-1==no command, and it=0):
it=0;
std::map<std::string,int>::iterator found;
found=commandMap.find(in);
if(found!=commandMap.end())
{
wP=found->second;//save the command index
}
State B: Or process a command (wP>-1, and it++), for example, molecule:
switch(wP)
{
case MOLECULE:
if(it>0)
{
if(mol!=current)
{
Reset molecule indices to zero:
molState=0, bondState=0, bondNumber=0
set type to input value
}
else
{
Based on type (BOND,BEND,CHAIN,etc...), set:
nMoleculeConstants
nMoleculeParticles
if(nMoleculeParticles==0) //default is useless
{
read bond index, increment bondIndex counter
if(bondIndex>=4) increment mol(ecule) counter
}
else
{
if(molState==0)
{
read number of bonds (nBonds), allocate bonds
}
else
{
if(molState<=nMoleculeConstants)
{
read a constant (lBond, kBond, etc...)
}
else
{
read a bond index, increment bond state and bond number
if(bondState>=nBonds) increment mol(ecule) counter
}
}
}
}
increment molecule state counter (molState)
error checking
}
else
{
check that nMolecules was read before this
Initialize mol(ecule) to zero, and set current type to none
}
}
break;