00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "base/Parameter.h"
00012 #include "base/class_list.h"
00013
00014 using namespace shogun;
00015
00016 extern IO* sg_io;
00017
00018
00019
00020
00021 void
00022 Parameter::add(bool* param, const char* name,
00023 const char* description) {
00024 TSGDataType type(CT_SCALAR, ST_NONE, PT_BOOL);
00025 add_type(&type, param, name, description);
00026 }
00027
00028 void
00029 Parameter::add(char* param, const char* name,
00030 const char* description) {
00031 TSGDataType type(CT_SCALAR, ST_NONE, PT_CHAR);
00032 add_type(&type, param, name, description);
00033 }
00034
00035 void
00036 Parameter::add(int8_t* param, const char* name,
00037 const char* description) {
00038 TSGDataType type(CT_SCALAR, ST_NONE, PT_INT8);
00039 add_type(&type, param, name, description);
00040 }
00041
00042 void
00043 Parameter::add(uint8_t* param, const char* name,
00044 const char* description) {
00045 TSGDataType type(CT_SCALAR, ST_NONE, PT_UINT8);
00046 add_type(&type, param, name, description);
00047 }
00048
00049 void
00050 Parameter::add(int16_t* param, const char* name,
00051 const char* description) {
00052 TSGDataType type(CT_SCALAR, ST_NONE, PT_INT16);
00053 add_type(&type, param, name, description);
00054 }
00055
00056 void
00057 Parameter::add(uint16_t* param, const char* name,
00058 const char* description) {
00059 TSGDataType type(CT_SCALAR, ST_NONE, PT_UINT16);
00060 add_type(&type, param, name, description);
00061 }
00062
00063 void
00064 Parameter::add(int32_t* param, const char* name,
00065 const char* description) {
00066 TSGDataType type(CT_SCALAR, ST_NONE, PT_INT32);
00067 add_type(&type, param, name, description);
00068 }
00069
00070 void
00071 Parameter::add(uint32_t* param, const char* name,
00072 const char* description) {
00073 TSGDataType type(CT_SCALAR, ST_NONE, PT_UINT32);
00074 add_type(&type, param, name, description);
00075 }
00076
00077 void
00078 Parameter::add(int64_t* param, const char* name,
00079 const char* description) {
00080 TSGDataType type(CT_SCALAR, ST_NONE, PT_INT64);
00081 add_type(&type, param, name, description);
00082 }
00083
00084 void
00085 Parameter::add(uint64_t* param, const char* name,
00086 const char* description) {
00087 TSGDataType type(CT_SCALAR, ST_NONE, PT_UINT64);
00088 add_type(&type, param, name, description);
00089 }
00090
00091 void
00092 Parameter::add(float32_t* param, const char* name,
00093 const char* description) {
00094 TSGDataType type(CT_SCALAR, ST_NONE, PT_FLOAT32);
00095 add_type(&type, param, name, description);
00096 }
00097
00098 void
00099 Parameter::add(float64_t* param, const char* name,
00100 const char* description) {
00101 TSGDataType type(CT_SCALAR, ST_NONE, PT_FLOAT64);
00102 add_type(&type, param, name, description);
00103 }
00104
00105 void
00106 Parameter::add(floatmax_t* param, const char* name,
00107 const char* description) {
00108 TSGDataType type(CT_SCALAR, ST_NONE, PT_FLOATMAX);
00109 add_type(&type, param, name, description);
00110 }
00111
00112 void
00113 Parameter::add(CSGObject** param,
00114 const char* name, const char* description) {
00115 TSGDataType type(CT_SCALAR, ST_NONE, PT_SGOBJECT);
00116 add_type(&type, param, name, description);
00117 }
00118
00119 void
00120 Parameter::add(TString<bool>* param, const char* name,
00121 const char* description) {
00122 TSGDataType type(CT_SCALAR, ST_STRING, PT_BOOL);
00123 add_type(&type, param, name, description);
00124 }
00125
00126 void
00127 Parameter::add(TString<char>* param, const char* name,
00128 const char* description) {
00129 TSGDataType type(CT_SCALAR, ST_STRING, PT_CHAR);
00130 add_type(&type, param, name, description);
00131 }
00132
00133 void
00134 Parameter::add(TString<int8_t>* param, const char* name,
00135 const char* description) {
00136 TSGDataType type(CT_SCALAR, ST_STRING, PT_INT8);
00137 add_type(&type, param, name, description);
00138 }
00139
00140 void
00141 Parameter::add(TString<uint8_t>* param, const char* name,
00142 const char* description) {
00143 TSGDataType type(CT_SCALAR, ST_STRING, PT_UINT8);
00144 add_type(&type, param, name, description);
00145 }
00146
00147 void
00148 Parameter::add(TString<int16_t>* param, const char* name,
00149 const char* description) {
00150 TSGDataType type(CT_SCALAR, ST_STRING, PT_INT16);
00151 add_type(&type, param, name, description);
00152 }
00153
00154 void
00155 Parameter::add(TString<uint16_t>* param, const char* name,
00156 const char* description) {
00157 TSGDataType type(CT_SCALAR, ST_STRING, PT_UINT16);
00158 add_type(&type, param, name, description);
00159 }
00160
00161 void
00162 Parameter::add(TString<int32_t>* param, const char* name,
00163 const char* description) {
00164 TSGDataType type(CT_SCALAR, ST_STRING, PT_INT32);
00165 add_type(&type, param, name, description);
00166 }
00167
00168 void
00169 Parameter::add(TString<uint32_t>* param, const char* name,
00170 const char* description) {
00171 TSGDataType type(CT_SCALAR, ST_STRING, PT_UINT32);
00172 add_type(&type, param, name, description);
00173 }
00174
00175 void
00176 Parameter::add(TString<int64_t>* param, const char* name,
00177 const char* description) {
00178 TSGDataType type(CT_SCALAR, ST_STRING, PT_INT64);
00179 add_type(&type, param, name, description);
00180 }
00181
00182 void
00183 Parameter::add(TString<uint64_t>* param, const char* name,
00184 const char* description) {
00185 TSGDataType type(CT_SCALAR, ST_STRING, PT_UINT64);
00186 add_type(&type, param, name, description);
00187 }
00188
00189 void
00190 Parameter::add(TString<float32_t>* param, const char* name,
00191 const char* description) {
00192 TSGDataType type(CT_SCALAR, ST_STRING, PT_FLOAT32);
00193 add_type(&type, param, name, description);
00194 }
00195
00196 void
00197 Parameter::add(TString<float64_t>* param, const char* name,
00198 const char* description) {
00199 TSGDataType type(CT_SCALAR, ST_STRING, PT_FLOAT64);
00200 add_type(&type, param, name, description);
00201 }
00202
00203 void
00204 Parameter::add(TString<floatmax_t>* param, const char* name,
00205 const char* description) {
00206 TSGDataType type(CT_SCALAR, ST_STRING, PT_FLOATMAX);
00207 add_type(&type, param, name, description);
00208 }
00209
00210 void
00211 Parameter::add(TSparse<bool>* param, const char* name,
00212 const char* description) {
00213 TSGDataType type(CT_SCALAR, ST_SPARSE, PT_BOOL);
00214 add_type(&type, param, name, description);
00215 }
00216
00217 void
00218 Parameter::add(TSparse<char>* param, const char* name,
00219 const char* description) {
00220 TSGDataType type(CT_SCALAR, ST_SPARSE, PT_CHAR);
00221 add_type(&type, param, name, description);
00222 }
00223
00224 void
00225 Parameter::add(TSparse<int8_t>* param, const char* name,
00226 const char* description) {
00227 TSGDataType type(CT_SCALAR, ST_SPARSE, PT_INT8);
00228 add_type(&type, param, name, description);
00229 }
00230
00231 void
00232 Parameter::add(TSparse<uint8_t>* param, const char* name,
00233 const char* description) {
00234 TSGDataType type(CT_SCALAR, ST_SPARSE, PT_UINT8);
00235 add_type(&type, param, name, description);
00236 }
00237
00238 void
00239 Parameter::add(TSparse<int16_t>* param, const char* name,
00240 const char* description) {
00241 TSGDataType type(CT_SCALAR, ST_SPARSE, PT_INT16);
00242 add_type(&type, param, name, description);
00243 }
00244
00245 void
00246 Parameter::add(TSparse<uint16_t>* param, const char* name,
00247 const char* description) {
00248 TSGDataType type(CT_SCALAR, ST_SPARSE, PT_UINT16);
00249 add_type(&type, param, name, description);
00250 }
00251
00252 void
00253 Parameter::add(TSparse<int32_t>* param, const char* name,
00254 const char* description) {
00255 TSGDataType type(CT_SCALAR, ST_SPARSE, PT_INT32);
00256 add_type(&type, param, name, description);
00257 }
00258
00259 void
00260 Parameter::add(TSparse<uint32_t>* param, const char* name,
00261 const char* description) {
00262 TSGDataType type(CT_SCALAR, ST_SPARSE, PT_UINT32);
00263 add_type(&type, param, name, description);
00264 }
00265
00266 void
00267 Parameter::add(TSparse<int64_t>* param, const char* name,
00268 const char* description) {
00269 TSGDataType type(CT_SCALAR, ST_SPARSE, PT_INT64);
00270 add_type(&type, param, name, description);
00271 }
00272
00273 void
00274 Parameter::add(TSparse<uint64_t>* param, const char* name,
00275 const char* description) {
00276 TSGDataType type(CT_SCALAR, ST_SPARSE, PT_UINT64);
00277 add_type(&type, param, name, description);
00278 }
00279
00280 void
00281 Parameter::add(TSparse<float32_t>* param, const char* name,
00282 const char* description) {
00283 TSGDataType type(CT_SCALAR, ST_SPARSE, PT_FLOAT32);
00284 add_type(&type, param, name, description);
00285 }
00286
00287 void
00288 Parameter::add(TSparse<float64_t>* param, const char* name,
00289 const char* description) {
00290 TSGDataType type(CT_SCALAR, ST_SPARSE, PT_FLOAT64);
00291 add_type(&type, param, name, description);
00292 }
00293
00294 void
00295 Parameter::add(TSparse<floatmax_t>* param, const char* name,
00296 const char* description) {
00297 TSGDataType type(CT_SCALAR, ST_SPARSE, PT_FLOATMAX);
00298 add_type(&type, param, name, description);
00299 }
00300
00301
00302
00303
00304 void
00305 Parameter::add_vector(
00306 bool** param, index_t* length, const char* name,
00307 const char* description) {
00308 TSGDataType type(CT_VECTOR, ST_NONE, PT_BOOL, length);
00309 add_type(&type, param, name, description);
00310 }
00311
00312 void
00313 Parameter::add_vector(
00314 char** param, index_t* length, const char* name,
00315 const char* description) {
00316 TSGDataType type(CT_VECTOR, ST_NONE, PT_CHAR, length);
00317 add_type(&type, param, name, description);
00318 }
00319
00320 void
00321 Parameter::add_vector(
00322 int8_t** param, index_t* length, const char* name,
00323 const char* description) {
00324 TSGDataType type(CT_VECTOR, ST_NONE, PT_INT8, length);
00325 add_type(&type, param, name, description);
00326 }
00327
00328 void
00329 Parameter::add_vector(
00330 uint8_t** param, index_t* length, const char* name,
00331 const char* description) {
00332 TSGDataType type(CT_VECTOR, ST_NONE, PT_UINT8, length);
00333 add_type(&type, param, name, description);
00334 }
00335
00336 void
00337 Parameter::add_vector(
00338 int16_t** param, index_t* length, const char* name,
00339 const char* description) {
00340 TSGDataType type(CT_VECTOR, ST_NONE, PT_INT16, length);
00341 add_type(&type, param, name, description);
00342 }
00343
00344 void
00345 Parameter::add_vector(
00346 uint16_t** param, index_t* length, const char* name,
00347 const char* description) {
00348 TSGDataType type(CT_VECTOR, ST_NONE, PT_UINT16, length);
00349 add_type(&type, param, name, description);
00350 }
00351
00352 void
00353 Parameter::add_vector(
00354 int32_t** param, index_t* length, const char* name,
00355 const char* description) {
00356 TSGDataType type(CT_VECTOR, ST_NONE, PT_INT32, length);
00357 add_type(&type, param, name, description);
00358 }
00359
00360 void
00361 Parameter::add_vector(
00362 uint32_t** param, index_t* length, const char* name,
00363 const char* description) {
00364 TSGDataType type(CT_VECTOR, ST_NONE, PT_UINT32, length);
00365 add_type(&type, param, name, description);
00366 }
00367
00368 void
00369 Parameter::add_vector(
00370 int64_t** param, index_t* length, const char* name,
00371 const char* description) {
00372 TSGDataType type(CT_VECTOR, ST_NONE, PT_INT64, length);
00373 add_type(&type, param, name, description);
00374 }
00375
00376 void
00377 Parameter::add_vector(
00378 uint64_t** param, index_t* length, const char* name,
00379 const char* description) {
00380 TSGDataType type(CT_VECTOR, ST_NONE, PT_UINT64, length);
00381 add_type(&type, param, name, description);
00382 }
00383
00384 void
00385 Parameter::add_vector(
00386 float32_t** param, index_t* length, const char* name,
00387 const char* description) {
00388 TSGDataType type(CT_VECTOR, ST_NONE, PT_FLOAT32, length);
00389 add_type(&type, param, name, description);
00390 }
00391
00392 void
00393 Parameter::add_vector(
00394 float64_t** param, index_t* length, const char* name,
00395 const char* description) {
00396 TSGDataType type(CT_VECTOR, ST_NONE, PT_FLOAT64, length);
00397 add_type(&type, param, name, description);
00398 }
00399
00400 void
00401 Parameter::add_vector(
00402 floatmax_t** param, index_t* length, const char* name,
00403 const char* description) {
00404 TSGDataType type(CT_VECTOR, ST_NONE, PT_FLOATMAX, length);
00405 add_type(&type, param, name, description);
00406 }
00407
00408 void
00409 Parameter::add_vector(CSGObject*** param, index_t* length,
00410 const char* name, const char* description) {
00411 TSGDataType type(CT_VECTOR, ST_NONE, PT_SGOBJECT,
00412 length);
00413 add_type(&type, param, name, description);
00414 }
00415
00416 void
00417 Parameter::add_vector(TString<bool>** param, index_t* length,
00418 const char* name, const char* description) {
00419 TSGDataType type(CT_VECTOR, ST_STRING, PT_BOOL, length);
00420 add_type(&type, param, name, description);
00421 }
00422
00423 void
00424 Parameter::add_vector(TString<char>** param, index_t* length,
00425 const char* name, const char* description) {
00426 TSGDataType type(CT_VECTOR, ST_STRING, PT_CHAR, length);
00427 add_type(&type, param, name, description);
00428 }
00429
00430 void
00431 Parameter::add_vector(TString<int8_t>** param, index_t* length,
00432 const char* name, const char* description) {
00433 TSGDataType type(CT_VECTOR, ST_STRING, PT_INT8, length);
00434 add_type(&type, param, name, description);
00435 }
00436
00437 void
00438 Parameter::add_vector(TString<uint8_t>** param, index_t* length,
00439 const char* name, const char* description) {
00440 TSGDataType type(CT_VECTOR, ST_STRING, PT_UINT8, length);
00441 add_type(&type, param, name, description);
00442 }
00443
00444 void
00445 Parameter::add_vector(TString<int16_t>** param, index_t* length,
00446 const char* name, const char* description) {
00447 TSGDataType type(CT_VECTOR, ST_STRING, PT_INT16, length);
00448 add_type(&type, param, name, description);
00449 }
00450
00451 void
00452 Parameter::add_vector(TString<uint16_t>** param, index_t* length,
00453 const char* name, const char* description) {
00454 TSGDataType type(CT_VECTOR, ST_STRING, PT_UINT16, length);
00455 add_type(&type, param, name, description);
00456 }
00457
00458 void
00459 Parameter::add_vector(TString<int32_t>** param, index_t* length,
00460 const char* name, const char* description) {
00461 TSGDataType type(CT_VECTOR, ST_STRING, PT_INT32, length);
00462 add_type(&type, param, name, description);
00463 }
00464
00465 void
00466 Parameter::add_vector(TString<uint32_t>** param, index_t* length,
00467 const char* name, const char* description) {
00468 TSGDataType type(CT_VECTOR, ST_STRING, PT_UINT32, length);
00469 add_type(&type, param, name, description);
00470 }
00471
00472 void
00473 Parameter::add_vector(TString<int64_t>** param, index_t* length,
00474 const char* name, const char* description) {
00475 TSGDataType type(CT_VECTOR, ST_STRING, PT_INT64, length);
00476 add_type(&type, param, name, description);
00477 }
00478
00479 void
00480 Parameter::add_vector(TString<uint64_t>** param, index_t* length,
00481 const char* name, const char* description) {
00482 TSGDataType type(CT_VECTOR, ST_STRING, PT_UINT64, length);
00483 add_type(&type, param, name, description);
00484 }
00485
00486 void
00487 Parameter::add_vector(TString<float32_t>** param, index_t* length,
00488 const char* name, const char* description) {
00489 TSGDataType type(CT_VECTOR, ST_STRING, PT_FLOAT32, length);
00490 add_type(&type, param, name, description);
00491 }
00492
00493 void
00494 Parameter::add_vector(TString<float64_t>** param, index_t* length,
00495 const char* name, const char* description) {
00496 TSGDataType type(CT_VECTOR, ST_STRING, PT_FLOAT64, length);
00497 add_type(&type, param, name, description);
00498 }
00499
00500 void
00501 Parameter::add_vector(TString<floatmax_t>** param, index_t* length,
00502 const char* name, const char* description) {
00503 TSGDataType type(CT_VECTOR, ST_STRING, PT_FLOATMAX, length);
00504 add_type(&type, param, name, description);
00505 }
00506
00507 void
00508 Parameter::add_vector(TSparse<bool>** param, index_t* length,
00509 const char* name, const char* description) {
00510 TSGDataType type(CT_VECTOR, ST_SPARSE, PT_BOOL, length);
00511 add_type(&type, param, name, description);
00512 }
00513
00514 void
00515 Parameter::add_vector(TSparse<char>** param, index_t* length,
00516 const char* name, const char* description) {
00517 TSGDataType type(CT_VECTOR, ST_SPARSE, PT_CHAR, length);
00518 add_type(&type, param, name, description);
00519 }
00520
00521 void
00522 Parameter::add_vector(TSparse<int8_t>** param, index_t* length,
00523 const char* name, const char* description) {
00524 TSGDataType type(CT_VECTOR, ST_SPARSE, PT_INT8, length);
00525 add_type(&type, param, name, description);
00526 }
00527
00528 void
00529 Parameter::add_vector(TSparse<uint8_t>** param, index_t* length,
00530 const char* name, const char* description) {
00531 TSGDataType type(CT_VECTOR, ST_SPARSE, PT_UINT8, length);
00532 add_type(&type, param, name, description);
00533 }
00534
00535 void
00536 Parameter::add_vector(TSparse<int16_t>** param, index_t* length,
00537 const char* name, const char* description) {
00538 TSGDataType type(CT_VECTOR, ST_SPARSE, PT_INT16, length);
00539 add_type(&type, param, name, description);
00540 }
00541
00542 void
00543 Parameter::add_vector(TSparse<uint16_t>** param, index_t* length,
00544 const char* name, const char* description) {
00545 TSGDataType type(CT_VECTOR, ST_SPARSE, PT_UINT16, length);
00546 add_type(&type, param, name, description);
00547 }
00548
00549 void
00550 Parameter::add_vector(TSparse<int32_t>** param, index_t* length,
00551 const char* name, const char* description) {
00552 TSGDataType type(CT_VECTOR, ST_SPARSE, PT_INT32, length);
00553 add_type(&type, param, name, description);
00554 }
00555
00556 void
00557 Parameter::add_vector(TSparse<uint32_t>** param, index_t* length,
00558 const char* name, const char* description) {
00559 TSGDataType type(CT_VECTOR, ST_SPARSE, PT_UINT32, length);
00560 add_type(&type, param, name, description);
00561 }
00562
00563 void
00564 Parameter::add_vector(TSparse<int64_t>** param, index_t* length,
00565 const char* name, const char* description) {
00566 TSGDataType type(CT_VECTOR, ST_SPARSE, PT_INT64, length);
00567 add_type(&type, param, name, description);
00568 }
00569
00570 void
00571 Parameter::add_vector(TSparse<uint64_t>** param, index_t* length,
00572 const char* name, const char* description) {
00573 TSGDataType type(CT_VECTOR, ST_SPARSE, PT_UINT64, length);
00574 add_type(&type, param, name, description);
00575 }
00576
00577 void
00578 Parameter::add_vector(TSparse<float32_t>** param, index_t* length,
00579 const char* name, const char* description) {
00580 TSGDataType type(CT_VECTOR, ST_SPARSE, PT_FLOAT32, length);
00581 add_type(&type, param, name, description);
00582 }
00583
00584 void
00585 Parameter::add_vector(TSparse<float64_t>** param, index_t* length,
00586 const char* name, const char* description) {
00587 TSGDataType type(CT_VECTOR, ST_SPARSE, PT_FLOAT64, length);
00588 add_type(&type, param, name, description);
00589 }
00590
00591 void
00592 Parameter::add_vector(TSparse<floatmax_t>** param, index_t* length,
00593 const char* name, const char* description) {
00594 TSGDataType type(CT_VECTOR, ST_SPARSE, PT_FLOATMAX, length);
00595 add_type(&type, param, name, description);
00596 }
00597
00598
00599
00600
00601 void
00602 Parameter::add_matrix(
00603 bool** param, index_t* length_y, index_t* length_x,
00604 const char* name, const char* description) {
00605 TSGDataType type(CT_MATRIX, ST_NONE, PT_BOOL, length_y,
00606 length_x);
00607 add_type(&type, param, name, description);
00608 }
00609
00610 void
00611 Parameter::add_matrix(
00612 char** param, index_t* length_y, index_t* length_x,
00613 const char* name, const char* description) {
00614 TSGDataType type(CT_MATRIX, ST_NONE, PT_CHAR, length_y,
00615 length_x);
00616 add_type(&type, param, name, description);
00617 }
00618
00619 void
00620 Parameter::add_matrix(
00621 int8_t** param, index_t* length_y, index_t* length_x,
00622 const char* name, const char* description) {
00623 TSGDataType type(CT_MATRIX, ST_NONE, PT_INT8, length_y,
00624 length_x);
00625 add_type(&type, param, name, description);
00626 }
00627
00628 void
00629 Parameter::add_matrix(
00630 uint8_t** param, index_t* length_y, index_t* length_x,
00631 const char* name, const char* description) {
00632 TSGDataType type(CT_MATRIX, ST_NONE, PT_UINT8, length_y,
00633 length_x);
00634 add_type(&type, param, name, description);
00635 }
00636
00637 void
00638 Parameter::add_matrix(
00639 int16_t** param, index_t* length_y, index_t* length_x,
00640 const char* name, const char* description) {
00641 TSGDataType type(CT_MATRIX, ST_NONE, PT_INT16, length_y,
00642 length_x);
00643 add_type(&type, param, name, description);
00644 }
00645
00646 void
00647 Parameter::add_matrix(
00648 uint16_t** param, index_t* length_y, index_t* length_x,
00649 const char* name, const char* description) {
00650 TSGDataType type(CT_MATRIX, ST_NONE, PT_UINT16, length_y,
00651 length_x);
00652 add_type(&type, param, name, description);
00653 }
00654
00655 void
00656 Parameter::add_matrix(
00657 int32_t** param, index_t* length_y, index_t* length_x,
00658 const char* name, const char* description) {
00659 TSGDataType type(CT_MATRIX, ST_NONE, PT_INT32, length_y,
00660 length_x);
00661 add_type(&type, param, name, description);
00662 }
00663
00664 void
00665 Parameter::add_matrix(
00666 uint32_t** param, index_t* length_y, index_t* length_x,
00667 const char* name, const char* description) {
00668 TSGDataType type(CT_MATRIX, ST_NONE, PT_UINT32, length_y,
00669 length_x);
00670 add_type(&type, param, name, description);
00671 }
00672
00673 void
00674 Parameter::add_matrix(
00675 int64_t** param, index_t* length_y, index_t* length_x,
00676 const char* name, const char* description) {
00677 TSGDataType type(CT_MATRIX, ST_NONE, PT_INT64, length_y,
00678 length_x);
00679 add_type(&type, param, name, description);
00680 }
00681
00682 void
00683 Parameter::add_matrix(
00684 uint64_t** param, index_t* length_y, index_t* length_x,
00685 const char* name, const char* description) {
00686 TSGDataType type(CT_MATRIX, ST_NONE, PT_UINT64, length_y,
00687 length_x);
00688 add_type(&type, param, name, description);
00689 }
00690
00691 void
00692 Parameter::add_matrix(
00693 float32_t** param, index_t* length_y, index_t* length_x,
00694 const char* name, const char* description) {
00695 TSGDataType type(CT_MATRIX, ST_NONE, PT_FLOAT32, length_y,
00696 length_x);
00697 add_type(&type, param, name, description);
00698 }
00699
00700 void
00701 Parameter::add_matrix(
00702 float64_t** param, index_t* length_y, index_t* length_x,
00703 const char* name, const char* description) {
00704 TSGDataType type(CT_MATRIX, ST_NONE, PT_FLOAT64, length_y,
00705 length_x);
00706 add_type(&type, param, name, description);
00707 }
00708
00709 void
00710 Parameter::add_matrix(
00711 floatmax_t** param, index_t* length_y, index_t* length_x,
00712 const char* name, const char* description) {
00713 TSGDataType type(CT_MATRIX, ST_NONE, PT_FLOATMAX, length_y,
00714 length_x);
00715 add_type(&type, param, name, description);
00716 }
00717
00718 void
00719 Parameter::add_matrix(
00720 CSGObject*** param, index_t* length_y, index_t* length_x,
00721 const char* name, const char* description) {
00722 TSGDataType type(CT_MATRIX, ST_NONE, PT_SGOBJECT,
00723 length_y, length_x);
00724 add_type(&type, param, name, description);
00725 }
00726
00727 void
00728 Parameter::add_matrix(TString<bool>** param,
00729 index_t* length_y, index_t* length_x,
00730 const char* name, const char* description) {
00731 TSGDataType type(CT_MATRIX, ST_STRING, PT_BOOL, length_y,
00732 length_x);
00733 add_type(&type, param, name, description);
00734 }
00735
00736 void
00737 Parameter::add_matrix(TString<char>** param,
00738 index_t* length_y, index_t* length_x,
00739 const char* name, const char* description) {
00740 TSGDataType type(CT_MATRIX, ST_STRING, PT_CHAR, length_y,
00741 length_x);
00742 add_type(&type, param, name, description);
00743 }
00744
00745 void
00746 Parameter::add_matrix(TString<int8_t>** param,
00747 index_t* length_y, index_t* length_x,
00748 const char* name, const char* description) {
00749 TSGDataType type(CT_MATRIX, ST_STRING, PT_INT8, length_y,
00750 length_x);
00751 add_type(&type, param, name, description);
00752 }
00753
00754 void
00755 Parameter::add_matrix(TString<uint8_t>** param,
00756 index_t* length_y, index_t* length_x,
00757 const char* name, const char* description) {
00758 TSGDataType type(CT_MATRIX, ST_STRING, PT_UINT8, length_y,
00759 length_x);
00760 add_type(&type, param, name, description);
00761 }
00762
00763 void
00764 Parameter::add_matrix(TString<int16_t>** param,
00765 index_t* length_y, index_t* length_x,
00766 const char* name, const char* description) {
00767 TSGDataType type(CT_MATRIX, ST_STRING, PT_INT16, length_y,
00768 length_x);
00769 add_type(&type, param, name, description);
00770 }
00771
00772 void
00773 Parameter::add_matrix(TString<uint16_t>** param,
00774 index_t* length_y, index_t* length_x,
00775 const char* name, const char* description) {
00776 TSGDataType type(CT_MATRIX, ST_STRING, PT_UINT16, length_y,
00777 length_x);
00778 add_type(&type, param, name, description);
00779 }
00780
00781 void
00782 Parameter::add_matrix(TString<int32_t>** param,
00783 index_t* length_y, index_t* length_x,
00784 const char* name, const char* description) {
00785 TSGDataType type(CT_MATRIX, ST_STRING, PT_INT32, length_y,
00786 length_x);
00787 add_type(&type, param, name, description);
00788 }
00789
00790 void
00791 Parameter::add_matrix(TString<uint32_t>** param,
00792 index_t* length_y, index_t* length_x,
00793 const char* name, const char* description) {
00794 TSGDataType type(CT_MATRIX, ST_STRING, PT_UINT32, length_y,
00795 length_x);
00796 add_type(&type, param, name, description);
00797 }
00798
00799 void
00800 Parameter::add_matrix(TString<int64_t>** param,
00801 index_t* length_y, index_t* length_x,
00802 const char* name, const char* description) {
00803 TSGDataType type(CT_MATRIX, ST_STRING, PT_INT64, length_y,
00804 length_x);
00805 add_type(&type, param, name, description);
00806 }
00807
00808 void
00809 Parameter::add_matrix(TString<uint64_t>** param,
00810 index_t* length_y, index_t* length_x,
00811 const char* name, const char* description) {
00812 TSGDataType type(CT_MATRIX, ST_STRING, PT_UINT64, length_y,
00813 length_x);
00814 add_type(&type, param, name, description);
00815 }
00816
00817 void
00818 Parameter::add_matrix(TString<float32_t>** param,
00819 index_t* length_y, index_t* length_x,
00820 const char* name, const char* description) {
00821 TSGDataType type(CT_MATRIX, ST_STRING, PT_FLOAT32, length_y,
00822 length_x);
00823 add_type(&type, param, name, description);
00824 }
00825
00826 void
00827 Parameter::add_matrix(TString<float64_t>** param,
00828 index_t* length_y, index_t* length_x,
00829 const char* name, const char* description) {
00830 TSGDataType type(CT_MATRIX, ST_STRING, PT_FLOAT64, length_y,
00831 length_x);
00832 add_type(&type, param, name, description);
00833 }
00834
00835 void
00836 Parameter::add_matrix(TString<floatmax_t>** param,
00837 index_t* length_y, index_t* length_x,
00838 const char* name, const char* description) {
00839 TSGDataType type(CT_MATRIX, ST_STRING, PT_FLOATMAX, length_y,
00840 length_x);
00841 add_type(&type, param, name, description);
00842 }
00843
00844 void
00845 Parameter::add_matrix(TSparse<bool>** param,
00846 index_t* length_y, index_t* length_x,
00847 const char* name, const char* description) {
00848 TSGDataType type(CT_MATRIX, ST_SPARSE, PT_BOOL, length_y,
00849 length_x);
00850 add_type(&type, param, name, description);
00851 }
00852
00853 void
00854 Parameter::add_matrix(TSparse<char>** param,
00855 index_t* length_y, index_t* length_x,
00856 const char* name, const char* description) {
00857 TSGDataType type(CT_MATRIX, ST_SPARSE, PT_CHAR, length_y,
00858 length_x);
00859 add_type(&type, param, name, description);
00860 }
00861
00862 void
00863 Parameter::add_matrix(TSparse<int8_t>** param,
00864 index_t* length_y, index_t* length_x,
00865 const char* name, const char* description) {
00866 TSGDataType type(CT_MATRIX, ST_SPARSE, PT_INT8, length_y,
00867 length_x);
00868 add_type(&type, param, name, description);
00869 }
00870
00871 void
00872 Parameter::add_matrix(TSparse<uint8_t>** param,
00873 index_t* length_y, index_t* length_x,
00874 const char* name, const char* description) {
00875 TSGDataType type(CT_MATRIX, ST_SPARSE, PT_UINT8, length_y,
00876 length_x);
00877 add_type(&type, param, name, description);
00878 }
00879
00880 void
00881 Parameter::add_matrix(TSparse<int16_t>** param,
00882 index_t* length_y, index_t* length_x,
00883 const char* name, const char* description) {
00884 TSGDataType type(CT_MATRIX, ST_SPARSE, PT_INT16, length_y,
00885 length_x);
00886 add_type(&type, param, name, description);
00887 }
00888
00889 void
00890 Parameter::add_matrix(TSparse<uint16_t>** param,
00891 index_t* length_y, index_t* length_x,
00892 const char* name, const char* description) {
00893 TSGDataType type(CT_MATRIX, ST_SPARSE, PT_UINT16, length_y,
00894 length_x);
00895 add_type(&type, param, name, description);
00896 }
00897
00898 void
00899 Parameter::add_matrix(TSparse<int32_t>** param,
00900 index_t* length_y, index_t* length_x,
00901 const char* name, const char* description) {
00902 TSGDataType type(CT_MATRIX, ST_SPARSE, PT_INT32, length_y,
00903 length_x);
00904 add_type(&type, param, name, description);
00905 }
00906
00907 void
00908 Parameter::add_matrix(TSparse<uint32_t>** param,
00909 index_t* length_y, index_t* length_x,
00910 const char* name, const char* description) {
00911 TSGDataType type(CT_MATRIX, ST_SPARSE, PT_UINT32, length_y,
00912 length_x);
00913 add_type(&type, param, name, description);
00914 }
00915
00916 void
00917 Parameter::add_matrix(TSparse<int64_t>** param,
00918 index_t* length_y, index_t* length_x,
00919 const char* name, const char* description) {
00920 TSGDataType type(CT_MATRIX, ST_SPARSE, PT_INT64, length_y,
00921 length_x);
00922 add_type(&type, param, name, description);
00923 }
00924
00925 void
00926 Parameter::add_matrix(TSparse<uint64_t>** param,
00927 index_t* length_y, index_t* length_x,
00928 const char* name, const char* description) {
00929 TSGDataType type(CT_MATRIX, ST_SPARSE, PT_UINT64, length_y,
00930 length_x);
00931 add_type(&type, param, name, description);
00932 }
00933
00934 void
00935 Parameter::add_matrix(TSparse<float32_t>** param,
00936 index_t* length_y, index_t* length_x,
00937 const char* name, const char* description) {
00938 TSGDataType type(CT_MATRIX, ST_SPARSE, PT_FLOAT32, length_y,
00939 length_x);
00940 add_type(&type, param, name, description);
00941 }
00942
00943 void
00944 Parameter::add_matrix(TSparse<float64_t>** param,
00945 index_t* length_y, index_t* length_x,
00946 const char* name, const char* description) {
00947 TSGDataType type(CT_MATRIX, ST_SPARSE, PT_FLOAT64, length_y,
00948 length_x);
00949 add_type(&type, param, name, description);
00950 }
00951
00952 void
00953 Parameter::add_matrix(TSparse<floatmax_t>** param,
00954 index_t* length_y, index_t* length_x,
00955 const char* name, const char* description) {
00956 TSGDataType type(CT_MATRIX, ST_SPARSE, PT_FLOATMAX, length_y,
00957 length_x);
00958 add_type(&type, param, name, description);
00959 }
00960
00961
00962
00963
00964 TParameter::TParameter(const TSGDataType* datatype, void* parameter,
00965 const char* name, const char* description)
00966 :m_datatype(*datatype)
00967 {
00968 m_parameter = parameter;
00969 m_name = strdup(name);
00970 m_description = strdup(description);
00971 }
00972
00973 TParameter::~TParameter(void)
00974 {
00975 free(m_description); free(m_name);
00976 }
00977
00978 char*
00979 TParameter::new_prefix(const char* s1, const char* s2)
00980 {
00981 char* tmp = new char[strlen(s1)+strlen(s2)+2];
00982
00983 sprintf(tmp, "%s%s/", s1, s2);
00984
00985 return tmp;
00986 }
00987
00988 void
00989 TParameter::print(const char* prefix)
00990 {
00991 string_t buf;
00992 m_datatype.to_string(buf, STRING_LEN);
00993
00994 SG_SPRINT("\n%s\n%35s %24s :%s\n", prefix, m_description == NULL
00995 || *m_description == '\0' ? "(Parameter)": m_description,
00996 m_name, buf);
00997
00998 if (m_datatype.m_ptype == PT_SGOBJECT
00999 && m_datatype.m_stype == ST_NONE
01000 && m_datatype.m_ctype == CT_SCALAR
01001 && *(CSGObject**) m_parameter != NULL) {
01002 char* p = new_prefix(prefix, m_name);
01003 (*(CSGObject**) m_parameter)->print_serializable(p);
01004 delete p;
01005 }
01006 }
01007
01008 void
01009 TParameter::delete_cont(void)
01010 {
01011 if (*(void**) m_parameter != NULL) {
01012 index_t old_length = *m_datatype.m_length_y;
01013 switch (m_datatype.m_ctype) {
01014 case CT_MATRIX:
01015 old_length *= *m_datatype.m_length_x; break;
01016 case CT_SCALAR: case CT_VECTOR: break;
01017 }
01018
01019 switch (m_datatype.m_stype) {
01020 case ST_NONE:
01021 switch (m_datatype.m_ptype) {
01022 case PT_BOOL:
01023 delete[] *(bool**) m_parameter; break;
01024 case PT_CHAR:
01025 delete[] *(char**) m_parameter; break;
01026 case PT_INT8:
01027 delete[] *(int8_t**) m_parameter; break;
01028 case PT_UINT8:
01029 delete[] *(uint8_t**) m_parameter; break;
01030 case PT_INT16:
01031 delete[] *(int16_t**) m_parameter; break;
01032 case PT_UINT16:
01033 delete[] *(uint16_t**) m_parameter; break;
01034 case PT_INT32:
01035 delete[] *(int32_t**) m_parameter; break;
01036 case PT_UINT32:
01037 delete[] *(uint32_t**) m_parameter; break;
01038 case PT_INT64:
01039 delete[] *(int64_t**) m_parameter; break;
01040 case PT_UINT64:
01041 delete[] *(uint64_t**) m_parameter; break;
01042 case PT_FLOAT32:
01043 delete[] *(float32_t**) m_parameter; break;
01044 case PT_FLOAT64:
01045 delete[] *(float64_t**) m_parameter; break;
01046 case PT_FLOATMAX:
01047 delete[] *(floatmax_t**) m_parameter; break;
01048 case PT_SGOBJECT:
01049 CSGObject** buf =
01050 *(CSGObject***) m_parameter;
01051 for (index_t i=0; i<old_length; i++)
01052 if (buf[i] != NULL) SG_UNREF(buf[i]);
01053 delete buf;
01054 break;
01055 }
01056 break;
01057 case ST_STRING:
01058 for (index_t i=0; i<old_length; i++) {
01059 TString<char>* buf = (TString<char>*) (*(char**)
01060 m_parameter + i *m_datatype.sizeof_stype());
01061 if (buf->length > 0) delete[] buf->string;
01062 }
01063
01064 switch (m_datatype.m_ptype) {
01065 case PT_BOOL:
01066 delete[] *(TString<bool>**) m_parameter; break;
01067 case PT_CHAR:
01068 delete[] *(TString<char>**) m_parameter; break;
01069 case PT_INT8:
01070 delete[] *(TString<int8_t>**) m_parameter; break;
01071 case PT_UINT8:
01072 delete[] *(TString<uint8_t>**) m_parameter; break;
01073 case PT_INT16:
01074 delete[] *(TString<int16_t>**) m_parameter; break;
01075 case PT_UINT16:
01076 delete[] *(TString<uint16_t>**) m_parameter; break;
01077 case PT_INT32:
01078 delete[] *(TString<int32_t>**) m_parameter; break;
01079 case PT_UINT32:
01080 delete[] *(TString<uint32_t>**) m_parameter; break;
01081 case PT_INT64:
01082 delete[] *(TString<int64_t>**) m_parameter; break;
01083 case PT_UINT64:
01084 delete[] *(TString<uint64_t>**) m_parameter; break;
01085 case PT_FLOAT32:
01086 delete[] *(TString<float32_t>**) m_parameter; break;
01087 case PT_FLOAT64:
01088 delete[] *(TString<float64_t>**) m_parameter; break;
01089 case PT_FLOATMAX:
01090 delete[] *(TString<floatmax_t>**) m_parameter; break;
01091 case PT_SGOBJECT:
01092 SG_SERROR("TParameter::delete_cont(): Implementation "
01093 "error: Could not delete "
01094 "String<SGSerializable*>");
01095 break;
01096 }
01097 break;
01098 case ST_SPARSE:
01099 for (index_t i=0; i<old_length; i++) {
01100 TSparse<char>* buf = (TSparse<char>*) (*(char**)
01101 m_parameter + i *m_datatype.sizeof_stype());
01102 if (buf->num_feat_entries > 0) delete[] buf->features;
01103 }
01104
01105 switch (m_datatype.m_ptype) {
01106 case PT_BOOL:
01107 delete[] *(TSparse<bool>**) m_parameter; break;
01108 case PT_CHAR:
01109 delete[] *(TSparse<char>**) m_parameter; break;
01110 case PT_INT8:
01111 delete[] *(TSparse<int8_t>**) m_parameter; break;
01112 case PT_UINT8:
01113 delete[] *(TSparse<uint8_t>**) m_parameter; break;
01114 case PT_INT16:
01115 delete[] *(TSparse<int16_t>**) m_parameter; break;
01116 case PT_UINT16:
01117 delete[] *(TSparse<uint16_t>**) m_parameter; break;
01118 case PT_INT32:
01119 delete[] *(TSparse<int32_t>**) m_parameter; break;
01120 case PT_UINT32:
01121 delete[] *(TSparse<uint32_t>**) m_parameter; break;
01122 case PT_INT64:
01123 delete[] *(TSparse<int64_t>**) m_parameter; break;
01124 case PT_UINT64:
01125 delete[] *(TSparse<uint64_t>**) m_parameter; break;
01126 case PT_FLOAT32:
01127 delete[] *(TSparse<float32_t>**) m_parameter; break;
01128 case PT_FLOAT64:
01129 delete[] *(TSparse<float64_t>**) m_parameter; break;
01130 case PT_FLOATMAX:
01131 delete[] *(TSparse<floatmax_t>**) m_parameter; break;
01132 case PT_SGOBJECT:
01133 SG_SERROR("TParameter::delete_cont(): Implementation "
01134 "error: Could not delete "
01135 "Sparse<SGSerializable*>");
01136 break;
01137 }
01138 break;
01139 }
01140 }
01141
01142 *(void**) m_parameter = NULL;
01143 }
01144
01145 void
01146 TParameter::new_cont(index_t new_len_y, index_t new_len_x)
01147 {
01148 delete_cont();
01149
01150 index_t new_length = new_len_y*new_len_x;
01151 if (new_length == 0) return;
01152
01153 switch (m_datatype.m_stype) {
01154 case ST_NONE:
01155 switch (m_datatype.m_ptype) {
01156 case PT_BOOL:
01157 *(bool**) m_parameter
01158 = new bool[new_length]; break;
01159 case PT_CHAR:
01160 *(char**) m_parameter
01161 = new char[new_length]; break;
01162 case PT_INT8:
01163 *(int8_t**) m_parameter
01164 = new int8_t[new_length]; break;
01165 case PT_UINT8:
01166 *(uint8_t**) m_parameter
01167 = new uint8_t[new_length]; break;
01168 case PT_INT16:
01169 *(int16_t**) m_parameter
01170 = new int16_t[new_length]; break;
01171 case PT_UINT16:
01172 *(uint16_t**) m_parameter
01173 = new uint16_t[new_length]; break;
01174 case PT_INT32:
01175 *(int32_t**) m_parameter
01176 = new int32_t[new_length]; break;
01177 case PT_UINT32:
01178 *(uint32_t**) m_parameter
01179 = new uint32_t[new_length]; break;
01180 case PT_INT64:
01181 *(int64_t**) m_parameter
01182 = new int64_t[new_length]; break;
01183 case PT_UINT64:
01184 *(uint64_t**) m_parameter
01185 = new uint64_t[new_length]; break;
01186 case PT_FLOAT32:
01187 *(float32_t**) m_parameter
01188 = new float32_t[new_length]; break;
01189 case PT_FLOAT64:
01190 *(float64_t**) m_parameter
01191 = new float64_t[new_length]; break;
01192 case PT_FLOATMAX:
01193 *(floatmax_t**) m_parameter
01194 = new floatmax_t[new_length]; break;
01195 case PT_SGOBJECT:
01196 *(CSGObject***) m_parameter
01197 = new CSGObject*[new_length]();
01198 break;
01199 }
01200 break;
01201 case ST_STRING:
01202 switch (m_datatype.m_ptype) {
01203 case PT_BOOL:
01204 *(TString<bool>**) m_parameter
01205 = new TString<bool>[new_length]; break;
01206 case PT_CHAR:
01207 *(TString<char>**) m_parameter
01208 = new TString<char>[new_length]; break;
01209 case PT_INT8:
01210 *(TString<int8_t>**) m_parameter
01211 = new TString<int8_t>[new_length]; break;
01212 case PT_UINT8:
01213 *(TString<uint8_t>**) m_parameter
01214 = new TString<uint8_t>[new_length]; break;
01215 case PT_INT16:
01216 *(TString<int16_t>**) m_parameter
01217 = new TString<int16_t>[new_length]; break;
01218 case PT_UINT16:
01219 *(TString<uint16_t>**) m_parameter
01220 = new TString<uint16_t>[new_length]; break;
01221 case PT_INT32:
01222 *(TString<int32_t>**) m_parameter
01223 = new TString<int32_t>[new_length]; break;
01224 case PT_UINT32:
01225 *(TString<uint32_t>**) m_parameter
01226 = new TString<uint32_t>[new_length]; break;
01227 case PT_INT64:
01228 *(TString<int64_t>**) m_parameter
01229 = new TString<int64_t>[new_length]; break;
01230 case PT_UINT64:
01231 *(TString<uint64_t>**) m_parameter
01232 = new TString<uint64_t>[new_length]; break;
01233 case PT_FLOAT32:
01234 *(TString<float32_t>**) m_parameter
01235 = new TString<float32_t>[new_length]; break;
01236 case PT_FLOAT64:
01237 *(TString<float64_t>**) m_parameter
01238 = new TString<float64_t>[new_length]; break;
01239 case PT_FLOATMAX:
01240 *(TString<floatmax_t>**) m_parameter
01241 = new TString<floatmax_t>[new_length]; break;
01242 case PT_SGOBJECT:
01243 SG_SERROR("TParameter::new_cont(): Implementation "
01244 "error: Could not allocate "
01245 "String<SGSerializable*>");
01246 break;
01247 }
01248 memset(*(void**) m_parameter, 0, new_length
01249 *m_datatype.sizeof_stype());
01250 break;
01251 case ST_SPARSE:
01252 switch (m_datatype.m_ptype) {
01253 case PT_BOOL:
01254 *(TSparse<bool>**) m_parameter
01255 = new TSparse<bool>[new_length]; break;
01256 case PT_CHAR:
01257 *(TSparse<char>**) m_parameter
01258 = new TSparse<char>[new_length]; break;
01259 case PT_INT8:
01260 *(TSparse<int8_t>**) m_parameter
01261 = new TSparse<int8_t>[new_length]; break;
01262 case PT_UINT8:
01263 *(TSparse<uint8_t>**) m_parameter
01264 = new TSparse<uint8_t>[new_length]; break;
01265 case PT_INT16:
01266 *(TSparse<int16_t>**) m_parameter
01267 = new TSparse<int16_t>[new_length]; break;
01268 case PT_UINT16:
01269 *(TSparse<uint16_t>**) m_parameter
01270 = new TSparse<uint16_t>[new_length]; break;
01271 case PT_INT32:
01272 *(TSparse<int32_t>**) m_parameter
01273 = new TSparse<int32_t>[new_length]; break;
01274 case PT_UINT32:
01275 *(TSparse<uint32_t>**) m_parameter
01276 = new TSparse<uint32_t>[new_length]; break;
01277 case PT_INT64:
01278 *(TSparse<int64_t>**) m_parameter
01279 = new TSparse<int64_t>[new_length]; break;
01280 case PT_UINT64:
01281 *(TSparse<uint64_t>**) m_parameter
01282 = new TSparse<uint64_t>[new_length]; break;
01283 case PT_FLOAT32:
01284 *(TSparse<float32_t>**) m_parameter
01285 = new TSparse<float32_t>[new_length]; break;
01286 case PT_FLOAT64:
01287 *(TSparse<float64_t>**) m_parameter
01288 = new TSparse<float64_t>[new_length]; break;
01289 case PT_FLOATMAX:
01290 *(TSparse<floatmax_t>**) m_parameter
01291 = new TSparse<floatmax_t>[new_length]; break;
01292 case PT_SGOBJECT:
01293 SG_SERROR("TParameter::new_cont(): Implementation "
01294 "error: Could not allocate "
01295 "Sparse<SGSerializable*>");
01296 break;
01297 }
01298 memset(*(void**) m_parameter, 0, new_length
01299 *m_datatype.sizeof_stype());
01300 break;
01301 }
01302 }
01303
01304 bool
01305 TParameter::new_sgserial(CSGObject** param,
01306 EPrimitiveType generic,
01307 const char* sgserializable_name,
01308 const char* prefix)
01309 {
01310 if (*param != NULL)
01311 SG_UNREF(*param);
01312
01313 *param = new_sgserializable(sgserializable_name, generic);
01314
01315 if (*param == NULL) {
01316 string_t buf = {'\0'};
01317
01318 if (generic != PT_NOT_GENERIC) {
01319 buf[0] = '<';
01320 TSGDataType::ptype_to_string(buf+1, generic,
01321 STRING_LEN - 3);
01322 strcat(buf, ">");
01323 }
01324
01325 SG_SWARNING("TParameter::new_sgserial(): "
01326 "Class `C%s%s' was not listed during compiling Shogun"
01327 " :( ... Can not construct it for `%s%s'!",
01328 sgserializable_name, buf, prefix, m_name);
01329
01330 return false;
01331 }
01332
01333 SG_REF(*param);
01334 return true;
01335 }
01336
01337 bool
01338 TParameter::save_ptype(CSerializableFile* file, const void* param,
01339 const char* prefix)
01340 {
01341 if (m_datatype.m_ptype == PT_SGOBJECT) {
01342 const char* sgserial_name = "";
01343 EPrimitiveType generic = PT_NOT_GENERIC;
01344
01345 if (*(CSGObject**) param != NULL) {
01346 sgserial_name = (*(CSGObject**) param)->get_name();
01347 (*(CSGObject**) param)->is_generic(&generic);
01348 }
01349
01350 if (!file->write_sgserializable_begin(
01351 &m_datatype, m_name, prefix, sgserial_name, generic))
01352 return false;
01353 if (*sgserial_name != '\0') {
01354 char* p = new_prefix(prefix, m_name);
01355 bool result = (*(CSGObject**) param)
01356 ->save_serializable(file, p);
01357 delete p;
01358 if (!result) return false;
01359 }
01360 if (!file->write_sgserializable_end(
01361 &m_datatype, m_name, prefix, sgserial_name, generic))
01362 return false;
01363 } else
01364 if (!file->write_scalar(&m_datatype, m_name, prefix,
01365 param)) return false;
01366
01367 return true;
01368 }
01369
01370 bool
01371 TParameter::load_ptype(CSerializableFile* file, void* param,
01372 const char* prefix)
01373 {
01374 if (m_datatype.m_ptype == PT_SGOBJECT) {
01375 string_t sgserial_name = {'\0'};
01376 EPrimitiveType generic = PT_NOT_GENERIC;
01377
01378 if (!file->read_sgserializable_begin(
01379 &m_datatype, m_name, prefix, sgserial_name, &generic))
01380 return false;
01381 if (*sgserial_name != '\0') {
01382 if (!new_sgserial((CSGObject**) param, generic,
01383 sgserial_name, prefix))
01384 return false;
01385
01386 char* p = new_prefix(prefix, m_name);
01387 bool result = (*(CSGObject**) param)
01388 ->load_serializable(file, p);
01389 delete p;
01390 if (!result) return false;
01391 }
01392 if (!file->read_sgserializable_end(
01393 &m_datatype, m_name, prefix, sgserial_name, generic))
01394 return false;
01395 } else
01396 if (!file->read_scalar(&m_datatype, m_name, prefix,
01397 param)) return false;
01398
01399 return true;
01400 }
01401
01402 bool
01403 TParameter::save_stype(CSerializableFile* file, const void* param,
01404 const char* prefix)
01405 {
01406 TString<char>* str_ptr = (TString<char>*) param;
01407 TSparse<char>* spr_ptr = (TSparse<char>*) param;
01408 index_t len_real;
01409
01410 switch (m_datatype.m_stype) {
01411 case ST_NONE:
01412 if (!save_ptype(file, param, prefix)) return false;
01413 break;
01414 case ST_STRING:
01415 len_real = str_ptr->length;
01416 if (str_ptr->string == NULL && len_real != 0) {
01417 SG_SWARNING("Inconsistency between data structure and "
01418 "len during saving string `%s%s'! Continuing"
01419 " with len=0.\n",
01420 prefix, m_name);
01421 len_real = 0;
01422 }
01423 if (!file->write_string_begin(
01424 &m_datatype, m_name, prefix, len_real)) return false;
01425 for (index_t i=0; i<len_real; i++) {
01426 if (!file->write_stringentry_begin(
01427 &m_datatype, m_name, prefix, i)) return false;
01428 if (!save_ptype(file, (char*) str_ptr->string
01429 + i *m_datatype.sizeof_ptype(), prefix))
01430 return false;
01431 if (!file->write_stringentry_end(
01432 &m_datatype, m_name, prefix, i)) return false;
01433 }
01434 if (!file->write_string_end(
01435 &m_datatype, m_name, prefix, len_real)) return false;
01436 break;
01437 case ST_SPARSE:
01438 len_real = spr_ptr->num_feat_entries;
01439 if (spr_ptr->features == NULL && len_real != 0) {
01440 SG_SWARNING("Inconsistency between data structure and "
01441 "len during saving sparse `%s%s'! Continuing"
01442 " with len=0.\n",
01443 prefix, m_name);
01444 len_real = 0;
01445 }
01446 if (!file->write_sparse_begin(
01447 &m_datatype, m_name, prefix, spr_ptr->vec_index,
01448 len_real)) return false;
01449 for (index_t i=0; i<len_real; i++) {
01450 TSparseEntry<char>* cur = (TSparseEntry<char>*)
01451 ((char*) spr_ptr->features + i *TSGDataType
01452 ::sizeof_sparseentry(m_datatype.m_ptype));
01453 if (!file->write_sparseentry_begin(
01454 &m_datatype, m_name, prefix, spr_ptr->features,
01455 cur->feat_index, i)) return false;
01456 if (!save_ptype(file, (char*) cur + TSGDataType
01457 ::offset_sparseentry(m_datatype.m_ptype),
01458 prefix)) return false;
01459 if (!file->write_sparseentry_end(
01460 &m_datatype, m_name, prefix, spr_ptr->features,
01461 cur->feat_index, i)) return false;
01462 }
01463 if (!file->write_sparse_end(
01464 &m_datatype, m_name, prefix, spr_ptr->vec_index,
01465 len_real)) return false;
01466 break;
01467 }
01468
01469 return true;
01470 }
01471
01472 bool
01473 TParameter::load_stype(CSerializableFile* file, void* param,
01474 const char* prefix)
01475 {
01476 TString<char>* str_ptr = (TString<char>*) param;
01477 TSparse<char>* spr_ptr = (TSparse<char>*) param;
01478 index_t len_real = 0;
01479
01480 switch (m_datatype.m_stype) {
01481 case ST_NONE:
01482 if (!load_ptype(file, param, prefix)) return false;
01483 break;
01484 case ST_STRING:
01485 if (!file->read_string_begin(
01486 &m_datatype, m_name, prefix, &len_real))
01487 return false;
01488 str_ptr->string = len_real > 0
01489 ? new char[len_real*m_datatype.sizeof_ptype()]: NULL;
01490 for (index_t i=0; i<len_real; i++) {
01491 if (!file->read_stringentry_begin(
01492 &m_datatype, m_name, prefix, i)) return false;
01493 if (!load_ptype(file, (char*) str_ptr->string
01494 + i *m_datatype.sizeof_ptype(), prefix))
01495 return false;
01496 if (!file->read_stringentry_end(
01497 &m_datatype, m_name, prefix, i)) return false;
01498 }
01499 if (!file->read_string_end(
01500 &m_datatype, m_name, prefix, len_real))
01501 return false;
01502 str_ptr->length = len_real;
01503 break;
01504 case ST_SPARSE:
01505 if (!file->read_sparse_begin(
01506 &m_datatype, m_name, prefix, &spr_ptr->vec_index,
01507 &len_real)) return false;
01508 spr_ptr->features = len_real > 0? (TSparseEntry<char>*)
01509 new char[len_real *TSGDataType::sizeof_sparseentry(
01510 m_datatype.m_ptype)]: NULL;
01511 for (index_t i=0; i<len_real; i++) {
01512 TSparseEntry<char>* cur = (TSparseEntry<char>*)
01513 ((char*) spr_ptr->features + i *TSGDataType
01514 ::sizeof_sparseentry(m_datatype.m_ptype));
01515 if (!file->read_sparseentry_begin(
01516 &m_datatype, m_name, prefix, spr_ptr->features,
01517 &cur->feat_index, i)) return false;
01518 if (!load_ptype(file, (char*) cur + TSGDataType
01519 ::offset_sparseentry(m_datatype.m_ptype),
01520 prefix)) return false;
01521 if (!file->read_sparseentry_end(
01522 &m_datatype, m_name, prefix, spr_ptr->features,
01523 &cur->feat_index, i)) return false;
01524 }
01525 if (!file->read_sparse_end(
01526 &m_datatype, m_name, prefix, &spr_ptr->vec_index,
01527 len_real)) return false;
01528 spr_ptr->num_feat_entries = len_real;
01529 break;
01530 }
01531
01532 return true;
01533 }
01534
01535 bool
01536 TParameter::save(CSerializableFile* file, const char* prefix)
01537 {
01538 const int32_t buflen=100;
01539 char* buf=new char[buflen];
01540 m_datatype.to_string(buf, buflen);
01541 SG_SDEBUG("Saving parameter '%s' of type '%s'\n", m_name, buf);
01542 delete[] buf;
01543
01544 if (!file->write_type_begin(&m_datatype, m_name, prefix))
01545 return false;
01546
01547 switch (m_datatype.m_ctype) {
01548 case CT_SCALAR:
01549 if (!save_stype(file, m_parameter, prefix)) return false;
01550 break;
01551 case CT_VECTOR: case CT_MATRIX:
01552 index_t len_real_y = 0, len_real_x = 0;
01553
01554 len_real_y = *m_datatype.m_length_y;
01555 if (*(void**) m_parameter == NULL && len_real_y != 0) {
01556 SG_SWARNING("Inconsistency between data structure and "
01557 "len_y during saving `%s%s'! Continuing with "
01558 "len_y=0.\n",
01559 prefix, m_name);
01560 len_real_y = 0;
01561 }
01562
01563 switch (m_datatype.m_ctype) {
01564 case CT_VECTOR:
01565 len_real_x = 1; break;
01566 case CT_MATRIX:
01567 len_real_x = *m_datatype.m_length_x;
01568 if (*(void**) m_parameter == NULL && len_real_x != 0) {
01569 SG_SWARNING("Inconsistency between data structure and "
01570 "len_x during saving `%s%s'! Continuing "
01571 "with len_x=0.\n",
01572 prefix, m_name);
01573 len_real_x = 0;
01574 }
01575
01576 if (len_real_x *len_real_y == 0)
01577 len_real_x = len_real_y = 0;
01578
01579 break;
01580 case CT_SCALAR: break;
01581 }
01582
01583 if (!file->write_cont_begin(&m_datatype, m_name, prefix,
01584 len_real_y, len_real_x))
01585 return false;
01586
01587
01588
01589 for (index_t x=0; x<len_real_x; x++)
01590 for (index_t y=0; y<len_real_y; y++) {
01591 if (!file->write_item_begin(
01592 &m_datatype, m_name, prefix, y, x))
01593 return false;
01594 if (!save_stype(
01595 file, (*(char**) m_parameter)
01596 + (x*len_real_y + y)*m_datatype.sizeof_stype(),
01597 prefix)) return false;
01598 if (!file->write_item_end(
01599 &m_datatype, m_name, prefix, y, x))
01600 return false;
01601 }
01602
01603
01604
01605 if (!file->write_cont_end(&m_datatype, m_name, prefix,
01606 len_real_y, len_real_x))
01607 return false;
01608
01609 break;
01610 }
01611
01612 if (!file->write_type_end(&m_datatype, m_name, prefix))
01613 return false;
01614
01615 return true;
01616 }
01617
01618 bool
01619 TParameter::load(CSerializableFile* file, const char* prefix)
01620 {
01621 const int32_t buflen=100;
01622 char* buf=new char[buflen];
01623 m_datatype.to_string(buf, buflen);
01624 SG_SDEBUG("Loading parameter '%s' of type '%s'\n", m_name, buf);
01625 delete[] buf;
01626
01627 if (!file->read_type_begin(&m_datatype, m_name, prefix))
01628 return false;
01629
01630 switch (m_datatype.m_ctype) {
01631 case CT_SCALAR:
01632 if (!load_stype(file, m_parameter, prefix)) return false;
01633 break;
01634 case CT_VECTOR: case CT_MATRIX:
01635 index_t len_read_y = 0, len_read_x = 0;
01636
01637 if (!file->read_cont_begin(&m_datatype, m_name, prefix,
01638 &len_read_y, &len_read_x))
01639 return false;
01640
01641
01642
01643 switch (m_datatype.m_ctype) {
01644 case CT_VECTOR:
01645 len_read_x = 1;
01646 new_cont(len_read_y, len_read_x);
01647 break;
01648 case CT_MATRIX:
01649 new_cont(len_read_y, len_read_x);
01650 break;
01651 case CT_SCALAR: break;
01652 }
01653
01654 for (index_t x=0; x<len_read_x; x++)
01655 for (index_t y=0; y<len_read_y; y++) {
01656 if (!file->read_item_begin(
01657 &m_datatype, m_name, prefix, y, x))
01658 return false;
01659 if (!load_stype(
01660 file, (*(char**) m_parameter)
01661 + (x*len_read_y + y)*m_datatype.sizeof_stype(),
01662 prefix)) return false;
01663 if (!file->read_item_end(
01664 &m_datatype, m_name, prefix, y, x))
01665 return false;
01666 }
01667
01668 switch (m_datatype.m_ctype) {
01669 case CT_VECTOR:
01670 *m_datatype.m_length_y = len_read_y;
01671 break;
01672 case CT_MATRIX:
01673 *m_datatype.m_length_y = len_read_y;
01674 *m_datatype.m_length_x = len_read_x;
01675 break;
01676 case CT_SCALAR: break;
01677 }
01678
01679
01680
01681 if (!file->read_cont_end(&m_datatype, m_name, prefix,
01682 len_read_y, len_read_x))
01683 return false;
01684
01685 break;
01686 }
01687
01688 if (!file->read_type_end(&m_datatype, m_name, prefix))
01689 return false;
01690
01691 return true;
01692 }
01693
01694 Parameter::Parameter(void)
01695 {
01696 SG_REF(sg_io);
01697 }
01698
01699 Parameter::~Parameter(void)
01700 {
01701 for (int32_t i=0; i<get_num_parameters(); i++)
01702 delete m_params.get_element(i);
01703
01704 SG_UNREF(sg_io);
01705 }
01706
01707 void
01708 Parameter::add_type(const TSGDataType* type, void* param,
01709 const char* name, const char* description)
01710 {
01711 if (name == NULL || *name == '\0')
01712 SG_SERROR("FATAL: Parameter::add_type(): `name' is empty!");
01713
01714 for (int32_t i=0; i<get_num_parameters(); i++)
01715 if (strcmp(m_params.get_element(i)->m_name, name) == 0)
01716 SG_SERROR("FATAL: Parameter::add_type(): "
01717 "Double parameter `%s'!", name);
01718
01719 m_params.append_element(
01720 new TParameter(type, param, name, description)
01721 );
01722 }
01723
01724 void
01725 Parameter::print(const char* prefix)
01726 {
01727 for (int32_t i=0; i<get_num_parameters(); i++)
01728 m_params.get_element(i)->print(prefix);
01729 }
01730
01731 bool
01732 Parameter::save(CSerializableFile* file, const char* prefix)
01733 {
01734 for (int32_t i=0; i<get_num_parameters(); i++)
01735 {
01736 if (!m_params.get_element(i)->save(file, prefix))
01737 return false;
01738 }
01739
01740 return true;
01741 }
01742
01743 bool
01744 Parameter::load(CSerializableFile* file, const char* prefix)
01745 {
01746 for (int32_t i=0; i<get_num_parameters(); i++)
01747 if (!m_params.get_element(i)->load(file, prefix))
01748 return false;
01749
01750 return true;
01751 }