#include <orsa_file.h>
Inheritance diagram for OrsaConfigFile:
Public Member Functions | |
OrsaConfigFile () | |
orsa configuration file | |
void | Read () |
void | Write () |
void | Open (const FILE_STATUS st=OPEN_R) |
void | Close () |
virtual std::string | GetFileName () const |
virtual void | SetFileName (std::string name_in) |
virtual void | SetFileName (char *name_in) |
Protected Attributes | |
std::string | filename |
FILE_TYPE | file |
FILE_STATUS | status |
Definition at line 489 of file orsa_file.h.
OrsaConfigFile | ( | ) |
orsa configuration file
Definition at line 1336 of file orsa_file.cc.
References orsa::ASTDYS_ALLNUM_CAT, orsa::ASTDYS_ALLNUM_CTC, orsa::ASTDYS_ALLNUM_CTM, orsa::ASTDYS_UFITOBS_CAT, orsa::ASTDYS_UFITOBS_CTC, orsa::ASTDYS_UFITOBS_CTM, orsa::JPL_DASTCOM_COMET, orsa::JPL_DASTCOM_NUM, orsa::JPL_DASTCOM_UNNUM, orsa::JPL_EPHEM_FILE, orsa::LOWELL_ASTORB, orsa::MPC_COMET, orsa::MPC_DAILY, orsa::MPC_DISTANT, orsa::MPC_MPCORB, orsa::MPC_NEA, orsa::MPC_PHA, orsa::MPC_UNUSUALS, orsa::NEODYS_CAT, orsa::NEODYS_CTC, orsa::OBSCODE, File::SetFileName(), orsa::TEXTURE_EARTH, orsa::TEXTURE_JUPITER, orsa::TEXTURE_MARS, orsa::TEXTURE_MERCURY, orsa::TEXTURE_MOON, orsa::TEXTURE_NEPTUNE, orsa::TEXTURE_SATURN, orsa::TEXTURE_SUN, orsa::TEXTURE_URANUS, orsa::TEXTURE_VENUS, orsa::TLE_GEO, orsa::TLE_GPS, orsa::TLE_ISS, orsa::TLE_KEPELE, orsa::TLE_NASA, orsa::TLE_VISUAL, orsa::TLE_WEATHER, and OrsaPaths::work_path().
01336 : ReadWriteFile() { 01337 01338 // status = CLOSE; 01339 01340 // conf = conf_in; 01341 01342 char path[1024], command[1024]; 01343 01344 // needed to avoid some odd segfaults... 01345 // OrsaPaths p; // make sure the constructor gets called 01346 01347 // cerr << "OrsaPaths::work_path() = " << OrsaPaths::work_path() << endl; 01348 01349 strcpy(path, OrsaPaths::work_path()); 01350 #ifndef _WIN32 01351 sprintf(command,"mkdir -p %s",path); 01352 system(command); 01353 #else 01354 _mkdir(path); 01355 #endif 01356 strcat(path,"config"); 01357 01358 SetFileName(path); 01359 01360 list_enum.push_back(JPL_EPHEM_FILE); 01361 list_enum.push_back(JPL_DASTCOM_NUM); 01362 list_enum.push_back(JPL_DASTCOM_UNNUM); 01363 list_enum.push_back(JPL_DASTCOM_COMET); 01364 list_enum.push_back(LOWELL_ASTORB); 01365 list_enum.push_back(MPC_MPCORB); 01366 list_enum.push_back(MPC_COMET); 01367 list_enum.push_back(MPC_NEA); 01368 list_enum.push_back(MPC_DAILY); 01369 list_enum.push_back(MPC_DISTANT); 01370 list_enum.push_back(MPC_PHA); 01371 list_enum.push_back(MPC_UNUSUALS); 01372 list_enum.push_back(ASTDYS_ALLNUM_CAT); 01373 list_enum.push_back(ASTDYS_ALLNUM_CTC); 01374 list_enum.push_back(ASTDYS_ALLNUM_CTM); 01375 list_enum.push_back(ASTDYS_UFITOBS_CAT); 01376 list_enum.push_back(ASTDYS_UFITOBS_CTC); 01377 list_enum.push_back(ASTDYS_UFITOBS_CTM); 01378 list_enum.push_back(NEODYS_CAT); 01379 list_enum.push_back(NEODYS_CTC); 01380 list_enum.push_back(OBSCODE); 01381 // TLE 01382 list_enum.push_back(TLE_NASA); 01383 list_enum.push_back(TLE_GEO); 01384 list_enum.push_back(TLE_GPS); 01385 list_enum.push_back(TLE_ISS); 01386 list_enum.push_back(TLE_KEPELE); 01387 list_enum.push_back(TLE_VISUAL); 01388 list_enum.push_back(TLE_WEATHER); 01389 // textures 01390 list_enum.push_back(TEXTURE_SUN); 01391 list_enum.push_back(TEXTURE_MERCURY); 01392 list_enum.push_back(TEXTURE_VENUS); 01393 list_enum.push_back(TEXTURE_EARTH); 01394 list_enum.push_back(TEXTURE_MOON); 01395 list_enum.push_back(TEXTURE_MARS); 01396 list_enum.push_back(TEXTURE_JUPITER); 01397 list_enum.push_back(TEXTURE_SATURN); 01398 list_enum.push_back(TEXTURE_URANUS); 01399 list_enum.push_back(TEXTURE_NEPTUNE); 01400 }
Here is the call graph for this function:
void Close | ( | ) | [inherited] |
Definition at line 114 of file orsa_file.cc.
References orsa::CLOSE, CLOSE_FILE, File::file, and File::status.
Referenced by SWIFTFile::AsteroidsInFile(), ReadWriteFile::Open(), OrsaFile::Read(), OrsaConfigFile::Read(), SWIFTFile::Read(), Config::read_from_file(), File::SetFileName(), OrsaFile::Write(), OrsaConfigFile::Write(), Config::write_to_file(), and File::~File().
virtual std::string GetFileName | ( | ) | const [inline, virtual, inherited] |
Definition at line 99 of file orsa_file.h.
References File::filename.
Referenced by OrsaFile::Read().
00099 { return filename; }
void Open | ( | const FILE_STATUS | st = OPEN_R |
) | [inherited] |
Definition at line 83 of file orsa_file.cc.
References File::Close(), orsa::CLOSE, File::file, File::filename, OPEN_FILE, orsa::OPEN_R, OPEN_READ, orsa::OPEN_W, OPEN_WRITE, ORSA_ERROR, and File::status.
Referenced by OrsaFile::Read(), OrsaConfigFile::Read(), OrsaFile::Write(), and OrsaConfigFile::Write().
00083 { 00084 00085 // already in the right status 00086 if (status == st) return; 00087 00088 // anomalous... 00089 if (st == CLOSE) { 00090 Close(); 00091 return; 00092 } 00093 00094 Close(); 00095 00096 if ((st == OPEN_R) && ((file = OPEN_FILE(filename.c_str(),OPEN_READ)) != 0)) { 00097 status = OPEN_R; 00098 return; 00099 } 00100 00101 if ((st == OPEN_W) && ((file = OPEN_FILE(filename.c_str(),OPEN_WRITE)) != 0)) { 00102 status = OPEN_W; 00103 return; 00104 } 00105 00106 if (file == 0) { 00107 ORSA_ERROR("Can't open file %s",filename.c_str()); 00108 } 00109 00110 status = CLOSE; 00111 }
Here is the call graph for this function:
void Read | ( | ) | [virtual] |
Implements ReadWriteFile.
Definition at line 1402 of file orsa_file.cc.
References File::Close(), orsa::config, File::file, GETS_FILE, ReadWriteFile::Open(), orsa::OPEN_R, ORSA_ERROR, Config::paths, orsa::remove_leading_trailing_spaces(), REWIND_FILE, and File::status.
Referenced by Config::read_from_file().
01402 { 01403 01404 // if (file == 0) Open(); 01405 // if (status == CLOSE) Open(); 01406 01407 Open(OPEN_R); 01408 01409 // should improve this check 01410 // if (status != OPEN_R) return; 01411 01412 if (status != OPEN_R) { 01413 ORSA_ERROR("Status error!"); 01414 return; 01415 } 01416 01417 char line[1024]; 01418 string stag, svalue; 01419 01420 REWIND_FILE(file); 01421 01422 while (GETS_FILE(line,1024,file) != 0) { 01423 01424 { 01425 // the first white space is the separator between tag and value 01426 string s_line=line; 01427 string::size_type white_space_pos; 01428 white_space_pos = s_line.find(" ",0); 01429 if (white_space_pos != string::npos) { 01430 stag.assign(s_line,0,white_space_pos); 01431 svalue.assign(s_line,white_space_pos+1,s_line.size()-white_space_pos-2); 01432 remove_leading_trailing_spaces(stag); 01433 remove_leading_trailing_spaces(svalue); 01434 // 01435 // cerr << "tag -->" << stag << "<-- value -->" << svalue << "<-- " << endl; 01436 } 01437 } 01438 01439 if (svalue.size()>0) { 01440 01441 list<ConfigEnum>::const_iterator it = list_enum.begin(); 01442 while (it != list_enum.end()) { 01443 if (stag == config->paths[(*it)]->tag) { 01444 config->paths[(*it)]->SetValue(svalue); 01445 break; 01446 } 01447 ++it; 01448 } 01449 01450 } 01451 01452 } 01453 01454 Close(); 01455 }
Here is the call graph for this function:
virtual void SetFileName | ( | char * | name_in | ) | [inline, virtual, inherited] |
Definition at line 106 of file orsa_file.h.
References File::SetFileName().
00106 { 00107 std::string n = name_in; 00108 SetFileName (n); 00109 }
Here is the call graph for this function:
virtual void SetFileName | ( | std::string | name_in | ) | [inline, virtual, inherited] |
Definition at line 101 of file orsa_file.h.
References File::Close(), orsa::CLOSE, File::filename, and File::status.
Referenced by OrsaConfigFile::OrsaConfigFile(), and File::SetFileName().
Here is the call graph for this function:
void Write | ( | ) | [virtual] |
Implements ReadWriteFile.
Definition at line 1457 of file orsa_file.cc.
References File::Close(), orsa::config, File::file, FLUSH_FILE, ReadWriteFile::Open(), orsa::OPEN_W, ORSA_ERROR, Config::paths, PUTS_FILE, and File::status.
Referenced by Config::write_to_file().
01457 { 01458 01459 // this close is necessary to avoid multiple write of the same options 01460 Close(); 01461 01462 // *** TODO: make a backup copy before to save the new one! *** 01463 01464 Open(OPEN_W); 01465 01466 if (status != OPEN_W) { 01467 ORSA_ERROR("Status error!"); 01468 return; 01469 } 01470 01471 // cerr << "OrsaConfigFile::Write() ==> " << filename << endl; 01472 01473 // rewind(file); 01474 01475 char line[1024]; 01476 01477 list<ConfigEnum>::const_iterator it = list_enum.begin(); 01478 while (it != list_enum.end()) { 01479 sprintf(line,"%s %s\n",config->paths[(*it)]->tag.c_str(),config->paths[(*it)]->GetValue().c_str()); 01480 PUTS_FILE(line,file); 01481 ++it; 01482 } 01483 01484 FLUSH_FILE(file); 01485 01486 Close(); 01487 }
Here is the call graph for this function:
FILE_TYPE file [protected, inherited] |
Definition at line 113 of file orsa_file.h.
Referenced by SWIFTFile::AsteroidsInFile(), File::Close(), File::File(), ReadWriteFile::Open(), WriteFile::Open(), ReadFile::Open(), Mercury5IntegrationFile::Read(), OrsaFile::Read(), OrsaConfigFile::Read(), SWIFTFile::Read(), LocationFile::Read(), RWOFile::Read(), MPCObsFile::Read(), MPCCometFile::Read(), MPCOrbFile::Read(), AstorbFile::Read(), OrsaFile::Write(), and OrsaConfigFile::Write().
std::string filename [protected, inherited] |
Definition at line 112 of file orsa_file.h.
Referenced by File::GetFileName(), ReadWriteFile::Open(), WriteFile::Open(), ReadFile::Open(), and File::SetFileName().
FILE_STATUS status [protected, inherited] |
Definition at line 114 of file orsa_file.h.
Referenced by File::Close(), File::File(), Mercury5IntegrationFile::Mercury5IntegrationFile(), ReadWriteFile::Open(), WriteFile::Open(), ReadFile::Open(), Mercury5IntegrationFile::Read(), TLEFile::Read(), NEODYSCAT::Read(), JPLDastcomCometFile::Read(), JPLDastcomUnnumFile::Read(), JPLDastcomNumFile::Read(), AstDySMatrixFile::Read(), RadauModIntegrationFile::Read(), OrsaFile::Read(), OrsaConfigFile::Read(), SWIFTFile::Read(), LocationFile::Read(), MPCObsFile::Read(), MPCCometFile::Read(), MPCOrbFile::Read(), AstorbFile::Read(), File::SetFileName(), OrsaFile::Write(), and OrsaConfigFile::Write().