Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #include <cmtkconfig.h>
00032
00033 #include <string>
00034 #include <sstream>
00035
00036 namespace
00037 cmtk
00038 {
00039
00042
00043 template<class T>
00044 class CommandLineTypeTraitsBase
00045 {
00046 public:
00048 static std::string ValueToString( const T* value )
00049 {
00050 std::ostringstream stream;
00051 stream << *value;
00052 return stream.str();
00053 }
00054
00056 static std::string ValueToStringMinimal( const T* value )
00057 {
00058 std::ostringstream stream;
00059 stream << *value;
00060 return stream.str();
00061 }
00062 };
00063
00065 template<class T>
00066 class
00067 CommandLineTypeTraits
00069 : public CommandLineTypeTraitsBase<T>
00070 {
00071 public:
00073 static const char* GetName()
00074 {
00075 return "none";
00076 }
00077 };
00078
00079 template<>
00080 class
00081 CommandLineTypeTraits<const char*>
00083 : public CommandLineTypeTraitsBase<const char*>
00084 {
00085 public:
00086 static const char* GetName()
00087 {
00088 return "string";
00089 }
00090
00091 static std::string ValueToString( const char *const * value )
00092 {
00093 std::ostringstream stream;
00094 if ( value && *value )
00095 stream << "\"" << *value << "\"";
00096 else
00097 stream << "NONE";
00098 return stream.str();
00099 }
00100
00101 static std::string ValueToStringMinimal( const char *const * value )
00102 {
00103 std::ostringstream stream;
00104 if ( value && *value )
00105 stream << *value;
00106 return stream.str();
00107 }
00108 };
00109
00110 template<>
00111 class
00112 CommandLineTypeTraits<std::string>
00114 : public CommandLineTypeTraitsBase<std::string>
00115 {
00116 public:
00117 static const char* GetName()
00118 {
00119 return "string";
00120 }
00121 };
00122
00123 template<>
00124 class
00125 CommandLineTypeTraits< std::vector<std::string> >
00127 : public CommandLineTypeTraitsBase< std::vector<std::string> >
00128 {
00129 public:
00130 static const char* GetName()
00131 {
00132 return "vector<string>";
00133 }
00134
00135 static std::string ValueToString( const std::vector<std::string>* value )
00136 {
00137 std::ostringstream stream;
00138 for ( size_t i = 0; i < value->size(); ++i )
00139 stream << (*value)[i] << " ";
00140 return stream.str();
00141 }
00142
00144 static std::string ValueToStringMinimal( const std::vector<std::string>* value )
00145 {
00146 return ValueToString( value );
00147 }
00148 };
00149
00150 template<>
00151 class
00152 CommandLineTypeTraits<int>
00154 : public CommandLineTypeTraitsBase<int>
00155 {
00156 public:
00157 static const char* GetName()
00158 {
00159 return "integer";
00160 }
00161 };
00162
00163 template<>
00164 class
00165 CommandLineTypeTraits<unsigned int>
00167 : public CommandLineTypeTraitsBase<unsigned int>
00168 {
00169 public:
00170 static const char* GetName()
00171 {
00172 return "integer";
00173 }
00174 };
00175
00176 template<>
00177 class
00178 CommandLineTypeTraits<short>
00180 : public CommandLineTypeTraitsBase<short>
00181 {
00182 public:
00183 static const char* GetName()
00184 {
00185 return "integer";
00186 }
00187 };
00188
00189 template<>
00190 class
00191 CommandLineTypeTraits<unsigned short>
00193 : public CommandLineTypeTraitsBase<unsigned short>
00194 {
00195 public:
00196 static const char* GetName()
00197 {
00198 return "integer";
00199 }
00200 };
00201
00202 template<>
00203 class
00204 CommandLineTypeTraits<signed char>
00206 : public CommandLineTypeTraitsBase<signed char>
00207 {
00208 public:
00209 static const char* GetName()
00210 {
00211 return "integer";
00212 }
00213 };
00214
00215 template<>
00216 class
00217 CommandLineTypeTraits<unsigned char> :
00219 public CommandLineTypeTraitsBase<unsigned char>
00220 {
00221 public:
00222 static const char* GetName()
00223 {
00224 return "integer";
00225 }
00226 };
00227
00228 template<>
00229 class
00230 CommandLineTypeTraits<float>
00232 : public CommandLineTypeTraitsBase<float>
00233 {
00234 public:
00235 static const char* GetName()
00236 {
00237 return "float";
00238 }
00239 };
00240
00241 template<>
00242 class
00243 CommandLineTypeTraits<double>
00245 : public CommandLineTypeTraitsBase<double>
00246 {
00247 public:
00248 static const char* GetName()
00249 {
00250 return "double";
00251 }
00252 };
00253
00254 template<>
00255 class
00256 CommandLineTypeTraits<bool>
00258 : public CommandLineTypeTraitsBase<bool>
00259 {
00260 public:
00261 static const char* GetName()
00262 {
00263 return "boolean";
00264 }
00265 };
00266
00267 }