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 #ifndef OPENMS_DATASTRUCTURES_PARAM_H
00028 #define OPENMS_DATASTRUCTURES_PARAM_H
00029
00030
00031 #include <OpenMS/CONCEPT/Types.h>
00032 #include <OpenMS/DATASTRUCTURES/DataValue.h>
00033 #include <OpenMS/DATASTRUCTURES/String.h>
00034 #include <OpenMS/CONCEPT/Exception.h>
00035 #include <OpenMS/FORMAT/XMLFile.h>
00036
00037 #include <map>
00038 #include <iostream>
00039
00040
00041 namespace OpenMS
00042 {
00062 class Param
00063 : public Internal::XMLFile
00064 {
00065 public:
00066
00068 struct ParamEntry
00069 {
00071 ParamEntry();
00073 ParamEntry(const String& n, const DataValue& v, const String& d, bool a);
00075 bool operator==(const ParamEntry& rhs) const;
00076
00078 String name;
00080 String description;
00082 DataValue value;
00084 bool advanced;
00086
00087 DoubleReal min_float;
00088 DoubleReal max_float;
00089 Int min_int;
00090 Int max_int;
00091 std::vector<String> valid_strings;
00092
00093 };
00094
00096 struct ParamNode
00097 {
00099 typedef std::vector<ParamNode>::iterator NodeIterator;
00101 typedef std::vector<ParamEntry>::iterator EntryIterator;
00102
00104 ParamNode();
00106 ParamNode(const String& n, const String& d);
00108 bool operator==(const ParamNode& rhs) const;
00109
00115 EntryIterator findEntry(const String& name);
00121 NodeIterator findNode(const String& name);
00127 ParamNode* findParentOf(const String& name);
00133 ParamEntry* findEntryRecursive(const String& name);
00134
00136 void insert(const ParamNode& node, const String& prefix = "");
00138 void insert(const ParamEntry& entry, const String& prefix = "");
00140 UInt size() const;
00142 String suffix(const String& key) const;
00143
00145 String name;
00147 String description;
00149 std::vector<ParamEntry> entries;
00151 std::vector<ParamNode> nodes;
00152 };
00153
00154 public:
00155
00157 class ParamIterator
00158 {
00159 public:
00161 struct TraceInfo
00162 {
00163 inline TraceInfo(const String& n, const String& d, bool o)
00164 : name(n),
00165 description(d),
00166 opened(o)
00167 {
00168 }
00170 String name;
00172 String description;
00174 bool opened;
00175 };
00176
00178 ParamIterator();
00180 ParamIterator(const Param::ParamNode& root);
00182 const Param::ParamEntry& operator*();
00184 const Param::ParamEntry* operator->();
00186 ParamIterator& operator++();
00188 ParamIterator operator++(Int);
00190 bool operator==(const ParamIterator& rhs) const;
00192 bool operator!=(const ParamIterator& rhs) const;
00194 String getName() const;
00196 const std::vector< TraceInfo >& getTrace() const;
00197
00198 protected:
00200 const Param::ParamNode* root_;
00202 Int current_;
00204 std::vector<const Param::ParamNode*> stack_;
00206 std::vector< TraceInfo > trace_;
00207
00208 };
00209
00213
00214 Param();
00215
00217 Param(const Param& rhs);
00218
00220 ~Param();
00222
00224 Param& operator = (const Param& rhs);
00225
00227 bool operator == (const Param& rhs) const;
00228
00230
00231
00239 void setValue(const String& key, Int value, const String& description="", bool advanced=false);
00248 void setValue(const String& key, UInt value, const String& description="", bool advanced=false);
00257 void setValue(const String& key, Real value, const String& description="", bool advanced=false);
00266 void setValue(const String& key, DoubleReal value, const String& description="", bool advanced=false);
00275 void setValue(const String& key, const String& value, const String& description="", bool advanced=false);
00276
00282 const DataValue& getValue(const String& key) const throw (Exception::ElementNotFound<String>);
00288 const ParamEntry& getEntry(const String& key) const throw (Exception::ElementNotFound<String>);
00294 const String& getDescription(const String& key) const throw (Exception::ElementNotFound<String>);
00303 bool isAdvancedParameter(const String& key) const throw (Exception::ElementNotFound<String>);
00310 void setSectionDescription(const String& key, const String& description) throw (Exception::ElementNotFound<String>);
00316 const String& getSectionDescription(const String& key) const;
00318 ParamIterator begin() const;
00320 ParamIterator end() const;
00322 bool exists(const String& key) const;
00324
00326
00327
00328 UInt size() const;
00330 bool empty() const;
00332 void clear();
00334 void insert(String prefix, const Param& param);
00336 void remove(const String& prefix);
00344 Param copy(const String& prefix, bool remove_prefix=false) const;
00346
00348
00349
00358 void setDefaults(const Param& defaults, String prefix="", bool showMessage=false);
00373 void checkDefaults(const String& name, const Param& defaults, String prefix="", std::ostream& os = std::cout) const throw (Exception::InvalidParameter);
00382 void setValidStrings(const String& key, const std::vector<String>& strings) throw (Exception::ElementNotFound<String>,Exception::InvalidParameter);
00389 void setMinInt(const String& key, Int min) throw (Exception::ElementNotFound<String>);
00396 void setMaxInt(const String& key, Int max) throw (Exception::ElementNotFound<String>);
00403 void setMinFloat(const String& key, DoubleReal min) throw (Exception::ElementNotFound<String>);
00410 void setMaxFloat(const String& key, DoubleReal max) throw (Exception::ElementNotFound<String>);
00412
00414
00415
00433 void parseCommandLine(const int argc , const char** argv, String prefix = "");
00444 void parseCommandLine(const int argc , const char** argv, const std::map<String, String>& options_with_argument, const std::map<String, String>& options_without_argument, const String& misc="misc", const String& unknown="unknown");
00446
00448
00449
00450 void store(const String& filename) const throw (Exception::UnableToCreateFile);
00452 void load(const String& filename) throw (Exception::FileNotFound,Exception::ParseError);
00454
00455 protected:
00457 ParamEntry& getEntry_(const String& key) const throw (Exception::ElementNotFound<String>);
00458
00460 Param(const Param::ParamNode& node);
00461
00463 mutable Param::ParamNode root_;
00464 };
00465
00467 std::ostream& operator<< (std::ostream& os, const Param& param);
00468
00469
00470 }
00471
00472 #endif // OPENMS_DATASTRUCTURES_PARAM_H