00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef COMMAND_LINE_OPTION_HPP
00021 #define COMMAND_LINE_OPTION_HPP
00022
00023 #include <StreamCenter.hpp>
00024
00025 #include <ErrorHandler.hpp>
00026
00027 #include <string>
00028 #include <vector>
00029
00038 class CommandLineOption
00039 {
00040 public:
00041 enum ArgumentsType
00042 {
00043 integer,
00044 real,
00045 string,
00046 end
00047 };
00048
00049 private:
00050 const int __identifier;
00052 const std::string __longName;
00053 const std::string __shortName;
00054 const std::string __description;
00055 std::vector<ArgumentsType> __arguments;
00057 public:
00058
00064 const std::string& shortName() const
00065 {
00066 return __shortName;
00067 }
00068
00074 const std::string& longName() const
00075 {
00076 return __longName;
00077 }
00078
00084 const std::string& description() const
00085 {
00086 return __description;
00087 }
00088
00089 const std::string arguments() const
00090 {
00091 std::string argument;
00092 for (size_t i=0; i<__arguments.size(); ++i) {
00093 if (i!=0) argument += ',';
00094 switch (__arguments[i]) {
00095 case CommandLineOption::integer: {
00096 argument += "int";
00097 break;
00098 }
00099 case CommandLineOption::real: {
00100 argument += "real";
00101 break;
00102 }
00103 case CommandLineOption::string: {
00104 argument += "str";
00105 break;
00106 }
00107 case CommandLineOption::end:
00108 default: {
00109 throw ErrorHandler(__FILE__,__LINE__,
00110 "unexpected command line option",
00111 ErrorHandler::unexpected);
00112 }
00113 }
00114 }
00115 return argument;
00116 }
00117
00123 const int& identifier() const
00124 {
00125 return __identifier;
00126 }
00127
00132 CommandLineOption(const int& id,
00133 const std::string& longName,
00134 const std::string& shortName,
00135 const std::string& description,
00136 ArgumentsType arguments[] = 0)
00137 : __identifier(id),
00138 __longName(longName),
00139 __shortName(shortName),
00140 __description(description)
00141 {
00142 if (arguments != 0) {
00143 for (int i=0; arguments[i]!=CommandLineOption::end; ++i) {
00144 __arguments.push_back(arguments[i]);
00145 }
00146 }
00147 }
00152 ~CommandLineOption()
00153 {
00154 ;
00155 }
00156 };
00157
00158 #endif // COMMAND_LINE_OPTION_HPP