SHOGUN
v2.0.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 * Written (W) 2011 Heiko Strathmann 00009 * Copyright (C) 2010 Berlin Institute of Technology 00010 */ 00011 00012 #include <shogun/base/Parameter.h> 00013 #include <shogun/base/class_list.h> 00014 #include <shogun/lib/Hash.h> 00015 00016 using namespace shogun; 00017 00018 extern IO* sg_io; 00019 00020 /* **************************************************************** */ 00021 /* Scalar wrappers */ 00022 00023 void 00024 Parameter::add(bool* param, const char* name, 00025 const char* description) { 00026 TSGDataType type(CT_SCALAR, ST_NONE, PT_BOOL); 00027 add_type(&type, param, name, description); 00028 } 00029 00030 void 00031 Parameter::add(char* param, const char* name, 00032 const char* description) { 00033 TSGDataType type(CT_SCALAR, ST_NONE, PT_CHAR); 00034 add_type(&type, param, name, description); 00035 } 00036 00037 void 00038 Parameter::add(int8_t* param, const char* name, 00039 const char* description) { 00040 TSGDataType type(CT_SCALAR, ST_NONE, PT_INT8); 00041 add_type(&type, param, name, description); 00042 } 00043 00044 void 00045 Parameter::add(uint8_t* param, const char* name, 00046 const char* description) { 00047 TSGDataType type(CT_SCALAR, ST_NONE, PT_UINT8); 00048 add_type(&type, param, name, description); 00049 } 00050 00051 void 00052 Parameter::add(int16_t* param, const char* name, 00053 const char* description) { 00054 TSGDataType type(CT_SCALAR, ST_NONE, PT_INT16); 00055 add_type(&type, param, name, description); 00056 } 00057 00058 void 00059 Parameter::add(uint16_t* param, const char* name, 00060 const char* description) { 00061 TSGDataType type(CT_SCALAR, ST_NONE, PT_UINT16); 00062 add_type(&type, param, name, description); 00063 } 00064 00065 void 00066 Parameter::add(int32_t* param, const char* name, 00067 const char* description) { 00068 TSGDataType type(CT_SCALAR, ST_NONE, PT_INT32); 00069 add_type(&type, param, name, description); 00070 } 00071 00072 void 00073 Parameter::add(uint32_t* param, const char* name, 00074 const char* description) { 00075 TSGDataType type(CT_SCALAR, ST_NONE, PT_UINT32); 00076 add_type(&type, param, name, description); 00077 } 00078 00079 void 00080 Parameter::add(int64_t* param, const char* name, 00081 const char* description) { 00082 TSGDataType type(CT_SCALAR, ST_NONE, PT_INT64); 00083 add_type(&type, param, name, description); 00084 } 00085 00086 void 00087 Parameter::add(uint64_t* param, const char* name, 00088 const char* description) { 00089 TSGDataType type(CT_SCALAR, ST_NONE, PT_UINT64); 00090 add_type(&type, param, name, description); 00091 } 00092 00093 void 00094 Parameter::add(float32_t* param, const char* name, 00095 const char* description) { 00096 TSGDataType type(CT_SCALAR, ST_NONE, PT_FLOAT32); 00097 add_type(&type, param, name, description); 00098 } 00099 00100 void 00101 Parameter::add(float64_t* param, const char* name, 00102 const char* description) { 00103 TSGDataType type(CT_SCALAR, ST_NONE, PT_FLOAT64); 00104 add_type(&type, param, name, description); 00105 } 00106 00107 void 00108 Parameter::add(floatmax_t* param, const char* name, 00109 const char* description) { 00110 TSGDataType type(CT_SCALAR, ST_NONE, PT_FLOATMAX); 00111 add_type(&type, param, name, description); 00112 } 00113 00114 void 00115 Parameter::add(CSGObject** param, 00116 const char* name, const char* description) { 00117 TSGDataType type(CT_SCALAR, ST_NONE, PT_SGOBJECT); 00118 add_type(&type, param, name, description); 00119 } 00120 00121 void 00122 Parameter::add(SGString<bool>* param, const char* name, 00123 const char* description) { 00124 TSGDataType type(CT_SCALAR, ST_STRING, PT_BOOL); 00125 add_type(&type, param, name, description); 00126 } 00127 00128 void 00129 Parameter::add(SGString<char>* param, const char* name, 00130 const char* description) { 00131 TSGDataType type(CT_SCALAR, ST_STRING, PT_CHAR); 00132 add_type(&type, param, name, description); 00133 } 00134 00135 void 00136 Parameter::add(SGString<int8_t>* param, const char* name, 00137 const char* description) { 00138 TSGDataType type(CT_SCALAR, ST_STRING, PT_INT8); 00139 add_type(&type, param, name, description); 00140 } 00141 00142 void 00143 Parameter::add(SGString<uint8_t>* param, const char* name, 00144 const char* description) { 00145 TSGDataType type(CT_SCALAR, ST_STRING, PT_UINT8); 00146 add_type(&type, param, name, description); 00147 } 00148 00149 void 00150 Parameter::add(SGString<int16_t>* param, const char* name, 00151 const char* description) { 00152 TSGDataType type(CT_SCALAR, ST_STRING, PT_INT16); 00153 add_type(&type, param, name, description); 00154 } 00155 00156 void 00157 Parameter::add(SGString<uint16_t>* param, const char* name, 00158 const char* description) { 00159 TSGDataType type(CT_SCALAR, ST_STRING, PT_UINT16); 00160 add_type(&type, param, name, description); 00161 } 00162 00163 void 00164 Parameter::add(SGString<int32_t>* param, const char* name, 00165 const char* description) { 00166 TSGDataType type(CT_SCALAR, ST_STRING, PT_INT32); 00167 add_type(&type, param, name, description); 00168 } 00169 00170 void 00171 Parameter::add(SGString<uint32_t>* param, const char* name, 00172 const char* description) { 00173 TSGDataType type(CT_SCALAR, ST_STRING, PT_UINT32); 00174 add_type(&type, param, name, description); 00175 } 00176 00177 void 00178 Parameter::add(SGString<int64_t>* param, const char* name, 00179 const char* description) { 00180 TSGDataType type(CT_SCALAR, ST_STRING, PT_INT64); 00181 add_type(&type, param, name, description); 00182 } 00183 00184 void 00185 Parameter::add(SGString<uint64_t>* param, const char* name, 00186 const char* description) { 00187 TSGDataType type(CT_SCALAR, ST_STRING, PT_UINT64); 00188 add_type(&type, param, name, description); 00189 } 00190 00191 void 00192 Parameter::add(SGString<float32_t>* param, const char* name, 00193 const char* description) { 00194 TSGDataType type(CT_SCALAR, ST_STRING, PT_FLOAT32); 00195 add_type(&type, param, name, description); 00196 } 00197 00198 void 00199 Parameter::add(SGString<float64_t>* param, const char* name, 00200 const char* description) { 00201 TSGDataType type(CT_SCALAR, ST_STRING, PT_FLOAT64); 00202 add_type(&type, param, name, description); 00203 } 00204 00205 void 00206 Parameter::add(SGString<floatmax_t>* param, const char* name, 00207 const char* description) { 00208 TSGDataType type(CT_SCALAR, ST_STRING, PT_FLOATMAX); 00209 add_type(&type, param, name, description); 00210 } 00211 00212 void 00213 Parameter::add(SGSparseVector<bool>* param, const char* name, 00214 const char* description) { 00215 TSGDataType type(CT_SCALAR, ST_SPARSE, PT_BOOL); 00216 add_type(&type, param, name, description); 00217 } 00218 00219 void 00220 Parameter::add(SGSparseVector<char>* param, const char* name, 00221 const char* description) { 00222 TSGDataType type(CT_SCALAR, ST_SPARSE, PT_CHAR); 00223 add_type(&type, param, name, description); 00224 } 00225 00226 void 00227 Parameter::add(SGSparseVector<int8_t>* param, const char* name, 00228 const char* description) { 00229 TSGDataType type(CT_SCALAR, ST_SPARSE, PT_INT8); 00230 add_type(&type, param, name, description); 00231 } 00232 00233 void 00234 Parameter::add(SGSparseVector<uint8_t>* param, const char* name, 00235 const char* description) { 00236 TSGDataType type(CT_SCALAR, ST_SPARSE, PT_UINT8); 00237 add_type(&type, param, name, description); 00238 } 00239 00240 void 00241 Parameter::add(SGSparseVector<int16_t>* param, const char* name, 00242 const char* description) { 00243 TSGDataType type(CT_SCALAR, ST_SPARSE, PT_INT16); 00244 add_type(&type, param, name, description); 00245 } 00246 00247 void 00248 Parameter::add(SGSparseVector<uint16_t>* param, const char* name, 00249 const char* description) { 00250 TSGDataType type(CT_SCALAR, ST_SPARSE, PT_UINT16); 00251 add_type(&type, param, name, description); 00252 } 00253 00254 void 00255 Parameter::add(SGSparseVector<int32_t>* param, const char* name, 00256 const char* description) { 00257 TSGDataType type(CT_SCALAR, ST_SPARSE, PT_INT32); 00258 add_type(&type, param, name, description); 00259 } 00260 00261 void 00262 Parameter::add(SGSparseVector<uint32_t>* param, const char* name, 00263 const char* description) { 00264 TSGDataType type(CT_SCALAR, ST_SPARSE, PT_UINT32); 00265 add_type(&type, param, name, description); 00266 } 00267 00268 void 00269 Parameter::add(SGSparseVector<int64_t>* param, const char* name, 00270 const char* description) { 00271 TSGDataType type(CT_SCALAR, ST_SPARSE, PT_INT64); 00272 add_type(&type, param, name, description); 00273 } 00274 00275 void 00276 Parameter::add(SGSparseVector<uint64_t>* param, const char* name, 00277 const char* description) { 00278 TSGDataType type(CT_SCALAR, ST_SPARSE, PT_UINT64); 00279 add_type(&type, param, name, description); 00280 } 00281 00282 void 00283 Parameter::add(SGSparseVector<float32_t>* param, const char* name, 00284 const char* description) { 00285 TSGDataType type(CT_SCALAR, ST_SPARSE, PT_FLOAT32); 00286 add_type(&type, param, name, description); 00287 } 00288 00289 void 00290 Parameter::add(SGSparseVector<float64_t>* param, const char* name, 00291 const char* description) { 00292 TSGDataType type(CT_SCALAR, ST_SPARSE, PT_FLOAT64); 00293 add_type(&type, param, name, description); 00294 } 00295 00296 void 00297 Parameter::add(SGSparseVector<floatmax_t>* param, const char* name, 00298 const char* description) { 00299 TSGDataType type(CT_SCALAR, ST_SPARSE, PT_FLOATMAX); 00300 add_type(&type, param, name, description); 00301 } 00302 00303 /* **************************************************************** */ 00304 /* Vector wrappers */ 00305 00306 void 00307 Parameter::add_vector( 00308 bool** param, index_t* length, const char* name, 00309 const char* description) { 00310 TSGDataType type(CT_VECTOR, ST_NONE, PT_BOOL, length); 00311 add_type(&type, param, name, description); 00312 } 00313 00314 void 00315 Parameter::add_vector( 00316 char** param, index_t* length, const char* name, 00317 const char* description) { 00318 TSGDataType type(CT_VECTOR, ST_NONE, PT_CHAR, length); 00319 add_type(&type, param, name, description); 00320 } 00321 00322 void 00323 Parameter::add_vector( 00324 int8_t** param, index_t* length, const char* name, 00325 const char* description) { 00326 TSGDataType type(CT_VECTOR, ST_NONE, PT_INT8, length); 00327 add_type(&type, param, name, description); 00328 } 00329 00330 void 00331 Parameter::add_vector( 00332 uint8_t** param, index_t* length, const char* name, 00333 const char* description) { 00334 TSGDataType type(CT_VECTOR, ST_NONE, PT_UINT8, length); 00335 add_type(&type, param, name, description); 00336 } 00337 00338 void 00339 Parameter::add_vector( 00340 int16_t** param, index_t* length, const char* name, 00341 const char* description) { 00342 TSGDataType type(CT_VECTOR, ST_NONE, PT_INT16, length); 00343 add_type(&type, param, name, description); 00344 } 00345 00346 void 00347 Parameter::add_vector( 00348 uint16_t** param, index_t* length, const char* name, 00349 const char* description) { 00350 TSGDataType type(CT_VECTOR, ST_NONE, PT_UINT16, length); 00351 add_type(&type, param, name, description); 00352 } 00353 00354 void 00355 Parameter::add_vector( 00356 int32_t** param, index_t* length, const char* name, 00357 const char* description) { 00358 TSGDataType type(CT_VECTOR, ST_NONE, PT_INT32, length); 00359 add_type(&type, param, name, description); 00360 } 00361 00362 void 00363 Parameter::add_vector( 00364 uint32_t** param, index_t* length, const char* name, 00365 const char* description) { 00366 TSGDataType type(CT_VECTOR, ST_NONE, PT_UINT32, length); 00367 add_type(&type, param, name, description); 00368 } 00369 00370 void 00371 Parameter::add_vector( 00372 int64_t** param, index_t* length, const char* name, 00373 const char* description) { 00374 TSGDataType type(CT_VECTOR, ST_NONE, PT_INT64, length); 00375 add_type(&type, param, name, description); 00376 } 00377 00378 void 00379 Parameter::add_vector( 00380 uint64_t** param, index_t* length, const char* name, 00381 const char* description) { 00382 TSGDataType type(CT_VECTOR, ST_NONE, PT_UINT64, length); 00383 add_type(&type, param, name, description); 00384 } 00385 00386 void 00387 Parameter::add_vector( 00388 float32_t** param, index_t* length, const char* name, 00389 const char* description) { 00390 TSGDataType type(CT_VECTOR, ST_NONE, PT_FLOAT32, length); 00391 add_type(&type, param, name, description); 00392 } 00393 00394 void 00395 Parameter::add_vector( 00396 float64_t** param, index_t* length, const char* name, 00397 const char* description) { 00398 TSGDataType type(CT_VECTOR, ST_NONE, PT_FLOAT64, length); 00399 add_type(&type, param, name, description); 00400 } 00401 00402 void 00403 Parameter::add_vector( 00404 floatmax_t** param, index_t* length, const char* name, 00405 const char* description) { 00406 TSGDataType type(CT_VECTOR, ST_NONE, PT_FLOATMAX, length); 00407 add_type(&type, param, name, description); 00408 } 00409 00410 void 00411 Parameter::add_vector(CSGObject*** param, index_t* length, 00412 const char* name, const char* description) { 00413 TSGDataType type(CT_VECTOR, ST_NONE, PT_SGOBJECT, 00414 length); 00415 add_type(&type, param, name, description); 00416 } 00417 00418 void 00419 Parameter::add_vector(SGString<bool>** param, index_t* length, 00420 const char* name, const char* description) { 00421 TSGDataType type(CT_VECTOR, ST_STRING, PT_BOOL, length); 00422 add_type(&type, param, name, description); 00423 } 00424 00425 void 00426 Parameter::add_vector(SGString<char>** param, index_t* length, 00427 const char* name, const char* description) { 00428 TSGDataType type(CT_VECTOR, ST_STRING, PT_CHAR, length); 00429 add_type(&type, param, name, description); 00430 } 00431 00432 void 00433 Parameter::add_vector(SGString<int8_t>** param, index_t* length, 00434 const char* name, const char* description) { 00435 TSGDataType type(CT_VECTOR, ST_STRING, PT_INT8, length); 00436 add_type(&type, param, name, description); 00437 } 00438 00439 void 00440 Parameter::add_vector(SGString<uint8_t>** param, index_t* length, 00441 const char* name, const char* description) { 00442 TSGDataType type(CT_VECTOR, ST_STRING, PT_UINT8, length); 00443 add_type(&type, param, name, description); 00444 } 00445 00446 void 00447 Parameter::add_vector(SGString<int16_t>** param, index_t* length, 00448 const char* name, const char* description) { 00449 TSGDataType type(CT_VECTOR, ST_STRING, PT_INT16, length); 00450 add_type(&type, param, name, description); 00451 } 00452 00453 void 00454 Parameter::add_vector(SGString<uint16_t>** param, index_t* length, 00455 const char* name, const char* description) { 00456 TSGDataType type(CT_VECTOR, ST_STRING, PT_UINT16, length); 00457 add_type(&type, param, name, description); 00458 } 00459 00460 void 00461 Parameter::add_vector(SGString<int32_t>** param, index_t* length, 00462 const char* name, const char* description) { 00463 TSGDataType type(CT_VECTOR, ST_STRING, PT_INT32, length); 00464 add_type(&type, param, name, description); 00465 } 00466 00467 void 00468 Parameter::add_vector(SGString<uint32_t>** param, index_t* length, 00469 const char* name, const char* description) { 00470 TSGDataType type(CT_VECTOR, ST_STRING, PT_UINT32, length); 00471 add_type(&type, param, name, description); 00472 } 00473 00474 void 00475 Parameter::add_vector(SGString<int64_t>** param, index_t* length, 00476 const char* name, const char* description) { 00477 TSGDataType type(CT_VECTOR, ST_STRING, PT_INT64, length); 00478 add_type(&type, param, name, description); 00479 } 00480 00481 void 00482 Parameter::add_vector(SGString<uint64_t>** param, index_t* length, 00483 const char* name, const char* description) { 00484 TSGDataType type(CT_VECTOR, ST_STRING, PT_UINT64, length); 00485 add_type(&type, param, name, description); 00486 } 00487 00488 void 00489 Parameter::add_vector(SGString<float32_t>** param, index_t* length, 00490 const char* name, const char* description) { 00491 TSGDataType type(CT_VECTOR, ST_STRING, PT_FLOAT32, length); 00492 add_type(&type, param, name, description); 00493 } 00494 00495 void 00496 Parameter::add_vector(SGString<float64_t>** param, index_t* length, 00497 const char* name, const char* description) { 00498 TSGDataType type(CT_VECTOR, ST_STRING, PT_FLOAT64, length); 00499 add_type(&type, param, name, description); 00500 } 00501 00502 void 00503 Parameter::add_vector(SGString<floatmax_t>** param, index_t* length, 00504 const char* name, const char* description) { 00505 TSGDataType type(CT_VECTOR, ST_STRING, PT_FLOATMAX, length); 00506 add_type(&type, param, name, description); 00507 } 00508 00509 void 00510 Parameter::add_vector(SGSparseVector<bool>** param, index_t* length, 00511 const char* name, const char* description) { 00512 TSGDataType type(CT_VECTOR, ST_SPARSE, PT_BOOL, length); 00513 add_type(&type, param, name, description); 00514 } 00515 00516 void 00517 Parameter::add_vector(SGSparseVector<char>** param, index_t* length, 00518 const char* name, const char* description) { 00519 TSGDataType type(CT_VECTOR, ST_SPARSE, PT_CHAR, length); 00520 add_type(&type, param, name, description); 00521 } 00522 00523 void 00524 Parameter::add_vector(SGSparseVector<int8_t>** param, index_t* length, 00525 const char* name, const char* description) { 00526 TSGDataType type(CT_VECTOR, ST_SPARSE, PT_INT8, length); 00527 add_type(&type, param, name, description); 00528 } 00529 00530 void 00531 Parameter::add_vector(SGSparseVector<uint8_t>** param, index_t* length, 00532 const char* name, const char* description) { 00533 TSGDataType type(CT_VECTOR, ST_SPARSE, PT_UINT8, length); 00534 add_type(&type, param, name, description); 00535 } 00536 00537 void 00538 Parameter::add_vector(SGSparseVector<int16_t>** param, index_t* length, 00539 const char* name, const char* description) { 00540 TSGDataType type(CT_VECTOR, ST_SPARSE, PT_INT16, length); 00541 add_type(&type, param, name, description); 00542 } 00543 00544 void 00545 Parameter::add_vector(SGSparseVector<uint16_t>** param, index_t* length, 00546 const char* name, const char* description) { 00547 TSGDataType type(CT_VECTOR, ST_SPARSE, PT_UINT16, length); 00548 add_type(&type, param, name, description); 00549 } 00550 00551 void 00552 Parameter::add_vector(SGSparseVector<int32_t>** param, index_t* length, 00553 const char* name, const char* description) { 00554 TSGDataType type(CT_VECTOR, ST_SPARSE, PT_INT32, length); 00555 add_type(&type, param, name, description); 00556 } 00557 00558 void 00559 Parameter::add_vector(SGSparseVector<uint32_t>** param, index_t* length, 00560 const char* name, const char* description) { 00561 TSGDataType type(CT_VECTOR, ST_SPARSE, PT_UINT32, length); 00562 add_type(&type, param, name, description); 00563 } 00564 00565 void 00566 Parameter::add_vector(SGSparseVector<int64_t>** param, index_t* length, 00567 const char* name, const char* description) { 00568 TSGDataType type(CT_VECTOR, ST_SPARSE, PT_INT64, length); 00569 add_type(&type, param, name, description); 00570 } 00571 00572 void 00573 Parameter::add_vector(SGSparseVector<uint64_t>** param, index_t* length, 00574 const char* name, const char* description) { 00575 TSGDataType type(CT_VECTOR, ST_SPARSE, PT_UINT64, length); 00576 add_type(&type, param, name, description); 00577 } 00578 00579 void 00580 Parameter::add_vector(SGSparseVector<float32_t>** param, index_t* length, 00581 const char* name, const char* description) { 00582 TSGDataType type(CT_VECTOR, ST_SPARSE, PT_FLOAT32, length); 00583 add_type(&type, param, name, description); 00584 } 00585 00586 void 00587 Parameter::add_vector(SGSparseVector<float64_t>** param, index_t* length, 00588 const char* name, const char* description) { 00589 TSGDataType type(CT_VECTOR, ST_SPARSE, PT_FLOAT64, length); 00590 add_type(&type, param, name, description); 00591 } 00592 00593 void 00594 Parameter::add_vector(SGSparseVector<floatmax_t>** param, index_t* length, 00595 const char* name, const char* description) { 00596 TSGDataType type(CT_VECTOR, ST_SPARSE, PT_FLOATMAX, length); 00597 add_type(&type, param, name, description); 00598 } 00599 00600 00601 00602 00603 void Parameter::add(SGVector<bool>* param, const char* name, 00604 const char* description) 00605 { 00606 TSGDataType type(CT_SGVECTOR, ST_NONE, PT_BOOL, ¶m->vlen); 00607 add_type(&type, ¶m->vector, name, description); 00608 } 00609 00610 void Parameter::add(SGVector<char>* param, const char* name, 00611 const char* description) 00612 { 00613 TSGDataType type(CT_SGVECTOR, ST_NONE, PT_CHAR, ¶m->vlen); 00614 add_type(&type, ¶m->vector, name, description); 00615 } 00616 00617 void Parameter::add(SGVector<int8_t>* param, const char* name, 00618 const char* description) 00619 { 00620 TSGDataType type(CT_SGVECTOR, ST_NONE, PT_INT8, ¶m->vlen); 00621 add_type(&type, ¶m->vector, name, description); 00622 } 00623 00624 void Parameter::add(SGVector<uint8_t>* param, const char* name, 00625 const char* description) 00626 { 00627 TSGDataType type(CT_SGVECTOR, ST_NONE, PT_UINT8, ¶m->vlen); 00628 add_type(&type, ¶m->vector, name, description); 00629 } 00630 00631 void Parameter::add(SGVector<int16_t>* param, const char* name, 00632 const char* description) 00633 { 00634 TSGDataType type(CT_SGVECTOR, ST_NONE, PT_INT16, ¶m->vlen); 00635 add_type(&type, ¶m->vector, name, description); 00636 } 00637 00638 void Parameter::add(SGVector<uint16_t>* param, const char* name, 00639 const char* description) 00640 { 00641 TSGDataType type(CT_SGVECTOR, ST_NONE, PT_UINT16, ¶m->vlen); 00642 add_type(&type, ¶m->vector, name, description); 00643 } 00644 00645 void Parameter::add(SGVector<int32_t>* param, const char* name, 00646 const char* description) 00647 { 00648 TSGDataType type(CT_SGVECTOR, ST_NONE, PT_INT32, ¶m->vlen); 00649 add_type(&type, ¶m->vector, name, description); 00650 } 00651 00652 void Parameter::add(SGVector<uint32_t>* param, const char* name, 00653 const char* description) 00654 { 00655 TSGDataType type(CT_SGVECTOR, ST_NONE, PT_UINT32, ¶m->vlen); 00656 add_type(&type, ¶m->vector, name, description); 00657 } 00658 00659 void Parameter::add(SGVector<int64_t>* param, const char* name, 00660 const char* description) 00661 { 00662 TSGDataType type(CT_SGVECTOR, ST_NONE, PT_INT64, ¶m->vlen); 00663 add_type(&type, ¶m->vector, name, description); 00664 } 00665 00666 void Parameter::add(SGVector<uint64_t>* param, const char* name, 00667 const char* description) 00668 { 00669 TSGDataType type(CT_SGVECTOR, ST_NONE, PT_UINT64, ¶m->vlen); 00670 add_type(&type, ¶m->vector, name, description); 00671 } 00672 00673 void Parameter::add(SGVector<float32_t>* param, const char* name, 00674 const char* description) 00675 { 00676 TSGDataType type(CT_SGVECTOR, ST_NONE, PT_FLOAT32, ¶m->vlen); 00677 add_type(&type, ¶m->vector, name, description); 00678 } 00679 00680 void Parameter::add(SGVector<float64_t>* param, const char* name, 00681 const char* description) 00682 { 00683 TSGDataType type(CT_SGVECTOR, ST_NONE, PT_FLOAT64, ¶m->vlen); 00684 add_type(&type, ¶m->vector, name, description); 00685 } 00686 00687 void Parameter::add(SGVector<floatmax_t>* param, const char* name, 00688 const char* description) 00689 { 00690 TSGDataType type(CT_SGVECTOR, ST_NONE, PT_FLOATMAX, ¶m->vlen); 00691 add_type(&type, ¶m->vector, name, description); 00692 } 00693 00694 void Parameter::add(SGVector<CSGObject*>* param, const char* name, 00695 const char* description) 00696 { 00697 TSGDataType type(CT_SGVECTOR, ST_NONE, PT_SGOBJECT, ¶m->vlen); 00698 add_type(&type, ¶m->vector, name, description); 00699 } 00700 00701 void Parameter::add(SGVector<SGString<bool> >* param, const char* name, 00702 const char* description) 00703 { 00704 TSGDataType type(CT_SGVECTOR, ST_STRING, PT_BOOL, ¶m->vlen); 00705 add_type(&type, ¶m->vector, name, description); 00706 } 00707 00708 void Parameter::add(SGVector<SGString<char> >* param, const char* name, 00709 const char* description) 00710 { 00711 TSGDataType type(CT_SGVECTOR, ST_STRING, PT_CHAR, ¶m->vlen); 00712 add_type(&type, ¶m->vector, name, description); 00713 } 00714 00715 void Parameter::add(SGVector<SGString<int8_t> >* param, 00716 const char* name, const char* description) 00717 { 00718 TSGDataType type(CT_SGVECTOR, ST_STRING, PT_INT8, ¶m->vlen); 00719 add_type(&type, ¶m->vector, name, description); 00720 } 00721 00722 void Parameter::add(SGVector<SGString<uint8_t> >* param, 00723 const char* name, const char* description) 00724 { 00725 TSGDataType type(CT_SGVECTOR, ST_STRING, PT_UINT8, ¶m->vlen); 00726 add_type(&type, ¶m->vector, name, description); 00727 } 00728 00729 void Parameter::add(SGVector<SGString<int16_t> >* param, 00730 const char* name, const char* description) 00731 { 00732 TSGDataType type(CT_SGVECTOR, ST_STRING, PT_INT16, ¶m->vlen); 00733 add_type(&type, ¶m->vector, name, description); 00734 } 00735 00736 void Parameter::add(SGVector<SGString<uint16_t> >* param, 00737 const char* name, const char* description) 00738 { 00739 TSGDataType type(CT_SGVECTOR, ST_STRING, PT_UINT16, ¶m->vlen); 00740 add_type(&type, ¶m->vector, name, description); 00741 } 00742 00743 void Parameter::add(SGVector<SGString<int32_t> >* param, 00744 const char* name, const char* description) 00745 { 00746 TSGDataType type(CT_SGVECTOR, ST_STRING, PT_INT32, ¶m->vlen); 00747 add_type(&type, ¶m->vector, name, description); 00748 } 00749 00750 void Parameter::add(SGVector<SGString<uint32_t> >* param, 00751 const char* name, const char* description) 00752 { 00753 TSGDataType type(CT_SGVECTOR, ST_STRING, PT_UINT32, ¶m->vlen); 00754 add_type(&type, ¶m->vector, name, description); 00755 } 00756 00757 void Parameter::add(SGVector<SGString<int64_t> >* param, 00758 const char* name, const char* description) 00759 { 00760 TSGDataType type(CT_SGVECTOR, ST_STRING, PT_INT64, ¶m->vlen); 00761 add_type(&type, ¶m->vector, name, description); 00762 } 00763 00764 void Parameter::add(SGVector<SGString<uint64_t> >* param, 00765 const char* name, const char* description) 00766 { 00767 TSGDataType type(CT_SGVECTOR, ST_STRING, PT_UINT64, ¶m->vlen); 00768 add_type(&type, ¶m->vector, name, description); 00769 } 00770 00771 void Parameter::add(SGVector<SGString<float32_t> >* param, 00772 const char* name, const char* description) 00773 { 00774 TSGDataType type(CT_SGVECTOR, ST_STRING, PT_FLOAT32, ¶m->vlen); 00775 add_type(&type, ¶m->vector, name, description); 00776 } 00777 00778 void Parameter::add(SGVector<SGString<float64_t> >* param, 00779 const char* name, const char* description) 00780 { 00781 TSGDataType type(CT_SGVECTOR, ST_STRING, PT_FLOAT64, ¶m->vlen); 00782 add_type(&type, ¶m->vector, name, description); 00783 } 00784 00785 void Parameter::add(SGVector<SGString<floatmax_t> >* param, 00786 const char* name, const char* description) 00787 { 00788 TSGDataType type(CT_SGVECTOR, ST_STRING, PT_FLOATMAX, ¶m->vlen); 00789 add_type(&type, ¶m->vector, name, description); 00790 } 00791 00792 void Parameter::add(SGVector<SGSparseVector<bool> >* param, 00793 const char* name, const char* description) 00794 { 00795 TSGDataType type(CT_SGVECTOR, ST_SPARSE, PT_BOOL, ¶m->vlen); 00796 add_type(&type, ¶m->vector, name, description); 00797 } 00798 00799 void Parameter::add(SGVector<SGSparseVector<char> >* param, 00800 const char* name, const char* description) 00801 { 00802 TSGDataType type(CT_SGVECTOR, ST_SPARSE, PT_CHAR, ¶m->vlen); 00803 add_type(&type, ¶m->vector, name, description); 00804 } 00805 00806 void Parameter::add(SGVector<SGSparseVector<int8_t> >* param, 00807 const char* name, const char* description) 00808 { 00809 TSGDataType type(CT_SGVECTOR, ST_SPARSE, PT_INT8, ¶m->vlen); 00810 add_type(&type, ¶m->vector, name, description); 00811 } 00812 00813 void Parameter::add(SGVector<SGSparseVector<uint8_t> >* param, 00814 const char* name, const char* description) 00815 { 00816 TSGDataType type(CT_SGVECTOR, ST_SPARSE, PT_UINT8, ¶m->vlen); 00817 add_type(&type, ¶m->vector, name, description); 00818 } 00819 00820 void Parameter::add(SGVector<SGSparseVector<int16_t> >* param, 00821 const char* name, const char* description) 00822 { 00823 TSGDataType type(CT_SGVECTOR, ST_SPARSE, PT_INT16, ¶m->vlen); 00824 add_type(&type, ¶m->vector, name, description); 00825 } 00826 00827 void Parameter::add(SGVector<SGSparseVector<uint16_t> >* param, 00828 const char* name, const char* description) 00829 { 00830 TSGDataType type(CT_SGVECTOR, ST_SPARSE, PT_UINT16, ¶m->vlen); 00831 add_type(&type, ¶m->vector, name, description); 00832 } 00833 00834 void Parameter::add(SGVector<SGSparseVector<int32_t> >* param, 00835 const char* name, const char* description) 00836 { 00837 TSGDataType type(CT_SGVECTOR, ST_SPARSE, PT_INT32, ¶m->vlen); 00838 add_type(&type, ¶m->vector, name, description); 00839 } 00840 00841 void Parameter::add(SGVector<SGSparseVector<uint32_t> >* param, 00842 const char* name, const char* description) 00843 { 00844 TSGDataType type(CT_SGVECTOR, ST_SPARSE, PT_UINT32, ¶m->vlen); 00845 add_type(&type, ¶m->vector, name, description); 00846 } 00847 00848 void Parameter::add(SGVector<SGSparseVector<int64_t> >* param, 00849 const char* name, const char* description) 00850 { 00851 TSGDataType type(CT_SGVECTOR, ST_SPARSE, PT_INT64, ¶m->vlen); 00852 add_type(&type, ¶m->vector, name, description); 00853 } 00854 00855 void Parameter::add(SGVector<SGSparseVector<uint64_t> >* param, 00856 const char* name, const char* description) 00857 { 00858 TSGDataType type(CT_SGVECTOR, ST_SPARSE, PT_UINT64, ¶m->vlen); 00859 add_type(&type, ¶m->vector, name, description); 00860 } 00861 00862 void Parameter::add(SGVector<SGSparseVector<float32_t> >* param, 00863 const char* name, const char* description) 00864 { 00865 TSGDataType type(CT_SGVECTOR, ST_SPARSE, PT_FLOAT32, ¶m->vlen); 00866 add_type(&type, ¶m->vector, name, description); 00867 } 00868 00869 void Parameter::add(SGVector<SGSparseVector<float64_t> >* param, 00870 const char* name, const char* description) 00871 { 00872 TSGDataType type(CT_SGVECTOR, ST_SPARSE, PT_FLOAT64, ¶m->vlen); 00873 add_type(&type, ¶m->vector, name, description); 00874 } 00875 00876 void Parameter::add(SGVector<SGSparseVector<floatmax_t> >* param, 00877 const char* name, const char* description) 00878 { 00879 TSGDataType type(CT_SGVECTOR, ST_SPARSE, PT_FLOATMAX, ¶m->vlen); 00880 add_type(&type, ¶m->vector, name, description); 00881 } 00882 00883 /* **************************************************************** */ 00884 /* Matrix wrappers */ 00885 00886 void 00887 Parameter::add_matrix( 00888 bool** param, index_t* length_y, index_t* length_x, 00889 const char* name, const char* description) { 00890 TSGDataType type(CT_MATRIX, ST_NONE, PT_BOOL, length_y, 00891 length_x); 00892 add_type(&type, param, name, description); 00893 } 00894 00895 void 00896 Parameter::add_matrix( 00897 char** param, index_t* length_y, index_t* length_x, 00898 const char* name, const char* description) { 00899 TSGDataType type(CT_MATRIX, ST_NONE, PT_CHAR, length_y, 00900 length_x); 00901 add_type(&type, param, name, description); 00902 } 00903 00904 void 00905 Parameter::add_matrix( 00906 int8_t** param, index_t* length_y, index_t* length_x, 00907 const char* name, const char* description) { 00908 TSGDataType type(CT_MATRIX, ST_NONE, PT_INT8, length_y, 00909 length_x); 00910 add_type(&type, param, name, description); 00911 } 00912 00913 void 00914 Parameter::add_matrix( 00915 uint8_t** param, index_t* length_y, index_t* length_x, 00916 const char* name, const char* description) { 00917 TSGDataType type(CT_MATRIX, ST_NONE, PT_UINT8, length_y, 00918 length_x); 00919 add_type(&type, param, name, description); 00920 } 00921 00922 void 00923 Parameter::add_matrix( 00924 int16_t** param, index_t* length_y, index_t* length_x, 00925 const char* name, const char* description) { 00926 TSGDataType type(CT_MATRIX, ST_NONE, PT_INT16, length_y, 00927 length_x); 00928 add_type(&type, param, name, description); 00929 } 00930 00931 void 00932 Parameter::add_matrix( 00933 uint16_t** param, index_t* length_y, index_t* length_x, 00934 const char* name, const char* description) { 00935 TSGDataType type(CT_MATRIX, ST_NONE, PT_UINT16, length_y, 00936 length_x); 00937 add_type(&type, param, name, description); 00938 } 00939 00940 void 00941 Parameter::add_matrix( 00942 int32_t** param, index_t* length_y, index_t* length_x, 00943 const char* name, const char* description) { 00944 TSGDataType type(CT_MATRIX, ST_NONE, PT_INT32, length_y, 00945 length_x); 00946 add_type(&type, param, name, description); 00947 } 00948 00949 void 00950 Parameter::add_matrix( 00951 uint32_t** param, index_t* length_y, index_t* length_x, 00952 const char* name, const char* description) { 00953 TSGDataType type(CT_MATRIX, ST_NONE, PT_UINT32, length_y, 00954 length_x); 00955 add_type(&type, param, name, description); 00956 } 00957 00958 void 00959 Parameter::add_matrix( 00960 int64_t** param, index_t* length_y, index_t* length_x, 00961 const char* name, const char* description) { 00962 TSGDataType type(CT_MATRIX, ST_NONE, PT_INT64, length_y, 00963 length_x); 00964 add_type(&type, param, name, description); 00965 } 00966 00967 void 00968 Parameter::add_matrix( 00969 uint64_t** param, index_t* length_y, index_t* length_x, 00970 const char* name, const char* description) { 00971 TSGDataType type(CT_MATRIX, ST_NONE, PT_UINT64, length_y, 00972 length_x); 00973 add_type(&type, param, name, description); 00974 } 00975 00976 void 00977 Parameter::add_matrix( 00978 float32_t** param, index_t* length_y, index_t* length_x, 00979 const char* name, const char* description) { 00980 TSGDataType type(CT_MATRIX, ST_NONE, PT_FLOAT32, length_y, 00981 length_x); 00982 add_type(&type, param, name, description); 00983 } 00984 00985 void 00986 Parameter::add_matrix( 00987 float64_t** param, index_t* length_y, index_t* length_x, 00988 const char* name, const char* description) { 00989 TSGDataType type(CT_MATRIX, ST_NONE, PT_FLOAT64, length_y, 00990 length_x); 00991 add_type(&type, param, name, description); 00992 } 00993 00994 void 00995 Parameter::add_matrix( 00996 floatmax_t** param, index_t* length_y, index_t* length_x, 00997 const char* name, const char* description) { 00998 TSGDataType type(CT_MATRIX, ST_NONE, PT_FLOATMAX, length_y, 00999 length_x); 01000 add_type(&type, param, name, description); 01001 } 01002 01003 void 01004 Parameter::add_matrix( 01005 CSGObject*** param, index_t* length_y, index_t* length_x, 01006 const char* name, const char* description) { 01007 TSGDataType type(CT_MATRIX, ST_NONE, PT_SGOBJECT, 01008 length_y, length_x); 01009 add_type(&type, param, name, description); 01010 } 01011 01012 void 01013 Parameter::add_matrix(SGString<bool>** param, 01014 index_t* length_y, index_t* length_x, 01015 const char* name, const char* description) { 01016 TSGDataType type(CT_MATRIX, ST_STRING, PT_BOOL, length_y, 01017 length_x); 01018 add_type(&type, param, name, description); 01019 } 01020 01021 void 01022 Parameter::add_matrix(SGString<char>** param, 01023 index_t* length_y, index_t* length_x, 01024 const char* name, const char* description) { 01025 TSGDataType type(CT_MATRIX, ST_STRING, PT_CHAR, length_y, 01026 length_x); 01027 add_type(&type, param, name, description); 01028 } 01029 01030 void 01031 Parameter::add_matrix(SGString<int8_t>** param, 01032 index_t* length_y, index_t* length_x, 01033 const char* name, const char* description) { 01034 TSGDataType type(CT_MATRIX, ST_STRING, PT_INT8, length_y, 01035 length_x); 01036 add_type(&type, param, name, description); 01037 } 01038 01039 void 01040 Parameter::add_matrix(SGString<uint8_t>** param, 01041 index_t* length_y, index_t* length_x, 01042 const char* name, const char* description) { 01043 TSGDataType type(CT_MATRIX, ST_STRING, PT_UINT8, length_y, 01044 length_x); 01045 add_type(&type, param, name, description); 01046 } 01047 01048 void 01049 Parameter::add_matrix(SGString<int16_t>** param, 01050 index_t* length_y, index_t* length_x, 01051 const char* name, const char* description) { 01052 TSGDataType type(CT_MATRIX, ST_STRING, PT_INT16, length_y, 01053 length_x); 01054 add_type(&type, param, name, description); 01055 } 01056 01057 void 01058 Parameter::add_matrix(SGString<uint16_t>** param, 01059 index_t* length_y, index_t* length_x, 01060 const char* name, const char* description) { 01061 TSGDataType type(CT_MATRIX, ST_STRING, PT_UINT16, length_y, 01062 length_x); 01063 add_type(&type, param, name, description); 01064 } 01065 01066 void 01067 Parameter::add_matrix(SGString<int32_t>** param, 01068 index_t* length_y, index_t* length_x, 01069 const char* name, const char* description) { 01070 TSGDataType type(CT_MATRIX, ST_STRING, PT_INT32, length_y, 01071 length_x); 01072 add_type(&type, param, name, description); 01073 } 01074 01075 void 01076 Parameter::add_matrix(SGString<uint32_t>** param, 01077 index_t* length_y, index_t* length_x, 01078 const char* name, const char* description) { 01079 TSGDataType type(CT_MATRIX, ST_STRING, PT_UINT32, length_y, 01080 length_x); 01081 add_type(&type, param, name, description); 01082 } 01083 01084 void 01085 Parameter::add_matrix(SGString<int64_t>** param, 01086 index_t* length_y, index_t* length_x, 01087 const char* name, const char* description) { 01088 TSGDataType type(CT_MATRIX, ST_STRING, PT_INT64, length_y, 01089 length_x); 01090 add_type(&type, param, name, description); 01091 } 01092 01093 void 01094 Parameter::add_matrix(SGString<uint64_t>** param, 01095 index_t* length_y, index_t* length_x, 01096 const char* name, const char* description) { 01097 TSGDataType type(CT_MATRIX, ST_STRING, PT_UINT64, length_y, 01098 length_x); 01099 add_type(&type, param, name, description); 01100 } 01101 01102 void 01103 Parameter::add_matrix(SGString<float32_t>** param, 01104 index_t* length_y, index_t* length_x, 01105 const char* name, const char* description) { 01106 TSGDataType type(CT_MATRIX, ST_STRING, PT_FLOAT32, length_y, 01107 length_x); 01108 add_type(&type, param, name, description); 01109 } 01110 01111 void 01112 Parameter::add_matrix(SGString<float64_t>** param, 01113 index_t* length_y, index_t* length_x, 01114 const char* name, const char* description) { 01115 TSGDataType type(CT_MATRIX, ST_STRING, PT_FLOAT64, length_y, 01116 length_x); 01117 add_type(&type, param, name, description); 01118 } 01119 01120 void 01121 Parameter::add_matrix(SGString<floatmax_t>** param, 01122 index_t* length_y, index_t* length_x, 01123 const char* name, const char* description) { 01124 TSGDataType type(CT_MATRIX, ST_STRING, PT_FLOATMAX, length_y, 01125 length_x); 01126 add_type(&type, param, name, description); 01127 } 01128 01129 void 01130 Parameter::add_matrix(SGSparseVector<bool>** param, 01131 index_t* length_y, index_t* length_x, 01132 const char* name, const char* description) { 01133 TSGDataType type(CT_MATRIX, ST_SPARSE, PT_BOOL, length_y, 01134 length_x); 01135 add_type(&type, param, name, description); 01136 } 01137 01138 void 01139 Parameter::add_matrix(SGSparseVector<char>** param, 01140 index_t* length_y, index_t* length_x, 01141 const char* name, const char* description) { 01142 TSGDataType type(CT_MATRIX, ST_SPARSE, PT_CHAR, length_y, 01143 length_x); 01144 add_type(&type, param, name, description); 01145 } 01146 01147 void 01148 Parameter::add_matrix(SGSparseVector<int8_t>** param, 01149 index_t* length_y, index_t* length_x, 01150 const char* name, const char* description) { 01151 TSGDataType type(CT_MATRIX, ST_SPARSE, PT_INT8, length_y, 01152 length_x); 01153 add_type(&type, param, name, description); 01154 } 01155 01156 void 01157 Parameter::add_matrix(SGSparseVector<uint8_t>** param, 01158 index_t* length_y, index_t* length_x, 01159 const char* name, const char* description) { 01160 TSGDataType type(CT_MATRIX, ST_SPARSE, PT_UINT8, length_y, 01161 length_x); 01162 add_type(&type, param, name, description); 01163 } 01164 01165 void 01166 Parameter::add_matrix(SGSparseVector<int16_t>** param, 01167 index_t* length_y, index_t* length_x, 01168 const char* name, const char* description) { 01169 TSGDataType type(CT_MATRIX, ST_SPARSE, PT_INT16, length_y, 01170 length_x); 01171 add_type(&type, param, name, description); 01172 } 01173 01174 void 01175 Parameter::add_matrix(SGSparseVector<uint16_t>** param, 01176 index_t* length_y, index_t* length_x, 01177 const char* name, const char* description) { 01178 TSGDataType type(CT_MATRIX, ST_SPARSE, PT_UINT16, length_y, 01179 length_x); 01180 add_type(&type, param, name, description); 01181 } 01182 01183 void 01184 Parameter::add_matrix(SGSparseVector<int32_t>** param, 01185 index_t* length_y, index_t* length_x, 01186 const char* name, const char* description) { 01187 TSGDataType type(CT_MATRIX, ST_SPARSE, PT_INT32, length_y, 01188 length_x); 01189 add_type(&type, param, name, description); 01190 } 01191 01192 void 01193 Parameter::add_matrix(SGSparseVector<uint32_t>** param, 01194 index_t* length_y, index_t* length_x, 01195 const char* name, const char* description) { 01196 TSGDataType type(CT_MATRIX, ST_SPARSE, PT_UINT32, length_y, 01197 length_x); 01198 add_type(&type, param, name, description); 01199 } 01200 01201 void 01202 Parameter::add_matrix(SGSparseVector<int64_t>** param, 01203 index_t* length_y, index_t* length_x, 01204 const char* name, const char* description) { 01205 TSGDataType type(CT_MATRIX, ST_SPARSE, PT_INT64, length_y, 01206 length_x); 01207 add_type(&type, param, name, description); 01208 } 01209 01210 void 01211 Parameter::add_matrix(SGSparseVector<uint64_t>** param, 01212 index_t* length_y, index_t* length_x, 01213 const char* name, const char* description) { 01214 TSGDataType type(CT_MATRIX, ST_SPARSE, PT_UINT64, length_y, 01215 length_x); 01216 add_type(&type, param, name, description); 01217 } 01218 01219 void 01220 Parameter::add_matrix(SGSparseVector<float32_t>** param, 01221 index_t* length_y, index_t* length_x, 01222 const char* name, const char* description) { 01223 TSGDataType type(CT_MATRIX, ST_SPARSE, PT_FLOAT32, length_y, 01224 length_x); 01225 add_type(&type, param, name, description); 01226 } 01227 01228 void 01229 Parameter::add_matrix(SGSparseVector<float64_t>** param, 01230 index_t* length_y, index_t* length_x, 01231 const char* name, const char* description) { 01232 TSGDataType type(CT_MATRIX, ST_SPARSE, PT_FLOAT64, length_y, 01233 length_x); 01234 add_type(&type, param, name, description); 01235 } 01236 01237 void 01238 Parameter::add_matrix(SGSparseVector<floatmax_t>** param, 01239 index_t* length_y, index_t* length_x, 01240 const char* name, const char* description) { 01241 TSGDataType type(CT_MATRIX, ST_SPARSE, PT_FLOATMAX, length_y, 01242 length_x); 01243 add_type(&type, param, name, description); 01244 } 01245 01246 01247 01248 01249 void Parameter::add(SGMatrix<bool>* param, const char* name, 01250 const char* description) 01251 { 01252 TSGDataType type(CT_SGMATRIX, ST_NONE, PT_BOOL, ¶m->num_rows, 01253 ¶m->num_cols); 01254 add_type(&type, ¶m->matrix, name, description); 01255 } 01256 01257 void Parameter::add(SGMatrix<char>* param, const char* name, 01258 const char* description) 01259 { 01260 TSGDataType type(CT_SGMATRIX, ST_NONE, PT_CHAR, ¶m->num_rows, 01261 ¶m->num_cols); 01262 add_type(&type, ¶m->matrix, name, description); 01263 } 01264 01265 void Parameter::add(SGMatrix<int8_t>* param, const char* name, 01266 const char* description) 01267 { 01268 TSGDataType type(CT_SGMATRIX, ST_NONE, PT_INT8, ¶m->num_rows, 01269 ¶m->num_cols); 01270 add_type(&type, ¶m->matrix, name, description); 01271 } 01272 01273 void Parameter::add(SGMatrix<uint8_t>* param, const char* name, 01274 const char* description) 01275 { 01276 TSGDataType type(CT_SGMATRIX, ST_NONE, PT_UINT8, ¶m->num_rows, 01277 ¶m->num_cols); 01278 add_type(&type, ¶m->matrix, name, description); 01279 } 01280 01281 void Parameter::add(SGMatrix<int16_t>* param, const char* name, 01282 const char* description) 01283 { 01284 TSGDataType type(CT_SGMATRIX, ST_NONE, PT_INT16, ¶m->num_rows, 01285 ¶m->num_cols); 01286 add_type(&type, ¶m->matrix, name, description); 01287 } 01288 01289 void Parameter::add(SGMatrix<uint16_t>* param, const char* name, 01290 const char* description) 01291 { 01292 TSGDataType type(CT_SGMATRIX, ST_NONE, PT_UINT16, ¶m->num_rows, 01293 ¶m->num_cols); 01294 add_type(&type, ¶m->matrix, name, description); 01295 } 01296 01297 void Parameter::add(SGMatrix<int32_t>* param, const char* name, 01298 const char* description) 01299 { 01300 TSGDataType type(CT_SGMATRIX, ST_NONE, PT_INT32, ¶m->num_rows, 01301 ¶m->num_cols); 01302 add_type(&type, ¶m->matrix, name, description); 01303 } 01304 01305 void Parameter::add(SGMatrix<uint32_t>* param, const char* name, 01306 const char* description) 01307 { 01308 TSGDataType type(CT_SGMATRIX, ST_NONE, PT_UINT32, ¶m->num_rows, 01309 ¶m->num_cols); 01310 add_type(&type, ¶m->matrix, name, description); 01311 } 01312 01313 void Parameter::add(SGMatrix<int64_t>* param, const char* name, 01314 const char* description) 01315 { 01316 TSGDataType type(CT_SGMATRIX, ST_NONE, PT_INT64, ¶m->num_rows, 01317 ¶m->num_cols); 01318 add_type(&type, ¶m->matrix, name, description); 01319 } 01320 01321 void Parameter::add(SGMatrix<uint64_t>* param, const char* name, 01322 const char* description) 01323 { 01324 TSGDataType type(CT_SGMATRIX, ST_NONE, PT_UINT64, ¶m->num_rows, 01325 ¶m->num_cols); 01326 add_type(&type, ¶m->matrix, name, description); 01327 } 01328 01329 void Parameter::add(SGMatrix<float32_t>* param, const char* name, 01330 const char* description) 01331 { 01332 TSGDataType type(CT_SGMATRIX, ST_NONE, PT_FLOAT32, ¶m->num_rows, 01333 ¶m->num_cols); 01334 add_type(&type, ¶m->matrix, name, description); 01335 } 01336 01337 void Parameter::add(SGMatrix<float64_t>* param, const char* name, 01338 const char* description) 01339 { 01340 TSGDataType type(CT_SGMATRIX, ST_NONE, PT_FLOAT64, ¶m->num_rows, 01341 ¶m->num_cols); 01342 add_type(&type, ¶m->matrix, name, description); 01343 } 01344 01345 void Parameter::add(SGMatrix<floatmax_t>* param, const char* name, 01346 const char* description) 01347 { 01348 TSGDataType type(CT_SGMATRIX, ST_NONE, PT_FLOATMAX, ¶m->num_rows, 01349 ¶m->num_cols); 01350 add_type(&type, ¶m->matrix, name, description); 01351 } 01352 01353 void Parameter::add(SGMatrix<CSGObject*>* param, const char* name, 01354 const char* description) 01355 { 01356 TSGDataType type(CT_SGMATRIX, ST_NONE, PT_SGOBJECT, ¶m->num_rows, 01357 ¶m->num_cols); 01358 add_type(&type, ¶m->matrix, name, description); 01359 } 01360 01361 void Parameter::add(SGMatrix<SGString<bool> >* param, const char* name, 01362 const char* description) 01363 { 01364 TSGDataType type(CT_SGMATRIX, ST_STRING, PT_BOOL, ¶m->num_rows, 01365 ¶m->num_cols); 01366 add_type(&type, ¶m->matrix, name, description); 01367 } 01368 01369 void Parameter::add(SGMatrix<SGString<char> >* param, const char* name, 01370 const char* description) 01371 { 01372 TSGDataType type(CT_SGMATRIX, ST_STRING, PT_CHAR, ¶m->num_rows, 01373 ¶m->num_cols); 01374 add_type(&type, ¶m->matrix, name, description); 01375 } 01376 01377 void Parameter::add(SGMatrix<SGString<int8_t> >* param, 01378 const char* name, const char* description) 01379 { 01380 TSGDataType type(CT_SGMATRIX, ST_STRING, PT_INT8, ¶m->num_rows, 01381 ¶m->num_cols); 01382 add_type(&type, ¶m->matrix, name, description); 01383 } 01384 01385 void Parameter::add(SGMatrix<SGString<uint8_t> >* param, 01386 const char* name, const char* description) 01387 { 01388 TSGDataType type(CT_SGMATRIX, ST_STRING, PT_UINT8, ¶m->num_rows, 01389 ¶m->num_cols); 01390 add_type(&type, ¶m->matrix, name, description); 01391 } 01392 01393 void Parameter::add(SGMatrix<SGString<int16_t> >* param, 01394 const char* name, const char* description) 01395 { 01396 TSGDataType type(CT_SGMATRIX, ST_STRING, PT_INT16, ¶m->num_rows, 01397 ¶m->num_cols); 01398 add_type(&type, ¶m->matrix, name, description); 01399 } 01400 01401 void Parameter::add(SGMatrix<SGString<uint16_t> >* param, 01402 const char* name, const char* description) 01403 { 01404 TSGDataType type(CT_SGMATRIX, ST_STRING, PT_UINT16, ¶m->num_rows, 01405 ¶m->num_cols); 01406 add_type(&type, ¶m->matrix, name, description); 01407 } 01408 01409 void Parameter::add(SGMatrix<SGString<int32_t> >* param, 01410 const char* name, const char* description) 01411 { 01412 TSGDataType type(CT_SGMATRIX, ST_STRING, PT_INT32, ¶m->num_rows, 01413 ¶m->num_cols); 01414 add_type(&type, ¶m->matrix, name, description); 01415 } 01416 01417 void Parameter::add(SGMatrix<SGString<uint32_t> >* param, 01418 const char* name, const char* description) 01419 { 01420 TSGDataType type(CT_SGMATRIX, ST_STRING, PT_UINT32, ¶m->num_rows, 01421 ¶m->num_cols); 01422 add_type(&type, ¶m->matrix, name, description); 01423 } 01424 01425 void Parameter::add(SGMatrix<SGString<int64_t> >* param, 01426 const char* name, const char* description) 01427 { 01428 TSGDataType type(CT_SGMATRIX, ST_STRING, PT_INT64, ¶m->num_rows, 01429 ¶m->num_cols); 01430 add_type(&type, ¶m->matrix, name, description); 01431 } 01432 01433 void Parameter::add(SGMatrix<SGString<uint64_t> >* param, 01434 const char* name, const char* description) 01435 { 01436 TSGDataType type(CT_SGMATRIX, ST_STRING, PT_UINT64, ¶m->num_rows, 01437 ¶m->num_cols); 01438 add_type(&type, ¶m->matrix, name, description); 01439 } 01440 01441 void Parameter::add(SGMatrix<SGString<float32_t> >* param, 01442 const char* name, const char* description) 01443 { 01444 TSGDataType type(CT_SGMATRIX, ST_STRING, PT_FLOAT32, ¶m->num_rows, 01445 ¶m->num_cols); 01446 add_type(&type, ¶m->matrix, name, description); 01447 } 01448 01449 void Parameter::add(SGMatrix<SGString<float64_t> >* param, 01450 const char* name, const char* description) 01451 { 01452 TSGDataType type(CT_SGMATRIX, ST_STRING, PT_FLOAT64, ¶m->num_rows, 01453 ¶m->num_cols); 01454 add_type(&type, ¶m->matrix, name, description); 01455 } 01456 01457 void Parameter::add(SGMatrix<SGString<floatmax_t> >* param, 01458 const char* name, const char* description) 01459 { 01460 TSGDataType type(CT_SGMATRIX, ST_STRING, PT_FLOATMAX, ¶m->num_rows, 01461 ¶m->num_cols); 01462 add_type(&type, ¶m->matrix, name, description); 01463 } 01464 01465 void Parameter::add(SGMatrix<SGSparseVector<bool> >* param, 01466 const char* name, const char* description) 01467 { 01468 TSGDataType type(CT_SGMATRIX, ST_SPARSE, PT_BOOL, ¶m->num_rows, 01469 ¶m->num_cols); 01470 add_type(&type, ¶m->matrix, name, description); 01471 } 01472 01473 void Parameter::add(SGMatrix<SGSparseVector<char> >* param, 01474 const char* name, const char* description) 01475 { 01476 TSGDataType type(CT_SGMATRIX, ST_SPARSE, PT_CHAR, ¶m->num_rows, 01477 ¶m->num_cols); 01478 add_type(&type, ¶m->matrix, name, description); 01479 } 01480 01481 void Parameter::add(SGMatrix<SGSparseVector<int8_t> >* param, 01482 const char* name, const char* description) 01483 { 01484 TSGDataType type(CT_SGMATRIX, ST_SPARSE, PT_INT8, ¶m->num_rows, 01485 ¶m->num_cols); 01486 add_type(&type, ¶m->matrix, name, description); 01487 } 01488 01489 void Parameter::add(SGMatrix<SGSparseVector<uint8_t> >* param, 01490 const char* name, const char* description) 01491 { 01492 TSGDataType type(CT_SGMATRIX, ST_SPARSE, PT_UINT8, ¶m->num_rows, 01493 ¶m->num_cols); 01494 add_type(&type, ¶m->matrix, name, description); 01495 } 01496 01497 void Parameter::add(SGMatrix<SGSparseVector<int16_t> >* param, 01498 const char* name, const char* description) 01499 { 01500 TSGDataType type(CT_SGMATRIX, ST_SPARSE, PT_INT16, ¶m->num_rows, 01501 ¶m->num_cols); 01502 add_type(&type, ¶m->matrix, name, description); 01503 } 01504 01505 void Parameter::add(SGMatrix<SGSparseVector<uint16_t> >* param, 01506 const char* name, const char* description) 01507 { 01508 TSGDataType type(CT_SGMATRIX, ST_SPARSE, PT_UINT16, ¶m->num_rows, 01509 ¶m->num_cols); 01510 add_type(&type, ¶m->matrix, name, description); 01511 } 01512 01513 void Parameter::add(SGMatrix<SGSparseVector<int32_t> >* param, 01514 const char* name, const char* description) 01515 { 01516 TSGDataType type(CT_SGMATRIX, ST_SPARSE, PT_INT32, ¶m->num_rows, 01517 ¶m->num_cols); 01518 add_type(&type, ¶m->matrix, name, description); 01519 } 01520 01521 void Parameter::add(SGMatrix<SGSparseVector<uint32_t> >* param, 01522 const char* name, const char* description) 01523 { 01524 TSGDataType type(CT_SGMATRIX, ST_SPARSE, PT_UINT32, ¶m->num_rows, 01525 ¶m->num_cols); 01526 add_type(&type, ¶m->matrix, name, description); 01527 } 01528 01529 void Parameter::add(SGMatrix<SGSparseVector<int64_t> >* param, 01530 const char* name, const char* description) 01531 { 01532 TSGDataType type(CT_SGMATRIX, ST_SPARSE, PT_INT64, ¶m->num_rows, 01533 ¶m->num_cols); 01534 add_type(&type, ¶m->matrix, name, description); 01535 } 01536 01537 void Parameter::add(SGMatrix<SGSparseVector<uint64_t> >* param, 01538 const char* name, const char* description) 01539 { 01540 TSGDataType type(CT_SGMATRIX, ST_SPARSE, PT_UINT64, ¶m->num_rows, 01541 ¶m->num_cols); 01542 add_type(&type, ¶m->matrix, name, description); 01543 } 01544 01545 void Parameter::add(SGMatrix<SGSparseVector<float32_t> >* param, 01546 const char* name, const char* description) 01547 { 01548 TSGDataType type(CT_SGMATRIX, ST_SPARSE, PT_FLOAT32, ¶m->num_rows, 01549 ¶m->num_cols); 01550 add_type(&type, ¶m->matrix, name, description); 01551 } 01552 01553 void Parameter::add(SGMatrix<SGSparseVector<float64_t> >* param, 01554 const char* name, const char* description) 01555 { 01556 TSGDataType type(CT_SGMATRIX, ST_SPARSE, PT_FLOAT64, ¶m->num_rows, 01557 ¶m->num_cols); 01558 add_type(&type, ¶m->matrix, name, description); 01559 } 01560 01561 void Parameter::add(SGMatrix<SGSparseVector<floatmax_t> >* param, 01562 const char* name, const char* description) 01563 { 01564 TSGDataType type(CT_SGMATRIX, ST_SPARSE, PT_FLOATMAX, ¶m->num_rows, 01565 ¶m->num_cols); 01566 add_type(&type, ¶m->matrix, name, description); 01567 } 01568 /* **************************************************************** */ 01569 /* End of wrappers */ 01570 01571 TParameter::TParameter(const TSGDataType* datatype, void* parameter, 01572 const char* name, const char* description) 01573 :m_datatype(*datatype) 01574 { 01575 m_parameter = parameter; 01576 m_name = strdup(name); 01577 m_description = strdup(description); 01578 m_delete_data=false; 01579 m_was_allocated_from_scratch=false; 01580 } 01581 01582 TParameter::~TParameter() 01583 { 01584 // SG_SDEBUG("entering ~TParameter for \"%s\"\n", m_name); 01585 SG_FREE(m_description); 01586 SG_FREE(m_name); 01587 01588 /* possibly delete content, m_parameter variable */ 01589 if (m_was_allocated_from_scratch) 01590 { 01591 SG_SDEBUG("deleting from scratch data\n"); 01592 01593 if (m_delete_data) 01594 { 01595 /* for non-scalar data, delete_cont does the job, rest is handled 01596 * below */ 01597 SG_SDEBUG("deleting pure data\n"); 01598 if (m_datatype.m_ctype!=CT_SCALAR) 01599 delete_cont(); 01600 01601 if (m_datatype.m_ctype==CT_SCALAR && m_datatype.m_ptype==PT_SGOBJECT) 01602 SG_UNREF(*(CSGObject**)m_parameter); 01603 } 01604 01605 /* free pointer/data */ 01606 if (m_parameter) 01607 { 01608 SG_SDEBUG("freeing m_parameter pointer/data at %p\n", m_parameter); 01609 SG_FREE(m_parameter); 01610 } 01611 01612 /* free lengths */ 01613 if (m_datatype.m_length_x) 01614 SG_FREE(m_datatype.m_length_x); 01615 01616 if (m_datatype.m_length_y) 01617 SG_FREE(m_datatype.m_length_y); 01618 } 01619 01620 // SG_SDEBUG("leaving ~TParameter\n"); 01621 } 01622 01623 char* 01624 TParameter::new_prefix(const char* s1, const char* s2) 01625 { 01626 char* tmp = SG_MALLOC(char, strlen(s1)+strlen(s2)+2); 01627 01628 sprintf(tmp, "%s%s/", s1, s2); 01629 01630 return tmp; 01631 } 01632 01633 void 01634 TParameter::print(const char* prefix) 01635 { 01636 string_t buf; 01637 m_datatype.to_string(buf, STRING_LEN); 01638 01639 SG_SPRINT("\n%s\n%35s %24s :%s\n", prefix, m_description == NULL 01640 || *m_description == '\0' ? "(Parameter)": m_description, 01641 m_name, buf); 01642 01643 if (m_datatype.m_ptype == PT_SGOBJECT 01644 && m_datatype.m_stype == ST_NONE 01645 && m_datatype.m_ctype == CT_SCALAR 01646 && *(CSGObject**) m_parameter != NULL) { 01647 char* p = new_prefix(prefix, m_name); 01648 (*(CSGObject**) m_parameter)->print_serializable(p); 01649 delete p; 01650 } 01651 } 01652 01653 void 01654 TParameter::delete_cont() 01655 { 01656 if (*(void**) m_parameter != NULL) { 01657 index_t old_length = m_datatype.m_length_y ? *m_datatype.m_length_y : 0; 01658 switch (m_datatype.m_ctype) { 01659 case CT_NDARRAY: 01660 SG_SNOTIMPLEMENTED; 01661 case CT_MATRIX: case CT_SGMATRIX: 01662 old_length *= *m_datatype.m_length_x; break; 01663 case CT_SCALAR: case CT_VECTOR: case CT_SGVECTOR: break; 01664 } 01665 01666 switch (m_datatype.m_stype) { 01667 case ST_NONE: 01668 switch (m_datatype.m_ptype) { 01669 case PT_BOOL: 01670 SG_FREE(*(bool**) m_parameter); break; 01671 case PT_CHAR: 01672 SG_FREE(*(char**) m_parameter); break; 01673 case PT_INT8: 01674 SG_FREE(*(int8_t**) m_parameter); break; 01675 case PT_UINT8: 01676 SG_FREE(*(uint8_t**) m_parameter); break; 01677 case PT_INT16: 01678 SG_FREE(*(int16_t**) m_parameter); break; 01679 case PT_UINT16: 01680 SG_FREE(*(uint16_t**) m_parameter); break; 01681 case PT_INT32: 01682 SG_FREE(*(int32_t**) m_parameter); break; 01683 case PT_UINT32: 01684 SG_FREE(*(uint32_t**) m_parameter); break; 01685 case PT_INT64: 01686 SG_FREE(*(int64_t**) m_parameter); break; 01687 case PT_UINT64: 01688 SG_FREE(*(uint64_t**) m_parameter); break; 01689 case PT_FLOAT32: 01690 SG_FREE(*(float32_t**) m_parameter); break; 01691 case PT_FLOAT64: 01692 SG_FREE(*(float64_t**) m_parameter); break; 01693 case PT_FLOATMAX: 01694 SG_FREE(*(floatmax_t**) m_parameter); break; 01695 case PT_SGOBJECT: 01696 CSGObject** buf = 01697 *(CSGObject***) m_parameter; 01698 for (index_t i=0; i<old_length; i++) 01699 if (buf[i] != NULL) SG_UNREF(buf[i]); 01700 01701 SG_FREE(buf); 01702 break; 01703 } 01704 break; 01705 case ST_STRING: 01706 for (index_t i=0; i<old_length; i++) { 01707 SGString<char>* buf = (SGString<char>*) (*(char**) 01708 m_parameter + i *m_datatype.sizeof_stype()); 01709 if (buf->slen > 0) SG_FREE(buf->string); 01710 } 01711 01712 switch (m_datatype.m_ptype) { 01713 case PT_BOOL: 01714 SG_FREE(*(SGString<bool>**) m_parameter); break; 01715 case PT_CHAR: 01716 SG_FREE(*(SGString<char>**) m_parameter); break; 01717 case PT_INT8: 01718 SG_FREE(*(SGString<int8_t>**) m_parameter); break; 01719 case PT_UINT8: 01720 SG_FREE(*(SGString<uint8_t>**) m_parameter); break; 01721 case PT_INT16: 01722 SG_FREE(*(SGString<int16_t>**) m_parameter); break; 01723 case PT_UINT16: 01724 SG_FREE(*(SGString<uint16_t>**) m_parameter); break; 01725 case PT_INT32: 01726 SG_FREE(*(SGString<int32_t>**) m_parameter); break; 01727 case PT_UINT32: 01728 SG_FREE(*(SGString<uint32_t>**) m_parameter); break; 01729 case PT_INT64: 01730 SG_FREE(*(SGString<int64_t>**) m_parameter); break; 01731 case PT_UINT64: 01732 SG_FREE(*(SGString<uint64_t>**) m_parameter); break; 01733 case PT_FLOAT32: 01734 SG_FREE(*(SGString<float32_t>**) m_parameter); break; 01735 case PT_FLOAT64: 01736 SG_FREE(*(SGString<float64_t>**) m_parameter); break; 01737 case PT_FLOATMAX: 01738 SG_FREE(*(SGString<floatmax_t>**) m_parameter); break; 01739 case PT_SGOBJECT: 01740 SG_SERROR("TParameter::delete_cont(): Implementation " 01741 "error: Could not delete " 01742 "String<SGSerializable*>"); 01743 break; 01744 } 01745 break; 01746 case ST_SPARSE: 01747 for (index_t i=0; i<old_length; i++) { 01748 SGSparseVector<char>* buf = (SGSparseVector<char>*) (*(char**) 01749 m_parameter + i *m_datatype.sizeof_stype()); 01750 if (buf->num_feat_entries > 0) SG_FREE(buf->features); 01751 } 01752 01753 switch (m_datatype.m_ptype) { 01754 case PT_BOOL: 01755 SG_FREE(*(SGSparseVector<bool>**) m_parameter); break; 01756 case PT_CHAR: 01757 SG_FREE(*(SGSparseVector<char>**) m_parameter); break; 01758 case PT_INT8: 01759 SG_FREE(*(SGSparseVector<int8_t>**) m_parameter); break; 01760 case PT_UINT8: 01761 SG_FREE(*(SGSparseVector<uint8_t>**) m_parameter); break; 01762 case PT_INT16: 01763 SG_FREE(*(SGSparseVector<int16_t>**) m_parameter); break; 01764 case PT_UINT16: 01765 SG_FREE(*(SGSparseVector<uint16_t>**) m_parameter); break; 01766 case PT_INT32: 01767 SG_FREE(*(SGSparseVector<int32_t>**) m_parameter); break; 01768 case PT_UINT32: 01769 SG_FREE(*(SGSparseVector<uint32_t>**) m_parameter); break; 01770 case PT_INT64: 01771 SG_FREE(*(SGSparseVector<int64_t>**) m_parameter); break; 01772 case PT_UINT64: 01773 SG_FREE(*(SGSparseVector<uint64_t>**) m_parameter); break; 01774 case PT_FLOAT32: 01775 SG_FREE(*(SGSparseVector<float32_t>**) m_parameter); break; 01776 case PT_FLOAT64: 01777 SG_FREE(*(SGSparseVector<float64_t>**) m_parameter); break; 01778 case PT_FLOATMAX: 01779 SG_FREE(*(SGSparseVector<floatmax_t>**) m_parameter); break; 01780 case PT_SGOBJECT: 01781 SG_SERROR("TParameter::delete_cont(): Implementation " 01782 "error: Could not delete " 01783 "Sparse<SGSerializable*>"); 01784 break; 01785 } 01786 break; 01787 } /* switch (m_datatype.m_stype) */ 01788 } /* if (*(void**) m_parameter != NULL) */ 01789 01790 *(void**) m_parameter = NULL; 01791 } 01792 01793 void 01794 TParameter::new_cont(index_t new_len_y, index_t new_len_x) 01795 { 01796 char* s=SG_MALLOC(char, 200); 01797 m_datatype.to_string(s, 200); 01798 SG_SDEBUG("entering TParameter::new_cont(%d, %d) for \"%s\" of type %s\n", 01799 new_len_y, new_len_x, s, m_name ? m_name : "(nil)"); 01800 SG_FREE(s); 01801 delete_cont(); 01802 01803 index_t new_length = new_len_y*new_len_x; 01804 if (new_length == 0) return; 01805 01806 switch (m_datatype.m_stype) { 01807 case ST_NONE: 01808 switch (m_datatype.m_ptype) { 01809 case PT_BOOL: 01810 *(bool**) m_parameter 01811 = SG_MALLOC(bool, new_length); break; 01812 case PT_CHAR: 01813 *(char**) m_parameter 01814 = SG_MALLOC(char, new_length); break; 01815 case PT_INT8: 01816 *(int8_t**) m_parameter 01817 = SG_MALLOC(int8_t, new_length); break; 01818 case PT_UINT8: 01819 *(uint8_t**) m_parameter 01820 = SG_MALLOC(uint8_t, new_length); break; 01821 case PT_INT16: 01822 *(int16_t**) m_parameter 01823 = SG_MALLOC(int16_t, new_length); break; 01824 case PT_UINT16: 01825 *(uint16_t**) m_parameter 01826 = SG_MALLOC(uint16_t, new_length); break; 01827 case PT_INT32: 01828 *(int32_t**) m_parameter 01829 = SG_MALLOC(int32_t, new_length); break; 01830 case PT_UINT32: 01831 *(uint32_t**) m_parameter 01832 = SG_MALLOC(uint32_t, new_length); break; 01833 case PT_INT64: 01834 *(int64_t**) m_parameter 01835 = SG_MALLOC(int64_t, new_length); break; 01836 case PT_UINT64: 01837 *(uint64_t**) m_parameter 01838 = SG_MALLOC(uint64_t, new_length); break; 01839 case PT_FLOAT32: 01840 *(float32_t**) m_parameter 01841 = SG_MALLOC(float32_t, new_length); break; 01842 case PT_FLOAT64: 01843 *(float64_t**) m_parameter 01844 = SG_MALLOC(float64_t, new_length); break; 01845 case PT_FLOATMAX: 01846 *(floatmax_t**) m_parameter 01847 = SG_MALLOC(floatmax_t, new_length); break; 01848 case PT_SGOBJECT: 01849 *(CSGObject***) m_parameter 01850 = SG_CALLOC(CSGObject*, new_length); 01851 break; 01852 } 01853 break; 01854 case ST_STRING: 01855 switch (m_datatype.m_ptype) { 01856 case PT_BOOL: 01857 *(SGString<bool>**) m_parameter 01858 = SG_MALLOC(SGString<bool>, new_length); break; 01859 case PT_CHAR: 01860 *(SGString<char>**) m_parameter 01861 = SG_MALLOC(SGString<char>, new_length); break; 01862 case PT_INT8: 01863 *(SGString<int8_t>**) m_parameter 01864 = SG_MALLOC(SGString<int8_t>, new_length); break; 01865 case PT_UINT8: 01866 *(SGString<uint8_t>**) m_parameter 01867 = SG_MALLOC(SGString<uint8_t>, new_length); break; 01868 case PT_INT16: 01869 *(SGString<int16_t>**) m_parameter 01870 = SG_MALLOC(SGString<int16_t>, new_length); break; 01871 case PT_UINT16: 01872 *(SGString<uint16_t>**) m_parameter 01873 = SG_MALLOC(SGString<uint16_t>, new_length); break; 01874 case PT_INT32: 01875 *(SGString<int32_t>**) m_parameter 01876 = SG_MALLOC(SGString<int32_t>, new_length); break; 01877 case PT_UINT32: 01878 *(SGString<uint32_t>**) m_parameter 01879 = SG_MALLOC(SGString<uint32_t>, new_length); break; 01880 case PT_INT64: 01881 *(SGString<int64_t>**) m_parameter 01882 = SG_MALLOC(SGString<int64_t>, new_length); break; 01883 case PT_UINT64: 01884 *(SGString<uint64_t>**) m_parameter 01885 = SG_MALLOC(SGString<uint64_t>, new_length); break; 01886 case PT_FLOAT32: 01887 *(SGString<float32_t>**) m_parameter 01888 = SG_MALLOC(SGString<float32_t>, new_length); break; 01889 case PT_FLOAT64: 01890 *(SGString<float64_t>**) m_parameter 01891 = SG_MALLOC(SGString<float64_t>, new_length); break; 01892 case PT_FLOATMAX: 01893 *(SGString<floatmax_t>**) m_parameter 01894 = SG_MALLOC(SGString<floatmax_t>, new_length); break; 01895 case PT_SGOBJECT: 01896 SG_SERROR("TParameter::new_cont(): Implementation " 01897 "error: Could not allocate " 01898 "String<SGSerializable*>"); 01899 break; 01900 } 01901 memset(*(void**) m_parameter, 0, new_length 01902 *m_datatype.sizeof_stype()); 01903 break; 01904 case ST_SPARSE: 01905 switch (m_datatype.m_ptype) { 01906 case PT_BOOL: 01907 *(SGSparseVector<bool>**) m_parameter 01908 = SG_MALLOC(SGSparseVector<bool>, new_length); break; 01909 case PT_CHAR: 01910 *(SGSparseVector<char>**) m_parameter 01911 = SG_MALLOC(SGSparseVector<char>, new_length); break; 01912 case PT_INT8: 01913 *(SGSparseVector<int8_t>**) m_parameter 01914 = SG_MALLOC(SGSparseVector<int8_t>, new_length); break; 01915 case PT_UINT8: 01916 *(SGSparseVector<uint8_t>**) m_parameter 01917 = SG_MALLOC(SGSparseVector<uint8_t>, new_length); break; 01918 case PT_INT16: 01919 *(SGSparseVector<int16_t>**) m_parameter 01920 = SG_MALLOC(SGSparseVector<int16_t>, new_length); break; 01921 case PT_UINT16: 01922 *(SGSparseVector<uint16_t>**) m_parameter 01923 = SG_MALLOC(SGSparseVector<uint16_t>, new_length); break; 01924 case PT_INT32: 01925 *(SGSparseVector<int32_t>**) m_parameter 01926 = SG_MALLOC(SGSparseVector<int32_t>, new_length); break; 01927 case PT_UINT32: 01928 *(SGSparseVector<uint32_t>**) m_parameter 01929 = SG_MALLOC(SGSparseVector<uint32_t>, new_length); break; 01930 case PT_INT64: 01931 *(SGSparseVector<int64_t>**) m_parameter 01932 = SG_MALLOC(SGSparseVector<int64_t>, new_length); break; 01933 case PT_UINT64: 01934 *(SGSparseVector<uint64_t>**) m_parameter 01935 = SG_MALLOC(SGSparseVector<uint64_t>, new_length); break; 01936 case PT_FLOAT32: 01937 *(SGSparseVector<float32_t>**) m_parameter 01938 = SG_MALLOC(SGSparseVector<float32_t>, new_length); break; 01939 case PT_FLOAT64: 01940 *(SGSparseVector<float64_t>**) m_parameter 01941 = SG_MALLOC(SGSparseVector<float64_t>, new_length); break; 01942 case PT_FLOATMAX: 01943 *(SGSparseVector<floatmax_t>**) m_parameter 01944 = SG_MALLOC(SGSparseVector<floatmax_t>, new_length); break; 01945 case PT_SGOBJECT: 01946 SG_SERROR("TParameter::new_cont(): Implementation " 01947 "error: Could not allocate " 01948 "Sparse<SGSerializable*>"); 01949 break; 01950 } 01951 memset(*(void**) m_parameter, 0, new_length 01952 *m_datatype.sizeof_stype()); 01953 break; 01954 } /* switch (m_datatype.m_stype) */ 01955 01956 s=SG_MALLOC(char, 200); 01957 m_datatype.to_string(s, 200); 01958 SG_SDEBUG("leaving TParameter::new_cont(%d, %d) for \"%s\" of type %s\n", 01959 new_len_y, new_len_x, s, m_name ? m_name : "(nil)"); 01960 SG_FREE(s); 01961 } 01962 01963 bool 01964 TParameter::new_sgserial(CSGObject** param, 01965 EPrimitiveType generic, 01966 const char* sgserializable_name, 01967 const char* prefix) 01968 { 01969 if (*param != NULL) 01970 SG_UNREF(*param); 01971 01972 *param = new_sgserializable(sgserializable_name, generic); 01973 01974 if (*param == NULL) { 01975 string_t buf = {'\0'}; 01976 01977 if (generic != PT_NOT_GENERIC) { 01978 buf[0] = '<'; 01979 TSGDataType::ptype_to_string(buf+1, generic, 01980 STRING_LEN - 3); 01981 strcat(buf, ">"); 01982 } 01983 01984 SG_SWARNING("TParameter::new_sgserial(): " 01985 "Class `C%s%s' was not listed during compiling Shogun" 01986 " :( ... Can not construct it for `%s%s'!", 01987 sgserializable_name, buf, prefix, m_name); 01988 01989 return false; 01990 } 01991 01992 SG_REF(*param); 01993 return true; 01994 } 01995 01996 bool 01997 TParameter::save_ptype(CSerializableFile* file, const void* param, 01998 const char* prefix) 01999 { 02000 if (m_datatype.m_ptype == PT_SGOBJECT) { 02001 const char* sgserial_name = ""; 02002 EPrimitiveType generic = PT_NOT_GENERIC; 02003 02004 if (*(CSGObject**) param != NULL) { 02005 sgserial_name = (*(CSGObject**) param)->get_name(); 02006 (*(CSGObject**) param)->is_generic(&generic); 02007 } 02008 02009 if (!file->write_sgserializable_begin( 02010 &m_datatype, m_name, prefix, sgserial_name, generic)) 02011 return false; 02012 if (*sgserial_name != '\0') { 02013 char* p = new_prefix(prefix, m_name); 02014 bool result = (*(CSGObject**) param) 02015 ->save_serializable(file, p); 02016 delete p; 02017 if (!result) return false; 02018 } 02019 if (!file->write_sgserializable_end( 02020 &m_datatype, m_name, prefix, sgserial_name, generic)) 02021 return false; 02022 } else 02023 if (!file->write_scalar(&m_datatype, m_name, prefix, 02024 param)) return false; 02025 02026 return true; 02027 } 02028 02029 bool 02030 TParameter::load_ptype(CSerializableFile* file, void* param, 02031 const char* prefix) 02032 { 02033 if (m_datatype.m_ptype == PT_SGOBJECT) { 02034 string_t sgserial_name = {'\0'}; 02035 EPrimitiveType generic = PT_NOT_GENERIC; 02036 02037 if (!file->read_sgserializable_begin( 02038 &m_datatype, m_name, prefix, sgserial_name, &generic)) 02039 return false; 02040 if (*sgserial_name != '\0') { 02041 if (!new_sgserial((CSGObject**) param, generic, 02042 sgserial_name, prefix)) 02043 return false; 02044 02045 char* p = new_prefix(prefix, m_name); 02046 bool result = (*(CSGObject**) param) 02047 ->load_serializable(file, p); 02048 delete p; 02049 if (!result) return false; 02050 } 02051 if (!file->read_sgserializable_end( 02052 &m_datatype, m_name, prefix, sgserial_name, generic)) 02053 return false; 02054 } else 02055 if (!file->read_scalar(&m_datatype, m_name, prefix, 02056 param)) return false; 02057 02058 return true; 02059 } 02060 02061 bool 02062 TParameter::save_stype(CSerializableFile* file, const void* param, 02063 const char* prefix) 02064 { 02065 SGString<char>* str_ptr = (SGString<char>*) param; 02066 SGSparseVector<char>* spr_ptr = (SGSparseVector<char>*) param; 02067 index_t len_real; 02068 02069 switch (m_datatype.m_stype) { 02070 case ST_NONE: 02071 if (!save_ptype(file, param, prefix)) return false; 02072 break; 02073 case ST_STRING: 02074 len_real = str_ptr->slen; 02075 if (str_ptr->string == NULL && len_real != 0) { 02076 SG_SWARNING("Inconsistency between data structure and " 02077 "len during saving string `%s%s'! Continuing" 02078 " with len=0.\n", 02079 prefix, m_name); 02080 len_real = 0; 02081 } 02082 if (!file->write_string_begin( 02083 &m_datatype, m_name, prefix, len_real)) return false; 02084 for (index_t i=0; i<len_real; i++) { 02085 if (!file->write_stringentry_begin( 02086 &m_datatype, m_name, prefix, i)) return false; 02087 if (!save_ptype(file, (char*) str_ptr->string 02088 + i *m_datatype.sizeof_ptype(), prefix)) 02089 return false; 02090 if (!file->write_stringentry_end( 02091 &m_datatype, m_name, prefix, i)) return false; 02092 } 02093 if (!file->write_string_end( 02094 &m_datatype, m_name, prefix, len_real)) return false; 02095 break; 02096 case ST_SPARSE: 02097 len_real = spr_ptr->num_feat_entries; 02098 if (spr_ptr->features == NULL && len_real != 0) { 02099 SG_SWARNING("Inconsistency between data structure and " 02100 "len during saving sparse `%s%s'! Continuing" 02101 " with len=0.\n", 02102 prefix, m_name); 02103 len_real = 0; 02104 } 02105 if (!file->write_sparse_begin( 02106 &m_datatype, m_name, prefix, len_real)) return false; 02107 for (index_t i=0; i<len_real; i++) { 02108 SGSparseVectorEntry<char>* cur = (SGSparseVectorEntry<char>*) 02109 ((char*) spr_ptr->features + i *TSGDataType 02110 ::sizeof_sparseentry(m_datatype.m_ptype)); 02111 if (!file->write_sparseentry_begin( 02112 &m_datatype, m_name, prefix, spr_ptr->features, 02113 cur->feat_index, i)) return false; 02114 if (!save_ptype(file, (char*) cur + TSGDataType 02115 ::offset_sparseentry(m_datatype.m_ptype), 02116 prefix)) return false; 02117 if (!file->write_sparseentry_end( 02118 &m_datatype, m_name, prefix, spr_ptr->features, 02119 cur->feat_index, i)) return false; 02120 } 02121 if (!file->write_sparse_end( 02122 &m_datatype, m_name, prefix, len_real)) return false; 02123 break; 02124 } 02125 02126 return true; 02127 } 02128 02129 bool 02130 TParameter::load_stype(CSerializableFile* file, void* param, 02131 const char* prefix) 02132 { 02133 SGString<char>* str_ptr = (SGString<char>*) param; 02134 SGSparseVector<char>* spr_ptr = (SGSparseVector<char>*) param; 02135 index_t len_real = 0; 02136 02137 switch (m_datatype.m_stype) { 02138 case ST_NONE: 02139 if (!load_ptype(file, param, prefix)) return false; 02140 break; 02141 case ST_STRING: 02142 if (!file->read_string_begin( 02143 &m_datatype, m_name, prefix, &len_real)) 02144 return false; 02145 str_ptr->string = len_real > 0 02146 ? SG_MALLOC(char, len_real*m_datatype.sizeof_ptype()): NULL; 02147 for (index_t i=0; i<len_real; i++) { 02148 if (!file->read_stringentry_begin( 02149 &m_datatype, m_name, prefix, i)) return false; 02150 if (!load_ptype(file, (char*) str_ptr->string 02151 + i *m_datatype.sizeof_ptype(), prefix)) 02152 return false; 02153 if (!file->read_stringentry_end( 02154 &m_datatype, m_name, prefix, i)) return false; 02155 } 02156 if (!file->read_string_end( 02157 &m_datatype, m_name, prefix, len_real)) 02158 return false; 02159 str_ptr->slen = len_real; 02160 break; 02161 case ST_SPARSE: 02162 if (!file->read_sparse_begin( 02163 &m_datatype, m_name, prefix, &len_real)) return false; 02164 spr_ptr->features = len_real > 0? (SGSparseVectorEntry<char>*) 02165 SG_MALLOC(char, len_real *TSGDataType::sizeof_sparseentry( 02166 m_datatype.m_ptype)): NULL; 02167 for (index_t i=0; i<len_real; i++) { 02168 SGSparseVectorEntry<char>* cur = (SGSparseVectorEntry<char>*) 02169 ((char*) spr_ptr->features + i *TSGDataType 02170 ::sizeof_sparseentry(m_datatype.m_ptype)); 02171 if (!file->read_sparseentry_begin( 02172 &m_datatype, m_name, prefix, spr_ptr->features, 02173 &cur->feat_index, i)) return false; 02174 if (!load_ptype(file, (char*) cur + TSGDataType 02175 ::offset_sparseentry(m_datatype.m_ptype), 02176 prefix)) return false; 02177 if (!file->read_sparseentry_end( 02178 &m_datatype, m_name, prefix, spr_ptr->features, 02179 &cur->feat_index, i)) return false; 02180 } 02181 02182 if (!file->read_sparse_end(&m_datatype, m_name, prefix, len_real)) 02183 return false; 02184 02185 spr_ptr->num_feat_entries = len_real; 02186 break; 02187 } 02188 02189 return true; 02190 } 02191 02192 void TParameter::get_incremental_hash( 02193 uint32_t& hash, uint32_t& carry, uint32_t& total_length) 02194 { 02195 02196 switch (m_datatype.m_ctype) 02197 { 02198 case CT_NDARRAY: 02199 SG_SNOTIMPLEMENTED; 02200 case CT_SCALAR: 02201 { 02202 uint8_t* data = ((uint8_t*) m_parameter); 02203 uint32_t size = m_datatype.sizeof_stype(); 02204 total_length += size; 02205 CHash::IncrementalMurmurHash3( 02206 &hash, &carry, data, size); 02207 break; 02208 } 02209 case CT_VECTOR: case CT_MATRIX: case CT_SGVECTOR: case CT_SGMATRIX: 02210 index_t len_real_y = 0, len_real_x = 0; 02211 02212 if (m_datatype.m_length_y) 02213 len_real_y = *m_datatype.m_length_y; 02214 02215 else 02216 len_real_y = 1; 02217 02218 if (*(void**) m_parameter == NULL && len_real_y != 0) 02219 { 02220 SG_SWARNING("Inconsistency between data structure and " 02221 "len_y during hashing `%s'! Continuing with " 02222 "len_y=0.\n", 02223 m_name); 02224 len_real_y = 0; 02225 } 02226 02227 switch (m_datatype.m_ctype) 02228 { 02229 case CT_NDARRAY: 02230 SG_SNOTIMPLEMENTED; 02231 break; 02232 case CT_VECTOR: case CT_SGVECTOR: 02233 len_real_x = 1; 02234 break; 02235 case CT_MATRIX: case CT_SGMATRIX: 02236 len_real_x = *m_datatype.m_length_x; 02237 02238 if (*(void**) m_parameter == NULL && len_real_x != 0) 02239 { 02240 SG_SWARNING("Inconsistency between data structure and " 02241 "len_x during hashing %s'! Continuing " 02242 "with len_x=0.\n", 02243 m_name); 02244 len_real_x = 0; 02245 } 02246 02247 if (len_real_x *len_real_y == 0) 02248 len_real_x = len_real_y = 0; 02249 02250 break; 02251 02252 case CT_SCALAR: break; 02253 } 02254 uint32_t size = (len_real_x*len_real_y)*m_datatype.sizeof_stype(); 02255 02256 total_length += size; 02257 02258 uint8_t* data = (*(uint8_t**) m_parameter); 02259 02260 CHash::IncrementalMurmurHash3( 02261 &hash, &carry, data, size); 02262 break; 02263 } 02264 } 02265 02266 bool 02267 TParameter::save(CSerializableFile* file, const char* prefix) 02268 { 02269 const int32_t buflen=100; 02270 char* buf=SG_MALLOC(char, buflen); 02271 m_datatype.to_string(buf, buflen); 02272 SG_SDEBUG("Saving parameter '%s' of type '%s'\n", m_name, buf); 02273 SG_FREE(buf); 02274 02275 if (!file->write_type_begin(&m_datatype, m_name, prefix)) 02276 return false; 02277 02278 switch (m_datatype.m_ctype) { 02279 case CT_NDARRAY: 02280 SG_SNOTIMPLEMENTED; 02281 case CT_SCALAR: 02282 if (!save_stype(file, m_parameter, prefix)) return false; 02283 break; 02284 case CT_VECTOR: case CT_MATRIX: case CT_SGVECTOR: case CT_SGMATRIX: 02285 index_t len_real_y = 0, len_real_x = 0; 02286 02287 len_real_y = *m_datatype.m_length_y; 02288 if (*(void**) m_parameter == NULL && len_real_y != 0) { 02289 SG_SWARNING("Inconsistency between data structure and " 02290 "len_y during saving `%s%s'! Continuing with " 02291 "len_y=0.\n", 02292 prefix, m_name); 02293 len_real_y = 0; 02294 } 02295 02296 switch (m_datatype.m_ctype) { 02297 case CT_NDARRAY: 02298 SG_SNOTIMPLEMENTED; 02299 break; 02300 case CT_VECTOR: case CT_SGVECTOR: 02301 len_real_x = 1; 02302 break; 02303 case CT_MATRIX: case CT_SGMATRIX: 02304 len_real_x = *m_datatype.m_length_x; 02305 if (*(void**) m_parameter == NULL && len_real_x != 0) { 02306 SG_SWARNING("Inconsistency between data structure and " 02307 "len_x during saving `%s%s'! Continuing " 02308 "with len_x=0.\n", 02309 prefix, m_name); 02310 len_real_x = 0; 02311 } 02312 02313 if (len_real_x *len_real_y == 0) 02314 len_real_x = len_real_y = 0; 02315 02316 break; 02317 case CT_SCALAR: break; 02318 } 02319 02320 if (!file->write_cont_begin(&m_datatype, m_name, prefix, 02321 len_real_y, len_real_x)) 02322 return false; 02323 02324 /* ******************************************************** */ 02325 02326 for (index_t x=0; x<len_real_x; x++) 02327 for (index_t y=0; y<len_real_y; y++) { 02328 if (!file->write_item_begin( 02329 &m_datatype, m_name, prefix, y, x)) 02330 return false; 02331 02332 if (!save_stype( 02333 file, (*(char**) m_parameter) 02334 + (x*len_real_y + y)*m_datatype.sizeof_stype(), 02335 prefix)) return false; 02336 if (!file->write_item_end( 02337 &m_datatype, m_name, prefix, y, x)) 02338 return false; 02339 } 02340 02341 /* ******************************************************** */ 02342 02343 if (!file->write_cont_end(&m_datatype, m_name, prefix, 02344 len_real_y, len_real_x)) 02345 return false; 02346 02347 break; 02348 } 02349 02350 if (!file->write_type_end(&m_datatype, m_name, prefix)) 02351 return false; 02352 02353 return true; 02354 } 02355 02356 bool 02357 TParameter::load(CSerializableFile* file, const char* prefix) 02358 { 02359 const int32_t buflen=100; 02360 char* buf=SG_MALLOC(char, buflen); 02361 m_datatype.to_string(buf, buflen); 02362 SG_SDEBUG("Loading parameter '%s' of type '%s'\n", m_name, buf); 02363 SG_FREE(buf); 02364 02365 if (!file->read_type_begin(&m_datatype, m_name, prefix)) 02366 return false; 02367 02368 switch (m_datatype.m_ctype) 02369 { 02370 case CT_NDARRAY: 02371 SG_SNOTIMPLEMENTED; 02372 case CT_SCALAR: 02373 if (!load_stype(file, m_parameter, prefix)) 02374 return false; 02375 break; 02376 02377 case CT_VECTOR: case CT_MATRIX: case CT_SGVECTOR: case CT_SGMATRIX: 02378 index_t len_read_y = 0, len_read_x = 0; 02379 02380 if (!file->read_cont_begin(&m_datatype, m_name, prefix, 02381 &len_read_y, &len_read_x)) 02382 return false; 02383 02384 switch (m_datatype.m_ctype) 02385 { 02386 case CT_NDARRAY: 02387 SG_SNOTIMPLEMENTED; 02388 case CT_VECTOR: case CT_SGVECTOR: 02389 len_read_x = 1; 02390 new_cont(len_read_y, len_read_x); 02391 break; 02392 case CT_MATRIX: case CT_SGMATRIX: 02393 new_cont(len_read_y, len_read_x); 02394 break; 02395 case CT_SCALAR: 02396 break; 02397 } 02398 02399 for (index_t x=0; x<len_read_x; x++) 02400 { 02401 for (index_t y=0; y<len_read_y; y++) 02402 { 02403 if (!file->read_item_begin( 02404 &m_datatype, m_name, prefix, y, x)) 02405 return false; 02406 02407 if (!load_stype( 02408 file, (*(char**) m_parameter) 02409 + (x*len_read_y + y)*m_datatype.sizeof_stype(), 02410 prefix)) return false; 02411 if (!file->read_item_end( 02412 &m_datatype, m_name, prefix, y, x)) 02413 return false; 02414 } 02415 } 02416 02417 switch (m_datatype.m_ctype) 02418 { 02419 case CT_NDARRAY: 02420 SG_SNOTIMPLEMENTED; 02421 case CT_VECTOR: case CT_SGVECTOR: 02422 *m_datatype.m_length_y = len_read_y; 02423 break; 02424 case CT_MATRIX: case CT_SGMATRIX: 02425 *m_datatype.m_length_y = len_read_y; 02426 *m_datatype.m_length_x = len_read_x; 02427 break; 02428 case CT_SCALAR: 02429 break; 02430 } 02431 02432 if (!file->read_cont_end(&m_datatype, m_name, prefix, 02433 len_read_y, len_read_x)) 02434 return false; 02435 02436 break; 02437 } 02438 02439 if (!file->read_type_end(&m_datatype, m_name, prefix)) 02440 return false; 02441 02442 return true; 02443 } 02444 02445 Parameter::Parameter() 02446 { 02447 SG_REF(sg_io); 02448 } 02449 02450 Parameter::~Parameter() 02451 { 02452 for (int32_t i=0; i<get_num_parameters(); i++) 02453 delete m_params.get_element(i); 02454 02455 SG_UNREF(sg_io); 02456 } 02457 02458 void 02459 Parameter::add_type(const TSGDataType* type, void* param, 02460 const char* name, const char* description) 02461 { 02462 if (name == NULL || *name == '\0') 02463 SG_SERROR("FATAL: Parameter::add_type(): `name' is empty!\n"); 02464 02465 for (int32_t i=0; i<get_num_parameters(); i++) 02466 if (strcmp(m_params.get_element(i)->m_name, name) == 0) 02467 SG_SERROR("FATAL: Parameter::add_type(): " 02468 "Double parameter `%s'!\n", name); 02469 02470 m_params.append_element( 02471 new TParameter(type, param, name, description) 02472 ); 02473 } 02474 02475 void 02476 Parameter::print(const char* prefix) 02477 { 02478 for (int32_t i=0; i<get_num_parameters(); i++) 02479 m_params.get_element(i)->print(prefix); 02480 } 02481 02482 bool 02483 Parameter::save(CSerializableFile* file, const char* prefix) 02484 { 02485 for (int32_t i=0; i<get_num_parameters(); i++) 02486 { 02487 if (!m_params.get_element(i)->save(file, prefix)) 02488 return false; 02489 } 02490 02491 return true; 02492 } 02493 02494 //bool 02495 //Parameter::load(CSerializableFile* file, const char* prefix) 02496 //{ 02497 // for (int32_t i=0; i<get_num_parameters(); i++) 02498 // if (!m_params.get_element(i)->load(file, prefix)) 02499 // return false; 02500 // 02501 // return true; 02502 //} 02503 02504 void Parameter::set_from_parameters(Parameter* params) 02505 { 02506 /* iterate over parameters in the given list */ 02507 for (index_t i=0; i<params->get_num_parameters(); ++i) 02508 { 02509 TParameter* current=params->get_parameter(i); 02510 TSGDataType current_type=current->m_datatype; 02511 02512 ASSERT(m_params.get_num_elements()); 02513 02514 /* search for own parameter with same name and check types if found */ 02515 TParameter* own=NULL; 02516 for (index_t j=0; j<m_params.get_num_elements(); ++j) 02517 { 02518 own=m_params.get_element(j); 02519 if (!strcmp(own->m_name, current->m_name)) 02520 { 02521 if (own->m_datatype==current_type) 02522 { 02523 own=m_params.get_element(j); 02524 break; 02525 } 02526 else 02527 { 02528 index_t l=200; 02529 char* given_type=SG_MALLOC(char, l); 02530 char* own_type=SG_MALLOC(char, l); 02531 current->m_datatype.to_string(given_type, l); 02532 own->m_datatype.to_string(own_type, l); 02533 SG_SERROR("given parameter \"%s\" has a different type (%s)" 02534 " than existing one (%s)\n", current->m_name, 02535 given_type, own_type); 02536 SG_FREE(given_type); 02537 SG_FREE(own_type); 02538 } 02539 } 02540 else 02541 own=NULL; 02542 } 02543 02544 if (!own) 02545 { 02546 SG_SERROR("parameter with name %s does not exist\n", 02547 current->m_name); 02548 } 02549 02550 /* check if parameter contained CSGobjects (update reference counts) */ 02551 if (current_type.m_ptype==PT_SGOBJECT) 02552 { 02553 /* PT_SGOBJECT only occurs for ST_NONE */ 02554 if (own->m_datatype.m_stype==ST_NONE) 02555 { 02556 if (own->m_datatype.m_ctype==CT_SCALAR) 02557 { 02558 CSGObject** to_unref=(CSGObject**) own->m_parameter; 02559 CSGObject** to_ref=(CSGObject**) current->m_parameter; 02560 02561 if ((*to_ref)!=(*to_unref)) 02562 { 02563 SG_REF((*to_ref)); 02564 SG_UNREF((*to_unref)); 02565 } 02566 02567 } 02568 else 02569 { 02570 /* unref all SGObjects and reference the new ones */ 02571 CSGObject*** to_unref=(CSGObject***) own->m_parameter; 02572 CSGObject*** to_ref=(CSGObject***) current->m_parameter; 02573 02574 for (index_t j=0; j<own->m_datatype.get_num_elements(); ++j) 02575 { 02576 if ((*to_ref)[j]!=(*to_unref)[j]) 02577 { 02578 SG_REF(((*to_ref)[j])); 02579 SG_UNREF(((*to_unref)[j])); 02580 } 02581 } 02582 } 02583 } 02584 else 02585 SG_SERROR("primitive type PT_SGOBJECT occurred with structure " 02586 "type other than ST_NONE"); 02587 } 02588 02589 /* construct pointers to the to be copied parameter data */ 02590 void* dest=NULL; 02591 void* source=NULL; 02592 if (current_type.m_ctype==CT_SCALAR) 02593 { 02594 /* for scalar values, just copy content the pointer points to */ 02595 dest=own->m_parameter; 02596 source=current->m_parameter; 02597 02598 /* in case of CSGObject, pointers are not equal if CSGObjects are 02599 * equal, so check. For other values, the pointers are equal and 02600 * the not-copying is handled below before the memcpy call */ 02601 if (own->m_datatype.m_ptype==PT_SGOBJECT) 02602 { 02603 if (*((CSGObject**)dest) == *((CSGObject**)source)) 02604 { 02605 dest=NULL; 02606 source=NULL; 02607 } 02608 } 02609 } 02610 else 02611 { 02612 /* for matrices and vectors, sadly m_parameter has to be 02613 * de-referenced once, because a pointer to the array address is 02614 * saved, but the array address itself has to be copied. 02615 * consequently, for dereferencing, a type distinction is needed */ 02616 switch (own->m_datatype.m_ptype) 02617 { 02618 case PT_FLOAT64: 02619 dest=*((float64_t**) own->m_parameter); 02620 source=*((float64_t**) current->m_parameter); 02621 break; 02622 case PT_SGOBJECT: 02623 dest=*((CSGObject**) own->m_parameter); 02624 source=*((CSGObject**) current->m_parameter); 02625 break; 02626 default: 02627 SG_SNOTIMPLEMENTED; 02628 break; 02629 } 02630 } 02631 02632 /* copy parameter data, size in memory is equal because of same type */ 02633 if (dest!=source) 02634 memcpy(dest, source, own->m_datatype.get_size()); 02635 } 02636 } 02637 02638 void Parameter::add_parameters(Parameter* params) 02639 { 02640 for (index_t i=0; i<params->get_num_parameters(); ++i) 02641 { 02642 TParameter* current=params->get_parameter(i); 02643 add_type(&(current->m_datatype), current->m_parameter, current->m_name, 02644 current->m_description); 02645 } 02646 } 02647 02648 bool Parameter::contains_parameter(const char* name) 02649 { 02650 for (index_t i=0; i<m_params.get_num_elements(); ++i) 02651 { 02652 if (!strcmp(name, m_params[i]->m_name)) 02653 return true; 02654 } 02655 02656 return false; 02657 } 02658 02659 bool TParameter::operator==(const TParameter& other) const 02660 { 02661 bool result=true; 02662 result&=!strcmp(m_name, other.m_name); 02663 return result; 02664 } 02665 02666 bool TParameter::operator<(const TParameter& other) const 02667 { 02668 return strcmp(m_name, other.m_name)<0; 02669 } 02670 02671 bool TParameter::operator>(const TParameter& other) const 02672 { 02673 return strcmp(m_name, other.m_name)>0; 02674 } 02675 02676 void TParameter::allocate_data_from_scratch(index_t len_y, index_t len_x, 02677 bool new_cont_call) 02678 { 02679 SG_SDEBUG("entering TParameter::allocate_data_from_scratch(%d,%d) of " 02680 "\"%s\"\n", len_y, len_x, m_name); 02681 02682 /* set flag to delete all this stuff later on */ 02683 m_was_allocated_from_scratch=true; 02684 02685 /* length has to be allocated for matrices/vectors */ 02686 switch (m_datatype.m_ctype) 02687 { 02688 case CT_VECTOR: case CT_SGVECTOR: 02689 m_datatype.m_length_y=SG_MALLOC(index_t, 1); 02690 *m_datatype.m_length_y=len_y; 02691 break; 02692 case CT_MATRIX: case CT_SGMATRIX: 02693 m_datatype.m_length_x=SG_MALLOC(index_t, 1); 02694 m_datatype.m_length_y=SG_MALLOC(index_t, 1); 02695 *m_datatype.m_length_y=len_y; 02696 *m_datatype.m_length_x=len_x; 02697 break; 02698 case CT_SCALAR: 02699 m_datatype.m_length_x=NULL; 02700 m_datatype.m_length_y=NULL; 02701 break; 02702 case CT_NDARRAY: 02703 SG_SNOTIMPLEMENTED; 02704 } 02705 02706 /* check if there is no data loss */ 02707 if (m_parameter) 02708 SG_SERROR("TParameter::allocate_data_from_scratch must not be called " 02709 "when the underlying TParameter instance already has data.\n"); 02710 02711 /* scalars are treated differently than vectors/matrices. memory has to 02712 * be allocated for the data itself */ 02713 if (m_datatype.m_ctype==CT_SCALAR) 02714 { 02715 /* sgobjects are treated differently than the rest */ 02716 if (m_datatype.m_ptype!=PT_SGOBJECT) 02717 { 02718 /* for non-sgobject allocate memory because normally they are on 02719 * stack and excluded in the TParameter data allocation. 02720 * Will be deleted by the TParameter destructor */ 02721 m_parameter=SG_MALLOC(char, m_datatype.get_size()); 02722 } 02723 else 02724 { 02725 /* for sgobjects, allocate memory for pointer and set to NULL 02726 * Will be deleted by the TParameter destructor */ 02727 m_parameter=SG_MALLOC(CSGObject**, 1); 02728 *((CSGObject**)m_parameter)=NULL; 02729 } 02730 } 02731 else 02732 { 02733 /* allocate pointer for data pointer */ 02734 void** data_p=SG_MALLOC(void*, 1); 02735 *data_p=NULL; 02736 02737 /* allocate dummy data at the point the above pointer points to 02738 * will be freed by the delete_cont() method of TParameter. 02739 * This is needed because new_cont/delete_cont cannot handle 02740 * non-existing data. Set to NULL to avoid problems */ 02741 if (new_cont_call) 02742 { 02743 *data_p=SG_MALLOC(void**, 1); 02744 **(void***)data_p=NULL; 02745 } 02746 02747 m_parameter=data_p; 02748 02749 /* perform one data allocation. This may be repeated and therefore 02750 * redundant if load() is called afterwards, however, if one wants 02751 * to write directly to the array data after this call, it is 02752 * necessary */ 02753 if (new_cont_call) 02754 new_cont(len_y, len_x); 02755 } 02756 02757 SG_SDEBUG("leaving TParameter::allocate_data_from_scratch(%d,%d) of " 02758 "\"%s\"\n", len_y, len_x, m_name); 02759 } 02760 02761 void TParameter::copy_data(const TParameter* source) 02762 { 02763 SG_SDEBUG("entering TParameter::copy_data for %s\n", m_name); 02764 02765 /* assert that type is equal */ 02766 ASSERT(m_datatype.m_ctype==source->m_datatype.m_ctype); 02767 ASSERT(m_datatype.m_stype==source->m_datatype.m_stype); 02768 ASSERT(m_datatype.m_ptype==source->m_datatype.m_ptype); 02769 02770 /* first delete old data if non-scalar */ 02771 if (m_datatype.m_ctype!=CT_SCALAR) 02772 delete_cont(); 02773 02774 /* then copy data in case of numeric scalars, or pointer to data else */ 02775 if (m_datatype.m_ctype==CT_SCALAR && m_datatype.m_ptype!=PT_SGOBJECT) 02776 { 02777 /* just copy value behind pointer */ 02778 SG_SDEBUG("Copying scalar data of size %d from %p to %p\n", 02779 m_datatype.get_size(), source->m_parameter, m_parameter); 02780 memcpy(m_parameter, source->m_parameter, 02781 m_datatype.get_size()); 02782 } 02783 else 02784 { 02785 /* if this is a sgobject, the old one has to be unrefed */ 02786 if (m_datatype.m_ptype==PT_SGOBJECT) 02787 { 02788 if (m_datatype.m_ctype==CT_SCALAR) 02789 { 02790 SG_UNREF(*((CSGObject**)m_parameter)); 02791 } 02792 else 02793 { 02794 int32_t length=1; 02795 length*=m_datatype.m_length_x ? *m_datatype.m_length_x : 1; 02796 length*=m_datatype.m_length_y ? *m_datatype.m_length_y : 1; 02797 02798 for (index_t j=0; j<length; ++j) 02799 { 02800 SG_UNREF(((CSGObject**)(m_parameter))[j]); 02801 } 02802 } 02803 } 02804 02805 /* in this case, data is a pointer pointing to the actual 02806 * data, so copy pointer if non-NULL*/ 02807 SG_SDEBUG("Copying non-scalar pointer %p\n", *((void**)source->m_parameter)); 02808 *((void**)m_parameter)=*((void**)source->m_parameter); 02809 } 02810 02811 /* copy lengths */ 02812 if (source->m_datatype.m_length_x) 02813 *m_datatype.m_length_x=*source->m_datatype.m_length_x; 02814 02815 if (source->m_datatype.m_length_y) 02816 *m_datatype.m_length_y=*source->m_datatype.m_length_y; 02817 02818 SG_SDEBUG("leaving TParameter::copy_data for %s\n", m_name); 02819 }