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