00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045 #ifndef CONFIG_H
00046 #define CONFIG_H
00047
00048
00049
00050
00051
00052
00053
00054 static const char header_config_rcsid[] = "$Id: config.h,v 1.9 2004/09/01 19:51:04 ejt Exp $";
00055
00056
00057 #ifdef _MSC_VER // Microsoft
00058 #pragma warning (disable:4786) // Disable decorated name truncation warnings
00059 #pragma warning (disable:4503) // Disable decorated name truncation warnings
00060 #endif
00061 #include <iostream>
00062 #include <string>
00063 #include <iomanip>
00064 #include <fstream>
00065 #ifdef __WATCOMC__
00066 #include <strstrea.h>
00067 #else
00068 #include <sstream>
00069 #endif
00070 #include <vector>
00071
00072 #include "utils.h"
00073 #ifdef use_namespace
00074 namespace ROBOOP {
00075 using namespace NEWMAT;
00076 #endif
00077
00078
00079 #define CAN_NOT_OPEN_FILE -1
00080
00081
00082 #define CAN_NOT_CREATE_FILE -2
00083
00084
00085 #define SECTION_OR_PARAMETER_DOES_NOT_EXIST -3
00086
00087 #ifndef __WATCOMC__
00088 using namespace std;
00089 #endif
00090
00091
00092
00093 typedef struct Data{
00094 Data() : section(), parameter(), value() {}
00095 string section;
00096 string parameter;
00097 string value;
00098 } Data;
00099
00100
00101 typedef vector< Data > Conf_data;
00102
00103
00104 class Config {
00105 public:
00106 Config() : conf(), filename() {}
00107 Config(const string & filename_,bool doRead=false);
00108 Config(const Config & x);
00109 Config & operator=(const Config & x);
00110 short read_conf();
00111 void print();
00112
00113 bool section_exists(const string& section) const;
00114 bool parameter_exists(const string& section, const string& parameter) const;
00115
00116 short select_string(const string section, const string parameter,
00117 string & value) const;
00118 short select_bool(const string section, const string parameter,
00119 bool & value) const;
00120 short select_short(const string section, const string parameter,
00121 short & value) const;
00122 short select_int(const string section, const string parameter,
00123 int & value) const;
00124 short select_float(const string section, const string parameter,
00125 float & value) const;
00126 short select_double(const string section, const string parameter,
00127 double & value) const;
00128 short select_real(const string section, const string parameter,
00129 Real & value) const;
00130
00131 short write_conf(const string name, const string file_title,
00132 const int space_between_column);
00133 void add_string(const string section, const string parameter,
00134 const string value);
00135 void add_bool(const string section, const string parameter,
00136 const bool value);
00137 void add_int(const string section, const string parameter,
00138 const int value);
00139 void add_float(const string section, const string parameter,
00140 const float value);
00141 void add_double(const string section, const string parameter,
00142 const double value);
00143 void add_real(const string section, const string parameter,
00144 const Real value);
00145
00146 private:
00147 Conf_data conf;
00148 string filename;
00149 };
00150
00151 #ifdef use_namespace
00152 }
00153 #endif
00154
00155 #endif
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173