NOMAD Source  Version 4.0.0 Beta
ParameterEntry.hpp
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------------*/
2 /* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct Search - */
3 /* */
4 /* NOMAD - Version 4.0.0 has been created by */
5 /* Viviane Rochon Montplaisir - Polytechnique Montreal */
6 /* Christophe Tribes - Polytechnique Montreal */
7 /* */
8 /* The copyright of NOMAD - version 4.0.0 is owned by */
9 /* Charles Audet - Polytechnique Montreal */
10 /* Sebastien Le Digabel - Polytechnique Montreal */
11 /* Viviane Rochon Montplaisir - Polytechnique Montreal */
12 /* Christophe Tribes - Polytechnique Montreal */
13 /* */
14 /* NOMAD v4 has been funded by Rio Tinto, Hydro-Québec, NSERC (Natural */
15 /* Sciences and Engineering Research Council of Canada), InnovÉÉ (Innovation */
16 /* en Énergie Électrique) and IVADO (The Institute for Data Valorization) */
17 /* */
18 /* NOMAD v3 was created and developed by Charles Audet, Sebastien Le Digabel, */
19 /* Christophe Tribes and Viviane Rochon Montplaisir and was funded by AFOSR */
20 /* and Exxon Mobil. */
21 /* */
22 /* NOMAD v1 and v2 were created and developed by Mark Abramson, Charles Audet, */
23 /* Gilles Couture, and John E. Dennis Jr., and were funded by AFOSR and */
24 /* Exxon Mobil. */
25 /* */
26 /* Contact information: */
27 /* Polytechnique Montreal - GERAD */
28 /* C.P. 6079, Succ. Centre-ville, Montreal (Quebec) H3C 3A7 Canada */
29 /* e-mail: nomad@gerad.ca */
30 /* */
31 /* This program is free software: you can redistribute it and/or modify it */
32 /* under the terms of the GNU Lesser General Public License as published by */
33 /* the Free Software Foundation, either version 3 of the License, or (at your */
34 /* option) any later version. */
35 /* */
36 /* This program is distributed in the hope that it will be useful, but WITHOUT */
37 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
38 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License */
39 /* for more details. */
40 /* */
41 /* You should have received a copy of the GNU Lesser General Public License */
42 /* along with this program. If not, see <http://www.gnu.org/licenses/>. */
43 /* */
44 /* You can find information on the NOMAD software at www.gerad.ca/nomad */
45 /*---------------------------------------------------------------------------------*/
46 /**
47  \file ParameterEntry.hpp
48  \brief Parameter entry (headers)
49  \author Sebastien Le Digabel
50  \date 2010-04-05
51  \see ParameterEntry.cpp
52 */
53 #ifndef __NOMAD400_ParameterEntry__
54 #define __NOMAD400_ParameterEntry__
55 
56 #include "../Util/utils.hpp"
57 
58 #include "../nomad_nsbegin.hpp"
59 
60 
61 /// Parameter entry.
62 /**
63  - Describes the data relative to a parameter in a parameters file.
64  - Objects of this class are stored in a ParameterEntries object.
65 */
67 
68 private:
69 
70  std::string _name; ///< Name of the parameter.
71  std::list<std::string> _values; ///< List of values for the parameter.
72  bool _ok; ///< If the parameter is valid.
73  bool _unique; ///< If the parameter is unique.
74  std::shared_ptr<ParameterEntry> _next; ///< Acces to the next parameter.
75 
76  std::string _paramFile; ///< File from which this parameter was read
77  int _line; ///< Line for this parameter in _paramFile
78 
79  /// If the parameter has been interpreted.
81 
82 public:
83 
84  /// Constructor.
85  /**
86  Ignores all entries after \c '#'.
87  \param entry A string describing the parameter entry -- \b IN.
88  \param removeComments A boolean equal to \c true if entries after
89  \c '#' are ignored -- \b IN
90  (Opt) (default = \c true).
91  */
92  explicit ParameterEntry(const std::string & entry, bool removeComments = true);
93 
94  /// Destructor.
95  virtual ~ParameterEntry ( void ) {}
96 
97  /*---------------*/
98  /* GET methods */
99  /*---------------*/
100 
101  /// Access to the name of the parameter.
102  /**
103  \return The name.
104  */
105  const std::string & getName ( void ) const { return _name; }
106 
107  /// Access to the parameter values.
108  /**
109  \return The parameter values as a list of strings.
110  */
111  const std::list<std::string> & getValues ( void ) const { return _values; }
112 
113  std::string getAllValues ( void ) const;
114 
115  /// Access to the number of values of the parameter.
116  /**
117  \return The number of values.
118  */
119  size_t getNbValues ( void ) const { return _values.size(); }
120 
121  /// Access to the \c _ok flag.
122  /**
123  This flag is equal to \c true if the parameter entry is well defined.
124  \return A boolean equal to \c true if the parameter is valid.
125  */
126  bool isOk ( void ) const { return _ok; }
127 
128  /// Access to the \c _unique flag.
129  /**
130  This flag is decided when a parameters file is read.
131  \return A boolean equal to \c true if the parameter is unique
132  in a parameters file.
133  */
134  bool isUnique ( void ) const { return _unique; }
135 
136  /// Access to another ParameterEntry.
137  /**
138  ParameterEntry objects are stored in a ParameterEntries
139  object. The link between elements is assumed by the \c _next member
140  returned by this function.
141  \return A pointer to the next entry.
142  */
143  std::shared_ptr<ParameterEntry> getNext ( void ) const { return _next; }
144 
145  /// Access to the \c _hasBeenInterpreted flag.
146  /**
147  \return A boolean equal to \c true if the parameter has already
148  been interpreted.
149  */
150  bool hasBeenInterpreted ( void ) const { return _hasBeenInterpreted; }
151 
152  /// Access to the parameter file of the parameter.
153  /**
154  \return The parameter file where this parameter was read.
155  */
156  const std::string & getParamFile ( void ) const { return _paramFile; }
157 
158  /// Access to the line number for this parameter in the parameter file.
159  /**
160  \return The line number at which this parameter can be found in the parameter file.
161  */
162  const int & getLine ( void ) const { return _line; }
163 
164  /*---------------*/
165  /* SET methods */
166  /*---------------*/
167 
168  /// Set the \c _next pointer.
169  /**
170  \param p A pointer to the next ParameterEntry to be inserted -- \b IN.
171  */
172  void setNext ( std::shared_ptr<ParameterEntry> p ) { _next = p; }
173 
174  /// Set the \c _unique flag.
175  /**
176  \param u Value of the flag -- \b IN.
177  */
178  void setUnique ( bool u ) { _unique = u; }
179 
180  /// Set the \c _hasBeenInterpreted flag. to \c true.
181  void setHasBeenInterpreted ( void ) { _hasBeenInterpreted = true; }
182 
183  /// Set the name of the parameter file \c _paramFile
184  void setParamFile(const std::string& paramFile ) { _paramFile = paramFile; }
185 
186  /// Set the line \c _line for this parameter in the parameter file
187  void setLine( int line ) { _line = line; }
188 
189  /// Comparison with another entry.
190  /**
191  The comparison is based on the parameter name.
192 
193  \param p The right-hand side object -- \b IN.
194  \return A boolean equal to \c true if \c this->_name \c < \c p._name.
195  */
196  bool operator < ( const ParameterEntry & p ) const { return _name < p._name; }
197 
198  /// Display.
199  /**
200  \param out The std::ostream object -- \b IN.
201  */
202  void display(std::ostream &out) const;
203 };
204 
205  /// Allows the comparison of two ParameterEntry objects.
207  /// Comparison of two ParameterEntry objects.
208  /**
209  \param p1 Pointer to the first ParameterEntry -- \b IN.
210  \param p2 Pointer to the second ParameterEntry -- \b IN.
211  \return A boolean equal to \c true if \c *p1 \c < \c *p2.
212  */
213  bool operator() ( const std::shared_ptr<ParameterEntry> p1 , const std::shared_ptr<ParameterEntry> p2 ) const
214  {
215  return (*p1 < *p2);
216  }
217 };
218 
219 /// Display a ParameterEntry object.
220 /**
221  \param out The std::ostream object -- \b IN.
222  \param e The ParameterEntry object to be displayed -- \b IN.
223  \return The std::ostream object.
224 */
225 inline std::ostream& operator<< (std::ostream &out,
226  const ParameterEntry &e)
227 {
228  e.display(out);
229  return out;
230 }
231 
232 #include "../nomad_nsend.hpp"
233 
234 
235 #endif // __NOMAD400_ParameterEntry__
ParameterEntry::getLine
const int & getLine(void) const
Access to the line number for this parameter in the parameter file.
Definition: ParameterEntry.hpp:162
ParameterEntry::setUnique
void setUnique(bool u)
Set the _unique flag.
Definition: ParameterEntry.hpp:178
ParameterEntry::ParameterEntry
ParameterEntry(const std::string &entry, bool removeComments=true)
Constructor.
ParameterEntry::_paramFile
std::string _paramFile
File from which this parameter was read.
Definition: ParameterEntry.hpp:76
ParameterEntry::getNbValues
size_t getNbValues(void) const
Access to the number of values of the parameter.
Definition: ParameterEntry.hpp:119
ParameterEntry::display
void display(std::ostream &out) const
Display.
ParameterEntry::~ParameterEntry
virtual ~ParameterEntry(void)
Destructor.
Definition: ParameterEntry.hpp:95
ParameterEntry::setHasBeenInterpreted
void setHasBeenInterpreted(void)
Set the _hasBeenInterpreted flag. to true.
Definition: ParameterEntry.hpp:181
ParameterEntry::getParamFile
const std::string & getParamFile(void) const
Access to the parameter file of the parameter.
Definition: ParameterEntry.hpp:156
ParameterEntry::getNext
std::shared_ptr< ParameterEntry > getNext(void) const
Access to another ParameterEntry.
Definition: ParameterEntry.hpp:143
ParameterEntry::isUnique
bool isUnique(void) const
Access to the _unique flag.
Definition: ParameterEntry.hpp:134
ParameterEntry
Parameter entry.
Definition: ParameterEntry.hpp:66
ParameterEntry::_ok
bool _ok
If the parameter is valid.
Definition: ParameterEntry.hpp:72
ParameterEntryComp
Allows the comparison of two ParameterEntry objects.
Definition: ParameterEntry.hpp:206
ParameterEntry::operator<
bool operator<(const ParameterEntry &p) const
Comparison with another entry.
Definition: ParameterEntry.hpp:196
ParameterEntry::_values
std::list< std::string > _values
List of values for the parameter.
Definition: ParameterEntry.hpp:71
operator<<
std::ostream & operator<<(std::ostream &out, const ParameterEntry &e)
Display a ParameterEntry object.
Definition: ParameterEntry.hpp:225
ParameterEntry::_next
std::shared_ptr< ParameterEntry > _next
Acces to the next parameter.
Definition: ParameterEntry.hpp:74
ParameterEntry::hasBeenInterpreted
bool hasBeenInterpreted(void) const
Access to the _hasBeenInterpreted flag.
Definition: ParameterEntry.hpp:150
ParameterEntry::setNext
void setNext(std::shared_ptr< ParameterEntry > p)
Set the _next pointer.
Definition: ParameterEntry.hpp:172
ParameterEntry::setParamFile
void setParamFile(const std::string &paramFile)
Set the name of the parameter file _paramFile.
Definition: ParameterEntry.hpp:184
ParameterEntry::setLine
void setLine(int line)
Set the line _line for this parameter in the parameter file.
Definition: ParameterEntry.hpp:187
ParameterEntry::_line
int _line
Line for this parameter in _paramFile.
Definition: ParameterEntry.hpp:77
ParameterEntry::_unique
bool _unique
If the parameter is unique.
Definition: ParameterEntry.hpp:73
ParameterEntry::getName
const std::string & getName(void) const
Access to the name of the parameter.
Definition: ParameterEntry.hpp:105
ParameterEntryComp::operator()
bool operator()(const std::shared_ptr< ParameterEntry > p1, const std::shared_ptr< ParameterEntry > p2) const
Comparison of two ParameterEntry objects.
Definition: ParameterEntry.hpp:213
removeComments
void removeComments(std::string &line)
Definition: fileutils.cpp:242
ParameterEntry::getValues
const std::list< std::string > & getValues(void) const
Access to the parameter values.
Definition: ParameterEntry.hpp:111
ParameterEntry::isOk
bool isOk(void) const
Access to the _ok flag.
Definition: ParameterEntry.hpp:126
ParameterEntry::getAllValues
std::string getAllValues(void) const
ParameterEntry::_hasBeenInterpreted
bool _hasBeenInterpreted
If the parameter has been interpreted.
Definition: ParameterEntry.hpp:80
ParameterEntry::_name
std::string _name
Name of the parameter.
Definition: ParameterEntry.hpp:70