Home  · Classes  · Annotated Classes  · Modules  · Members  · Namespaces  · Related Pages
Param.h
Go to the documentation of this file.
1 // --------------------------------------------------------------------------
2 // OpenMS -- Open-Source Mass Spectrometry
3 // --------------------------------------------------------------------------
4 // Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
5 // ETH Zurich, and Freie Universitaet Berlin 2002-2015.
6 //
7 // This software is released under a three-clause BSD license:
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of any author or any participating institution
14 // may be used to endorse or promote products derived from this software
15 // without specific prior written permission.
16 // For a full list of authors, refer to the file AUTHORS.
17 // --------------------------------------------------------------------------
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 // ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING
22 // INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 //
30 // --------------------------------------------------------------------------
31 // $Maintainer: Stephan Aiche $
32 // $Authors: Marc Sturm, Clemens Groepl $
33 // --------------------------------------------------------------------------
34 
35 #ifndef OPENMS_DATASTRUCTURES_PARAM_H
36 #define OPENMS_DATASTRUCTURES_PARAM_H
37 
38 #include <OpenMS/CONCEPT/Types.h>
42 #include <OpenMS/OpenMSConfig.h>
43 
44 #include <iosfwd>
45 #include <set>
46 
47 namespace OpenMS
48 {
49 
50  template <class Key, class T>
51  class Map;
52 
53  namespace Logger
54  {
55  class LogStream;
56  }
57 
75  class OPENMS_DLLAPI Param
76  {
77 public:
78 
80  struct OPENMS_DLLAPI ParamEntry
81  {
83  ParamEntry();
85  ParamEntry(const String& n, const DataValue& v, const String& d, const StringList& t = StringList());
87  ParamEntry(const ParamEntry& other);
89  ~ParamEntry();
90 
92  bool isValid(String& message) const;
94  bool operator==(const ParamEntry& rhs) const;
95 
103  std::set<String> tags;
105 
106  double min_float;
107  double max_float;
110  std::vector<String> valid_strings;
111 
112  };
113 
115  struct OPENMS_DLLAPI ParamNode
116  {
118  typedef std::vector<ParamNode>::iterator NodeIterator;
120  typedef std::vector<ParamEntry>::iterator EntryIterator;
122  typedef std::vector<ParamNode>::const_iterator ConstNodeIterator;
124  typedef std::vector<ParamEntry>::const_iterator ConstEntryIterator;
125 
127  ParamNode();
129  ParamNode(const String& n, const String& d);
131  ~ParamNode();
133  bool operator==(const ParamNode& rhs) const;
134 
140  EntryIterator findEntry(const String& name);
146  NodeIterator findNode(const String& name);
152  ParamNode* findParentOf(const String& name);
158  ParamEntry* findEntryRecursive(const String& name);
159 
161  void insert(const ParamNode& node, const String& prefix = "");
163  void insert(const ParamEntry& entry, const String& prefix = "");
165  Size size() const;
167  String suffix(const String& key) const;
168 
174  std::vector<ParamEntry> entries;
176  std::vector<ParamNode> nodes;
177  };
178 
179 public:
180 
182  class OPENMS_DLLAPI ParamIterator
183  {
184 public:
186  struct OPENMS_DLLAPI TraceInfo
187  {
189  inline TraceInfo(const String& n, const String& d, bool o) :
190  name(n),
191  description(d),
192  opened(o)
193  {
194  }
195 
201  bool opened;
202  };
203 
205  ParamIterator();
207  ParamIterator(const Param::ParamNode& root);
209  ~ParamIterator();
211  const Param::ParamEntry& operator*();
213  const Param::ParamEntry* operator->();
215  ParamIterator& operator++();
217  ParamIterator operator++(int);
219  bool operator==(const ParamIterator& rhs) const;
221  bool operator!=(const ParamIterator& rhs) const;
223  String getName() const;
225  const std::vector<TraceInfo>& getTrace() const;
226 
227 protected:
233  std::vector<const Param::ParamNode*> stack_;
235  std::vector<TraceInfo> trace_;
236 
237  };
238 
240  Param();
241 
243  Param(const Param& rhs);
244 
246  ~Param();
247 
249  Param& operator=(const Param& rhs);
250 
252  bool operator==(const Param& rhs) const;
253 
255  ParamIterator begin() const;
256 
258  ParamIterator end() const;
259 
261 
262 
271  void setValue(const String& key, const DataValue& value, const String& description = "", const StringList& tags = StringList());
272 
278  const DataValue& getValue(const String& key) const;
279 
285  const ParamEntry& getEntry(const String& key) const;
286 
293  bool exists(const String& key) const;
294 
301  ParamIterator findFirst(const String& leaf) const;
302 
310  ParamIterator findNext(const String& leaf, const ParamIterator& start_leaf) const;
311 
312 
313 
315 
317 
318 
325  void addTag(const String& key, const String& tag);
326 
333  void addTags(const String& key, const StringList& tags);
334 
343  bool hasTag(const String& key, const String& tag) const;
344 
350  StringList getTags(const String& key) const;
351 
357  void clearTags(const String& key);
359 
360 
362 
363 
369  const String& getDescription(const String& key) const;
370 
379  void setSectionDescription(const String& key, const String& description);
380 
386  const String& getSectionDescription(const String& key) const;
388 
390 
391 
393  Size size() const;
394 
396  bool empty() const;
397 
399  void clear();
400 
403  void insert(const String& prefix, const Param& param);
404 
414  void remove(const String& key);
415 
424  void removeAll(const String& prefix);
425 
433  Param copy(const String& prefix, bool remove_prefix = false) const;
434 
440  void update(const Param& old_version, const bool add_unknown = false);
441 
457  void update(const Param& old_version, const bool add_unknown, Logger::LogStream& stream);
458 
464  void merge(const Param& toMerge);
465 
467 
468 
470 
471 
480  void setDefaults(const Param& defaults, const String& prefix = "", bool showMessage = false);
481 
501  void checkDefaults(const String& name, const Param& defaults, const String& prefix = "") const;
503 
505 
506 
514  void setValidStrings(const String& key, const std::vector<String>& strings);
515 
523  void setMinInt(const String& key, Int min);
524 
532  void setMaxInt(const String& key, Int max);
533 
541  void setMinFloat(const String& key, double min);
542 
550  void setMaxFloat(const String& key, double max);
552 
554 
555 
573  void parseCommandLine(const int argc, const char** argv, const String& prefix = "");
574 
588  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");
589 
591 
592 protected:
598  ParamEntry& getEntry_(const String& key) const;
599 
601  Param(const Param::ParamNode& node);
602 
605  };
606 
608  OPENMS_DLLAPI std::ostream& operator<<(std::ostream& os, const Param& param);
609 
610 } // namespace OpenMS
611 
612 #endif // OPENMS_DATASTRUCTURES_PARAM_H
DataValue value
Value associated with the entry.
Definition: Param.h:101
A more convenient string class.
Definition: String.h:57
std::vector< ParamNode > nodes
Subnodes.
Definition: Param.h:176
std::vector< ParamEntry >::iterator EntryIterator
Iterator for entries.
Definition: Param.h:120
String description
Description of the node.
Definition: Param.h:172
const Param::ParamNode * root_
Pointer to the root node.
Definition: Param.h:229
Parameter entry used to store the actual information inside of a Param entry.
Definition: Param.h:80
std::vector< const Param::ParamNode * > stack_
Pointers to the ParamNodes we are in.
Definition: Param.h:233
Int current_
Index of the current ParamEntry (-1 means invalid)
Definition: Param.h:231
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
double max_float
Default: std::numeric_limits::max()
Definition: Param.h:107
Log Stream Class.
Definition: LogStream.h:303
std::set< String > tags
Tags list, used e.g. for advanced parameter tag.
Definition: Param.h:103
Int min_int
Default: - std::numeric_limits::max()
Definition: Param.h:108
TraceInfo(const String &n, const String &d, bool o)
Constructor with name, description, and open flag.
Definition: Param.h:189
Class to hold strings, numeric values, lists of strings and lists of numeric values.
Definition: DataValue.h:57
String name
Name of the node.
Definition: Param.h:170
String description
description of the node
Definition: Param.h:199
std::vector< ParamEntry >::const_iterator ConstEntryIterator
Iterator for entries.
Definition: Param.h:124
std::vector< ParamNode >::iterator NodeIterator
Iterator for child nodes.
Definition: Param.h:118
Int max_int
Default: std::numeric_limits::max()
Definition: Param.h:109
String name
Name of the entry.
Definition: Param.h:97
String name
name of the node
Definition: Param.h:197
std::ostream & operator<<(std::ostream &os, const AccurateMassSearchResult &amsr)
DPosition< D, TCoordinateType > operator*(DPosition< D, TCoordinateType > position, typename DPosition< D, TCoordinateType >::CoordinateType scalar)
Scalar multiplication (a bit inefficient)
Definition: DPosition.h:421
Struct that captures information on entered / left nodes for ParamIterator.
Definition: Param.h:186
bool opened
If it was opened (true) or closed (false)
Definition: Param.h:201
std::vector< String > StringList
Vector of String.
Definition: ListUtils.h:74
String description
Description of the entry.
Definition: Param.h:99
Management and storage of parameters / INI files.
Definition: Param.h:75
std::vector< ParamNode >::const_iterator ConstNodeIterator
Iterator for child nodes.
Definition: Param.h:122
double min_float
Default: - std::numeric_limits::max()
Definition: Param.h:106
std::vector< String > valid_strings
Default: empty.
Definition: Param.h:110
Forward const iterator for the Param class.
Definition: Param.h:182
std::vector< TraceInfo > trace_
Node traversal data during last ++ operation.
Definition: Param.h:235
Node inside a Param object which is used to build the internal tree.
Definition: Param.h:115
std::vector< ParamEntry > entries
Entries (leafs) in the node.
Definition: Param.h:174
int Int
Signed integer type.
Definition: Types.h:96
Map class based on the STL map (containing several convenience functions)
Definition: Map.h:51
Param::ParamNode root_
Invisible root node that stores all the data.
Definition: Param.h:604

OpenMS / TOPP release 2.0.0 Documentation generated on Sat May 16 2015 16:13:29 using doxygen 1.8.9.1