From a2457cf12615b21cee60d8c468aeb94d9c52d82c Mon Sep 17 00:00:00 2001 From: mac Date: Thu, 23 Mar 2000 14:41:12 +0000 Subject: [PATCH] few minor mods --- eo/src/utils/compatibility.h | 4 ++++ eo/src/utils/eoParser.cpp | 26 ++++++++++++++++++++---- eo/src/utils/eoParser.h | 39 ++++++++++++++++++++++++++++++++++-- eo/src/utils/eoState.cpp | 25 ++++++++++++++++++----- eo/src/utils/eoState.h | 3 +++ 5 files changed, 86 insertions(+), 11 deletions(-) diff --git a/eo/src/utils/compatibility.h b/eo/src/utils/compatibility.h index 353183f7..73d2cc0b 100644 --- a/eo/src/utils/compatibility.h +++ b/eo/src/utils/compatibility.h @@ -31,6 +31,10 @@ #include #include +#ifdef __GNUC__ +typedef ios ios_base; // not currently defined in GCC +#endif + #ifdef _MSC_VER /* Maarten: added this code here because Mirkosoft has the diff --git a/eo/src/utils/eoParser.cpp b/eo/src/utils/eoParser.cpp index 9a669c6c..3058bfba 100644 --- a/eo/src/utils/eoParser.cpp +++ b/eo/src/utils/eoParser.cpp @@ -7,7 +7,9 @@ #include #include -#include "eoParser.h" +#include + +#include using namespace std; @@ -18,10 +20,22 @@ void eoWarning(std::string str) std::ostream& printSectionHeader(std::ostream& os, std::string section) { + if (section == "") + section = "General"; + os << '\n' << setw(10) << "###### " << setw(20) << section << setw(10) << " ######\n"; return os; } +eoParameterLoader::~eoParameterLoader() +{ + for (int i = 0; i < ownedParams.size(); ++i) + { + delete ownedParams[i]; + } +} + + eoParser::eoParser ( int _argc, char **_argv , string _programDescription, string _lFileParamName, char _shortHand) : programName( _argv[0]), programDescription( _programDescription), @@ -184,9 +198,13 @@ void eoParser::printOn(ostream& os) const string str = "--" + param->longName() + "=" + param->getValue(); - //os.setf(ios_base::left, ios_base::adjustfield); + os.setf(ios_base::left, ios_base::adjustfield); os << setw(40) << str; - os << " # " << '-' << param->shortName() << " : " << param->description(); + + os << setw(0) << " # "; + if (param->shortName()) + os << '-' << param->shortName() << " : "; + os << param->description(); if (param->required()) { @@ -205,7 +223,7 @@ void eoParser::printHelp(ostream& os) // print the usage when calling the program from the command line os << "Usage: "<< programName<<" [Options]\n"; // only short usage! - os << "Options of the form \"-ShortName value\" or \"--LongName value\"" << endl; + os << "Options of the form \"-f[Value]\" or \"--Name[=value]\"" << endl; os << "Where:"< + eoValueParam& createParam + (ValueType _defaultValue, + std::string _longName, + std::string _description, + char _shortHand = 0, + std::string _section = "", + bool _required = false) + { + eoValueParam* p = new eoValueParam(_defaultValue, _longName, _description, _shortHand, _required); + + ownedParams.push_back(p); + + processParam(*p, _section); + + return *p; + } + +private : + + std::vector ownedParams; + }; /** @@ -73,7 +106,8 @@ public: * * myEo --param-file=param.rc will then load using the parameter file param.rc * - * @param _argc, _ argv command line arguments + * @param _argc command line arguments count + * @param _argv command line parameters * @param _programDescription Description of the work the program does * @param _lFileParamName Name of the parameter specifying the configuration file (--param-file) * @param _shortHand Single charachter shorthand for specifying the configuration file @@ -128,4 +162,5 @@ private: eoValueParam needHelp; }; + #endif \ No newline at end of file diff --git a/eo/src/utils/eoState.cpp b/eo/src/utils/eoState.cpp index 3d60ed44..e1e2dd4c 100644 --- a/eo/src/utils/eoState.cpp +++ b/eo/src/utils/eoState.cpp @@ -46,7 +46,16 @@ void eoState::registerObject(eoPersistent& registrant) { string name = createObjectName(dynamic_cast(®istrant)); - objectMap[name] = ®istrant; + pair res = objectMap.insert(make_pair(name, ®istrant)); + + if (res.second == true) + { + creationOrder.push_back(res.first); + } + else + { + throw logic_error("Interval error: object already present in the state"); + } } void eoState::load(const string& _filename) @@ -107,13 +116,19 @@ void eoState::load(const string& _filename) } void eoState::save(const string& filename) -{ +{ // saves in order of insertion ofstream os(filename.c_str()); - for (ObjectMap::iterator it = objectMap.begin(); it != objectMap.end(); ++it) + if (os.fail()) { - os << "\\section{" << it->first << "}\n"; - it->second->printOn(os); + string msg = "Could not open file: " + filename + " for writing!"; + throw runtime_error(msg); + } + + for (vector::iterator it = creationOrder.begin(); it != creationOrder.end(); ++it) + { + os << "\\section{" << (*it)->first << "}\n"; + (*it)->second->printOn(os); os << '\n'; } } diff --git a/eo/src/utils/eoState.h b/eo/src/utils/eoState.h index 9f656a6c..e505f55f 100644 --- a/eo/src/utils/eoState.h +++ b/eo/src/utils/eoState.h @@ -30,6 +30,7 @@ #include #include #include +#include class eoObject; class eoPersistent; @@ -79,6 +80,8 @@ private : typedef std::map ObjectMap; ObjectMap objectMap; + + std::vector creationOrder; }; #endif //eoState_h