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-2013.
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/APPLICATIONS/TOPPBase.h>
41 #include <OpenMS/CONCEPT/Types.h>
45 
46 #include <set>
47 #include <iostream>
48 
49 
50 namespace OpenMS
51 {
69  class OPENMS_DLLAPI Param
70  {
71 public:
72 
74  struct OPENMS_DLLAPI ParamEntry
75  {
77  ParamEntry();
79  ParamEntry(const String& n, const DataValue& v, const String& d, const StringList& t = StringList());
81  ParamEntry(const ParamEntry &other);
83  ~ParamEntry();
84 
86  bool isValid(String& message) const;
88  bool operator==(const ParamEntry& rhs) const;
89 
97  std::set<String> tags;
99 
104  std::vector<String> valid_strings;
105 
106  };
107 
109  struct OPENMS_DLLAPI ParamNode
110  {
112  typedef std::vector<ParamNode>::iterator NodeIterator;
114  typedef std::vector<ParamEntry>::iterator EntryIterator;
116  typedef std::vector<ParamNode>::const_iterator ConstNodeIterator;
118  typedef std::vector<ParamEntry>::const_iterator ConstEntryIterator;
119 
121  ParamNode();
123  ParamNode(const String& n, const String& d);
125  ~ParamNode();
127  bool operator==(const ParamNode& rhs) const;
128 
134  EntryIterator findEntry(const String& name);
140  NodeIterator findNode(const String& name);
146  ParamNode* findParentOf(const String& name);
152  ParamEntry* findEntryRecursive(const String& name);
153 
155  void insert(const ParamNode& node, const String& prefix = "");
157  void insert(const ParamEntry& entry, const String& prefix = "");
159  Size size() const;
161  String suffix(const String& key) const;
162 
168  std::vector<ParamEntry> entries;
170  std::vector<ParamNode> nodes;
171  };
172 
173 public:
174 
176  class OPENMS_DLLAPI ParamIterator
177  {
178 public:
180  struct OPENMS_DLLAPI TraceInfo
181  {
183  inline TraceInfo(const String& n, const String& d, bool o) :
184  name(n),
185  description(d),
186  opened(o)
187  {
188  }
189 
195  bool opened;
196  };
197 
199  ParamIterator();
201  ParamIterator(const Param::ParamNode& root);
203  ~ParamIterator();
205  const Param::ParamEntry& operator*();
207  const Param::ParamEntry* operator->();
209  ParamIterator& operator++();
211  ParamIterator operator++(int);
213  bool operator==(const ParamIterator& rhs) const;
215  bool operator!=(const ParamIterator& rhs) const;
217  String getName() const;
219  const std::vector<TraceInfo>& getTrace() const;
220 
221 protected:
227  std::vector<const Param::ParamNode*> stack_;
229  std::vector<TraceInfo> trace_;
230 
231  };
232 
234  Param();
235 
237  Param(const Param& rhs);
238 
240  ~Param();
241 
243  Param& operator=(const Param& rhs);
244 
246  bool operator==(const Param& rhs) const;
247 
249  ParamIterator begin() const;
250 
252  ParamIterator end() const;
253 
255 
256 
265  void setValue(const String& key, const DataValue& value, const String& description = "", const StringList& tags = StringList());
266 
272  const DataValue& getValue(const String& key) const;
273 
279  const ParamEntry& getEntry(const String& key) const;
280 
287  bool exists(const String& key) const;
288 
295  ParamIterator findFirst(const String& leaf) const;
296 
304  ParamIterator findNext(const String& leaf, const ParamIterator& start_leaf) const;
305 
306 
307 
309 
311 
312 
319  void addTag(const String& key, const String& tag);
320 
327  void addTags(const String& key, const StringList& tags);
328 
337  bool hasTag(const String& key, const String& tag) const;
338 
344  StringList getTags(const String& key) const;
345 
351  void clearTags(const String& key);
353 
354 
356 
357 
363  const String& getDescription(const String& key) const;
364 
373  void setSectionDescription(const String& key, const String& description);
374 
380  const String& getSectionDescription(const String& key) const;
382 
384 
385 
387  Size size() const;
388 
390  bool empty() const;
391 
393  void clear();
394 
397  void insert(const String& prefix, const Param& param);
398 
408  void remove(const String& key);
409 
418  void removeAll(const String& prefix);
419 
427  Param copy(const String& prefix, bool remove_prefix = false) const;
428 
444  void update(const Param& old_version, const bool add_unknown = false, Logger::LogStream& stream = LOG_WARN);
445 
451  void merge(const Param& toMerge);
452 
454 
455 
457 
458 
467  void setDefaults(const Param& defaults, const String& prefix = "", bool showMessage = false);
468 
487  void checkDefaults(const String& name, const Param& defaults, const String& prefix = "", std::ostream& os = std::cout) const;
489 
491 
492 
500  void setValidStrings(const String& key, const std::vector<String>& strings);
501 
509  void setMinInt(const String& key, Int min);
510 
518  void setMaxInt(const String& key, Int max);
519 
527  void setMinFloat(const String& key, DoubleReal min);
528 
536  void setMaxFloat(const String& key, DoubleReal max);
538 
540 
541 
559  void parseCommandLine(const int argc, const char** argv, const String& prefix = "");
560 
574  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");
575 
577 
578 protected:
584  ParamEntry& getEntry_(const String& key) const;
585 
587  Param(const Param::ParamNode& node);
588 
591  };
592 
594  OPENMS_DLLAPI std::ostream& operator<<(std::ostream& os, const Param& param);
595 
596 } // namespace OpenMS
597 
598 #endif // OPENMS_DATASTRUCTURES_PARAM_H
DataValue value
Value associated with the entry.
Definition: Param.h:95
A more convenient string class.
Definition: String.h:56
std::vector< ParamNode > nodes
Subnodes.
Definition: Param.h:170
std::vector< ParamEntry >::iterator EntryIterator
Iterator for entries.
Definition: Param.h:114
String description
Description of the node.
Definition: Param.h:166
const Param::ParamNode * root_
Pointer to the root node.
Definition: Param.h:223
std::ostream & operator<<(std::ostream &os, const ItraqQuantifier::ItraqQuantifierStats &stats)
Parameter entry used to store the actual information inside of a Param entry.
Definition: Param.h:74
std::vector< const Param::ParamNode * > stack_
Pointers to the ParmNodes we are in.
Definition: Param.h:227
Int current_
Index of the current ParamEntry (-1 means invalid)
Definition: Param.h:225
Log Stream Class.
Definition: LogStream.h:303
std::set< String > tags
Tags list, used e.g. for advanced parameter tag.
Definition: Param.h:97
Int min_int
Default: - std::numeric_limits&lt;Int&gt;::max()
Definition: Param.h:102
TraceInfo(const String &n, const String &d, bool o)
Constructor with name, description, and open flag.
Definition: Param.h:183
Class to hold strings, numeric values, lists of strings and lists of numeric values.
Definition: DataValue.h:57
#define LOG_WARN
Macro if a warning, a piece of information which should be read by the user, should be logged...
Definition: LogStream.h:451
String name
Name of the node.
Definition: Param.h:164
String description
description of the node
Definition: Param.h:193
DoubleReal max_float
Default: std::numeric_limits&lt;DoubleReal&gt;::max()
Definition: Param.h:101
std::vector< ParamEntry >::const_iterator ConstEntryIterator
Iterator for entries.
Definition: Param.h:118
std::vector< ParamNode >::iterator NodeIterator
Iterator for child nodes.
Definition: Param.h:112
Int max_int
Default: std::numeric_limits&lt;Int&gt;::max()
Definition: Param.h:103
String name
Name of the entry.
Definition: Param.h:91
String name
name of the node
Definition: Param.h:191
DPosition< D, TCoordinateType > operator*(DPosition< D, TCoordinateType > position, typename DPosition< D, TCoordinateType >::CoordinateType scalar)
Scalar multiplication (a bit inefficient)
Definition: DPosition.h:415
Struct that captures information on entered / left nodes for ParamIterator.
Definition: Param.h:180
bool opened
If it was opened (true) or closed (false)
Definition: Param.h:195
String description
Description of the entry.
Definition: Param.h:93
Management and storage of parameters / INI files.
Definition: Param.h:69
std::vector< ParamNode >::const_iterator ConstNodeIterator
Iterator for child nodes.
Definition: Param.h:116
String list.
Definition: StringList.h:56
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:144
std::vector< String > valid_strings
Default: empty.
Definition: Param.h:104
Forward const iterator for the Param class.
Definition: Param.h:176
std::vector< TraceInfo > trace_
Node traversal data during last ++ operation.
Definition: Param.h:229
DoubleReal min_float
Default: - std::numeric_limits&lt;DoubleReal&gt;::max()
Definition: Param.h:100
Node inside a Param object which is used to build the internal tree.
Definition: Param.h:109
std::vector< ParamEntry > entries
Entries (leafs) in the node.
Definition: Param.h:168
int Int
Signed integer type.
Definition: Types.h:100
Map class based on the STL map (containing serveral convenience functions)
Definition: Map.h:50
Param::ParamNode root_
Invisible root node that stores all the data.
Definition: Param.h:590

OpenMS / TOPP release 1.11.1 Documentation generated on Thu Nov 14 2013 11:19:19 using doxygen 1.8.5