SHOGUN v0.9.0
|
00001 /* 00002 * This program is free software; you can redistribute it and/or modify 00003 * it under the terms of the GNU General Public License as published by 00004 * the Free Software Foundation; either version 3 of the License, or 00005 * (at your option) any later version. 00006 * 00007 * Written (W) 2010 Soeren Sonnenburg 00008 * Copyright (C) 2010 Berlin Institute of Technology 00009 */ 00010 #ifndef __PARAMETER_H__ 00011 #define __PARAMETER_H__ 00012 00013 #include "lib/common.h" 00014 #include "lib/io.h" 00015 #include "lib/DataType.h" 00016 #include "lib/SerializableFile.h" 00017 #include "base/DynArray.h" 00018 00019 namespace shogun 00020 { 00021 struct TParameter 00022 { 00023 explicit TParameter(const TSGDataType* datatype, void* parameter, 00024 const char* name, const char* description); 00025 ~TParameter(); 00026 00027 void print(const char* prefix); 00028 bool save(CSerializableFile* file, const char* prefix=""); 00029 bool load(CSerializableFile* file, const char* prefix=""); 00030 00031 TSGDataType m_datatype; 00032 void* m_parameter; 00033 char* m_name; 00034 char* m_description; 00035 00036 private: 00037 char* new_prefix(const char* s1, const char* s2); 00038 void delete_cont(void); 00039 void new_cont(index_t new_len_y, index_t new_len_x); 00040 bool new_sgserial(CSGObject** param, EPrimitiveType generic, 00041 const char* sgserializable_name, 00042 const char* prefix); 00043 bool save_ptype(CSerializableFile* file, const void* param, 00044 const char* prefix); 00045 bool load_ptype(CSerializableFile* file, void* param, 00046 const char* prefix); 00047 bool save_stype(CSerializableFile* file, const void* param, 00048 const char* prefix); 00049 bool load_stype(CSerializableFile* file, void* param, 00050 const char* prefix); 00051 }; 00052 00053 /* Must not be an CSGObject to prevent a recursive call of 00054 * constructors. 00055 */ 00056 class Parameter 00057 { 00058 public: 00059 explicit Parameter(void); 00060 virtual ~Parameter(void); 00061 00062 virtual void print(const char* prefix=""); 00063 virtual bool save(CSerializableFile* file, const char* prefix=""); 00064 virtual bool load(CSerializableFile* file, const char* prefix=""); 00065 00066 inline virtual int32_t get_num_parameters(void) 00067 { 00068 return m_params.get_num_elements(); 00069 } 00070 00071 /* ************************************************************ */ 00072 /* Scalar wrappers */ 00073 00074 void add(bool* param, const char* name, 00075 const char* description=""); 00076 void add(char* param, const char* name, 00077 const char* description=""); 00078 void add(int8_t* param, const char* name, 00079 const char* description=""); 00080 void add(uint8_t* param, const char* name, 00081 const char* description=""); 00082 void add(int16_t* param, const char* name, 00083 const char* description=""); 00084 void add(uint16_t* param, const char* name, 00085 const char* description=""); 00086 void add(int32_t* param, const char* name, 00087 const char* description=""); 00088 void add(uint32_t* param, const char* name, 00089 const char* description=""); 00090 void add(int64_t* param, const char* name, 00091 const char* description=""); 00092 void add(uint64_t* param, const char* name, 00093 const char* description=""); 00094 void add(float32_t* param, const char* name, 00095 const char* description=""); 00096 void add(float64_t* param, const char* name, 00097 const char* description=""); 00098 void add(floatmax_t* param, const char* name, 00099 const char* description=""); 00100 00101 void add(CSGObject** param, 00102 const char* name, const char* description=""); 00103 00104 void add(TString<bool>* param, const char* name, 00105 const char* description=""); 00106 void add(TString<char>* param, const char* name, 00107 const char* description=""); 00108 void add(TString<int8_t>* param, const char* name, 00109 const char* description=""); 00110 void add(TString<uint8_t>* param, const char* name, 00111 const char* description=""); 00112 void add(TString<int16_t>* param, const char* name, 00113 const char* description=""); 00114 void add(TString<uint16_t>* param, const char* name, 00115 const char* description=""); 00116 void add(TString<int32_t>* param, const char* name, 00117 const char* description=""); 00118 void add(TString<uint32_t>* param, const char* name, 00119 const char* description=""); 00120 void add(TString<int64_t>* param, const char* name, 00121 const char* description=""); 00122 void add(TString<uint64_t>* param, const char* name, 00123 const char* description=""); 00124 void add(TString<float32_t>* param, const char* name, 00125 const char* description=""); 00126 void add(TString<float64_t>* param, const char* name, 00127 const char* description=""); 00128 void add(TString<floatmax_t>* param, const char* name, 00129 const char* description=""); 00130 00131 void add(TSparse<bool>* param, const char* name, 00132 const char* description=""); 00133 void add(TSparse<char>* param, const char* name, 00134 const char* description=""); 00135 void add(TSparse<int8_t>* param, const char* name, 00136 const char* description=""); 00137 void add(TSparse<uint8_t>* param, const char* name, 00138 const char* description=""); 00139 void add(TSparse<int16_t>* param, const char* name, 00140 const char* description=""); 00141 void add(TSparse<uint16_t>* param, const char* name, 00142 const char* description=""); 00143 void add(TSparse<int32_t>* param, const char* name, 00144 const char* description=""); 00145 void add(TSparse<uint32_t>* param, const char* name, 00146 const char* description=""); 00147 void add(TSparse<int64_t>* param, const char* name, 00148 const char* description=""); 00149 void add(TSparse<uint64_t>* param, const char* name, 00150 const char* description=""); 00151 void add(TSparse<float32_t>* param, const char* name, 00152 const char* description=""); 00153 void add(TSparse<float64_t>* param, const char* name, 00154 const char* description=""); 00155 void add(TSparse<floatmax_t>* param, const char* name, 00156 const char* description=""); 00157 00158 /* ************************************************************ */ 00159 /* Vector wrappers */ 00160 00161 void add_vector(bool** param, index_t* length, 00162 const char* name, const char* description=""); 00163 void add_vector(char** param, index_t* length, 00164 const char* name, const char* description=""); 00165 void add_vector(int8_t** param, index_t* length, 00166 const char* name, const char* description=""); 00167 void add_vector(uint8_t** param, index_t* length, 00168 const char* name, const char* description=""); 00169 void add_vector(int16_t** param, index_t* length, 00170 const char* name, const char* description=""); 00171 void add_vector(uint16_t** param, index_t* length, 00172 const char* name, const char* description=""); 00173 void add_vector(int32_t** param, index_t* length, 00174 const char* name, const char* description=""); 00175 void add_vector(uint32_t** param, index_t* length, 00176 const char* name, const char* description=""); 00177 void add_vector(int64_t** param, index_t* length, 00178 const char* name, const char* description=""); 00179 void add_vector(uint64_t** param, index_t* length, 00180 const char* name, const char* description=""); 00181 void add_vector(float32_t** param, index_t* length, 00182 const char* name, const char* description=""); 00183 void add_vector(float64_t** param, index_t* length, 00184 const char* name, const char* description=""); 00185 void add_vector(floatmax_t** param, index_t* length, 00186 const char* name, const char* description=""); 00187 00188 void add_vector(CSGObject*** param, index_t* length, 00189 const char* name, const char* description=""); 00190 00191 void add_vector(TString<bool>** param, index_t* length, 00192 const char* name, const char* description=""); 00193 void add_vector(TString<char>** param, index_t* length, 00194 const char* name, const char* description=""); 00195 void add_vector(TString<int8_t>** param, index_t* length, 00196 const char* name, const char* description=""); 00197 void add_vector(TString<uint8_t>** param, index_t* length, 00198 const char* name, const char* description=""); 00199 void add_vector(TString<int16_t>** param, index_t* length, 00200 const char* name, const char* description=""); 00201 void add_vector(TString<uint16_t>** param, index_t* length, 00202 const char* name, const char* description=""); 00203 void add_vector(TString<int32_t>** param, index_t* length, 00204 const char* name, const char* description=""); 00205 void add_vector(TString<uint32_t>** param, index_t* length, 00206 const char* name, const char* description=""); 00207 void add_vector(TString<int64_t>** param, index_t* length, 00208 const char* name, const char* description=""); 00209 void add_vector(TString<uint64_t>** param, index_t* length, 00210 const char* name, const char* description=""); 00211 void add_vector(TString<float32_t>** param, index_t* length, 00212 const char* name, const char* description=""); 00213 void add_vector(TString<float64_t>** param, index_t* length, 00214 const char* name, const char* description=""); 00215 void add_vector(TString<floatmax_t>** param, index_t* length, 00216 const char* name, const char* description=""); 00217 00218 void add_vector(TSparse<bool>** param, index_t* length, 00219 const char* name, const char* description=""); 00220 void add_vector(TSparse<char>** param, index_t* length, 00221 const char* name, const char* description=""); 00222 void add_vector(TSparse<int8_t>** param, index_t* length, 00223 const char* name, const char* description=""); 00224 void add_vector(TSparse<uint8_t>** param, index_t* length, 00225 const char* name, const char* description=""); 00226 void add_vector(TSparse<int16_t>** param, index_t* length, 00227 const char* name, const char* description=""); 00228 void add_vector(TSparse<uint16_t>** param, index_t* length, 00229 const char* name, const char* description=""); 00230 void add_vector(TSparse<int32_t>** param, index_t* length, 00231 const char* name, const char* description=""); 00232 void add_vector(TSparse<uint32_t>** param, index_t* length, 00233 const char* name, const char* description=""); 00234 void add_vector(TSparse<int64_t>** param, index_t* length, 00235 const char* name, const char* description=""); 00236 void add_vector(TSparse<uint64_t>** param, index_t* length, 00237 const char* name, const char* description=""); 00238 void add_vector(TSparse<float32_t>** param, index_t* length, 00239 const char* name, const char* description=""); 00240 void add_vector(TSparse<float64_t>** param, index_t* length, 00241 const char* name, const char* description=""); 00242 void add_vector(TSparse<floatmax_t>** param, index_t* length, 00243 const char* name, const char* description=""); 00244 00245 /* ************************************************************ */ 00246 /* Matrix wrappers */ 00247 00248 void add_matrix(bool** param, 00249 index_t* length_y, index_t* length_x, 00250 const char* name, const char* description=""); 00251 void add_matrix(char** param, 00252 index_t* length_y, index_t* length_x, 00253 const char* name, const char* description=""); 00254 void add_matrix(int8_t** param, 00255 index_t* length_y, index_t* length_x, 00256 const char* name, const char* description=""); 00257 void add_matrix(uint8_t** param, 00258 index_t* length_y, index_t* length_x, 00259 const char* name, const char* description=""); 00260 void add_matrix(int16_t** param, 00261 index_t* length_y, index_t* length_x, 00262 const char* name, const char* description=""); 00263 void add_matrix(uint16_t** param, 00264 index_t* length_y, index_t* length_x, 00265 const char* name, const char* description=""); 00266 void add_matrix(int32_t** param, 00267 index_t* length_y, index_t* length_x, 00268 const char* name, const char* description=""); 00269 void add_matrix(uint32_t** param, 00270 index_t* length_y, index_t* length_x, 00271 const char* name, const char* description=""); 00272 void add_matrix(int64_t** param, 00273 index_t* length_y, index_t* length_x, 00274 const char* name, const char* description=""); 00275 void add_matrix(uint64_t** param, 00276 index_t* length_y, index_t* length_x, 00277 const char* name, const char* description=""); 00278 void add_matrix(float32_t** param, 00279 index_t* length_y, index_t* length_x, 00280 const char* name, const char* description=""); 00281 void add_matrix(float64_t** param, 00282 index_t* length_y, index_t* length_x, 00283 const char* name, const char* description=""); 00284 void add_matrix(floatmax_t** param, 00285 index_t* length_y, index_t* length_x, 00286 const char* name, const char* description=""); 00287 00288 void add_matrix(CSGObject*** param, 00289 index_t* length_y, index_t* length_x, 00290 const char* name, const char* description=""); 00291 00292 void add_matrix(TString<bool>** param, 00293 index_t* length_y, index_t* length_x, 00294 const char* name, const char* description=""); 00295 void add_matrix(TString<char>** param, 00296 index_t* length_y, index_t* length_x, 00297 const char* name, const char* description=""); 00298 void add_matrix(TString<int8_t>** param, 00299 index_t* length_y, index_t* length_x, 00300 const char* name, const char* description=""); 00301 void add_matrix(TString<uint8_t>** param, 00302 index_t* length_y, index_t* length_x, 00303 const char* name, const char* description=""); 00304 void add_matrix(TString<int16_t>** param, 00305 index_t* length_y, index_t* length_x, 00306 const char* name, const char* description=""); 00307 void add_matrix(TString<uint16_t>** param, 00308 index_t* length_y, index_t* length_x, 00309 const char* name, const char* description=""); 00310 void add_matrix(TString<int32_t>** param, 00311 index_t* length_y, index_t* length_x, 00312 const char* name, const char* description=""); 00313 void add_matrix(TString<uint32_t>** param, 00314 index_t* length_y, index_t* length_x, 00315 const char* name, const char* description=""); 00316 void add_matrix(TString<int64_t>** param, 00317 index_t* length_y, index_t* length_x, 00318 const char* name, const char* description=""); 00319 void add_matrix(TString<uint64_t>** param, 00320 index_t* length_y, index_t* length_x, 00321 const char* name, const char* description=""); 00322 void add_matrix(TString<float32_t>** param, 00323 index_t* length_y, index_t* length_x, 00324 const char* name, const char* description=""); 00325 void add_matrix(TString<float64_t>** param, 00326 index_t* length_y, index_t* length_x, 00327 const char* name, const char* description=""); 00328 void add_matrix(TString<floatmax_t>** param, 00329 index_t* length_y, index_t* length_x, 00330 const char* name, const char* description=""); 00331 00332 void add_matrix(TSparse<bool>** param, 00333 index_t* length_y, index_t* length_x, 00334 const char* name, const char* description=""); 00335 void add_matrix(TSparse<char>** param, 00336 index_t* length_y, index_t* length_x, 00337 const char* name, const char* description=""); 00338 void add_matrix(TSparse<int8_t>** param, 00339 index_t* length_y, index_t* length_x, 00340 const char* name, const char* description=""); 00341 void add_matrix(TSparse<uint8_t>** param, 00342 index_t* length_y, index_t* length_x, 00343 const char* name, const char* description=""); 00344 void add_matrix(TSparse<int16_t>** param, 00345 index_t* length_y, index_t* length_x, 00346 const char* name, const char* description=""); 00347 void add_matrix(TSparse<uint16_t>** param, 00348 index_t* length_y, index_t* length_x, 00349 const char* name, const char* description=""); 00350 void add_matrix(TSparse<int32_t>** param, 00351 index_t* length_y, index_t* length_x, 00352 const char* name, const char* description=""); 00353 void add_matrix(TSparse<uint32_t>** param, 00354 index_t* length_y, index_t* length_x, 00355 const char* name, const char* description=""); 00356 void add_matrix(TSparse<int64_t>** param, 00357 index_t* length_y, index_t* length_x, 00358 const char* name, const char* description=""); 00359 void add_matrix(TSparse<uint64_t>** param, 00360 index_t* length_y, index_t* length_x, 00361 const char* name, const char* description=""); 00362 void add_matrix(TSparse<float32_t>** param, 00363 index_t* length_y, index_t* length_x, 00364 const char* name, const char* description=""); 00365 void add_matrix(TSparse<float64_t>** param, 00366 index_t* length_y, index_t* length_x, 00367 const char* name, const char* description=""); 00368 void add_matrix(TSparse<floatmax_t>** param, 00369 index_t* length_y, index_t* length_x, 00370 const char* name, const char* description=""); 00371 00372 protected: 00373 DynArray<TParameter*> m_params; 00374 00375 virtual void add_type(const TSGDataType* type, void* param, 00376 const char* name, 00377 const char* description); 00378 00379 }; 00380 } 00381 #endif //__PARAMETER_H__