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