OpenMS
ModelDescription.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-2023.
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: Timo Sachsenberg $
32 // $Authors: $
33 // --------------------------------------------------------------------------
34 
35 #pragma once
36 
39 #include <OpenMS/CONCEPT/Factory.h>
40 
41 #include <sstream>
42 
43 namespace OpenMS
44 {
52  template <UInt D>
54  {
55 public:
56 
59  name_(),
60  parameters_()
61  {
62  }
63 
66  name_(source.name_),
67  parameters_(source.parameters_)
68  {
69  }
70 
72  ModelDescription(const BaseModel<D> * model) :
73  name_(model->getName()),
74  parameters_(model->getParameters())
75  {
76  }
77 
80  {
81  }
82 
84  virtual ModelDescription & operator=(const ModelDescription & source)
85  {
86  if (&source == this) return *this;
87 
88  name_ = source.name_;
89  parameters_ = source.parameters_;
90 
91  return *this;
92  }
93 
97  {
98  if (name_.empty()) return nullptr;
99 
100  BaseModel<D> * model = Factory<BaseModel<D> >::create(name_);
101  model->setParameters(parameters_);
102  return model;
103  }
104 
108  const String & getName() const
109  {
110  return name_;
111  }
112 
115  {
116  return name_;
117  }
118 
120  void setName(const String & name)
121  {
122  name_ = name;
123  }
124 
126  const Param & getParam() const
127  {
128  return parameters_;
129  }
130 
133  {
134  return parameters_;
135  }
136 
138  void setParam(const Param & param)
139  {
140  parameters_ = param;
141  }
142 
145  virtual bool operator==(const ModelDescription & rhs) const
146  {
147  return (name_ == rhs.name_) && (parameters_ == rhs.parameters_);
148  }
149 
150  virtual bool operator!=(const ModelDescription & rhs) const
151  {
152  return !(operator==(rhs));
153  }
154 
156 
157 protected:
158 
161  };
162 }
Abstract base class for all D-dimensional models.
Definition: BaseModel.h:51
void setParameters(const Param &param)
Sets the parameters.
Returns FactoryProduct* based on the name of the desired concrete FactoryProduct.
Definition: Factory.h:63
Stores the name and parameters of a model.
Definition: ModelDescription.h:54
void setParam(const Param &param)
Set the model parameters.
Definition: ModelDescription.h:138
Param & getParam()
Mutable access to the model parameters.
Definition: ModelDescription.h:132
BaseModel< D > * createModel()
Definition: ModelDescription.h:96
const Param & getParam() const
Non-mutable access to model parameters.
Definition: ModelDescription.h:126
String name_
Definition: ModelDescription.h:159
virtual bool operator==(const ModelDescription &rhs) const
Definition: ModelDescription.h:145
ModelDescription(const BaseModel< D > *model)
constructor provided for convenience
Definition: ModelDescription.h:72
void setName(const String &name)
Set the model name.
Definition: ModelDescription.h:120
virtual ~ModelDescription()
destructor
Definition: ModelDescription.h:79
virtual bool operator!=(const ModelDescription &rhs) const
Definition: ModelDescription.h:150
ModelDescription()
Default constructor.
Definition: ModelDescription.h:58
virtual ModelDescription & operator=(const ModelDescription &source)
assignment operator
Definition: ModelDescription.h:84
const String & getName() const
Non-mutable access to model name.
Definition: ModelDescription.h:108
Param parameters_
Definition: ModelDescription.h:160
ModelDescription(const ModelDescription &source)
copy constructor
Definition: ModelDescription.h:65
String & getName()
Mutable access to the model name.
Definition: ModelDescription.h:114
Management and storage of parameters / INI files.
Definition: Param.h:70
A more convenient string class.
Definition: String.h:60
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:48