00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef PARSEOPTIONS_H
00017
00018 #define PARSEOPTIONS_H
00019
00020 #include "common.h"
00021 #include "Vector.h"
00022
00023 class StringList;
00024 class ConfigList;
00025
00026 enum Range { FREE_RANGE, POSITIVE, NOT_NEGATIVE , NEGATIVE, NOT_POSITIVE };
00027
00028 enum Units { N_UNIT, N_FSEC, N_NSEC, N_SEC, N_MIN, N_HOUR, N_ANGSTROM, N_NANOMETER, N_METER,
00029 N_KCAL, N_KJOULE, N_EV, N_KELVIN, N_UNITS_UNDEFINED};
00030
00031 BigReal convert(Units to, Units from);
00032
00033 #define PARSE_FLOAT (BigReal *) NULL
00034 #define PARSE_BIGREAL (BigReal *) NULL
00035 #define PARSE_VECTOR (Vector *) NULL
00036 #define PARSE_INT (int *) NULL
00037 #define PARSE_BOOL (int *) NULL
00038 #define PARSE_STRING (char *) NULL
00039 #define PARSE_ANYTHING (StringList **) NULL
00040 #define PARSE_MULTIPLES (StringList **) NULL, TRUE
00041
00042 class ParseOptions {
00043 public:
00044
00045 class DataElement {
00046 public:
00047 enum data_types {UNDEF, FLOAT, VECTOR, UINT, INT, BOOL, STRINGLIST, STRING};
00048 int index;
00049 char *name;
00050 int is_optional;
00051 int is_defined;
00052 char *parent;
00053 DataElement *parent_ptr;
00054 char *error_message;
00055 data_types type;
00056 int has_default;
00057 int many_allowed;
00058 union {
00059 BigReal fdef;
00060 int idef;
00061 unsigned int uidef;
00062
00063 };
00064 Vector vdef;
00065 union {
00066 BigReal *fptr;
00067 int *iptr;
00068 unsigned int *uiptr;
00069 Vector *vptr;
00070 StringList **slptr;
00071 char *sptr;
00072 };
00073 union {
00074 BigReal fdata;
00075 int idata;
00076 int uidata;
00077 StringList *sldata;
00078 };
00079 Vector vdata;
00080 Range range;
00081 Units units;
00082
00083 private:
00084 void init(const char *newname, const char *newparent, int optional,
00085 const char *err);
00086 public:
00087 ~DataElement(void);
00088
00089 DataElement(const char *newname, const char *newparent, int optional,
00090 const char *err, BigReal *ptr, BigReal defalt);
00091 DataElement(const char *newname, const char *newparent, int optional,
00092 const char *err, BigReal *ptr);
00093
00094 DataElement(const char *newname, const char *newparent, int optional,
00095 const char *err, Vector *ptr, Vector defalt);
00096 DataElement(const char *newname, const char *newparent, int optional,
00097 const char *err, Vector *ptr);
00098
00099
00100 DataElement(const char *newname, const char *newparent, int optional,
00101 const char *err, int *ptr, int defalt);
00102 DataElement(const char *newname, const char *newparent, int optional,
00103 const char *err, int *ptr);
00104
00105
00106 DataElement(const char *newname, const char *newparent, int optional,
00107 const char *err, unsigned int *ptr, unsigned int defalt);
00108 DataElement(const char *newname, const char *newparent, int optional,
00109 const char *err, unsigned int *ptr);
00110
00111
00112 DataElement(const char *newname, const char *newparent, int optional,
00113 const char *err, StringList **ptr, int many_allowed = FALSE);
00114
00115 DataElement(const char *newname, const char *newparent, int optional,
00116 const char *err, char *ptr);
00117 };
00118 private:
00119 ConfigList const *configList;
00120 DataElement **data_array;
00121 int array_size;
00122 int array_max_size;
00123 void add_element(DataElement *el);
00124 int make_dependencies(DataElement *el);
00125
00126
00127
00128 int atoBool(const char *s);
00129
00130 Units atoUnits(const char *s);
00131
00132
00133 Bool is_parent_node(DataElement *el);
00134
00135 public:
00136 ParseOptions(void);
00137 ~ParseOptions(void);
00138
00139
00140
00141 int require(const char *newname, const char *parent, const char *msg,
00142 BigReal *ptr, BigReal defalt);
00143 int require(const char *newname, const char *parent, const char *msg,
00144 BigReal *ptr);
00145
00146 int require(const char *newname, const char *parent, const char *msg,
00147 Vector *ptr, Vector defalt);
00148 int require(const char *newname, const char *parent, const char *msg,
00149 Vector *ptr);
00150
00151 int require(const char *newname, const char *parent, const char *msg,
00152 int *ptr, int defalt);
00153 int require(const char *newname, const char *parent, const char *msg,
00154 int *ptr);
00155
00156 int require(const char *newname, const char *parent, const char *msg,
00157 unsigned int *ptr, unsigned int defalt);
00158 int require(const char *newname, const char *parent, const char *msg,
00159 unsigned int *ptr);
00160
00161
00162
00163
00164 int requireB(const char *newname, const char *parent, const char *msg,
00165 int *ptr, int defalt);
00166 int requireB(const char *newname, const char *parent, const char *msg,
00167 int *ptr);
00168
00169 int require(const char *newname, const char *parent, const char *msg,
00170 StringList **ptr = NULL, int many_allowed = FALSE);
00171
00172 int require(const char *newname, const char *parent, const char *msg,
00173 char *ptr);
00174
00175 int optional(const char *newname, const char *parent, const char *msg,
00176 BigReal *ptr, BigReal defalt);
00177 int optional(const char *newname, const char *parent, const char *msg,
00178 BigReal *ptr);
00179
00180 int optional(const char *newname, const char *parent, const char *msg,
00181 Vector *ptr, Vector defalt);
00182 int optional(const char *newname, const char *parent, const char *msg,
00183 Vector *ptr);
00184
00185 int optional(const char *newname, const char *parent, const char *msg,
00186 int *ptr, int defalt);
00187 int optional(const char *newname, const char *parent, const char *msg,
00188 int *ptr);
00189
00190 int optional(const char *newname, const char *parent, const char *msg,
00191 unsigned int *ptr, unsigned int defalt);
00192 int optional(const char *newname, const char *parent, const char *msg,
00193 unsigned int *ptr);
00194
00195 int optionalB(const char *newname, const char *parent, const char *msg,
00196 int *ptr, int defalt);
00197 int optionalB(const char *newname, const char *parent, const char *msg,
00198 int *ptr);
00199
00200 int optional(const char *newname, const char *parent, const char *msg,
00201 StringList **ptr = NULL, int many_allowed = FALSE);
00202 int optional(const char *newname, const char *parent, const char *msg,
00203 char *ptr);
00204
00205
00206
00207 Range range(const char *name);
00208
00209 void range(const char *name, Range newrange);
00210 private:
00211
00212 int check_children(int idx, int *flg);
00213
00214
00215 Bool scan_float(DataElement *el, const char *s);
00216 Bool scan_int(DataElement *el, const char *s);
00217 Bool scan_uint(DataElement *el, const char *s);
00218 Bool scan_bool(DataElement *el, const char *s);
00219 Bool scan_vector(DataElement *el, const char *s);
00220
00221
00222
00223 Bool set_float(DataElement *el);
00224 void set_vector(DataElement *el);
00225 Bool set_int(DataElement *el);
00226 Bool set_uint(DataElement *el);
00227 void set_bool(DataElement *el);
00228 void set_stringlist(DataElement *el);
00229 void set_string(DataElement *el);
00230 public:
00231
00232 Bool check_consistancy(void);
00233
00234 Bool set(const ConfigList& configlist);
00235
00236
00237 private:
00238 DataElement *internal_find(const char *name);
00239 public:
00240
00241
00242 Bool get(const char* name, int *val);
00243 Bool get(const char* name, BigReal *val);
00244 Bool get(const char* name, Vector *val);
00245 Bool get(const char* name, StringList **val);
00246 Bool get(const char* name, char *val, int n=0);
00247
00248
00249 int num(const char* name);
00250
00251 Bool defined(const char *name);
00252 Bool exists(const char *name);
00253
00254
00255 Bool units(const char *name, Units units);
00256 Bool units(const char *name, Units *units);
00257 };
00258
00259 #endif
00260