00001 // -*- Mode: C++; tab-width: 2; -*- 00002 // vi: set ts=2: 00003 // 00004 // $Id: parameterSection.h,v 1.25 2005/12/23 17:01:46 amoll Exp $ 00005 // 00006 00007 // Format: general parameter section class 00008 00009 #ifndef BALL_FORMAT_PARAMETERSECTION_H 00010 #define BALL_FORMAT_PARAMETERSECTION_H 00011 00012 #ifndef BALL_DATATYPE_OPTIONS_H 00013 # include <BALL/DATATYPE/options.h> 00014 #endif 00015 00016 namespace BALL 00017 { 00018 class Parameters; 00019 00039 class BALL_EXPORT ParameterSection 00040 { 00041 public: 00042 00043 BALL_CREATE(ParameterSection) 00044 00045 00046 00048 static const String UNDEFINED; 00049 00050 00054 00056 enum 00057 { 00058 MAX_FIELDS = 20 00059 }; 00060 00062 00066 00069 ParameterSection() ; 00070 00073 ParameterSection(const ParameterSection& parameter_section) ; 00074 00077 virtual ~ParameterSection() ; 00078 00080 00083 00092 bool extractSection(Parameters& parameters, const String& section_name) 00093 ; 00094 00099 const String& getSectionName() const 00100 ; 00101 00106 const String& getValue(const String& key, const String& variable) const 00107 ; 00108 00117 bool has(const String& key, const String& variable) const ; 00118 00123 bool has(const String& key) const ; 00124 00127 bool hasVariable(const String& variable) const ; 00128 00133 Position getColumnIndex(const String& variable) const ; 00134 00137 Size getNumberOfVariables() const ; 00138 00141 Size getNumberOfKeys() const ; 00142 00146 const String& getValue(Position key_index, Position variable_index) 00147 const ; 00148 00153 const String& getKey(Position key_index) const ; 00154 00156 00159 00162 virtual void clear() 00163 ; 00164 00167 const ParameterSection& operator = (const ParameterSection& section) 00168 ; 00169 00171 00174 00177 virtual bool isValid() const ; 00178 00181 bool operator == (const ParameterSection& parameter_section) const 00182 ; 00183 00185 00188 00193 Options options; 00194 00196 00197 protected: 00198 00199 /*_ The name of the section. 00200 */ 00201 String section_name_; 00202 00203 /*_ The format line. 00204 */ 00205 String format_line_; 00206 00207 /*_ String hash map containing an index for each key. 00208 This index is the index for the entries_ array. 00209 */ 00210 StringHashMap<Index> section_entries_; 00211 00212 /*_ String has map relating a variable name to the index in entries_. 00213 */ 00214 StringHashMap<Index> variable_names_; 00215 00216 /*_ One-dimensional array of the values read from the section. 00217 The index of a specific value is calculated as 00218 section_entries_[key] * number_of_variables_ * variable_names_[name] 00219 */ 00220 std::vector<String> entries_; 00221 00222 /*_ One-dimensional array of the keys read from the section. 00223 */ 00224 std::vector<String> keys_; 00225 00226 /*_ The number of variables specified in the format line. 00227 Variables also include "ver:" entries. 00228 */ 00229 Size number_of_variables_; 00230 00231 /*_ The version numbers of each key. 00232 */ 00233 std::vector<float> version_; 00234 00235 /*_ The valid flag. 00236 */ 00237 bool valid_; 00238 00239 }; 00240 } // namespace BALL 00241 00242 #endif // BALL_FORMAT_PARAMETERSECTION_H