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 void getline(
string& s) { std::getline(ifs, s); };
173 strDataLinesRead(0), strBlankLinesRead(0),
174 strCommentLinesRead(0), strBlkCommentLinesRead(0),
175 strBytesRead(0), strBlkCommntSet(false),
177 {setDefaultDelimiters(); setCommentDelimiter(
"#"); };
187 void openForRead(
const string& fn);
188 void openForWrite(
const string& fn);
193 bool isOpen() {
return (ifs.is_open() || ofs.is_open()) ?
true :
false; }
202 else if (ofs.is_open())
219 bool read(
string& token);
225 bool readLine(
string& ln);
231 void tokenize(
const string& str, vector<string>& tokens);
241 void setDefaultDelimiters();
252 void setDelimiters(
const string& wspcDelims,
253 const string& strgDelim,
254 const string& cmntDelim,
255 const string& begBlk,
256 const string& endBlk)
258 strDelim[0] = wspcDelims;
259 strDelim[1] = strgDelim;
260 strDelim[2] = cmntDelim;
261 strDelim[3] = begBlk;
262 strDelim[4] = endBlk;
268 void setWhitespaceDelimiters(
const string& wsDelims)
269 { strDelim[0] = wsDelims; };
274 const string& getWhitespaceDelimiters()
const
275 {
return strDelim[0]; };
280 void setStringDelimiter(
const string& strgDelim)
281 { strDelim[1] = strgDelim; };
286 const string& getStringDelimiter()
const
287 {
return strDelim[1]; };
292 void setCommentDelimiter(
const string& cmntDelim)
293 { strDelim[2] = cmntDelim; };
298 const string& getCommentDelimiter()
const
299 {
return strDelim[2]; };
305 void setBlockCommentDelimiters(
const string& begBlk,
306 const string& endBlk)
308 strDelim[3] = begBlk;
309 strDelim[4] = endBlk;
315 void setBeginBlockCommentDelimiter(
const string& begBlkCmntDelim)
316 { strDelim[3] = begBlkCmntDelim; };
321 const string& getBeginBlockCommentDelimiter()
const
322 {
return strDelim[3]; };
327 void setEndBlockCommentDelimiter(
const string& endBlkCmntDelim)
328 { strDelim[4] = endBlkCmntDelim; };
333 const string& getEndBlockCommentDelimiter()
const
334 {
return strDelim[4]; };
339 int getTotalLinesRead()
const
340 {
return strTotlLinesRead; };
345 int getDataLinesRead()
const
346 {
return strDataLinesRead; };
351 int getBlankLinesRead()
const
352 {
return strBlankLinesRead; };
357 int getCommentLinesRead()
const
358 {
return strCommentLinesRead; };
363 int getBlockCommentLinesRead()
const
364 {
return strBlkCommentLinesRead; };
369 int getBytesRead()
const
370 {
return strBytesRead; };
390 bool readString(
string& s);
405 bool readByte(
byte& b);
420 bool readShort(
short& s);
435 bool readInteger(
int& i);
465 bool readFloat(
float& f);
475 bool readType(
double& d) {
return readDouble(d); };
480 bool readDouble(
double& d);
526 inline bool IFStreamAscii::read(
string& token)
532 if (strTokenPtr >= (
int) strTokens.size())
542 if (!readLine(ln))
return false;
546 tokenize(ln, strTokens);
551 token = strTokens[strTokenPtr++];
558 inline bool IFStreamAscii::isEOF()
const
560 return (ifs.eof() && (strTokenPtr >= (int) strTokens.size()));
566 inline string IFStreamAscii::readString()
576 inline bool IFStreamAscii::readString(
string& s)
584 inline bool IFStreamAscii::next()
593 inline byte IFStreamAscii::readByte()
603 inline bool IFStreamAscii::readByte(
byte& b)
609 if (!read(sb))
return false;
613 if (sscanf(sb.c_str(),
"%hhd", &b) != 1)
616 os << endl <<
"ERROR in IFStreamAscii::readByte" << endl
617 <<
" Could Not Scan Byte From Token = " << sb << endl
618 <<
" On File Line: " << strTotlLinesRead <<
" ..." << endl;
630 inline short IFStreamAscii::readShort()
640 inline bool IFStreamAscii::readShort(
short& s)
646 if (!read(ss))
return false;
650 if (sscanf(ss.c_str(),
"%hd", &s) != 1)
653 os << endl <<
"ERROR in IFStreamAscii::readShort" << endl
654 <<
" Could Not Scan Short From Token = " << ss << endl
655 <<
" On File Line: " << strTotlLinesRead <<
" ..." << endl;
667 inline int IFStreamAscii::readInteger()
677 inline bool IFStreamAscii::readInteger(
int& i)
683 if (!read(si))
return false;
687 if (sscanf(si.c_str(),
"%d", &i) != 1)
690 os << endl <<
"ERROR in IFStreamAscii::readInteger" << endl
691 <<
" Could Not Scan Integer From Token = " << si << endl
692 <<
" On File Line: " << strTotlLinesRead <<
" ..." << endl;
720 if (!read(sl))
return false;
727 os << endl <<
"ERROR in IFStreamAscii::readLong" << endl
728 <<
" Could Not Scan Long From Token = " << sl << endl
729 <<
" On File Line: " << strTotlLinesRead <<
" ..." << endl;
741 inline float IFStreamAscii::readFloat()
751 inline bool IFStreamAscii::readFloat(
float& f)
757 if (!read(sf))
return false;
761 if (sscanf(sf.c_str(),
"%f", &f) != 1)
764 os << endl <<
"ERROR in IFStreamAscii::readFloat" << endl
765 <<
" Could Not Scan Float From Token = " << sf << endl
766 <<
" On File Line: " << strTotlLinesRead <<
" ..." << endl;
778 inline double IFStreamAscii::readDouble()
788 inline bool IFStreamAscii::readDouble(
double& d)
794 if (!read(sd))
return false;
798 if (sscanf(sd.c_str(),
"%lf", &d) != 1)
801 os << endl <<
"ERROR in IFStreamAscii::readDouble" << endl
802 <<
" Could Not Scan Double From Token = " << sd << endl
803 <<
" On File Line: " << strTotlLinesRead <<
" ..." << endl;
814 #endif // INTERPOLATOR_OBJECT_H