40 laFileParser::laFileParser(
void)
45 strcpy(_strSeparators,
" ");
47 _cTextSep[0] = M_DTEXT;
48 _cTextSep[1] = M_DTEXT;
50 _cSectSep[0] = M_DSECTION_1;
51 _cSectSep[1] = M_DSECTION_2;
53 _bHaltOnErrors = M_TRUE;
56 laFileParser::laFileParser(
char* strFile)
61 strcpy(_strSeparators,
" ");
63 _cTextSep[0] = M_DTEXT;
64 _cTextSep[1] = M_DTEXT;
66 _cSectSep[0] = M_DSECTION_1;
67 _cSectSep[1] = M_DSECTION_2;
69 _bHaltOnErrors = M_TRUE;
74 laFileParser::~laFileParser(
void)
76 if(_pFile) fileClose();
79 FILE* laFileParser::fileOpen(
char* strFile)
81 _pFile = fopen(strFile,
"r");
83 ASSERT(_pFile,
"Unable to open file '%s'", strFile);
84 strcpy(_strFileName, strFile);
89 void laFileParser::fileClose()
91 ASSERT(_pFile,
"File is not open.");
95 void laFileParser::readLabel(
char *buf)
97 ASSERT(_pFile,
"File is not open.");
100 M_BOOL internal_buf = M_FALSE;
105 buffer =
new char[128];
106 internal_buf = M_TRUE;
112 throw laError(
"laFileParser::readLabel() failed");
115 while( (c=getc(_pFile))==
' ' );
118 while( (c=getc(_pFile))!=M_DLABEL )
120 if(feof(_pFile))
break;
126 if(internal_buf)
delete [] buffer;
129 void laFileParser::readInt(
int *var, M_BOOL labeled)
131 ASSERT(_pFile,
"File is not open.");
133 char strFormat[128] =
"%d";
134 strcat(strFormat, _strSeparators);
136 if(labeled) readLabel();
137 fscanf(_pFile, strFormat, var);
140 void laFileParser::readUnsigned(
unsigned *var, M_BOOL labeled)
142 ASSERT(_pFile,
"File is not open.");
144 char strFormat[128] =
"%u";
145 strcat(strFormat, _strSeparators);
147 if(labeled) readLabel();
148 fscanf(_pFile, strFormat, var);
151 void laFileParser::readDouble(
double *var, M_BOOL labeled)
153 ASSERT(_pFile,
"File is not open.");
155 char strFormat[128] =
"%f";
156 strcat(strFormat, _strSeparators);
158 if(labeled) readLabel();
160 fscanf(_pFile, strFormat, &f);
164 void laFileParser::readText(
char *var, M_BOOL labeled)
166 ASSERT(_pFile,
"File is not open.");
171 while( getc(_pFile)!=_cTextSep[0] )
176 throw laError(
"laFileParser::readText() failed");
180 while( (c=getc(_pFile))!=_cTextSep[1] )
182 if(feof(_pFile))
break;
189 void laFileParser::readSectionSeparator(
char *buf)
191 ASSERT(_pFile,
"File is not open.");
194 ts[0] = _cTextSep[0];
195 ts[1] = _cTextSep[1];
196 _cTextSep[0] = _cSectSep[0];
197 _cTextSep[1] = _cSectSep[1];
201 char *my_buff =
new char[128];
202 readText(my_buff, M_FALSE);
205 else readText(buf, M_FALSE);
207 _cTextSep[0] = ts[0];
208 _cTextSep[1] = ts[1];
211 void laFileParser::readBool(M_BOOL *var, M_BOOL labeled)
213 ASSERT(_pFile,
"File is not open.");
219 while( getc(_pFile)!=M_DTEXT );
221 while( (c=getc(_pFile))!=M_DTEXT )
227 if(!strcmp(txt,
"true")) *var = M_TRUE;
231 void laFileParser::readObj(
laLoadableObj *obj, M_BOOL labeled)
233 ASSERT(_pFile,
"File is not open.");
235 if(labeled) readLabel();
Interface for loadable objects.