Ipopt Documentation  
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:
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:
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 
195  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 
212  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 
237  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 
245  const std::string& tag,
246  Number value,
247  bool allow_clobber = true,
248  bool dont_print = false
249  );
250 
252  const std::string& tag,
253  Index value,
254  bool allow_clobber = true,
255  bool dont_print = false
256  );
258 
263  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:
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 
365  const std::string& tag
366  ) const;
367 
373  std::istream& is,
374  std::string& token
375  );
376 
378  mutable std::string lowercase_buffer_;
379 };
380 
381 } // namespace Ipopt
382 
383 #endif
IpUtils.hpp
Ipopt::OptionsList::OptionValue::OptionValue
OptionValue(std::string value, bool allow_clobber, bool dont_print)
Constructor given the value.
Definition: IpOptionsList.hpp:46
Ipopt::OptionsList::OptionsList
OptionsList(const OptionsList &copy)
Copy Constructor.
Definition: IpOptionsList.hpp:162
Ipopt::OptionsList::GetIntegerValue
virtual bool GetIntegerValue(const std::string &tag, Index &value, const std::string &prefix) const
Ipopt::OptionsList::OptionValue::~OptionValue
~OptionValue()
Default Destructor.
Definition: IpOptionsList.hpp:84
Ipopt::OptionsList::SetStringValueIfUnset
virtual bool SetStringValueIfUnset(const std::string &tag, const std::string &value, bool allow_clobber=true, bool dont_print=false)
Ipopt::OptionsList::SetJournalist
virtual void SetJournalist(const SmartPtr< Journalist > jnlst)
Definition: IpOptionsList.hpp:202
IpRegOptions.hpp
Ipopt::OptionsList::PrintList
virtual void PrintList(std::string &list) const
Get a string with the list of all options (tag, value, counter)
Ipopt::OptionsList::readnexttoken
bool readnexttoken(std::istream &is, std::string &token)
read the next token from stream is
Ipopt::OptionsList::clear
virtual void clear()
Method for clearing all previously set options.
Definition: IpOptionsList.hpp:188
Ipopt::OptionsList::PrintUserOptions
virtual void PrintUserOptions(std::string &list) const
Get a string with the list of all options set by the user (tag, value, used/notused).
Ipopt::OptionsList::SetRegisteredOptions
virtual void SetRegisteredOptions(const SmartPtr< RegisteredOptions > reg_options)
Definition: IpOptionsList.hpp:195
Ipopt::OptionsList::OptionValue::value_
std::string value_
Value for this option.
Definition: IpOptionsList.hpp:131
Ipopt::OptionsList::ReadFromStream
virtual bool ReadFromStream(const Journalist &jnlst, std::istream &is, bool allow_clobber=false)
Read options from the stream is.
Ipopt
This file contains a base class for all exceptions and a set of macros to help with exceptions.
Definition: IpInexactAlgBuilder.hpp:14
Ipopt::Number
double Number
Type of all numbers.
Definition: IpTypes.hpp:15
Ipopt::OptionsList::jnlst_
SmartPtr< Journalist > jnlst_
Journalist for writing error messages, etc.
Definition: IpOptionsList.hpp:339
Ipopt::OptionsList::OptionValue::counter_
Index counter_
Counter for requests.
Definition: IpOptionsList.hpp:134
Ipopt::OptionsList::GetBoolValue
virtual bool GetBoolValue(const std::string &tag, bool &value, const std::string &prefix) const
Ipopt::OptionsList::OptionsList
OptionsList()
Definition: IpOptionsList.hpp:158
Ipopt::OptionsList::OptionValue::GetValue
std::string GetValue() const
Method for retrieving the value of an option.
Definition: IpOptionsList.hpp:92
Ipopt::OptionsList::SetIntegerValue
virtual bool SetIntegerValue(const std::string &tag, Index value, bool allow_clobber=true, bool dont_print=false)
Ipopt::OptionsList::lowercase_buffer_
std::string lowercase_buffer_
auxiliary string set by lowercase method
Definition: IpOptionsList.hpp:378
Ipopt::OptionsList::lowercase
const std::string & lowercase(const std::string tag) const
auxiliary method for converting sting to all lower-case letters
IPOPTLIB_EXPORT
#define IPOPTLIB_EXPORT
Definition: config_default.h:16
Ipopt::Index
int Index
Type of all indices of vectors, matrices etc.
Definition: IpTypes.hpp:17
Ipopt::OptionsList::SetNumericValue
virtual bool SetNumericValue(const std::string &tag, Number value, bool allow_clobber=true, bool dont_print=false)
Ipopt::OptionsList::OptionValue::Counter
Index Counter() const
Method for accessing current value of the request counter.
Definition: IpOptionsList.hpp:107
Ipopt::OptionsList::OptionValue::DontPrint
bool DontPrint() const
True if this option is not to show up in the print_user_options output.
Definition: IpOptionsList.hpp:123
Ipopt::OptionsList::GetNumericValue
virtual bool GetNumericValue(const std::string &tag, Number &value, const std::string &prefix) const
Ipopt::SmartPtr
Template class for Smart Pointers.
Definition: IpSmartPtr.hpp:172
Ipopt::OptionsList::OptionValue::allow_clobber_
bool allow_clobber_
True if the option can be overwritten.
Definition: IpOptionsList.hpp:140
Ipopt::OptionsList::reg_options_
SmartPtr< RegisteredOptions > reg_options_
list of all the registered options to validate against
Definition: IpOptionsList.hpp:336
Ipopt::OptionsList::OptionValue::initialized_
bool initialized_
for debugging
Definition: IpOptionsList.hpp:137
Ipopt::OptionsList::find_tag
bool find_tag(const std::string &tag, const std::string &prefix, std::string &value) const
auxiliary method for finding the value for a tag in the options list
IpReferenced.hpp
Ipopt::OptionsList::SetStringValue
virtual bool SetStringValue(const std::string &tag, const std::string &value, bool allow_clobber=true, bool dont_print=false)
Ipopt::OptionsList::OptionValue::AllowClobber
bool AllowClobber() const
True if the option can be overwritten.
Definition: IpOptionsList.hpp:114
Ipopt::OptionsList::OptionValue::operator=
void operator=(const OptionValue &copy)
Equals operator.
Definition: IpOptionsList.hpp:72
Ipopt::Journalist
Class responsible for all message output.
Definition: IpJournalist.hpp:117
Ipopt::OptionsList::~OptionsList
virtual ~OptionsList()
Destructor.
Definition: IpOptionsList.hpp:173
Ipopt::OptionsList::SetNumericValueIfUnset
virtual bool SetNumericValueIfUnset(const std::string &tag, Number value, bool allow_clobber=true, bool dont_print=false)
Ipopt::OptionsList::will_allow_clobber
bool will_allow_clobber(const std::string &tag) const
tells whether or not we can clobber a particular option
Ipopt::OptionsList::OptionValue
Class for storing the value and counter for each option in OptionsList.
Definition: IpOptionsList.hpp:36
Ipopt::OptionsList::GetStringValue
virtual bool GetStringValue(const std::string &tag, std::string &value, const std::string &prefix) const
Ipopt::OptionsList::operator=
virtual void operator=(const OptionsList &source)
Default Assignment Operator.
Definition: IpOptionsList.hpp:177
Ipopt::OptionsList::SetIntegerValueIfUnset
virtual bool SetIntegerValueIfUnset(const std::string &tag, Index value, bool allow_clobber=true, bool dont_print=false)
Ipopt::OptionsList::options_
std::map< std::string, OptionValue > options_
Default Constructor.
Definition: IpOptionsList.hpp:333
IpException.hpp
Ipopt::DECLARE_STD_EXCEPTION
DECLARE_STD_EXCEPTION(FATAL_ERROR_IN_LINEAR_SOLVER)
DBG_ASSERT
#define DBG_ASSERT(test)
Definition: IpDebug.hpp:28
Ipopt::OptionsList::OptionValue::OptionValue
OptionValue(const OptionValue &copy)
Copy Constructor.
Definition: IpOptionsList.hpp:60
Ipopt::OptionsList
This class stores a list of user set options.
Definition: IpOptionsList.hpp:33
Ipopt::OptionsList::OptionValue::dont_print_
bool dont_print_
True if this option is not to show up in the print_user_options output.
Definition: IpOptionsList.hpp:144
Ipopt::OptionsList::OptionValue::OptionValue
OptionValue()
Default constructor.
Definition: IpOptionsList.hpp:41
Ipopt::OptionsList::OptionValue::Value
std::string Value() const
Method for retrieving the value without increasing the counter.
Definition: IpOptionsList.hpp:100
Ipopt::ReferencedObject
Storing the reference count of all the smart pointers that currently reference it.
Definition: IpReferenced.hpp:170
Ipopt::OptionsList::GetEnumValue
virtual bool GetEnumValue(const std::string &tag, Index &value, const std::string &prefix) const
Ipopt::OptionsList::OptionsList
OptionsList(SmartPtr< RegisteredOptions > reg_options, SmartPtr< Journalist > jnlst)
Definition: IpOptionsList.hpp:150