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 #ifndef TABLE_H
00034 #define TABLE_H
00035
00036 #include "std_cpp_includes.hh"
00037 #include "except.hh"
00038 #include "utility.hh"
00039
00040 namespace RVL {
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059 class Table {
00060
00061 private:
00062
00063 typedef map<string,string> str_map;
00064 typedef str_map::iterator iterator;
00065 typedef str_map::const_iterator const_iterator;
00066 typedef str_map::value_type value_type;
00067
00068 string prefixes;
00069 str_map table;
00070
00071 static bool isPunct(char c);
00072 static string stripWord(const string word);
00073
00074 public:
00075
00076
00077 Table(string fname="",string prefixes="");
00078
00079
00080 Table(const Table & T);
00081
00082
00083 virtual ~Table();
00084
00085
00086 int mergeFile(string fname);
00087
00088
00089 int getSize() const { return table.size(); }
00090
00091
00092 string getKey(unsigned i);
00093
00094
00095 string strValue(string key);
00096
00097
00098 int getValue(string key,int & value) const;
00099 int getValue(string key,double & value) const;
00100 int getValue(string key,float & value) const;
00101 int getValue(string key,string & value,int length=0) const;
00102
00103
00104 void putValue(string key,int value);
00105 void putValue(string key,float value);
00106 void putValue(string key,double value);
00107 void putValue(string key,const string value);
00108
00109
00110 int getArrayValue(string key,int ind,int & value) const;
00111 int getArrayValue(string key,int ind,float & value) const;
00112 int getArrayValue(string key,int ind,double & value) const;
00113 int getArrayValue(string key,int ind,string & value,int length=0) const;
00114
00115
00116 void putArrayValue(string key,int ind,int value);
00117 void putArrayValue(string key,int ind,float value);
00118 void putArrayValue(string key,int ind,double value);
00119 void putArrayValue(string key,int ind,const string value);
00120
00121 ostream & write(ostream & os);
00122
00123 };
00124
00125 ostream & operator << (ostream & os,Table & t);
00126
00127
00128
00129 string getStringFromTable(Table const & par, string key);
00130 int getIntFromTable(Table const & par, string key);
00131 float getFloatFromTable(Table const & par, string key);
00132 double getDoubleFromTable(Table const & par, string key);
00133
00134 template<typename Scalar>
00135 Scalar getValueFromTable(Table const & par, string key);
00136
00137 template<>
00138 int getValueFromTable<int>(Table const & par, string key);
00139
00140 template<>
00141 double getValueFromTable<double>(Table const & par, string key);
00142
00143 template<>
00144 float getValueFromTable<float>(Table const & par, string key);
00145
00146 template<>
00147 string getValueFromTable<string>(Table const & par, string key);
00148
00149 template<>
00150 bool getValueFromTable<bool>(Table const & par, string key);
00151
00152 }
00153
00154 #endif
00155
00156