00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include <cmath>
00019 #include <cstdlib>
00020 #include <fstream>
00021 #include <iostream>
00022 #include <string>
00023 #include <sstream>
00024
00025
00026
00027 #include "inputs_outputs_information.h"
00028
00029
00030
00031 #include "../../parsers/tinyxml/tinyxml.h"
00032
00033 namespace OpenNN
00034 {
00035
00036
00037
00040
00041 InputsOutputsInformation::InputsOutputsInformation(void)
00042 {
00043 set();
00044 }
00045
00046
00047
00048
00054
00055 InputsOutputsInformation::InputsOutputsInformation(const unsigned int& new_inputs_number, const unsigned int& new_outputs_number)
00056 {
00057 set(new_inputs_number, new_outputs_number);
00058 }
00059
00060
00061
00062
00066
00067 InputsOutputsInformation::InputsOutputsInformation(TiXmlElement* inputs_outputs_information_element)
00068 {
00069 from_XML(inputs_outputs_information_element);
00070 }
00071
00072
00073
00074
00078
00079 InputsOutputsInformation::InputsOutputsInformation(const InputsOutputsInformation& other_inputs_outputs_information)
00080 {
00081 set(other_inputs_outputs_information);
00082 }
00083
00084
00085
00086
00088
00089 InputsOutputsInformation::~InputsOutputsInformation(void)
00090 {
00091 }
00092
00093
00094
00095
00099
00100 InputsOutputsInformation& InputsOutputsInformation::operator = (const InputsOutputsInformation& other_inputs_outputs_information)
00101 {
00102 if(this != &other_inputs_outputs_information)
00103 {
00104 inputs_name = other_inputs_outputs_information.inputs_name;
00105
00106 inputs_units = other_inputs_outputs_information.inputs_units;
00107
00108 inputs_description = other_inputs_outputs_information.inputs_description;
00109
00110 outputs_name = other_inputs_outputs_information.outputs_name;
00111
00112 outputs_units = other_inputs_outputs_information.outputs_units;
00113
00114 outputs_description = other_inputs_outputs_information.outputs_description;
00115
00116 display = other_inputs_outputs_information.display;
00117 }
00118
00119 return(*this);
00120 }
00121
00122
00123
00124
00125
00126
00127
00128
00129
00134
00135 bool InputsOutputsInformation::operator == (const InputsOutputsInformation& other_inputs_outputs_information) const
00136 {
00137 if(inputs_name == other_inputs_outputs_information.inputs_name
00138 && inputs_units == other_inputs_outputs_information.inputs_units
00139 && inputs_description == other_inputs_outputs_information.inputs_description
00140 && outputs_name == other_inputs_outputs_information.outputs_name
00141 && outputs_units == other_inputs_outputs_information.outputs_units
00142 && outputs_description == other_inputs_outputs_information.outputs_description
00143 && display == other_inputs_outputs_information.display)
00144 {
00145 return(true);
00146 }
00147 else
00148 {
00149 return(false);
00150 }
00151 }
00152
00153
00154
00155
00157
00158 bool InputsOutputsInformation::is_empty(void) const
00159 {
00160 const unsigned int inputs_number = count_inputs_number();
00161 const unsigned int outputs_number = count_outputs_number();
00162
00163 if(inputs_number == 0 && outputs_number == 0)
00164 {
00165 return(true);
00166 }
00167 else
00168 {
00169 return(false);
00170 }
00171 }
00172
00173
00174
00175
00178
00179 const Vector<std::string>& InputsOutputsInformation::get_inputs_name(void) const
00180 {
00181 return(inputs_name);
00182 }
00183
00184
00185
00186
00190
00191 const std::string& InputsOutputsInformation::get_input_name(const unsigned int& input_index) const
00192 {
00193
00194
00195 #ifdef _DEBUG
00196
00197 const unsigned int inputs_number = count_inputs_number();
00198
00199 if(input_index >= inputs_number)
00200 {
00201 std::ostringstream buffer;
00202
00203 buffer << "OpenNN Exception: InputsOutputsInformation class.\n"
00204 << "const std::string get_input_name(const unsigned int&) const method.\n"
00205 << "Input variable index must be less than number of inputs.\n";
00206
00207 throw std::logic_error(buffer.str());
00208 }
00209
00210 if(inputs_name.size() == 0)
00211 {
00212 std::ostringstream buffer;
00213
00214 buffer << "OpenNN Exception: InputsOutputsInformation class.\n"
00215 << "const std::string get_input_name(const unsigned int&) const method.\n"
00216 << "Input variables size is zero.\n";
00217
00218 throw std::logic_error(buffer.str());
00219 }
00220
00221 #endif
00222
00223 return(inputs_name[input_index]);
00224 }
00225
00226
00227
00228
00231
00232 const Vector<std::string>& InputsOutputsInformation::get_inputs_units(void) const
00233 {
00234 return(inputs_units);
00235 }
00236
00237
00238
00239
00243
00244 const std::string& InputsOutputsInformation::get_input_units(const unsigned int& input_index) const
00245 {
00246
00247
00248 #ifdef _DEBUG
00249
00250 const unsigned int inputs_number = count_inputs_number();
00251
00252 if(input_index >= inputs_number)
00253 {
00254 std::ostringstream buffer;
00255
00256 buffer << "OpenNN Exception: InputsOutputsInformation class.\n"
00257 << "const std::string get_input_units(const unsigned int&) const method.\n"
00258 << "Index of input variable must be less than number of inputs.\n";
00259
00260 throw std::logic_error(buffer.str());
00261 }
00262
00263 #endif
00264
00265 return(inputs_units[input_index]);
00266 }
00267
00268
00269
00270
00273
00274 const Vector<std::string>& InputsOutputsInformation::get_inputs_description(void) const
00275 {
00276 return(inputs_description);
00277 }
00278
00279
00280
00281
00285
00286 const std::string& InputsOutputsInformation::get_input_description(const unsigned int& input_index) const
00287 {
00288
00289
00290 #ifdef _DEBUG
00291
00292 const unsigned int inputs_number = count_inputs_number();
00293
00294 if(input_index >= inputs_number)
00295 {
00296 std::ostringstream buffer;
00297
00298 buffer << "OpenNN Exception: InputsOutputsInformation class.\n"
00299 << "const std::string& get_input_description(const unsigned int&) const method.\n"
00300 << "Index of input variable must be less than number of inputs.\n";
00301
00302 throw std::logic_error(buffer.str());
00303 }
00304
00305 #endif
00306
00307 return(inputs_description[input_index]);
00308 }
00309
00310
00311
00312
00315
00316 const Vector<std::string>& InputsOutputsInformation::get_outputs_name(void) const
00317 {
00318 return(outputs_name);
00319 }
00320
00321
00322
00323
00327
00328 const std::string& InputsOutputsInformation::get_output_name(const unsigned int& output_index) const
00329 {
00330
00331
00332 #ifdef _DEBUG
00333
00334 const unsigned int outputs_number = count_outputs_number();
00335
00336 if(output_index >= outputs_number)
00337 {
00338 std::ostringstream buffer;
00339
00340 buffer << "OpenNN Exception: InputsOutputsInformation class.\n"
00341 << "const std::string get_output_name(const unsigned int&) const method.\n"
00342 << "Output variable index must be less than number of outputs.\n";
00343
00344 throw std::logic_error(buffer.str());
00345 }
00346
00347 #endif
00348
00349 return(outputs_name[output_index]);
00350 }
00351
00352
00353
00354
00357
00358 const Vector<std::string>& InputsOutputsInformation::get_outputs_description(void) const
00359 {
00360 return(outputs_description);
00361 }
00362
00363
00364
00365
00369
00370 const std::string& InputsOutputsInformation::get_output_description(const unsigned int& output_index) const
00371 {
00372
00373
00374 #ifdef _DEBUG
00375
00376 const unsigned int outputs_number = count_outputs_number();
00377
00378 if(output_index >= outputs_number)
00379 {
00380 std::ostringstream buffer;
00381
00382 buffer << "OpenNN Exception: InputsOutputsInformation class.\n"
00383 << "const std::string& get_output_description(const unsigned int&) const method.\n"
00384 << "Index of output variable must be less than number of outputs.\n";
00385
00386 throw std::logic_error(buffer.str());
00387 }
00388
00389 #endif
00390
00391 return(outputs_description[output_index]);
00392 }
00393
00394
00395
00396
00399
00400 const Vector<std::string>& InputsOutputsInformation::get_outputs_units(void) const
00401 {
00402 return(outputs_units);
00403 }
00404
00405
00406
00407
00411
00412 const std::string& InputsOutputsInformation::get_output_units(const unsigned int& output_index) const
00413 {
00414
00415
00416 #ifdef _DEBUG
00417
00418 const unsigned int outputs_number = count_outputs_number();
00419
00420 if(output_index >= outputs_number)
00421 {
00422 std::ostringstream buffer;
00423
00424 buffer << "OpenNN Exception: InputsOutputsInformation class.\n"
00425 << "const std::string get_output_units(const unsigned int&) const method.\n"
00426 << "Index of output variable must be less than number of outputs.\n";
00427
00428 throw std::logic_error(buffer.str());
00429 }
00430
00431 #endif
00432
00433 return(outputs_units[output_index]);
00434 }
00435
00436
00437
00438
00449
00450 Vector< Vector<std::string>* > InputsOutputsInformation::get_information(void)
00451 {
00452 Vector< Vector<std::string>* > information(6);
00453
00454 information[0] = &inputs_name;
00455 information[1] = &outputs_name;
00456
00457 information[2] = &inputs_units;
00458 information[3] = &outputs_units;
00459
00460 information[4] = &inputs_description;
00461 information[5] = &outputs_description;
00462
00463 return(information);
00464 }
00465
00466
00467
00468
00471
00472 const bool& InputsOutputsInformation::get_display(void) const
00473 {
00474 return(display);
00475 }
00476
00477
00478
00479
00482
00483 void InputsOutputsInformation::set(void)
00484 {
00485 set_inputs_number(0);
00486
00487 set_outputs_number(0);
00488
00489 set_default();
00490 }
00491
00492
00493
00494
00499
00500 void InputsOutputsInformation::set(const unsigned int& new_inputs_number, const unsigned int& new_outputs_number)
00501 {
00502 set_inputs_number(new_inputs_number);
00503
00504 set_outputs_number(new_outputs_number);
00505
00506 set_default();
00507 }
00508
00509
00510
00511
00514
00515 void InputsOutputsInformation::set(const InputsOutputsInformation& other_inputs_outputs_information)
00516 {
00517 inputs_name = other_inputs_outputs_information.inputs_name;
00518
00519 inputs_units = other_inputs_outputs_information.inputs_units;
00520
00521 inputs_description = other_inputs_outputs_information.inputs_description;
00522
00523 outputs_name = other_inputs_outputs_information.outputs_name;
00524
00525 outputs_units = other_inputs_outputs_information.outputs_units;
00526
00527 outputs_description = other_inputs_outputs_information.outputs_description;
00528
00529 display = other_inputs_outputs_information.display;
00530 }
00531
00532
00533
00534
00546
00547 void InputsOutputsInformation::set(const Vector< Vector<std::string> >& new_variables_information)
00548 {
00549
00550
00551 #ifdef _DEBUG
00552
00553 const unsigned int new_variables_information_size = new_variables_information.size();
00554
00555 if(new_variables_information_size != 6)
00556 {
00557 std::ostringstream buffer;
00558
00559 buffer << "OpenNN Exception: InputsOutputsInformation class.\n"
00560 << "void set(const Vector< Vector<std::string> >&) method.\n"
00561 << "Size of variables information must be six.\n";
00562
00563 throw std::logic_error(buffer.str());
00564 }
00565
00566 #endif
00567
00568 set_inputs_name(new_variables_information[0]);
00569 set_inputs_units(new_variables_information[1]);
00570 set_inputs_description(new_variables_information[2]);
00571
00572 set_outputs_name(new_variables_information[3]);
00573 set_outputs_units(new_variables_information[4]);
00574 set_outputs_description(new_variables_information[5]);
00575 }
00576
00577
00578
00579
00582
00583 void InputsOutputsInformation::set_inputs_number(const unsigned int& new_inputs_number)
00584 {
00585 inputs_name.set(new_inputs_number);
00586 inputs_units.set(new_inputs_number);
00587 inputs_description.set(new_inputs_number);
00588 }
00589
00590
00591
00592
00595
00596 void InputsOutputsInformation::set_outputs_number(const unsigned int& new_outputs_number)
00597 {
00598 outputs_name.set(new_outputs_number);
00599 outputs_units.set(new_outputs_number);
00600 outputs_description.set(new_outputs_number);
00601 }
00602
00603
00604
00605
00607
00608 void InputsOutputsInformation::set_default(void)
00609 {
00610 const unsigned int inputs_number = count_inputs_number();
00611 const unsigned int outputs_number = count_outputs_number();
00612
00613 inputs_name.set(inputs_number, "");
00614
00615 inputs_units.set(inputs_number, "");
00616
00617 inputs_description.set(inputs_number, "");
00618
00619 outputs_name.set(outputs_number, "");
00620
00621 outputs_units.set(outputs_number, "");
00622
00623 outputs_description.set(outputs_number, "");
00624
00625 set_display(true);
00626 }
00627
00628
00629
00630
00634
00635 void InputsOutputsInformation::set_inputs_name(const Vector<std::string>& new_inputs_name)
00636 {
00637
00638
00639 #ifdef _DEBUG
00640
00641 const unsigned int size = new_inputs_name.size();
00642
00643 const unsigned int inputs_number = count_inputs_number();
00644
00645 if(size != inputs_number)
00646 {
00647 std::ostringstream buffer;
00648
00649 buffer << "OpenNN Exception: InputsOutputsInformation class.\n"
00650 << "void set_inputs_name(const Vector<std::string>&) method.\n"
00651 << "Size of name of input variables vector must be equal to number of inputs.\n";
00652
00653 throw std::logic_error(buffer.str());
00654 }
00655
00656 #endif
00657
00658
00659
00660 inputs_name = new_inputs_name;
00661 }
00662
00663
00664
00665
00670
00671 void InputsOutputsInformation::set_input_name(const unsigned int& input_index, const std::string& new_input_name)
00672 {
00673 const unsigned int inputs_number = count_inputs_number();
00674
00675
00676
00677 #ifdef _DEBUG
00678
00679 if(input_index >= inputs_number)
00680 {
00681 std::ostringstream buffer;
00682
00683 buffer << "OpenNN Exception: InputsOutputsInformation class.\n"
00684 << "void set_input_name(const unsigned int&, const std::string&) method.\n"
00685 << "Index of input variable must be less than number of inputs.\n";
00686
00687 throw std::logic_error(buffer.str());
00688 }
00689
00690 #endif
00691
00692 if(inputs_name.size() != inputs_number)
00693 {
00694 inputs_name.set(inputs_number);
00695 }
00696
00697
00698
00699 inputs_name[input_index] = new_input_name;
00700 }
00701
00702
00703
00704
00708
00709 void InputsOutputsInformation::set_inputs_units(const Vector<std::string>& new_inputs_units)
00710 {
00711
00712
00713 #ifdef _DEBUG
00714
00715 const unsigned int inputs_number = count_inputs_number();
00716
00717 const unsigned int size = new_inputs_units.size();
00718
00719 if(size != inputs_number)
00720 {
00721 std::ostringstream buffer;
00722
00723 buffer << "OpenNN Exception: InputsOutputsInformation class.\n"
00724 << "void set_inputs_units(const Vector<std::string>&) method.\n"
00725 << "Size must be equal to number of input variables.\n";
00726
00727 throw std::logic_error(buffer.str());
00728 }
00729
00730 #endif
00731
00732
00733
00734 inputs_units = new_inputs_units;
00735 }
00736
00737
00738
00739
00744
00745 void InputsOutputsInformation::set_input_units(const unsigned int& input_index, const std::string& new_input_units)
00746 {
00747 const unsigned int inputs_number = count_inputs_number();
00748
00749
00750
00751 #ifdef _DEBUG
00752
00753 if(input_index >= inputs_number)
00754 {
00755 std::ostringstream buffer;
00756
00757 buffer << "OpenNN Exception: InputsOutputsInformation class.\n"
00758 << "void set_input_units(const unsigned int&, const std::string&) method.\n"
00759 << "Index of input variable must be less than number of inputs.\n";
00760
00761 throw std::logic_error(buffer.str());
00762 }
00763
00764 #endif
00765
00766 if(inputs_units.size() != inputs_number)
00767 {
00768 inputs_units.set(inputs_number);
00769 }
00770
00771
00772
00773 inputs_units[input_index] = new_input_units;
00774 }
00775
00776
00777
00778
00782
00783 void InputsOutputsInformation::set_inputs_description(const Vector<std::string>& new_inputs_description)
00784 {
00785
00786
00787 #ifdef _DEBUG
00788
00789 const unsigned int inputs_number = count_inputs_number();
00790
00791 const unsigned int size = new_inputs_description.size();
00792
00793 if(size != inputs_number)
00794 {
00795 std::ostringstream buffer;
00796
00797 buffer << "OpenNN Exception: InputsOutputsInformation class.\n"
00798 << "void set_inputs_description(const Vector<std::string>&) method.\n"
00799 << "Size must be equal to number of input variables.\n";
00800
00801 throw std::logic_error(buffer.str());
00802 }
00803
00804 #endif
00805
00806
00807
00808 inputs_description = new_inputs_description;
00809 }
00810
00811
00812
00813
00819
00820 void InputsOutputsInformation::set_input_description(const unsigned int& input_index, const std::string& new_input_description)
00821 {
00822 const unsigned int inputs_number = count_inputs_number();
00823
00824
00825
00826 #ifdef _DEBUG
00827
00828 if(input_index >= inputs_number)
00829 {
00830 std::ostringstream buffer;
00831
00832 buffer << "OpenNN Exception: InputsOutputsInformation class.\n"
00833 << "void set_input_description(const unsigned int&, const std::string&) method.\n"
00834 << "Index of input variable must be less than number of inputs.\n";
00835
00836 throw std::logic_error(buffer.str());
00837 }
00838
00839 #endif
00840
00841 if(inputs_description.size() != inputs_number)
00842 {
00843 inputs_description.set(inputs_number);
00844 }
00845
00846
00847
00848 inputs_description[input_index] = new_input_description;
00849 }
00850
00851
00852
00853
00857
00858 void InputsOutputsInformation::set_outputs_name(const Vector<std::string>& new_outputs_name)
00859 {
00860
00861
00862 #ifdef _DEBUG
00863
00864 const unsigned int size = new_outputs_name.size();
00865
00866 const unsigned int outputs_number = count_outputs_number();
00867
00868 if(size != outputs_number)
00869 {
00870 std::ostringstream buffer;
00871
00872 buffer << "OpenNN Exception: InputsOutputsInformation class.\n"
00873 << "void set_outputs_name(const Vector<std::string>&) method.\n"
00874 << "Size of name of outputs vector must be equal to number of output variables.\n";
00875
00876 throw std::logic_error(buffer.str());
00877 }
00878
00879 #endif
00880
00881
00882
00883 outputs_name = new_outputs_name;
00884 }
00885
00886
00887
00888
00893
00894 void InputsOutputsInformation::set_output_name(const unsigned int& output_layer_index, const std::string& new_output_name)
00895 {
00896 const unsigned int outputs_number = count_outputs_number();
00897
00898
00899
00900 #ifdef _DEBUG
00901
00902 if(output_layer_index >= outputs_number)
00903 {
00904 std::ostringstream buffer;
00905
00906 buffer << "OpenNN Exception: InputsOutputsInformation class.\n"
00907 << "void set_output_name(const unsigned int&, const std::string&) method.\n"
00908 << "Index of output variable must be less than number of outputs.\n";
00909
00910 throw std::logic_error(buffer.str());
00911 }
00912
00913 #endif
00914
00915 if(outputs_name.size() != outputs_number)
00916 {
00917 outputs_name.set(outputs_number);
00918 }
00919
00920
00921
00922 outputs_name[output_layer_index] = new_output_name;
00923 }
00924
00925
00926
00927
00931
00932 void InputsOutputsInformation::set_outputs_units(const Vector<std::string>& new_outputs_units)
00933 {
00934
00935
00936 #ifdef _DEBUG
00937
00938 const unsigned int outputs_number = count_outputs_number();
00939
00940 const unsigned int size = new_outputs_units.size();
00941
00942 if(size != outputs_number)
00943 {
00944 std::ostringstream buffer;
00945
00946 buffer << "OpenNN Exception: InputsOutputsInformation class.\n"
00947 << "void set_outputs_units(const Vector<std::string>&) method.\n"
00948 << "Size must be equal to number of output variables.\n";
00949
00950 throw std::logic_error(buffer.str());
00951 }
00952
00953 #endif
00954
00955
00956
00957 outputs_units = new_outputs_units;
00958 }
00959
00960
00961
00962
00967
00968 void InputsOutputsInformation::set_output_units(const unsigned int& output_index, const std::string& new_output_units)
00969 {
00970 const unsigned int outputs_number = count_outputs_number();
00971
00972
00973
00974 #ifdef _DEBUG
00975
00976 if(output_index >= outputs_number)
00977 {
00978 std::ostringstream buffer;
00979
00980 buffer << "OpenNN Exception: InputsOutputsInformation class.\n"
00981 << "void set_output_units(const unsigned int&, const std::string&) method.\n"
00982 << "Index of output variable must be less than number of outputs.\n";
00983
00984 throw std::logic_error(buffer.str());
00985 }
00986
00987 #endif
00988
00989 if(outputs_units.size() != outputs_number)
00990 {
00991 outputs_units.set(outputs_number);
00992 }
00993
00994
00995
00996 outputs_units[output_index] = new_output_units;
00997 }
00998
00999
01000
01001
01005
01006 void InputsOutputsInformation::set_outputs_description(const Vector<std::string>& new_outputs_description)
01007 {
01008
01009
01010 #ifdef _DEBUG
01011
01012 const unsigned int size = new_outputs_description.size();
01013
01014 const unsigned int outputs_number = count_outputs_number();
01015
01016 if(size != outputs_number)
01017 {
01018 std::ostringstream buffer;
01019
01020 buffer << "OpenNN Exception: InputsOutputsInformation class.\n"
01021 << "void set_outputs_description(const Vector<std::string>&) method.\n"
01022 << "Size must be equal to number of outputs.\n";
01023
01024 throw std::logic_error(buffer.str());
01025 }
01026
01027 #endif
01028
01029
01030
01031 outputs_description = new_outputs_description;
01032 }
01033
01034
01035
01036
01041
01042 void InputsOutputsInformation::set_output_description(const unsigned int& output_index, const std::string& new_output_description)
01043 {
01044 const unsigned int outputs_number = count_outputs_number();
01045
01046
01047
01048 #ifdef _DEBUG
01049
01050 if(output_index >= outputs_number)
01051 {
01052 std::ostringstream buffer;
01053
01054 buffer << "OpenNN Exception: InputsOutputsInformation class.\n"
01055 << "void set_output_description(const unsigned int&, const std::string&) method.\n"
01056 << "Index of output variable must be less than number of outputs.\n";
01057
01058 throw std::logic_error(buffer.str());
01059 }
01060
01061 #endif
01062
01063 if(outputs_description.size() != outputs_number)
01064 {
01065 outputs_description.set(outputs_number);
01066 }
01067
01068
01069
01070 outputs_description[output_index] = new_output_description;
01071 }
01072
01073
01074
01075
01087
01088 void InputsOutputsInformation::set_information(const Vector< Vector<std::string> >& new_information)
01089 {
01090
01091
01092 #ifdef _DEBUG
01093
01094 const unsigned int size = new_information.size();
01095
01096 if(size != 6)
01097 {
01098 std::ostringstream buffer;
01099
01100 buffer << "OpenNN Exception: InputsOutputsInformation class.\n"
01101 << "void set_information(const Vector< Vector<std::string> >&) method.\n"
01102 << "Size of vector must be 6.\n";
01103
01104 throw std::logic_error(buffer.str());
01105 }
01106
01107 #endif
01108
01109
01110
01111 set_inputs_name(new_information[0]);
01112 set_inputs_units(new_information[1]);
01113 set_inputs_description(new_information[2]);
01114
01115 set_outputs_name(new_information[3]);
01116 set_outputs_units(new_information[4]);
01117 set_outputs_description(new_information[5]);
01118 }
01119
01120
01121
01122
01127
01128 void InputsOutputsInformation::set_display(const bool& new_display)
01129 {
01130 display = new_display;
01131 }
01132
01133
01134
01135
01137
01138 void InputsOutputsInformation::initialize_random(void)
01139 {
01140
01141 }
01142
01143
01144
01145
01152
01153 Vector<std::string> InputsOutputsInformation::write_default_inputs_name(void) const
01154 {
01155 const unsigned int inputs_number = count_inputs_number();
01156
01157 Vector<std::string> default_inputs_name(inputs_number);
01158
01159 std::ostringstream buffer;
01160
01161 for(unsigned int i = 0; i < inputs_number; i++)
01162 {
01163 if(inputs_name[i] != "")
01164 {
01165 default_inputs_name[i] = inputs_name[i];
01166 }
01167 else
01168 {
01169 buffer.str("");
01170
01171 buffer << "input_" << i+1;
01172
01173 default_inputs_name[i] = buffer.str();
01174 }
01175 }
01176
01177 return(default_inputs_name);
01178 }
01179
01180
01181
01182
01189
01190 Vector<std::string> InputsOutputsInformation::write_default_outputs_name(void) const
01191 {
01192 const unsigned int outputs_number = count_outputs_number();
01193
01194 Vector<std::string> default_outputs_name(outputs_number);
01195
01196 std::ostringstream buffer;
01197
01198 for(unsigned int i = 0; i < outputs_number; i++)
01199 {
01200 if(outputs_name[i] != "")
01201 {
01202 default_outputs_name[i] = outputs_name[i];
01203 }
01204 else
01205 {
01206 buffer.str("");
01207
01208 buffer << "output_" << i+1;
01209
01210 default_outputs_name[i] = buffer.str();
01211 }
01212 }
01213
01214 return(default_outputs_name);
01215 }
01216
01217
01218
01219
01221
01222 std::string InputsOutputsInformation::to_string(void) const
01223 {
01224 std::ostringstream buffer;
01225
01226 buffer << "Inputs outputs information\n"
01227 << "Inputs name:" << inputs_name << "\n"
01228 << "Inputs units:" << inputs_units << "\n"
01229 << "Inputs description:" << inputs_description << "\n"
01230 << "Outputs name:" << outputs_name << "\n"
01231 << "Outputs units:" << outputs_units << "\n"
01232 << "Outputs description:" << outputs_description << "\n"
01233 << "Display:" << display << "\n";
01234
01235 return(buffer.str());
01236 }
01237
01238
01239
01240
01243
01244 TiXmlElement* InputsOutputsInformation::to_XML(void) const
01245 {
01246 const unsigned int inputs_number = count_inputs_number();
01247 const unsigned int outputs_number = count_outputs_number();
01248
01249 std::ostringstream buffer;
01250
01251 TiXmlElement* variables_information_element = new TiXmlElement("InputsOutputsInformation");
01252 variables_information_element->SetAttribute("Version", 4);
01253
01254
01255 {
01256 TiXmlElement* inputs_name_element = new TiXmlElement("InputsName");
01257 variables_information_element->LinkEndChild(inputs_name_element);
01258
01259 Vector<TiXmlElement*> elements(inputs_number);
01260 Vector<TiXmlText*> texts(inputs_number);
01261
01262 for(unsigned int i = 0; i < inputs_number; i++)
01263 {
01264 elements[i] = new TiXmlElement("InputName");
01265 elements[i]->SetAttribute("Index", i+1);
01266 inputs_name_element->LinkEndChild(elements[i]);
01267
01268 texts[i] = new TiXmlText(inputs_name[i].c_str());
01269 elements[i]->LinkEndChild(texts[i]);
01270 }
01271 }
01272
01273
01274 {
01275 TiXmlElement* inputs_units_element = new TiXmlElement("InputsUnits");
01276 variables_information_element->LinkEndChild(inputs_units_element);
01277
01278 Vector<TiXmlElement*> elements(inputs_number);
01279 Vector<TiXmlText*> texts(inputs_number);
01280
01281 for(unsigned int i = 0; i < inputs_number; i++)
01282 {
01283 elements[i] = new TiXmlElement("InputUnits");
01284 elements[i]->SetAttribute("Index", i+1);
01285 inputs_units_element->LinkEndChild(elements[i]);
01286
01287 texts[i] = new TiXmlText(inputs_units[i].c_str());
01288 elements[i]->LinkEndChild(texts[i]);
01289 }
01290 }
01291
01292
01293 {
01294 TiXmlElement* inputs_description_element = new TiXmlElement("InputsDescription");
01295 variables_information_element->LinkEndChild(inputs_description_element);
01296
01297 Vector<TiXmlElement*> elements(inputs_number);
01298 Vector<TiXmlText*> texts(inputs_number);
01299
01300 for(unsigned int i = 0; i < inputs_number; i++)
01301 {
01302 elements[i] = new TiXmlElement("InputDescription");
01303 elements[i]->SetAttribute("Index", i+1);
01304 inputs_description_element->LinkEndChild(elements[i]);
01305
01306 texts[i] = new TiXmlText(inputs_description[i].c_str());
01307 elements[i]->LinkEndChild(texts[i]);
01308 }
01309 }
01310
01311
01312 {
01313 TiXmlElement* outputs_name_element = new TiXmlElement("OutputsName");
01314 variables_information_element->LinkEndChild(outputs_name_element);
01315
01316 TiXmlElement* element;
01317 TiXmlText* text;
01318
01319 for(unsigned int i = 0; i < outputs_number; i++)
01320 {
01321 element = new TiXmlElement("OutputName");
01322 element->SetAttribute("Index", i+1);
01323
01324 outputs_name_element->LinkEndChild(element);
01325
01326 text = new TiXmlText(outputs_name[i].c_str());
01327 element->LinkEndChild(text);
01328 }
01329 }
01330
01331
01332 {
01333 TiXmlElement* outputs_units_element = new TiXmlElement("OutputsUnits");
01334 variables_information_element->LinkEndChild(outputs_units_element);
01335
01336 TiXmlElement* element = NULL;
01337 TiXmlText* text = NULL;
01338
01339 for(unsigned int i = 0; i < outputs_number; i++)
01340 {
01341 element = new TiXmlElement("OutputUnits");
01342 element->SetAttribute("Index", i+1);
01343
01344 outputs_units_element->LinkEndChild(element);
01345
01346 text = new TiXmlText(outputs_units[i].c_str());
01347 element->LinkEndChild(text);
01348 }
01349 }
01350
01351
01352 {
01353 TiXmlElement* outputs_description_element = new TiXmlElement("OutputsDescription");
01354 variables_information_element->LinkEndChild(outputs_description_element);
01355
01356 Vector<TiXmlElement*> elements(outputs_number);
01357 Vector<TiXmlText*> texts(outputs_number);
01358
01359 for(unsigned int i = 0; i < outputs_number; i++)
01360 {
01361 elements[i] = new TiXmlElement("OutputDescription");
01362 elements[i]->SetAttribute("Index", i+1);
01363
01364 outputs_description_element->LinkEndChild(elements[i]);
01365
01366 texts[i] = new TiXmlText(outputs_description[i].c_str());
01367 elements[i]->LinkEndChild(texts[i]);
01368 }
01369 }
01370
01371
01372 {
01373 TiXmlElement* display_element = new TiXmlElement("Display");
01374 variables_information_element->LinkEndChild(display_element);
01375
01376 buffer.str("");
01377 buffer << display;
01378
01379 TiXmlText* display_text = new TiXmlText(buffer.str().c_str());
01380 display_element->LinkEndChild(display_text);
01381 }
01382
01383 return(variables_information_element);
01384 }
01385
01386
01387
01388
01391
01392 void InputsOutputsInformation::from_XML(TiXmlElement* inputs_outputs_information_element)
01393 {
01394 if(inputs_outputs_information_element)
01395 {
01396 int input_index = 0;
01397
01398
01399 {
01400 TiXmlElement* inputs_number_element = inputs_outputs_information_element->FirstChildElement("InputsName");
01401
01402 if(inputs_number_element)
01403 {
01404 TiXmlElement* input_name_element = inputs_number_element->FirstChildElement("InputName");
01405
01406 if(input_name_element)
01407 {
01408 input_name_element->QueryIntAttribute("Index", &input_index);
01409
01410 for( ; input_name_element; input_name_element=input_name_element->NextSiblingElement())
01411 {
01412 input_name_element->QueryIntAttribute("Index", &input_index);
01413 }
01414 }
01415 }
01416 }
01417
01418 const unsigned int inputs_number = input_index;
01419
01420
01421 {
01422 TiXmlElement* inputs_name_element = inputs_outputs_information_element->FirstChildElement("InputsName");
01423
01424 if(inputs_name_element)
01425 {
01426 Vector<std::string> new_inputs_name(inputs_number);
01427
01428 TiXmlElement* input_name_element = inputs_name_element->FirstChildElement("InputName");
01429
01430 if(input_name_element)
01431 {
01432 input_name_element->QueryIntAttribute("Index", &input_index);
01433
01434 if(input_name_element->GetText())
01435 {
01436 new_inputs_name[input_index-1] = input_name_element->GetText();
01437 }
01438
01439 for( ; input_name_element; input_name_element=input_name_element->NextSiblingElement())
01440 {
01441 input_name_element->QueryIntAttribute("Index", &input_index);
01442
01443 if(input_name_element->GetText())
01444 {
01445 new_inputs_name[input_index-1] = input_name_element->GetText();
01446 }
01447 }
01448 }
01449
01450 try
01451 {
01452 set_inputs_name(new_inputs_name);
01453 }
01454 catch(std::exception& e)
01455 {
01456 std::cout << e.what() << std::endl;
01457 }
01458 }
01459 }
01460
01461
01462 {
01463 TiXmlElement* inputs_units_element = inputs_outputs_information_element->FirstChildElement("InputsUnits");
01464
01465 if(inputs_units_element)
01466 {
01467 Vector<std::string> new_inputs_units(inputs_number);
01468
01469 TiXmlElement* input_units_element = inputs_units_element->FirstChildElement("InputUnits");
01470
01471 if(input_units_element)
01472 {
01473 input_units_element->QueryIntAttribute("Index", &input_index);
01474
01475 if(input_units_element->GetText())
01476 {
01477 new_inputs_units[input_index-1] = input_units_element->GetText();
01478 }
01479
01480 for( ; input_units_element; input_units_element=input_units_element->NextSiblingElement())
01481 {
01482 input_units_element->QueryIntAttribute("Index", &input_index);
01483
01484 if(input_units_element->GetText())
01485 {
01486 new_inputs_units[input_index-1] = input_units_element->GetText();
01487 }
01488 }
01489 }
01490
01491 try
01492 {
01493 set_inputs_units(new_inputs_units);
01494 }
01495 catch(std::exception& e)
01496 {
01497 std::cout << e.what() << std::endl;
01498 }
01499 }
01500 }
01501
01502
01503 {
01504 TiXmlElement* inputs_description_element = inputs_outputs_information_element->FirstChildElement("InputsDescription");
01505
01506 if(inputs_description_element)
01507 {
01508 Vector<std::string> new_inputs_description(inputs_number);
01509
01510 TiXmlElement* input_description_element = inputs_description_element->FirstChildElement("InputDescription");
01511
01512 if(input_description_element)
01513 {
01514 input_description_element->QueryIntAttribute("Index", &input_index);
01515
01516 if(input_description_element->GetText())
01517 {
01518 new_inputs_description[input_index-1] = input_description_element->GetText();
01519 }
01520
01521 for( ; input_description_element; input_description_element=input_description_element->NextSiblingElement())
01522 {
01523 input_description_element->QueryIntAttribute("Index", &input_index);
01524
01525 if(input_description_element->GetText())
01526 {
01527 new_inputs_description[input_index-1] = input_description_element->GetText();
01528 }
01529 }
01530 }
01531
01532 try
01533 {
01534 set_inputs_description(new_inputs_description);
01535 }
01536 catch(std::exception& e)
01537 {
01538 std::cout << e.what() << std::endl;
01539 }
01540 }
01541 }
01542
01543 int output_index = 0;
01544
01545
01546 {
01547 TiXmlElement* inputs_number_element = inputs_outputs_information_element->FirstChildElement("OutputsName");
01548
01549 if(inputs_number_element)
01550 {
01551 TiXmlElement* input_name_element = inputs_number_element->FirstChildElement("OutputName");
01552
01553 if(input_name_element)
01554 {
01555 input_name_element->QueryIntAttribute("Index", &output_index);
01556
01557 for( ; input_name_element; input_name_element=input_name_element->NextSiblingElement())
01558 {
01559 input_name_element->QueryIntAttribute("Index", &output_index);
01560 }
01561 }
01562 }
01563 }
01564
01565 const unsigned int outputs_number = output_index;
01566
01567
01568 {
01569 TiXmlElement* outputs_name_element = inputs_outputs_information_element->FirstChildElement("OutputsName");
01570
01571 if(outputs_name_element)
01572 {
01573 Vector<std::string> new_outputs_name(outputs_number);
01574
01575 TiXmlElement* output_name_element = outputs_name_element->FirstChildElement("OutputName");
01576
01577 if(output_name_element)
01578 {
01579 output_name_element->QueryIntAttribute("Index", &output_index);
01580 new_outputs_name[output_index-1] = output_name_element->GetText();
01581
01582 for( ; output_name_element; output_name_element=output_name_element->NextSiblingElement())
01583 {
01584 output_name_element->QueryIntAttribute("Index", &output_index);
01585 new_outputs_name[output_index-1] = output_name_element->GetText();
01586 }
01587 }
01588
01589 try
01590 {
01591 set_outputs_name(new_outputs_name);
01592 }
01593 catch(std::exception& e)
01594 {
01595 std::cout << e.what() << std::endl;
01596 }
01597 }
01598 }
01599
01600
01601 {
01602 TiXmlElement* outputs_units_element = inputs_outputs_information_element->FirstChildElement("OutputsUnits");
01603
01604 if(outputs_units_element)
01605 {
01606 Vector<std::string> new_outputs_units(outputs_number);
01607
01608 TiXmlElement* output_units_element = outputs_units_element->FirstChildElement("OutputUnits");
01609
01610 if(output_units_element)
01611 {
01612 output_units_element->QueryIntAttribute("Index", &output_index);
01613
01614 if(output_units_element->GetText())
01615 {
01616 new_outputs_units[output_index-1] = output_units_element->GetText();
01617 }
01618
01619 for( ; output_units_element; output_units_element=output_units_element->NextSiblingElement())
01620 {
01621 output_units_element->QueryIntAttribute("Index", &output_index);
01622
01623 if(output_units_element->GetText())
01624 {
01625 new_outputs_units[output_index-1] = output_units_element->GetText();
01626 }
01627 }
01628 }
01629
01630 try
01631 {
01632 set_outputs_units(new_outputs_units);
01633 }
01634 catch(std::exception& e)
01635 {
01636 std::cout << e.what() << std::endl;
01637 }
01638 }
01639 }
01640
01641
01642 {
01643 TiXmlElement* outputs_description_element = inputs_outputs_information_element->FirstChildElement("OutputsDescription");
01644
01645 if(outputs_description_element)
01646 {
01647 Vector<std::string> new_outputs_description(outputs_number);
01648
01649 TiXmlElement* output_description_element = outputs_description_element->FirstChildElement("OutputDescription");
01650
01651 if(output_description_element)
01652 {
01653 output_description_element->QueryIntAttribute("Index", &output_index);
01654
01655 if(output_description_element->GetText())
01656 {
01657 new_outputs_description[output_index-1] = output_description_element->GetText();
01658 }
01659
01660 for( ; output_description_element; output_description_element=output_description_element->NextSiblingElement())
01661 {
01662 output_description_element->QueryIntAttribute("Index", &output_index);
01663
01664 if(output_description_element->GetText())
01665 {
01666 new_outputs_description[output_index-1] = output_description_element->GetText();
01667 }
01668 }
01669 }
01670
01671 try
01672 {
01673 set_outputs_description(new_outputs_description);
01674 }
01675 catch(std::exception& e)
01676 {
01677 std::cout << e.what() << std::endl;
01678 }
01679 }
01680 }
01681
01682 }
01683 }
01684
01685 }
01686
01687
01688
01689
01690
01691
01692
01693
01694
01695
01696
01697
01698
01699
01700
01701
01702