Ipopt Documentation  
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
IpOptionsList.hpp
Go to the documentation of this file.
1 // Copyright (C) 2004, 2006 International Business Machines and others.
2 // All Rights Reserved.
3 // This code is published under the Eclipse Public License.
4 //
5 // Authors: Carl Laird, Andreas Waechter IBM 2004-08-13
6 
7 #ifndef __IPOPTLIST_HPP__
8 #define __IPOPTLIST_HPP__
9 
10 #include "IpUtils.hpp"
11 #include "IpReferenced.hpp"
12 #include "IpException.hpp"
13 #include "IpRegOptions.hpp"
14 
15 #include <iostream>
16 #include <map>
17 
18 namespace Ipopt
19 {
21 DECLARE_STD_EXCEPTION(OPTION_INVALID);
22 
33 {
36  {
37  public:
39 
42  : initialized_(false)
43  { }
44 
47  std::string value,
48  bool allow_clobber,
49  bool dont_print
50  )
51  : value_(value),
52  counter_(0),
53  initialized_(true),
54  allow_clobber_(allow_clobber),
55  dont_print_(dont_print)
56  {
57  }
58 
61  const OptionValue& copy
62  )
63  : value_(copy.value_),
64  counter_(copy.counter_),
65  initialized_(copy.initialized_),
66  allow_clobber_(copy.allow_clobber_),
67  dont_print_(copy.dont_print_)
68  {
69  }
70 
72  void operator=(
73  const OptionValue& copy
74  )
75  {
76  value_ = copy.value_;
77  counter_ = copy.counter_;
78  initialized_ = copy.initialized_;
79  allow_clobber_ = copy.allow_clobber_;
80  dont_print_ = copy.dont_print_;
81  }
82 
85  { }
87 
92  std::string GetValue() const
93  {
94  DBG_ASSERT(initialized_);
95  counter_++;
96  return value_;
97  }
98 
100  std::string Value() const
101  {
102  DBG_ASSERT(initialized_);
103  return value_;
104  }
105 
107  Index Counter() const
108  {
109  DBG_ASSERT(initialized_);
110  return counter_;
111  }
112 
114  bool AllowClobber() const
115  {
116  DBG_ASSERT(initialized_);
117  return allow_clobber_;
118  }
119 
123  bool DontPrint() const
124  {
125  DBG_ASSERT(initialized_);
126  return dont_print_;
127  }
128 
129  private:
131  std::string value_;
132 
134  mutable Index counter_;
135 
138 
141 
145  };
146 
147 public:
149  OptionsList(
151  SmartPtr<RegisteredOptions> reg_options,
153  )
154  : reg_options_(reg_options),
155  jnlst_(jnlst)
156  { }
157 
159  { }
160 
163  const OptionsList& copy
164  )
165  {
166  // copy all the option strings and values
167  options_ = copy.options_;
168  // copy the registered options pointer
169  reg_options_ = copy.reg_options_;
170  }
171 
173  virtual ~OptionsList()
174  { }
175 
177  virtual void operator=(
178  const OptionsList& source
179  )
180  {
181  options_ = source.options_;
182  reg_options_ = source.reg_options_;
183  jnlst_ = source.jnlst_;
184  }
186 
188  virtual void clear()
189  {
190  options_.clear();
191  }
192 
194  virtual void SetRegisteredOptions(
196  const SmartPtr<RegisteredOptions> reg_options
197  )
198  {
199  reg_options_ = reg_options;
200  }
201 
202  virtual void SetJournalist(
203  const SmartPtr<Journalist> jnlst
204  )
205  {
206  jnlst_ = jnlst;
207  }
208 
210 
211  virtual bool SetStringValue(
213  const std::string& tag,
214  const std::string& value,
215  bool allow_clobber = true,
216  bool dont_print = false
217  );
218 
219  virtual bool SetNumericValue(
220  const std::string& tag,
221  Number value,
222  bool allow_clobber = true,
223  bool dont_print = false
224  );
225 
226  virtual bool SetIntegerValue(
227  const std::string& tag,
228  Index value,
229  bool allow_clobber = true,
230  bool dont_print = false
231  );
233 
236  virtual bool SetStringValueIfUnset(
238  const std::string& tag,
239  const std::string& value,
240  bool allow_clobber = true,
241  bool dont_print = false
242  );
243 
244  virtual bool SetNumericValueIfUnset(
245  const std::string& tag,
246  Number value,
247  bool allow_clobber = true,
248  bool dont_print = false
249  );
250 
251  virtual bool SetIntegerValueIfUnset(
252  const std::string& tag,
253  Index value,
254  bool allow_clobber = true,
255  bool dont_print = false
256  );
258 
262  virtual bool GetStringValue(
264  const std::string& tag,
265  std::string& value,
266  const std::string& prefix
267  ) const;
268 
269  virtual bool GetEnumValue(
270  const std::string& tag,
271  Index& value,
272  const std::string& prefix
273  ) const;
274 
275  virtual bool GetBoolValue(
276  const std::string& tag,
277  bool& value,
278  const std::string& prefix
279  ) const;
280 
281  virtual bool GetNumericValue(
282  const std::string& tag,
283  Number& value,
284  const std::string& prefix
285  ) const;
286 
287  virtual bool GetIntegerValue(
288  const std::string& tag,
289  Index& value,
290  const std::string& prefix
291  ) const;
293 
295  virtual void PrintList(
296  std::string& list
297  ) const;
298 
304  virtual void PrintUserOptions(
305  std::string& list
306  ) const;
307 
312  virtual bool ReadFromStream(
313  const Journalist& jnlst,
314  std::istream& is,
315  bool allow_clobber = false
316  );
317 
318 private:
328 
330  // OptionsList();
332 
333  std::map<std::string, OptionValue> options_;
334 
337 
340 
342  const std::string& lowercase(
343  const std::string tag
344  ) const;
345 
354  bool find_tag(
355  const std::string& tag,
356  const std::string& prefix,
357  std::string& value
358  ) const;
359 
364  bool will_allow_clobber(
365  const std::string& tag
366  ) const;
367 
372  bool readnexttoken(
373  std::istream& is,
374  std::string& token
375  );
376 
378  mutable std::string lowercase_buffer_;
379 };
380 
381 } // namespace Ipopt
382 
383 #endif
std::string Value() const
Method for retrieving the value without increasing the counter.
virtual void SetJournalist(const SmartPtr< Journalist > jnlst)
OptionValue(std::string value, bool allow_clobber, bool dont_print)
Constructor given the value.
OptionValue(const OptionValue &copy)
Copy Constructor.
DECLARE_STD_EXCEPTION(FATAL_ERROR_IN_LINEAR_SOLVER)
double Number
Type of all numbers.
Definition: IpTypes.hpp:15
virtual void operator=(const OptionsList &source)
Default Assignment Operator.
~OptionValue()
Default Destructor.
bool dont_print_
True if this option is not to show up in the print_user_options output.
OptionsList(const OptionsList &copy)
Copy Constructor.
Template class for Smart Pointers.
Definition: IpSmartPtr.hpp:171
Storing the reference count of all the smart pointers that currently reference it.
This class stores a list of user set options.
Index counter_
Counter for requests.
bool AllowClobber() const
True if the option can be overwritten.
bool allow_clobber_
True if the option can be overwritten.
Index Counter() const
Method for accessing current value of the request counter.
std::map< std::string, OptionValue > options_
Default Constructor.
std::string lowercase_buffer_
auxiliary string set by lowercase method
int Index
Type of all indices of vectors, matrices etc.
Definition: IpTypes.hpp:17
#define DBG_ASSERT(test)
Definition: IpDebug.hpp:27
bool DontPrint() const
True if this option is not to show up in the print_user_options output.
#define IPOPTLIB_EXPORT
Class for storing the value and counter for each option in OptionsList.
Class responsible for all message output.
virtual ~OptionsList()
Destructor.
std::string GetValue() const
Method for retrieving the value of an option.
SmartPtr< Journalist > jnlst_
Journalist for writing error messages, etc.
OptionValue()
Default constructor.
void operator=(const OptionValue &copy)
Equals operator.
SmartPtr< RegisteredOptions > reg_options_
list of all the registered options to validate against
std::string value_
Value for this option.
virtual void clear()
Method for clearing all previously set options.