36 #ifndef IFSTREAMASCII_OBJECT_H
37 #define IFSTREAMASCII_OBJECT_H
117 int strTotlLinesRead;
119 int strDataLinesRead;
121 int strBlankLinesRead;
123 int strCommentLinesRead;
125 int strBlkCommentLinesRead;
133 bool strBlkCommntSet;
154 vector<string> strTokens;
161 void getLine(
string& buf);
167 strDataLinesRead(0), strBlankLinesRead(0),
168 strCommentLinesRead(0), strBlkCommentLinesRead(0),
169 strBytesRead(0), strBlkCommntSet(false),
171 {setDefaultDelimiters(); setCommentDelimiter(
"#"); };
181 void openForRead(
const string& fn);
182 void openForWrite(
const string& fn);
187 bool isOpen() {
return (ifs.is_open() || ofs.is_open()) ?
true :
false; }
196 else if (ofs.is_open())
213 bool read(
string& token);
219 bool readLine(
string& ln);
225 void tokenize(
const string& str, vector<string>& tokens);
235 void setDefaultDelimiters();
246 void setDelimiters(
const string& wspcDelims,
247 const string& strgDelim,
248 const string& cmntDelim,
249 const string& begBlk,
250 const string& endBlk)
252 strDelim[0] = wspcDelims;
253 strDelim[1] = strgDelim;
254 strDelim[2] = cmntDelim;
255 strDelim[3] = begBlk;
256 strDelim[4] = endBlk;
262 void setWhitespaceDelimiters(
const string& wsDelims)
263 { strDelim[0] = wsDelims; };
268 const string& getWhitespaceDelimiters()
const
269 {
return strDelim[0]; };
274 void setStringDelimiter(
const string& strgDelim)
275 { strDelim[1] = strgDelim; };
280 const string& getStringDelimiter()
const
281 {
return strDelim[1]; };
286 void setCommentDelimiter(
const string& cmntDelim)
287 { strDelim[2] = cmntDelim; };
292 const string& getCommentDelimiter()
const
293 {
return strDelim[2]; };
299 void setBlockCommentDelimiters(
const string& begBlk,
300 const string& endBlk)
302 strDelim[3] = begBlk;
303 strDelim[4] = endBlk;
309 void setBeginBlockCommentDelimiter(
const string& begBlkCmntDelim)
310 { strDelim[3] = begBlkCmntDelim; };
315 const string& getBeginBlockCommentDelimiter()
const
316 {
return strDelim[3]; };
321 void setEndBlockCommentDelimiter(
const string& endBlkCmntDelim)
322 { strDelim[4] = endBlkCmntDelim; };
327 const string& getEndBlockCommentDelimiter()
const
328 {
return strDelim[4]; };
333 int getTotalLinesRead()
const
334 {
return strTotlLinesRead; };
339 int getDataLinesRead()
const
340 {
return strDataLinesRead; };
345 int getBlankLinesRead()
const
346 {
return strBlankLinesRead; };
351 int getCommentLinesRead()
const
352 {
return strCommentLinesRead; };
357 int getBlockCommentLinesRead()
const
358 {
return strBlkCommentLinesRead; };
363 int getBytesRead()
const
364 {
return strBytesRead; };
384 bool readString(
string& s);
399 bool readByte(
byte& b);
414 bool readShort(
short& s);
429 bool readInteger(
int& i);
459 bool readFloat(
float& f);
469 bool readType(
double& d) {
return readDouble(d); };
474 bool readDouble(
double& d);
520 inline bool IFStreamAscii::read(
string& token)
526 if (strTokenPtr >= (
int) strTokens.size())
536 if (!readLine(ln))
return false;
540 tokenize(ln, strTokens);
545 token = strTokens[strTokenPtr++];
552 inline bool IFStreamAscii::isEOF()
const
554 return (ifs.eof() && (strTokenPtr >= (int) strTokens.size()));
560 inline string IFStreamAscii::readString()
570 inline bool IFStreamAscii::readString(
string& s)
578 inline bool IFStreamAscii::next()
587 inline byte IFStreamAscii::readByte()
597 inline bool IFStreamAscii::readByte(
byte& b)
603 if (!read(sb))
return false;
607 if (sscanf(sb.c_str(),
"%hhd", &b) != 1)
610 os << endl <<
"ERROR in IFStreamAscii::readByte" << endl
611 <<
" Could Not Scan Byte From Token = " << sb << endl
612 <<
" On File Line: " << strTotlLinesRead <<
" ..." << endl;
624 inline short IFStreamAscii::readShort()
634 inline bool IFStreamAscii::readShort(
short& s)
640 if (!read(ss))
return false;
644 if (sscanf(ss.c_str(),
"%hd", &s) != 1)
647 os << endl <<
"ERROR in IFStreamAscii::readShort" << endl
648 <<
" Could Not Scan Short From Token = " << ss << endl
649 <<
" On File Line: " << strTotlLinesRead <<
" ..." << endl;
661 inline int IFStreamAscii::readInteger()
671 inline bool IFStreamAscii::readInteger(
int& i)
677 if (!read(si))
return false;
681 if (sscanf(si.c_str(),
"%d", &i) != 1)
684 os << endl <<
"ERROR in IFStreamAscii::readInteger" << endl
685 <<
" Could Not Scan Integer From Token = " << si << endl
686 <<
" On File Line: " << strTotlLinesRead <<
" ..." << endl;
714 if (!read(sl))
return false;
721 os << endl <<
"ERROR in IFStreamAscii::readLong" << endl
722 <<
" Could Not Scan Long From Token = " << sl << endl
723 <<
" On File Line: " << strTotlLinesRead <<
" ..." << endl;
735 inline float IFStreamAscii::readFloat()
745 inline bool IFStreamAscii::readFloat(
float& f)
751 if (!read(sf))
return false;
755 if (sscanf(sf.c_str(),
"%f", &f) != 1)
758 os << endl <<
"ERROR in IFStreamAscii::readFloat" << endl
759 <<
" Could Not Scan Float From Token = " << sf << endl
760 <<
" On File Line: " << strTotlLinesRead <<
" ..." << endl;
772 inline double IFStreamAscii::readDouble()
782 inline bool IFStreamAscii::readDouble(
double& d)
788 if (!read(sd))
return false;
792 if (sscanf(sd.c_str(),
"%lf", &d) != 1)
795 os << endl <<
"ERROR in IFStreamAscii::readDouble" << endl
796 <<
" Could Not Scan Double From Token = " << sd << endl
797 <<
" On File Line: " << strTotlLinesRead <<
" ..." << endl;
808 #endif // INTERPOLATOR_OBJECT_H