#include <TeAsciiFile.h>

Definition at line 47 of file TeAsciiFile.h.
Public Member Functions | |
| FILE * | FilePtr () |
| void | findNewLine () |
| Goes to a new line. | |
| bool | isNotAtEOF () |
| Return true if the file pointer is not at the end of file. | |
| string | name () |
| operator FILE * () | |
| string | readAll () |
| Reads the entire content of the file, skipping new line characters only. | |
| double | readAngle (const std::string &value) |
| TeBox | readBox () |
| Reads a bounding box. | |
| char | readChar () |
| Reads a character. | |
| TeCoord2D | readCoord2D () |
| Reads a 2D coordinate ( x, y ). | |
| bool | readCoordPairVect2CSV (TeCoordPairVect &coordsVec) |
| double | readFloat () |
| Reads a float. | |
| double | readFloatCSV (const char del= ',') |
| Reads a comma-separated float. | |
| std::string | readFont () |
| int | readInt () |
| Reads an integer. | |
| int | readIntCSV (const char del= ',') |
| Reads a comma-separated int. | |
| string | readLine () |
| Reads a full line up to carriage return. | |
| void | readNStringCSV (vector< string > &, unsigned int n, const char sep= ',') |
| Reads the first n strings from a comma separated line string and put in a string list. | |
| char | readQuotedChar () |
| Reads a character whithin quotes. | |
| string | readQuotedString () |
| Reads a string whithin quotes. | |
| string | readString () |
| Reads a string. | |
| string | readStringCSV (const char sep= ',', bool skip=false, const char skip_char= ' ') |
| Reads a comma-separated string ( with a skip character ). | |
| string | readStringCSVNoQuote (const char del= ',') |
| Reads a comma-separated string (ignore quote ). | |
| string | readStringCSVNoSpace (const char del= ',') |
| Reads a comma-separated string(ignore spaces). | |
| void | readStringList (vector< string > &) |
| Reads a line and put in a stringlist. | |
| void | readStringListCSV (vector< string > &, const char sep= ',') |
| Reads a comma-separated line string and put in a string list. | |
| void | rewind () |
| TeAsciiFile (const string &name, const char *mode="r") | |
| Contructors. | |
| bool | writeCoordPairVect2CSV (const TeCoordPairVect &coordsVec) |
| void | writeNewLine () |
| Writes a carriage return character. | |
| void | writeString (const string &s) |
| Writes a generic string to the file. | |
| virtual | ~TeAsciiFile () |
| Destructor. | |
Protected Attributes | |
| FILE * | file_ |
| string | fileName_ |
| string | mode_ |
Private Member Functions | |
| TeAsciiFile & | operator= (const TeAsciiFile &) |
| TeAsciiFile (const TeAsciiFile &) | |
| TeAsciiFile::TeAsciiFile | ( | const string & | name, | |
| const char * | mode = "r" | |||
| ) |
| TeAsciiFile::~TeAsciiFile | ( | ) | [virtual] |
| TeAsciiFile::TeAsciiFile | ( | const TeAsciiFile & | ) | [private] |
| FILE* TeStdFile::FilePtr | ( | ) | [inline, inherited] |
Definition at line 63 of file TeStdFile.h.
Referenced by TeDecoderSPR::saveData(), and TeDecoderASCIIGrid::saveData().
00063 { return file_; }
| void TeAsciiFile::findNewLine | ( | ) |
Definition at line 46 of file TeAsciiFile.cpp.
References TeStdFile::file_.
Referenced by TeAddressLocator::loadDictionary(), main(), readContoursFromSPRFile(), TeDecoderSPR::readFile(), TeDecoderASCIIGrid::readFile(), TeDecoderSPR::readParameters(), TeDecoderASCIIGrid::readParameters(), TeRasterParams::readParametersFile(), readSamplesFromSPRFile(), TeImportSPR(), TeMIFOthersDecode(), TeMIFTransformDecode(), TeReadBNAObjects(), TeReadColorRampTextFile(), TeReadCSVFile(), TeReadGeoAttributeList(), TeReadMIFAttributeList(), and TeReadMIFAttributes().
00047 { 00048 if ( feof ( file_ ) != 0 ) 00049 return; 00050 char ch = '0'; 00051 00052 while ( ch != '\n' ) 00053 { 00054 fscanf ( file_, "%c", &ch ); 00055 if ( feof ( file_ ) != 0 ) 00056 return; 00057 } 00058 }
| bool TeStdFile::isNotAtEOF | ( | ) | [inline, inherited] |
Definition at line 48 of file TeStdFile.h.
Referenced by TeAddressLocator::loadDictionary(), main(), readContoursFromSPRFile(), TeDecoderSPR::readFile(), TeDecoderASCIIGrid::readFile(), TeDecoderSPR::readParameters(), TeDecoderASCIIGrid::readParameters(), TeRasterParams::readParametersFile(), readSamplesFromSPRFile(), TeImportSPR(), TeReadBNAAttributeList(), TeReadBNAObjects(), TeReadCSVFile(), TeReadGeoAttributeList(), TeReadMIFAttributeList(), TeReadMIFAttributes(), and TeReadMIFProjection().
00049 { 00050 if ( feof ( file_ ) != 0 ) 00051 return false; 00052 return true; 00053 }
| string TeStdFile::name | ( | ) | [inline, inherited] |
Definition at line 56 of file TeStdFile.h.
Referenced by readAll(), readBox(), readCoord2D(), readFloat(), readInt(), readLine(), readNStringCSV(), readString(), readStringCSV(), readStringListCSV(), TeExportQuerierToSPRING(), and TeSPRFile::writeAttributeInfo().
00057 { return fileName_; }
| TeStdFile::operator FILE * | ( | ) | [inline, inherited] |
| TeAsciiFile& TeAsciiFile::operator= | ( | const TeAsciiFile & | ) | [private] |
| string TeAsciiFile::readAll | ( | ) |
Definition at line 354 of file TeAsciiFile.cpp.
References END_OF_FILE_REACHED, TeStdFile::file_, TeStdFile::name(), and require.
Referenced by TeShapefileDriver::getDataProjection().
00355 { 00356 require ( file_ != 0 ); 00357 if ( feof ( file_ ) != 0 ) 00358 throw TeException ( END_OF_FILE_REACHED, name(), true ); 00359 00360 char ch = '0'; 00361 string text=""; 00362 int ret; 00363 while ((ret=fscanf ( file_, "%c", &ch )) != EOF) 00364 { 00365 if (ch != '\n') 00366 text = text + ch; 00367 } 00368 return text; 00369 }
| double TeAsciiFile::readAngle | ( | const std::string & | value | ) |
Read Angle
Method to return the angle of a mid/mif file when it has a text representation
Definition at line 434 of file TeAsciiFile.cpp.
References TeStdFile::file_, readString(), and TeStringCompare().
00435 { 00436 double angle=0; 00437 std::string textRead; 00438 00439 if ( feof ( file_ ) != 0 ) return 0; 00440 00441 if(TeStringCompare(value,"Angle")) 00442 fscanf(file_,"%lf",&angle); 00443 else 00444 { 00445 textRead=this->readString(); 00446 if(TeStringCompare(textRead,"Angle")) fscanf(file_,"%lf",&angle); 00447 } 00448 return angle; 00449 }
| TeBox TeAsciiFile::readBox | ( | ) |
Definition at line 336 of file TeAsciiFile.cpp.
References END_OF_FILE_REACHED, TeStdFile::file_, TeStdFile::name(), and require.
00337 { 00338 require ( file_ != 0 ); 00339 00340 if ( feof ( file_ ) != 0 ) 00341 { 00342 throw TeException ( END_OF_FILE_REACHED, name(), true ); 00343 } 00344 double x1, y1, x2, y2; 00345 00346 00347 fscanf ( file_, "%lf %lf %lf %lf", &x1, &y1, &x2, &y2 ); 00348 00349 return TeBox ( x1, y1, x2, y2 ); 00350 00351 }
| char TeAsciiFile::readChar | ( | ) |
Definition at line 79 of file TeAsciiFile.cpp.
References TeStdFile::file_, and require.
00080 { 00081 char ch=' '; 00082 require ( feof ( file_ ) == 0 ); 00083 while ( ch == ' ' ) 00084 { 00085 fscanf ( file_, "%c", &ch ); 00086 } 00087 return ch; 00088 }
| TeCoord2D TeAsciiFile::readCoord2D | ( | ) |
Definition at line 322 of file TeAsciiFile.cpp.
References END_OF_FILE_REACHED, TeStdFile::file_, TeStdFile::name(), and require.
Referenced by TeImportSPR().
00323 { 00324 require ( file_ != 0 ); 00325 00326 if ( feof ( file_ ) != 0 ) 00327 throw TeException ( END_OF_FILE_REACHED, name(), true ); 00328 00329 double x, y; 00330 fscanf ( file_, "%lf %lf", &x, &y); 00331 00332 return TeCoord2D( x, y ); 00333 }
| bool TeAsciiFile::readCoordPairVect2CSV | ( | TeCoordPairVect & | coordsVec | ) |
Read a vector os coordinates pairs using the CSV file format (one line per coordinate pair).
| coordsVec | The input coordinate pairs vector. |
Definition at line 395 of file TeAsciiFile.cpp.
References TeStdFile::file_, TeCoordPair::pt1, TeCoordPair::pt2, TeCoord2D::x_, and TeCoord2D::y_.
Referenced by TeAffineGT_RANSAC_remotion_test2().
00396 { 00397 coordsVec.clear(); 00398 00399 if( file_ ) 00400 { 00401 TeCoordPair auxPair; 00402 00403 while( fscanf( file_, "%lf;%lf;%lf;%lf", &auxPair.pt1.x_, &auxPair.pt1.y_, 00404 &auxPair.pt2.x_, &auxPair.pt2.y_ ) == 4 ) 00405 { 00406 coordsVec.push_back( auxPair ); 00407 } 00408 00409 return true; 00410 } 00411 else 00412 { 00413 return false; 00414 } 00415 }
| double TeAsciiFile::readFloat | ( | ) |
Definition at line 308 of file TeAsciiFile.cpp.
References END_OF_FILE_REACHED, TeStdFile::file_, TeStdFile::name(), and require.
Referenced by TeDecoderASCIIGrid::readFile(), TeDecoderSPR::readParameters(), and TeDecoderASCIIGrid::readParameters().
00309 { 00310 require ( file_ != 0 ); 00311 00312 if ( feof ( file_ ) != 0 ) 00313 throw TeException ( END_OF_FILE_REACHED, name(), true ); 00314 00315 double value; 00316 fscanf ( file_, "%lf", &value ); 00317 00318 return value; 00319 }
| double TeAsciiFile::readFloatCSV | ( | const char | del = ',' |
) |
Definition at line 298 of file TeAsciiFile.cpp.
References readStringCSV().
Referenced by TeImportSPR(), and TeMIFTransformDecode().
00299 { 00300 char blank = ' '; 00301 string line = readStringCSV ( del, true, blank ); 00302 00303 return atof(line.c_str()); 00304 }
| std::string TeAsciiFile::readFont | ( | ) |
Read a font name
Methodo to read a font name to text geometry
Definition at line 419 of file TeAsciiFile.cpp.
References TeStdFile::file_, readString(), and TeStringCompare().
00420 { 00421 std::string textRead; 00422 00423 if ( feof ( file_ ) != 0 ) return textRead; 00424 00425 textRead=this->readString(); 00426 if(TeStringCompare(textRead,"Font")) 00427 { 00428 textRead=this->readString(); 00429 return textRead; 00430 } 00431 return textRead; 00432 }
| int TeAsciiFile::readInt | ( | ) |
Definition at line 275 of file TeAsciiFile.cpp.
References END_OF_FILE_REACHED, TeStdFile::file_, TeStdFile::name(), and require.
Referenced by TeDecoderSPR::readParameters(), TeDecoderASCIIGrid::readParameters(), TeImportSPR(), TeReadColorRampTextFile(), and TeReadMIFAttributeList().
00276 { 00277 require ( file_ != 0 ); 00278 00279 if ( feof ( file_ ) != 0 ) 00280 throw TeException ( END_OF_FILE_REACHED, name(), true ); 00281 00282 int value; 00283 fscanf ( file_, "%d", &value ); 00284 00285 return value; 00286 }
| int TeAsciiFile::readIntCSV | ( | const char | del = ',' |
) |
Definition at line 289 of file TeAsciiFile.cpp.
References readStringCSV().
Referenced by TeReadGeoAttributeList(), and TeReadMIFAttributeList().
00290 { 00291 char blank = ' '; 00292 string line = readStringCSV ( del, true, blank ); 00293 00294 return atoi(line.c_str()); 00295 }
| string TeAsciiFile::readLine | ( | ) |
Definition at line 111 of file TeAsciiFile.cpp.
References END_OF_FILE_REACHED, TeStdFile::file_, TeStdFile::name(), and require.
Referenced by TeImportSPR(), and TeReadColorRampTextFile().
00112 { 00113 require ( file_ != 0 ); 00114 if ( feof ( file_ ) != 0 ) 00115 throw TeException ( END_OF_FILE_REACHED, name(), true ); 00116 00117 char ch = '0'; 00118 string text = ""; 00119 int ret = fscanf( file_, "%c", &ch ); 00120 while(ret != EOF && ch != '\n') 00121 { 00122 text = text + ch; 00123 ret = fscanf( file_, "%c", &ch ); 00124 } 00125 00126 return text; 00127 }
| void TeAsciiFile::readNStringCSV | ( | vector< string > & | strlist, | |
| unsigned int | n, | |||
| const char | sep = ',' | |||
| ) |
Definition at line 195 of file TeAsciiFile.cpp.
References END_OF_FILE_REACHED, TeStdFile::file_, TeStdFile::name(), and readStringCSV().
Referenced by main().
00196 { 00197 00198 if ( feof ( file_ ) != 0 ) 00199 throw TeException ( END_OF_FILE_REACHED, name(), true ); 00200 00201 strlist.clear(); 00202 char ch, lastChr = 0; 00203 while (fscanf ( file_, "%c", &ch ) != EOF ) 00204 { 00205 if ( ch == '\n' || ch == '\r') 00206 { 00207 if(lastChr==sep) 00208 strlist.push_back ( "" ); 00209 00210 ungetc ( ch, file_ ); 00211 return; 00212 } 00213 ungetc ( ch, file_ ); 00214 // there are still more values to be read 00215 string name = readStringCSV (sep); 00216 if ( name.size() != 0 || sep != ' ') 00217 strlist.push_back ( name ); 00218 if (strlist.size() == n) 00219 break; 00220 00221 lastChr = ch; 00222 } 00223 }
| char TeAsciiFile::readQuotedChar | ( | ) |
Definition at line 61 of file TeAsciiFile.cpp.
References ensure, TeStdFile::file_, and require.
00062 { 00063 require ( feof ( file_ ) == 0 ); 00064 00065 char ch = ',', ch2; 00066 00067 while ( ch != '"' ) 00068 { 00069 fscanf ( file_, "%c", &ch ); 00070 } 00071 fscanf ( file_, "%c", &ch ); 00072 fscanf ( file_, "%c", &ch2 ); 00073 00074 ensure ( ch2 == '"' ); // just to make sure 00075 return ch; 00076 }
| string TeAsciiFile::readQuotedString | ( | ) |
Definition at line 130 of file TeAsciiFile.cpp.
References TeStdFile::file_, and require.
00131 { 00132 require ( feof ( file_ ) == 0 ); 00133 00134 char ch = ' '; 00135 00136 string quote; 00137 00138 while ( ch != '"' ) 00139 { 00140 fscanf ( file_, "%c", &ch ); 00141 } 00142 00143 while ( true ) 00144 { 00145 fscanf ( file_, "%c", &ch ); 00146 if ( ch == '\n' || ch == '\r') 00147 { 00148 ungetc ( ch, file_ ); 00149 break; 00150 } 00151 if ( ch == '"' ) break; 00152 00153 quote = quote + ch; 00154 } 00155 return quote; 00156 }
| string TeAsciiFile::readString | ( | ) |
Definition at line 92 of file TeAsciiFile.cpp.
References END_OF_FILE_REACHED, TeStdFile::file_, TeStdFile::name(), and TeNAME_LENGTH.
Referenced by readAngle(), readContoursFromSPRFile(), TeDecoderSPR::readFile(), TeDecoderASCIIGrid::readFile(), readFont(), TeDecoderSPR::readParameters(), TeDecoderASCIIGrid::readParameters(), TeRasterParams::readParametersFile(), readSamplesFromSPRFile(), TeImportSPR(), TeReadGeoAttributeList(), TeReadMIFAttributeList(), and TeReadMIFProjection().
00093 { 00094 if ( feof ( file_ ) != 0 ) 00095 throw TeException ( END_OF_FILE_REACHED, name(), true ); 00096 00097 char input [TeNAME_LENGTH]; 00098 input[0]=0; 00099 fscanf ( file_, "%s", input ); 00100 00101 return input; 00102 }
| string TeAsciiFile::readStringCSV | ( | const char | sep = ',', |
|
| bool | skip = false, |
|||
| const char | skip_char = ' ' | |||
| ) |
Definition at line 226 of file TeAsciiFile.cpp.
References END_OF_FILE_REACHED, TeStdFile::file_, TeStdFile::name(), and require.
Referenced by readFloatCSV(), readIntCSV(), readNStringCSV(), readStringCSVNoQuote(), readStringCSVNoSpace(), readStringListCSV(), and TeImportSPR().
00227 { 00228 require ( file_ != 0 ); 00229 00230 if ( feof ( file_ ) != 0 ) 00231 throw TeException ( END_OF_FILE_REACHED, name(), true ); 00232 00233 char ch = '0'; 00234 string line; 00235 bool inQuotes = false; 00236 00237 int ret; 00238 while ( (ret=fscanf ( file_, "%c", &ch )) != EOF) 00239 { 00240 if ( ch == '\n' || ch == '\r') 00241 { 00242 ungetc ( ch, file_ ); 00243 break; 00244 } 00245 if ( ch == del && !inQuotes ) break; 00246 if (skip) 00247 if (ch == skip_char) 00248 { 00249 if (skip_char == '"') 00250 inQuotes = !inQuotes; 00251 continue; 00252 } 00253 line = line + ch; 00254 } 00255 return line; 00256 }
| string TeAsciiFile::readStringCSVNoQuote | ( | const char | del = ',' |
) |
Definition at line 267 of file TeAsciiFile.cpp.
References readStringCSV().
Referenced by TeReadBNAObjects(), and TeReadMIFAttributes().
00268 { 00269 char quote = '"'; 00270 string line = readStringCSV ( del, true, quote ); 00271 return line; 00272 }
| string TeAsciiFile::readStringCSVNoSpace | ( | const char | del = ',' |
) |
Definition at line 259 of file TeAsciiFile.cpp.
References readStringCSV().
Referenced by TeReadGeoAttributeList(), and TeReadMIFAttributeList().
00260 { 00261 char blank = ' '; 00262 string line = readStringCSV ( del, true, blank ); 00263 return line; 00264 }
Definition at line 159 of file TeAsciiFile.cpp.
References TeStdFile::file_, readStringListCSV(), and require.
Referenced by TeDecoderSPR::readParameters().
00160 { 00161 require ( file_ != 0 ); 00162 00163 this->readStringListCSV ( strlist, ' '); 00164 }
Definition at line 167 of file TeAsciiFile.cpp.
References END_OF_FILE_REACHED, TeStdFile::file_, TeStdFile::name(), and readStringCSV().
Referenced by TeAddressLocator::loadDictionary(), readStringList(), TeReadBNAAttributeList(), TeReadCSVFile(), and TeReadMIFProjection().
00168 { 00169 00170 if ( feof ( file_ ) != 0 ) 00171 throw TeException ( END_OF_FILE_REACHED, name(), true ); 00172 00173 char ch, lastChr = 0; 00174 while (fscanf ( file_, "%c", &ch ) != EOF ) 00175 { 00176 if ( ch == '\n' || ch == '\r') 00177 { 00178 if(lastChr==sep) 00179 strlist.push_back ( "" ); 00180 00181 ungetc ( ch, file_ ); 00182 return; 00183 } 00184 ungetc ( ch, file_ ); 00185 // there are still more values to be read 00186 string name = readStringCSV (sep); 00187 if ( name.size() != 0 || sep != ' ') 00188 strlist.push_back ( name ); 00189 00190 lastChr = ch; 00191 } 00192 }
| void TeStdFile::rewind | ( | ) | [inherited] |
Definition at line 57 of file TeStdFile.cpp.
References TeStdFile::file_, and fseek().
Referenced by TeReadCSVFile().
| bool TeAsciiFile::writeCoordPairVect2CSV | ( | const TeCoordPairVect & | coordsVec | ) |
Write a vector os coordinates pairs using the CSV file format (one line per coordinate pair).
| coordsVec | The input coordinate pairs vector. |
Definition at line 371 of file TeAsciiFile.cpp.
References TeStdFile::file_.
00372 { 00373 if( file_ ) 00374 { 00375 for( TeCoordPairVect::size_type idx = 0 ; idx < coordsVec.size() ; ++idx ) 00376 { 00377 if( fprintf( file_, "%.15f;%.15f;%.15f;%.15f\n", 00378 coordsVec[ idx ].pt1.x_, coordsVec[ idx ].pt1.y_, 00379 coordsVec[ idx ].pt2.x_, coordsVec[ idx ].pt2.y_ ) < 00380 1 ) 00381 { 00382 return false; 00383 } 00384 } 00385 00386 return true; 00387 } 00388 else 00389 { 00390 return false; 00391 } 00392 }
| void TeAsciiFile::writeNewLine | ( | ) | [inline] |
Definition at line 58 of file TeAsciiFile.h.
Referenced by TeErrorLog::endSession(), TeErrorLog::insert(), TeDecoderSPR::saveData(), TeDecoderASCIIGrid::saveData(), TeExportMIFAttributeList(), TeExportMIFRow(), TeExportQuerierToCSV(), TeExportQuerierToMIF(), TeExportQuerierToSPRING(), TeGeoOpAggregation(), TeGeoOpAssignDataLocationDistribute(), TeGeoOpBuffer(), TeGeoOpOverlayDifference(), TeGeoOpOverlayIntersection(), TeGeoOpOverlayUnion(), and TeRasterParams::writeParametersFile().
00059 { fprintf ( file_, "\n" ); }
| void TeAsciiFile::writeString | ( | const string & | s | ) |
Definition at line 105 of file TeAsciiFile.cpp.
References TeStdFile::file_.
Referenced by TeErrorLog::endSession(), TeDecoderJPEG::init(), TeErrorLog::insert(), TeDecoderSPR::saveData(), TeExportMIFAttributeList(), TeExportMIFCellSet(), TeExportMIFLineSet(), TeExportMIFPointSet(), TeExportMIFPolygonSet(), TeExportMIFProjection(), TeExportMIFRow(), TeExportQuerierToCSV(), TeExportQuerierToMIF(), TeExportQuerierToSPRING(), TeGeoOpAggregation(), TeGeoOpAssignDataLocationDistribute(), TeGeoOpBuffer(), TeGeoOpOverlayDifference(), TeGeoOpOverlayIntersection(), TeGeoOpOverlayUnion(), TeDecoderSPR::writeParameters(), TeDecoderASCIIGrid::writeParameters(), and TeRasterParams::writeParametersFile().
FILE* TeStdFile::file_ [protected, inherited] |
Definition at line 71 of file TeStdFile.h.
Referenced by findNewLine(), readAll(), readAngle(), readBox(), readChar(), readCoord2D(), readCoordPairVect2CSV(), readFloat(), readFont(), readInt(), readLine(), readNStringCSV(), readQuotedChar(), readQuotedString(), readString(), readStringCSV(), readStringList(), readStringListCSV(), TeStdFile::rewind(), TeStdFile::TeStdFile(), TeSPRFile::writeArcHeader(), TeSPRFile::writeAttributeInfo(), TeSPRFile::writeBox(), TeSPRFile::writeCadastralLabel(), writeCoordPairVect2CSV(), TeSPRFile::writeIntParameterInfo(), TeSPRFile::writeLabelHeader(), TeSPRFile::writeLinesHeader(), TeSPRFile::writeNetworkHeader(), TeSPRFile::writeNetworkLabel(), TeSPRFile::writePointsHeader(), TeSPRFile::writeProjection(), TeSPRFile::writeRealParameterInfo(), TeSPRFile::writeSample(), TeSPRFile::writeSampleHeader(), writeString(), TeSPRFile::writeTableHeader(), TeSPRFile::writeTextParameterInfo(), TeSPRFile::writeThematicLabel(), TeSPRFile::writeThematicPoint(), and TeStdFile::~TeStdFile().
string TeStdFile::fileName_ [protected, inherited] |
string TeStdFile::mode_ [protected, inherited] |
Definition at line 73 of file TeStdFile.h.
1.5.3