Removed "using namespace std" statements from header files in EO -- "std::" identifier were added where necessary.

This commit is contained in:
okoenig 2003-02-27 19:28:07 +00:00
commit 86fa476c67
263 changed files with 2009 additions and 1976 deletions

View file

@ -29,8 +29,8 @@
#include <string.h> // for strcasecmp ... maybe there's a c++ way of doing it?
// Yep there is, but needs either a simple functor for the equal function
// or a hand-rolled string template class (this isn't that horrible as
// it sounds, it just means a new string_traits class with two changed
// or a hand-rolled std::string template class (this isn't that horrible as
// it sounds, it just means a new std::string_traits class with two changed
// function definitions. (Maarten)
#ifdef _MSC_VER
#define strcasecmp(a,b) _strnicmp(a,b,strlen(a))
@ -44,8 +44,8 @@
#include <strstream>
#include <ctime>
// include for exceptions
#include <stdexcept> // logic_error
// include for std::exceptions
#include <stdexcept> // std::logic_error
//-----------------------------------------------------------------------------
// Class Param
@ -71,9 +71,9 @@ public:
* @param _description Description of the parameter. What is useful for.
* @param _required If it is a necessary parameter or not
*/
Param (string _shortName="-h", string _longName="--help",
string _default = "", valueType _valType= STRING,
string _description="Shows this help",
Param (std::string _shortName="-h", std::string _longName="--help",
std::string _default = "", valueType _valType= STRING,
std::string _description="Shows this help",
bool _required=false )
: repShortName(_shortName), repLongName(_longName),
repDescription(_description ), repEnv(""), repDefault(_default),
@ -108,38 +108,38 @@ public:
/**
* Returns the short name.
*/
const string& shortName ( void ) const { return repShortName; };
const std::string& shortName ( void ) const { return repShortName; };
/**
* Returns the long name.
*/
const string& longName ( void ) const { return repLongName; };
const std::string& longName ( void ) const { return repLongName; };
/**
* Returns the description of the argument
*/
const string& description ( void ) const { return repDescription; };
const std::string& description ( void ) const { return repDescription; };
/**
* Returns the environment variable of the argument
*/
const string& environment ( void ) const { return repEnv; };
const std::string& environment ( void ) const { return repEnv; };
/**
* Returns the default value of the argument
*/
const string& defValue ( void ) const { return repDefault; };
const std::string& defValue ( void ) const { return repDefault; };
/**
* Sets a value for the param.
* @param _value The new value.
*/
void value ( const string& _value ) { repValue = _value; repChanged = true; };
void value ( const std::string& _value ) { repValue = _value; repChanged = true; };
/**
* Returns the value of the param.
*/
const string& value ( void ) const { return repValue; };
const std::string& value ( void ) const { return repValue; };
/**
* Returns if required or not.
@ -157,13 +157,13 @@ public:
bool changed( void ) const { return repChanged; };
private:
string repShortName;
string repLongName;
string repDescription;
string repEnv;
string repDefault;
std::string repShortName;
std::string repLongName;
std::string repDescription;
std::string repEnv;
std::string repDefault;
string repValue;
std::string repValue;
Param::valueType repValType;
bool repRequired;
bool repChanged;
@ -194,15 +194,15 @@ public:
* @param _argc, _ argv command line arguments
* @param _programDescription Description of the work the program does
*/
Parser ( int _argc, char **_argv , string _programDescription,
string _sFileParamName = "-P",
string _lFileParamName = "--Param") :
Parser ( int _argc, char **_argv , std::string _programDescription,
std::string _sFileParamName = "-P",
std::string _lFileParamName = "--Param") :
params(),
programName( _argv[0]), programDescription( _programDescription),
parse_argc(_argc), parse_argv(_argv), InputFileName("") {
// the input file name has to be read immediately - from command-line or environement (not input0file :-)
string _default = _argv[0];
std::string _default = _argv[0];
_default += ".param";
Param param (_sFileParamName, _lFileParamName, _default, Param::STRING, "Name of the input file", 0);
@ -249,7 +249,7 @@ public:
* Adds a fake parameter == title in the output file
* @param the title
*/
void AddTitle (const string& _title)
void AddTitle (const std::string& _title)
{
Param param ( "", "", "", Param::TITLE, _title, false );
params.push_back( param );
@ -266,12 +266,12 @@ public:
*/
/**
* Gets the string value of a param from the full parameter description
* Gets the std::string value of a param from the full parameter description
* @param see above
*/
string getString (const string& _shortName, const string& _longName,
const string& _default = "",
const string& _description="", bool _required=false) {
std::string getString (const std::string& _shortName, const std::string& _longName,
const std::string& _default = "",
const std::string& _description="", bool _required=false) {
Param param ( _shortName, _longName, _default, Param::STRING, _description, _required );
parse( param );
params.push_back( param );
@ -284,8 +284,8 @@ public:
* @param see above
*/
bool getBool (const string& _shortName, const string& _longName,
const string& _description="") {
bool getBool (const std::string& _shortName, const std::string& _longName,
const std::string& _description="") {
Param param ( _shortName, _longName, "false", Param::BOOL, _description, false );
parse( param );
params.push_back( param );
@ -299,19 +299,19 @@ public:
};
/**
* Gets the "array" (vector of strings) value of a param from the full parameter description
* Gets the "array" (std::vector of std::strings) value of a param from the full parameter description
* @param see above
*/
vector<string> getArray (const string& _shortName, const string& _longName,
const string& _default = "",
const string& _description="", bool _required=false) {
std::vector<std::string> getArray (const std::string& _shortName, const std::string& _longName,
const std::string& _default = "",
const std::string& _description="", bool _required=false) {
Param param ( _shortName, _longName, _default, Param::ARRAY, _description, _required );
parse( param );
params.push_back( param );
istrstream is(param.value().c_str());
vector<string> retValue;
string tmpStr;
std::vector<std::string> retValue;
std::string tmpStr;
is >> tmpStr;
while(is){
@ -324,12 +324,12 @@ public:
/**
* Gets the int value of a param given the full description of the parameter
* @param see above
* @exception BadType if the param's value isn't a correct int
* @std::exception BadType if the param's value isn't a correct int
*/
int getInt (const string& _shortName, const string& _longName,
const string& _default = "",
const string& _description="", bool _required=false) {
int getInt (const std::string& _shortName, const std::string& _longName,
const std::string& _default = "",
const std::string& _description="", bool _required=false) {
Param param ( _shortName, _longName, _default, Param::INT, _description, _required );
parse( param );
params.push_back( param );
@ -350,12 +350,12 @@ public:
/**
* Gets the unsigned lon value of a param given ...
* @param see above
* @exception BadType if the param's value isn't a correct unsigned long
* @std::exception BadType if the param's value isn't a correct unsigned long
*/
int getUnsignedLong (const string& _shortName, const string& _longName,
const string& _default = "",
const string& _description="", bool _required=false) {
int getUnsignedLong (const std::string& _shortName, const std::string& _longName,
const std::string& _default = "",
const std::string& _description="", bool _required=false) {
Param param ( _shortName, _longName, _default, Param::UL, _description, _required );
parse( param );
params.push_back( param );
@ -376,12 +376,12 @@ public:
/**
* Gets the float value of a param given the description of the parameter
* @param see above
* @exception BadType if the param's value isn't a correct int
* @std::exception BadType if the param's value isn't a correct int
*/
float getFloat (const string& _shortName, const string& _longName,
const string& _default = "",
const string& _description="", bool _required=false) {
float getFloat (const std::string& _shortName, const std::string& _longName,
const std::string& _default = "",
const std::string& _description="", bool _required=false) {
Param param ( _shortName, _longName, _default, Param::FLOAT, _description, _required );
parse( param );
params.push_back( param );
@ -400,19 +400,19 @@ public:
};
string parse_string (istream & _is) {
string paramValue;
std::string parse_std::string (std::istream & _is) {
std::string paramValue;
_is >> paramValue;
//if the first character of the string or array is not a " => just one word or array-element.
//if the first character of the std::string or array is not a " => just one word or array-element.
if( paramValue[0] != '\"' )
return paramValue;
if( paramValue[1] == '\"' ) // the empty string
if( paramValue[1] == '\"' ) // the empty std::string
return "" ;
//else => read until the next " (the end of the string).
//else => read until the next " (the end of the std::string).
const char *c = paramValue.c_str();
string tmpStr = c+1;// skip the "
std::string tmpStr = c+1;// skip the "
if (tmpStr[tmpStr.length()-1] == '\"') { // one word only
//tmpStr[tmpStr.length()-1] = '\0';
tmpStr.erase( &tmpStr[tmpStr.length()-1] );
@ -436,11 +436,11 @@ public:
void parse (Param & param) {
int i;
string tmpStr, ReadStr, FirstWord;
std::string tmpStr, ReadStr, FirstWord;
// FIRST: look if the associated environment variables have any value, to use them.
if( getenv( param.environment().c_str() ) ) {
//cout <<"\t\t ENV param: ,"<<p->shortName()<<", ,"<<getenv(p->environment().c_str())<<endl;
//std::cout <<"\t\t ENV param: ,"<<p->shortName()<<", ,"<<getenv(p->environment().c_str())<<std::endl;
param.value(getenv(param.environment().c_str()) );
}
@ -457,7 +457,7 @@ public:
Param::valueType tmp = param.valType();
switch ( tmp ) {
case Param::TITLE:
cerr << "Error, we should not be there" << endl;
std::cerr << "Error, we should not be there" << std::endl;
exit(1);
break;
case Param::BOOL :
@ -472,18 +472,18 @@ public:
break;
case Param::STRING:
tmpStr = parse_string(is);
tmpStr = parse_std::string(is);
param.value(tmpStr);
break;
case Param::ARRAY:
ReadStr = parse_string(is);
if ( ReadStr != "<" ) { // no "<" ">" --> a single string in the array
ReadStr = parse_std::string(is);
if ( ReadStr != "<" ) { // no "<" ">" --> a single std::string in the array
param.value(ReadStr);
break;
}
// read next word - and keep it in case of <> mismatch
FirstWord = parse_string(is);
FirstWord = parse_std::string(is);
// test for empty array
if (FirstWord == ">") {
param.value("");
@ -491,15 +491,15 @@ public:
}
// else, read all words until ">"
tmpStr = FirstWord;
ReadStr = parse_string(is);
ReadStr = parse_std::string(is);
while ( is && (ReadStr != ">") ) {
tmpStr = tmpStr + " " + ReadStr;
ReadStr = parse_string(is);
ReadStr = parse_std::string(is);
}
if (!is) { // there was a "<" without the corresponding ">"
throw Parser::BadArrayParam( param.longName(), FirstWord );
param.value(FirstWord); // assume unique string
param.value(FirstWord); // assume unique std::string
}
else
param.value(tmpStr);
@ -516,18 +516,18 @@ public:
( ! strcmp(param.shortName().c_str(), parse_argv[i]) )
) { // found the parameter name
if (param.valType() == Param::BOOL) {
//cout <<"BOOL: "<<parse_argv[i]<<" <-- true"<<endl;
//std::cout <<"BOOL: "<<parse_argv[i]<<" <-- true"<<std::endl;
param.value("true");
}else{
if (param.valType() != Param::ARRAY) { //only if it is not an array
//cout <<"TYPE: "<<parse_argv[i]<<" <-- "<<parse_argv[i+1]<<endl;
//std::cout <<"TYPE: "<<parse_argv[i]<<" <-- "<<parse_argv[i+1]<<std::endl;
param.value(parse_argv[i+1]);
}else{ //if it is an ARRAY
i++;
ReadStr = parse_argv[i++];
//cout <<"ARRAY: <-- ";
//std::cout <<"ARRAY: <-- ";
if ( ReadStr != "<" ) { // no "<" ">" --> a single string in the array
if ( ReadStr != "<" ) { // no "<" ">" --> a single std::string in the array
param.value(ReadStr);
}else{
// read next word - and keep it in case of <> mismatch
@ -544,11 +544,11 @@ public:
tmpStr = tmpStr + " " + ReadStr;
ReadStr = parse_argv[i++];
}
//cout <<"tmpStr ;"<<tmpStr<<"; ("<<i<<","<<parse_argc<<") "<<endl;
//std::cout <<"tmpStr ;"<<tmpStr<<"; ("<<i<<","<<parse_argc<<") "<<std::endl;
if ( (i>=parse_argc) && (ReadStr != ">") ) { // there was a "<" without the corresponding ">"
throw Parser::BadArrayParam( param.longName(), FirstWord );
param.value(FirstWord); // assume unique string
param.value(FirstWord); // assume unique std::string
}else{
param.value(tmpStr);
}
@ -570,11 +570,11 @@ public:
* Sets a new value for a param given its short name or its long name.
* @param _name One of the names of the param.
* @param _value Value to be assigned.
* @exception UnknownArg if the param doesn't exist
* @exception MissingVal if the param hasn't got a value
* @std::exception UnknownArg if the param doesn't exist
* @std::exception MissingVal if the param hasn't got a value
*/
Param::valueType setParamValue (const string& _name, const char* _value){
vector<Param>::iterator pos;
Param::valueType setParamValue (const std::string& _name, const char* _value){
std::vector<Param>::iterator pos;
for (pos=params.begin() ; pos!=params.end() ; pos++)
if (pos->shortName()==_name || pos->longName()==_name)
@ -584,7 +584,7 @@ public:
if (pos!=params.end()) {
switch ( pos->valType() ) {
case Param::TITLE:
cerr << "Error, we should not be there" << endl;
std::cerr << "Error, we should not be there" << std::endl;
exit(1);
break;
case Param::BOOL :
@ -613,14 +613,14 @@ public:
};
/// the output method - generate the .status file (unless other name is given)
friend ostream & operator<< ( ostream & os, Parser & _parser )
friend std::ostream & operator<< ( std::ostream & os, Parser & _parser )
{
vector<Param>::iterator p;
std::vector<Param>::iterator p;
//print every param with its value
for ( p=_parser.params.begin(); p!=_parser.params.end(); p++ ) {
switch ( p->valType() ) {
case Param::BOOL :
if( p->value() == (string) "true")
if( p->value() == (std::string) "true")
os << p->longName();
else
os << "#" << p->longName() ; // so the name of the bool is commented out
@ -639,30 +639,30 @@ public:
os << p->longName()<<" \""<<p->value().c_str()<<"\" ";
break;
case Param::TITLE:
os << endl; // Title is in the description below
os << std::endl; // Title is in the description below
break;
} // switch
os << "\t #" << p->shortName() << " : " << p->description();
if (p->valType() != Param::TITLE)
os << " [" << p->defValue() << "]" ;
os << endl;
os << std::endl;
}
return os;
};
/**
* Prints out the list of parameters in the output file (if specified)
* Prints out the std::list of parameters in the output file (if specified)
*/
void outputParam(string _OutputFile="")
void outputParam(std::string _OutputFile="")
{
if (_OutputFile == "") {
_OutputFile = parse_argv[0];
_OutputFile += ".status";
}
ofstream os(_OutputFile.c_str());
std::ofstream os(_OutputFile.c_str());
os << "Parameters used by \"" << programName << "\" ("
<< programDescription << ")" << endl << endl;
<< programDescription << ")" << std::endl << std::endl;
os << *this;
};
@ -671,80 +671,80 @@ public:
* provided by parameters
*/
void printHelp() {
vector<Param>::iterator p;
std::vector<Param>::iterator p;
// unsigned i;
// print program name and description
cout << this->programName <<": "<<programDescription<<endl<<endl;
std::cout << this->programName <<": "<<programDescription<<std::endl<<std::endl;
// print the usage when calling the program from the command line
cout << "Usage: "<< programName<<" [Options]\n";
std::cout << "Usage: "<< programName<<" [Options]\n";
// only short usage!
cout << "Options of the form \"-ShortName value\" or \"--LongName value\"" << endl;
std::cout << "Options of the form \"-ShortName value\" or \"--LongName value\"" << std::endl;
// for ( i=0,p=params.begin(); p!=params.end(); i++,p++ )
// if( p->valType() != Param::TITLE ) {
// if( p->valType() != Param::BOOL ){
// cout << ( (!p->required())?"[":"");
// cout <<p->shortName()<<" value"<<i;
// cout << ( (!p->required())?"]":"")<<" ";
// std::cout << ( (!p->required())?"[":"");
// std::cout <<p->shortName()<<" value"<<i;
// std::cout << ( (!p->required())?"]":"")<<" ";
// }else{
// cout << "["<<p->shortName()<<"] ";
// std::cout << "["<<p->shortName()<<"] ";
// }
// } // for p
cout << "Where:"<<endl;
std::cout << "Where:"<<std::endl;
for ( p=params.begin(); p!=params.end(); p++ ) {
if( p->valType() != Param::TITLE ) {
// Victor: 04-Jan-2000
// Modified because the - and -- prefixes are not needed.
/*
cout << "-" << p->shortName()
std::cout << "-" << p->shortName()
<<", --"<<p->longName()<<":\t"
<<p->description()<<endl;
<<p->description()<<std::endl;
*/
cout << p->shortName()
std::cout << p->shortName()
<<", " << p->longName()<<":\t"
<<p->description()<<endl;
cout << "\t(";
<<p->description()<<std::endl;
std::cout << "\t(";
switch ( p->valType() ) {
case Param::INT: cout <<"Integer"; break;
case Param::UL: cout <<"Unsigned Long Integer"; break;
case Param::FLOAT: cout <<"Float"; break;
case Param::STRING: cout <<"String"; break;
case Param::ARRAY: cout <<"An array of strings, enclosed within < >"; break;
case Param::BOOL: cout << "Flag"; break;
case Param::INT: std::cout <<"Integer"; break;
case Param::UL: std::cout <<"Unsigned Long Integer"; break;
case Param::FLOAT: std::cout <<"Float"; break;
case Param::STRING: std::cout <<"String"; break;
case Param::ARRAY: std::cout <<"An array of std::strings, enclosed within < >"; break;
case Param::BOOL: std::cout << "Flag"; break;
case Param::TITLE: break;
} // switch
if(p->valType() == Param::BOOL)
cout << ") True if present" << endl;
std::cout << ") True if present" << std::endl;
else
cout<<") "<<( (p->required())?"Required":"Optional" )<<". By default: "<<p->defValue()<<endl;
std::cout<<") "<<( (p->required())?"Required":"Optional" )<<". By default: "<<p->defValue()<<std::endl;
}
else {
cout << "\n\t # " << p->description() << endl;
std::cout << "\n\t # " << p->description() << std::endl;
}
} // for p
cout << endl;
std::cout << std::endl;
};
/**
* This class managges unknown argument exceptions.
* This class managges unknown argument std::exceptions.
*/
class UnknownArg : public logic_error {
class UnknownArg : public std::logic_error {
public:
/**
* Constructor
* @param _arg string to be shown when the exception occurs
* @param _arg std::string to be shown when the std::exception occurs
*/
UnknownArg( const string& _arg): logic_error( "Invalid argument: "+_arg ) { };
UnknownArg( const std::string& _arg): std::logic_error( "Invalid argument: "+_arg ) { };
};
/**
* This class managges bad param types.
*/
class BadType : public logic_error {
class BadType : public std::logic_error {
public:
/**
@ -752,40 +752,40 @@ public:
* @param _param The param
* @param _value The value of the param
*/
BadType(const string& _param, const string& _value, const string& _correctType)
: logic_error("The value '" + _value + "' assigned to the argument " + _param + " isn't a correct "+_correctType) { };
BadType(const std::string& _param, const std::string& _value, const std::string& _correctType)
: std::logic_error("The value '" + _value + "' assigned to the argument " + _param + " isn't a correct "+_correctType) { };
};
/**
* This class managges exceptions produced when there isn't a value for a parameter.
* This class managges std::exceptions produced when there isn't a value for a parameter.
*/
class MissingVal : public logic_error {
class MissingVal : public std::logic_error {
public:
/**
* Constructor
* @param _param The param
*/
MissingVal(const string& _param) : logic_error("Missing value for parameter " + _param) {};
MissingVal(const std::string& _param) : std::logic_error("Missing value for parameter " + _param) {};
};
/**
* This class managges exceptions produced when the user forgot a required parameter.
* This class managges std::exceptions produced when the user forgot a required parameter.
*/
class MissingReqParam : public logic_error {
class MissingReqParam : public std::logic_error {
public:
/**
* Constructor
* @param _shortName The param's short name
*/
MissingReqParam(const string& _shortName) : logic_error("Missing required parameter " + _shortName) {};
MissingReqParam(const std::string& _shortName) : std::logic_error("Missing required parameter " + _shortName) {};
};
/**
* This class managges exceptions du to < without a > in array value
* This class managges std::exceptions du to < without a > in array value
*/
class BadArrayParam : public logic_error {
class BadArrayParam : public std::logic_error {
public:
/**
@ -793,17 +793,17 @@ public:
* @param _param The param
* @param _first_word The first word read after the "<"
*/
BadArrayParam(const string& _param, const string &_first_word) :
logic_error("Array parameter " + _param + ": No matching > (" + _first_word
BadArrayParam(const std::string& _param, const std::string &_first_word) :
std::logic_error("Array parameter " + _param + ": No matching > (" + _first_word
+ "... )") {};
};
void createParamFile( ostream& _os ) {
vector<Param>::iterator p;
void createParamFile( std::ostream& _os ) {
std::vector<Param>::iterator p;
for ( p=params.begin(); p!=params.end(); p++ ) {
switch( p->valType() ) {
case Param::TITLE:
_os << endl << "# -- ";
_os << std::endl << "# -- ";
break;
case Param::BOOL:
_os << ((p->value()=="true" )?"":"#")
@ -819,16 +819,16 @@ public:
_os << p->longName()<<"\t"<<p->value();
break;
} // switch
_os << "\t #" << p->description() << endl;
_os << "\t #" << p->description() << std::endl;
}
}
private:
vector<Param> params;
string programName;
string programDescription;
std::vector<Param> params;
std::string programName;
std::string programDescription;
int parse_argc;
char **parse_argv;
string InputFileName;
std::string InputFileName;
};