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 #ifndef OPENMS_DATASTRUCTURES_PARAM_H
00036 #define OPENMS_DATASTRUCTURES_PARAM_H
00037
00038
00039 #include <OpenMS/CONCEPT/Exception.h>
00040 #include <OpenMS/CONCEPT/LogStream.h>
00041 #include <OpenMS/CONCEPT/Types.h>
00042 #include <OpenMS/DATASTRUCTURES/DataValue.h>
00043 #include <OpenMS/DATASTRUCTURES/String.h>
00044 #include <OpenMS/DATASTRUCTURES/Map.h>
00045
00046 #include <set>
00047 #include <iostream>
00048
00049
00050 namespace OpenMS
00051 {
00052 struct ParameterInformation;
00053
00071 class OPENMS_DLLAPI Param
00072 {
00073 public:
00074
00076 struct OPENMS_DLLAPI ParamEntry
00077 {
00079 ParamEntry();
00081 ParamEntry(const String& n, const DataValue& v, const String& d, const StringList& t = StringList());
00083 ~ParamEntry();
00084
00086 bool isValid(String& message) const;
00088 bool operator==(const ParamEntry& rhs) const;
00089
00091 String name;
00093 String description;
00095 DataValue value;
00097 std::set<String> tags;
00099
00100 DoubleReal min_float;
00101 DoubleReal max_float;
00102 Int min_int;
00103 Int max_int;
00104 std::vector<String> valid_strings;
00105
00106 };
00107
00109 struct OPENMS_DLLAPI ParamNode
00110 {
00112 typedef std::vector<ParamNode>::iterator NodeIterator;
00114 typedef std::vector<ParamEntry>::iterator EntryIterator;
00116 typedef std::vector<ParamNode>::const_iterator ConstNodeIterator;
00118 typedef std::vector<ParamEntry>::const_iterator ConstEntryIterator;
00119
00121 ParamNode();
00123 ParamNode(const String& n, const String& d);
00125 ~ParamNode();
00127 bool operator==(const ParamNode& rhs) const;
00128
00134 EntryIterator findEntry(const String& name);
00140 NodeIterator findNode(const String& name);
00146 ParamNode* findParentOf(const String& name);
00152 ParamEntry* findEntryRecursive(const String& name);
00153
00155 void insert(const ParamNode& node, const String& prefix = "");
00157 void insert(const ParamEntry& entry, const String& prefix = "");
00159 Size size() const;
00161 String suffix(const String& key) const;
00162
00164 String name;
00166 String description;
00168 std::vector<ParamEntry> entries;
00170 std::vector<ParamNode> nodes;
00171 };
00172
00173 public:
00174
00176 class OPENMS_DLLAPI ParamIterator
00177 {
00178 public:
00180 struct OPENMS_DLLAPI TraceInfo
00181 {
00183 inline TraceInfo(const String& n, const String& d, bool o) :
00184 name(n),
00185 description(d),
00186 opened(o)
00187 {
00188 }
00189
00191 String name;
00193 String description;
00195 bool opened;
00196 };
00197
00199 ParamIterator();
00201 ParamIterator(const Param::ParamNode& root);
00203 ~ParamIterator();
00205 const Param::ParamEntry& operator*();
00207 const Param::ParamEntry* operator->();
00209 ParamIterator& operator++();
00211 ParamIterator operator++(int);
00213 bool operator==(const ParamIterator& rhs) const;
00215 bool operator!=(const ParamIterator& rhs) const;
00217 String getName() const;
00219 const std::vector<TraceInfo>& getTrace() const;
00220
00221 protected:
00223 const Param::ParamNode* root_;
00225 Int current_;
00227 std::vector<const Param::ParamNode*> stack_;
00229 std::vector<TraceInfo> trace_;
00230
00231 };
00232
00234 Param();
00235
00237 Param(const Param& rhs);
00238
00240 ~Param();
00241
00243 Param& operator=(const Param& rhs);
00244
00246 bool operator==(const Param& rhs) const;
00247
00249 ParamIterator begin() const;
00250
00252 ParamIterator end() const;
00253
00255
00256
00265 void setValue(const String& key, const DataValue& value, const String& description = "", const StringList& tags = StringList());
00266
00272 const DataValue& getValue(const String& key) const;
00273
00279 const ParamEntry& getEntry(const String& key) const;
00280
00282 bool exists(const String& key) const;
00283
00286 ParamIterator findFirst(const String& leaf) const;
00287
00290 ParamIterator findNext(const String& leaf, const ParamIterator& start_leaf) const;
00291
00292
00293
00295
00297
00298
00305 void addTag(const String& key, const String& tag);
00306
00313 void addTags(const String& key, const StringList& tags);
00314
00323 bool hasTag(const String& key, const String& tag) const;
00324
00330 StringList getTags(const String& key) const;
00331
00337 void clearTags(const String& key);
00339
00340
00342
00343
00349 const String& getDescription(const String& key) const;
00350
00359 void setSectionDescription(const String& key, const String& description);
00360
00366 const String& getSectionDescription(const String& key) const;
00368
00370
00371
00373 Size size() const;
00374
00376 bool empty() const;
00377
00379 void clear();
00380
00383 void insert(const String& prefix, const Param& param);
00384
00394 void remove(const String& key);
00395
00404 void removeAll(const String& prefix);
00405
00413 Param copy(const String& prefix, bool remove_prefix = false) const;
00414
00430 void update(const Param& old_version, const bool add_unknown = false, Logger::LogStream& stream = LOG_WARN);
00431
00437 void merge(const Param& toMerge);
00438
00440
00441
00443
00444
00453 void setDefaults(const Param& defaults, const String& prefix = "", bool showMessage = false);
00454
00473 void checkDefaults(const String& name, const Param& defaults, const String& prefix = "", std::ostream& os = std::cout) const;
00475
00477
00478
00486 void setValidStrings(const String& key, const std::vector<String>& strings);
00487
00495 void setMinInt(const String& key, Int min);
00496
00504 void setMaxInt(const String& key, Int max);
00505
00513 void setMinFloat(const String& key, DoubleReal min);
00514
00522 void setMaxFloat(const String& key, DoubleReal max);
00524
00526
00527
00545 void parseCommandLine(const int argc, const char** argv, const String& prefix = "");
00559 void parseCommandLine(const int argc, const char** argv, const Map<String, String>& options_with_one_argument, const Map<String, String>& options_without_argument, const Map<String, String>& options_with_multiple_argument, const String& misc = "misc", const String& unknown = "unknown");
00560
00572 void parseCommandLine(const int argc, const char** argv, const std::vector<ParameterInformation>& parameters, const String& misc = "misc", const String& unknown = "unknown");
00574
00575 protected:
00581 ParamEntry& getEntry_(const String& key) const;
00582
00584 Param(const Param::ParamNode& node);
00585
00587 mutable Param::ParamNode root_;
00588 };
00589
00591 OPENMS_DLLAPI std::ostream& operator<<(std::ostream& os, const Param& param);
00592
00593
00594 }
00595
00596 #endif // OPENMS_DATASTRUCTURES_PARAM_H