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;
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(
"#"); };
193 bool isOpen() {
return (ifs.is_open() || ofs.is_open()) ? true :
false; }
202 else if (ofs.is_open())
219 bool read(
string& token);
231 void tokenize(
const string& str, vector<string>& tokens);
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;
269 { strDelim[0] = wsDelims; };
275 {
return strDelim[0]; };
281 { strDelim[1] = strgDelim; };
287 {
return strDelim[1]; };
293 { strDelim[2] = cmntDelim; };
299 {
return strDelim[2]; };
306 const string& endBlk)
308 strDelim[3] = begBlk;
309 strDelim[4] = endBlk;
316 { strDelim[3] = begBlkCmntDelim; };
322 {
return strDelim[3]; };
328 { strDelim[4] = endBlkCmntDelim; };
334 {
return strDelim[4]; };
340 {
return strTotlLinesRead; };
346 {
return strDataLinesRead; };
352 {
return strBlankLinesRead; };
358 {
return strCommentLinesRead; };
364 {
return strBlkCommentLinesRead; };
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;
An exception class for all GeoTess objects.
Opens ascii file for read and write access.
void setWhitespaceDelimiters(const string &wsDelims)
void setEndBlockCommentDelimiter(const string &endBlkCmntDelim)
void writeLongNL(LONG_INT l)
void writeShortNL(short s)
bool readLine(string &ln)
const string & getBeginBlockCommentDelimiter() const
void setBeginBlockCommentDelimiter(const string &begBlkCmntDelim)
bool readType(LONG_INT &l)
void setBlockCommentDelimiters(const string &begBlk, const string &endBlk)
void setStringDelimiter(const string &strgDelim)
void openForWrite(const string &fn)
void setDelimiters(const string &wspcDelims, const string &strgDelim, const string &cmntDelim, const string &begBlk, const string &endBlk)
void tokenize(const string &str, vector< string > &tokens)
void openForRead(const string &fn)
void getLine(string &buf)
void writeTypeNL(float f)
int getBlockCommentLinesRead() const
int getCommentLinesRead() const
void writeTypeNL(const string &s)
void writeType(const string &s)
int getDataLinesRead() const
void writeFloatNL(float f)
void writeType(LONG_INT l)
void writeTypeNL(LONG_INT l)
void writeLong(LONG_INT l)
void setCommentDelimiter(const string &cmntDelim)
void writeString(const string &s)
const string & getFileName() const
void setDefaultDelimiters()
const string & getCommentDelimiter() const
void writeDoubleNL(double d)
const string & getEndBlockCommentDelimiter() const
void writeTypeNL(short s)
int getTotalLinesRead() const
void writeStringNL(const string &s)
int getBlankLinesRead() const
void writeDouble(double d)
void writeTypeNL(double d)
const string & getStringDelimiter() const
const string & getWhitespaceDelimiters() const