Home  · Classes  · Annotated Classes  · Modules  · Members  · Namespaces  · Related Pages

Param.h

Go to the documentation of this file.
00001 // --------------------------------------------------------------------------
00002 //                   OpenMS -- Open-Source Mass Spectrometry
00003 // --------------------------------------------------------------------------
00004 // Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
00005 // ETH Zurich, and Freie Universitaet Berlin 2002-2012.
00006 //
00007 // This software is released under a three-clause BSD license:
00008 //  * Redistributions of source code must retain the above copyright
00009 //    notice, this list of conditions and the following disclaimer.
00010 //  * Redistributions in binary form must reproduce the above copyright
00011 //    notice, this list of conditions and the following disclaimer in the
00012 //    documentation and/or other materials provided with the distribution.
00013 //  * Neither the name of any author or any participating institution
00014 //    may be used to endorse or promote products derived from this software
00015 //    without specific prior written permission.
00016 // For a full list of authors, refer to the file AUTHORS.
00017 // --------------------------------------------------------------------------
00018 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00019 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00020 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00021 // ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING
00022 // INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00023 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00024 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
00025 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
00026 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
00027 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
00028 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00029 //
00030 // --------------------------------------------------------------------------
00031 // $Maintainer: Erhan Kenar $
00032 // $Authors:  Marc Sturm, Clemens Groepl $
00033 // --------------------------------------------------------------------------
00034 
00035 #ifndef OPENMS_DATASTRUCTURES_PARAM_H
00036 #define OPENMS_DATASTRUCTURES_PARAM_H
00037 
00038 // #include <OpenMS/APPLICATIONS/TOPPBase.h>
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 } // namespace OpenMS
00595 
00596 #endif // OPENMS_DATASTRUCTURES_PARAM_H

OpenMS / TOPP release 1.10.0 Documentation generated on Thu Mar 7 2013 09:42:43 using doxygen 1.7.1