NOMAD Source  Version 4.0.0 Beta
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ParameterEntry.hpp
Go to the documentation of this file.
1 /**
2  \file ParameterEntry.hpp
3  \brief Parameter entry (headers)
4  \author Sebastien Le Digabel
5  \date 2010-04-05
6  \see ParameterEntry.cpp
7 */
8 #ifndef __NOMAD400_ParameterEntry__
9 #define __NOMAD400_ParameterEntry__
10 
11 #include <iostream>
12 #include "../Util/utils.hpp"
13 
14 #include "../nomad_nsbegin.hpp"
15 
16 
17 /// Parameter entry.
18 /**
19  - Describes the data relative to a parameter in a parameters file.
20  - Objects of this class are stored in a ParameterEntries object.
21 */
23 
24 private:
25 
26  std::string _name; ///< Name of the parameter.
27  std::list<std::string> _values; ///< List of values for the parameter.
28  bool _ok; ///< If the parameter is valid.
29  bool _unique; ///< If the parameter is unique.
30  std::shared_ptr<ParameterEntry> _next; ///< Acces to the next parameter.
31 
32  std::string _paramFile; ///< File from which this parameter was read
33  int _line; ///< Line for this parameter in _paramFile
34 
35  /// If the parameter has been interpreted.
37 
38 public:
39 
40  /// Constructor.
41  /**
42  Ignores all entries after \c '#'.
43  \param entry A string describing the parameter entry -- \b IN.
44  \param removeComments A boolean equal to \c true if entries after
45  \c '#' are ignored -- \b IN
46  (Opt) (default = \c true).
47  */
48  explicit ParameterEntry(const std::string & entry, bool removeComments = true);
49 
50  /// Destructor.
51  virtual ~ParameterEntry ( void ) {}
52 
53  /*---------------*/
54  /* GET methods */
55  /*---------------*/
56 
57  /// Access to the name of the parameter.
58  /**
59  \return The name.
60  */
61  const std::string & getName ( void ) const { return _name; }
62 
63  /// Access to the parameter values.
64  /**
65  \return The parameter values as a list of strings.
66  */
67  const std::list<std::string> & getValues ( void ) const { return _values; }
68 
69  std::string getAllValues ( void ) const;
70 
71  /// Access to the number of values of the parameter.
72  /**
73  \return The number of values.
74  */
75  size_t getNbValues ( void ) const { return _values.size(); }
76 
77  /// Access to the \c _ok flag.
78  /**
79  This flag is equal to \c true if the parameter entry is well defined.
80  \return A boolean equal to \c true if the parameter is valid.
81  */
82  bool isOk ( void ) const { return _ok; }
83 
84  /// Access to the \c _unique flag.
85  /**
86  This flag is decided when a parameters file is read.
87  \return A boolean equal to \c true if the parameter is unique
88  in a parameters file.
89  */
90  bool isUnique ( void ) const { return _unique; }
91 
92  /// Access to another ParameterEntry.
93  /**
94  ParameterEntry objects are stored in a ParameterEntries
95  object. The link between elements is assumed by the \c _next member
96  returned by this function.
97  \return A pointer to the next entry.
98  */
99  std::shared_ptr<ParameterEntry> getNext ( void ) const { return _next; }
100 
101  /// Access to the \c _hasBeenInterpreted flag.
102  /**
103  \return A boolean equal to \c true if the parameter has already
104  been interpreted.
105  */
106  bool hasBeenInterpreted ( void ) const { return _hasBeenInterpreted; }
107 
108  /// Access to the parameter file of the parameter.
109  /**
110  \return The parameter file where this parameter was read.
111  */
112  const std::string & getParamFile ( void ) const { return _paramFile; }
113 
114  /// Access to the line number for this parameter in the parameter file.
115  /**
116  \return The line number at which this parameter can be found in the parameter file.
117  */
118  const int & getLine ( void ) const { return _line; }
119 
120  /*---------------*/
121  /* SET methods */
122  /*---------------*/
123 
124  /// Set the \c _next pointer.
125  /**
126  \param p A pointer to the next ParameterEntry to be inserted -- \b IN.
127  */
128  void setNext ( std::shared_ptr<ParameterEntry> p ) { _next = p; }
129 
130  /// Set the \c _unique flag.
131  /**
132  \param u Value of the flag -- \b IN.
133  */
134  void setUnique ( bool u ) { _unique = u; }
135 
136  /// Set the \c _hasBeenInterpreted flag. to \c true.
137  void setHasBeenInterpreted ( void ) { _hasBeenInterpreted = true; }
138 
139  /// Set the name of the parameter file \c _paramFile
140  void setParamFile(const std::string& paramFile ) { _paramFile = paramFile; }
141 
142  /// Set the line \c _line for this parameter in the parameter file
143  void setLine( int line ) { _line = line; }
144 
145  /// Comparison with another entry.
146  /**
147  The comparison is based on the parameter name.
148  \param p The right-hand side object -- \b IN.
149  \return A boolean equal to \c true if \c this->_name \c < \c p._name.
150  */
151  bool operator < ( const ParameterEntry & p ) const { return _name < p._name; }
152 
153  /// Display.
154  /**
155  \param out The std::ostream object -- \b IN.
156  */
157  void display(std::ostream &out) const;
158 };
159 
160  /// Allows the comparison of two ParameterEntry objects.
162  /// Comparison of two ParameterEntry objects.
163  /**
164  \param p1 Pointer to the first ParameterEntry -- \b IN.
165  \param p2 Pointer to the second ParameterEntry -- \b IN.
166  \return A boolean equal to \c true if \c *p1 \c < \c *p2.
167  */
168  bool operator() ( const std::shared_ptr<ParameterEntry> p1 , const std::shared_ptr<ParameterEntry> p2 ) const
169  {
170  return (*p1 < *p2);
171  }
172 };
173 
174 /// Display a ParameterEntry object.
175 /**
176  \param out The std::ostream object -- \b IN.
177  \param e The ParameterEntry object to be displayed -- \b IN.
178  \return The std::ostream object.
179 */
180 inline std::ostream& operator<< (std::ostream &out,
181  const ParameterEntry &e)
182 {
183  e.display(out);
184  return out;
185 }
186 
187 #include "../nomad_nsend.hpp"
188 
189 
190 #endif // __NOMAD400_ParameterEntry__
const std::list< std::string > & getValues(void) const
Access to the parameter values.
const std::string & getName(void) const
Access to the name of the parameter.
std::string _name
Name of the parameter.
bool _ok
If the parameter is valid.
void setLine(int line)
Set the line _line for this parameter in the parameter file.
bool operator()(const std::shared_ptr< ParameterEntry > p1, const std::shared_ptr< ParameterEntry > p2) const
Comparison of two ParameterEntry objects.
void display(std::ostream &out) const
Display.
size_t getNbValues(void) const
Access to the number of values of the parameter.
bool _unique
If the parameter is unique.
const int & getLine(void) const
Access to the line number for this parameter in the parameter file.
int _line
Line for this parameter in _paramFile.
std::shared_ptr< ParameterEntry > _next
Acces to the next parameter.
void setUnique(bool u)
Set the _unique flag.
void setNext(std::shared_ptr< ParameterEntry > p)
Set the _next pointer.
virtual ~ParameterEntry(void)
Destructor.
bool _hasBeenInterpreted
If the parameter has been interpreted.
void setHasBeenInterpreted(void)
Set the _hasBeenInterpreted flag. to true.
bool isUnique(void) const
Access to the _unique flag.
std::string _paramFile
File from which this parameter was read.
Allows the comparison of two ParameterEntry objects.
bool hasBeenInterpreted(void) const
Access to the _hasBeenInterpreted flag.
void removeComments(std::string &line)
Definition: fileutils.cpp:198
bool isOk(void) const
Access to the _ok flag.
std::ostream & operator<<(std::ostream &os, const Algorithm &algo)
Operator to write parameters used for hot restart.
ParameterEntry(const std::string &entry, bool removeComments=true)
Constructor.
std::list< std::string > _values
List of values for the parameter.
bool operator<(const ParameterEntry &p) const
Comparison with another entry.
Parameter entry.
const std::string & getParamFile(void) const
Access to the parameter file of the parameter.
std::shared_ptr< ParameterEntry > getNext(void) const
Access to another ParameterEntry.
std::string getAllValues(void) const
void setParamFile(const std::string &paramFile)
Set the name of the parameter file _paramFile.