Ipopt 3.12.10

- Main Page
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
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 // $Id: IpOptionsList.hpp 2613 2015-11-04 14:42:02Z stefan $
6 //
7 // Authors: Carl Laird, Andreas Waechter IBM 2004-08-13
8
9 #ifndef __IPOPTLIST_HPP__
10 #define __IPOPTLIST_HPP__
11
12 #include "IpUtils.hpp"
13 #include "IpReferenced.hpp"
14 #include "IpException.hpp"
15 #include "IpRegOptions.hpp"
16
17 #include <iostream>
18 #include <map>
19
20 namespace Ipopt
21 {
23 DECLARE_STD_EXCEPTION(OPTION_INVALID);
24
32 class OptionsList : public ReferencedObject
33 {
36 class OptionValue
37 {
38 public:
42 OptionValue()
43 :
44 initialized_(false)
45 {}
46
48 OptionValue(std::string value, bool allow_clobber, bool dont_print)
49 :
50 value_(value),
51 counter_(0),
52 initialized_(true),
53 allow_clobber_(allow_clobber),
54 dont_print_(dont_print)
55 {}
56
58 OptionValue(const OptionValue& copy)
59 :
60 value_(copy.value_),
61 counter_(copy.counter_),
62 initialized_(copy.initialized_),
63 allow_clobber_(copy.allow_clobber_),
64 dont_print_(copy.dont_print_)
65 {}
66
68 void operator=(const OptionValue& copy)
69 {
70 value_=copy.value_;
71 counter_=copy.counter_;
72 initialized_=copy.initialized_;
73 allow_clobber_=copy.allow_clobber_;
74 dont_print_=copy.dont_print_;
75 }
76
78 ~OptionValue()
79 {}
81
84 std::string GetValue() const
85 {
86 DBG_ASSERT(initialized_);
87 counter_++;
88 return value_;
89 }
90
93 std::string Value() const
94 {
95 DBG_ASSERT(initialized_);
96 return value_;
97 }
98
100 Index Counter() const
101 {
102 DBG_ASSERT(initialized_);
103 return counter_;
104 }
105
107 bool AllowClobber() const
108 {
109 DBG_ASSERT(initialized_);
110 return allow_clobber_;
111 }
112
115 bool DontPrint() const
116 {
117 DBG_ASSERT(initialized_);
118 return dont_print_;
119 }
120
121 private:
123 std::string value_;
124
126 mutable Index counter_;
127
129 bool initialized_;
130
132 bool allow_clobber_;
133
136 bool dont_print_;
137 };
138
139 public:
142 OptionsList(SmartPtr<RegisteredOptions> reg_options, SmartPtr<Journalist> jnlst)
143 : reg_options_(reg_options), jnlst_(jnlst)
144 {}
145
146 OptionsList()
147 {}
148
150 OptionsList(const OptionsList& copy)
151 {
152 // copy all the option strings and values
153 options_ = copy.options_;
154 // copy the registered options pointer
155 reg_options_ = copy.reg_options_;
156 }
157
159 virtual ~OptionsList()
160 {}
161
163 virtual void operator=(const OptionsList& source)
164 {
165 options_ = source.options_;
166 reg_options_ = source.reg_options_;
167 jnlst_ = source.jnlst_;
168 }
170
172 virtual void clear()
173 {
174 options_.clear();
175 }
176
179 virtual void SetRegisteredOptions(const SmartPtr<RegisteredOptions> reg_options)
180 {
181 reg_options_ = reg_options;
182 }
183 virtual void SetJournalist(const SmartPtr<Journalist> jnlst)
184 {
185 jnlst_ = jnlst;
186 }
188
190 virtual bool SetStringValue(const std::string& tag, const std::string& value,
191 bool allow_clobber = true, bool dont_print = false);
192 virtual bool SetNumericValue(const std::string& tag, Number value,
193 bool allow_clobber = true, bool dont_print = false);
194 virtual bool SetIntegerValue(const std::string& tag, Index value,
195 bool allow_clobber = true, bool dont_print = false);
197
201 virtual bool SetStringValueIfUnset(const std::string& tag, const std::string& value,
202 bool allow_clobber = true, bool dont_print = false);
203 virtual bool SetNumericValueIfUnset(const std::string& tag, Number value,
204 bool allow_clobber = true, bool dont_print = false);
205 virtual bool SetIntegerValueIfUnset(const std::string& tag, Index value,
206 bool allow_clobber = true, bool dont_print = false);
208
213 virtual bool GetStringValue(const std::string& tag, std::string& value,
214 const std::string& prefix) const;
215 virtual bool GetEnumValue(const std::string& tag, Index& value,
216 const std::string& prefix) const;
217 virtual bool GetBoolValue(const std::string& tag, bool& value,
218 const std::string& prefix) const;
219 virtual bool GetNumericValue(const std::string& tag, Number& value,
220 const std::string& prefix) const;
221 virtual bool GetIntegerValue(const std::string& tag, Index& value,
222 const std::string& prefix) const;
224
226 virtual void PrintList(std::string& list) const;
227
231 virtual void PrintUserOptions(std::string& list) const;
232
235 virtual bool ReadFromStream(const Journalist& jnlst, std::istream& is, bool allow_clobber = false);
236
237 private:
247 // OptionsList();
248
250
252 std::map< std::string, OptionValue > options_;
253
255 SmartPtr<RegisteredOptions> reg_options_;
256
258 SmartPtr<Journalist> jnlst_;
259
262 const std::string& lowercase(const std::string tag) const;
263
270 bool find_tag(const std::string& tag, const std::string& prefix,
271 std::string& value) const;
272
277 bool will_allow_clobber(const std::string& tag) const;
278
281 bool readnexttoken(std::istream& is, std::string& token);
282
284 mutable std::string lowercase_buffer_;
285 };
286
287 } // namespace Ipopt
288
289 #endif
Ipopt::OptionsList::OptionValue::Value
std::string Value() const
Method for retrieving the value without increasing the counter.
Definition: IpOptionsList.hpp:93
Ipopt::OptionsList::GetEnumValue
virtual bool GetEnumValue(const std::string &tag, Index &value, const std::string &prefix) const
Ipopt::OptionsList::SetNumericValue
virtual bool SetNumericValue(const std::string &tag, Number value, bool allow_clobber=true, bool dont_print=false)
Ipopt::OptionsList::SetJournalist
virtual void SetJournalist(const SmartPtr< Journalist > jnlst)
Definition: IpOptionsList.hpp:183
Ipopt::OptionsList::OptionValue::OptionValue
OptionValue(std::string value, bool allow_clobber, bool dont_print)
Constructor given the value.
Definition: IpOptionsList.hpp:48
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, use/notused).
IpUtils.hpp
Ipopt::OptionsList::SetIntegerValue
virtual bool SetIntegerValue(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:252
Ipopt::OptionsList::OptionValue::OptionValue
OptionValue(const OptionValue &copy)
Copy Constructor.
Definition: IpOptionsList.hpp:58
Ipopt::OptionsList::GetBoolValue
virtual bool GetBoolValue(const std::string &tag, bool &value, const std::string &prefix) const
Ipopt::OptionsList::ReadFromStream
virtual bool ReadFromStream(const Journalist &jnlst, std::istream &is, bool allow_clobber=false)
Read options from the stream is.
Ipopt::Number
double Number
Type of all numbers.
Definition: IpTypes.hpp:17
Ipopt::OptionsList::find_tag
bool find_tag(const std::string &tag, const std::string &prefix, std::string &value) const
auxilliary method for finding the value for a tag in the options list.
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)
Overloaded Equals Operator.
Definition: IpOptionsList.hpp:163
Ipopt::OptionsList::SetIntegerValueIfUnset
virtual bool SetIntegerValueIfUnset(const std::string &tag, Index value, bool allow_clobber=true, bool dont_print=false)
Ipopt::OptionsList::OptionValue::~OptionValue
~OptionValue()
Default Destructor.
Definition: IpOptionsList.hpp:78
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:136
Ipopt::OptionsList::PrintList
virtual void PrintList(std::string &list) const
Get a string with the list of all options (tag, value, counter)
Ipopt::OptionsList::OptionsList
OptionsList(const OptionsList &copy)
Copy Constructor.
Definition: IpOptionsList.hpp:150
Ipopt::SmartPtr
Template class for Smart Pointers.
Definition: IpSmartPtr.hpp:172
Ipopt::ReferencedObject
ReferencedObject class.
Definition: IpReferenced.hpp:174
Ipopt::OptionsList
This class stores a list of user set options.
Definition: IpOptionsList.hpp:32
Ipopt::OptionsList::readnexttoken
bool readnexttoken(std::istream &is, std::string &token)
read the next token from stream is.
Ipopt::OptionsList::OptionValue::counter_
Index counter_
Counter for requests.
Definition: IpOptionsList.hpp:126
Ipopt::OptionsList::OptionsList
OptionsList()
Definition: IpOptionsList.hpp:146
Ipopt::OptionsList::OptionsList
OptionsList(SmartPtr< RegisteredOptions > reg_options, SmartPtr< Journalist > jnlst)
Definition: IpOptionsList.hpp:142
Ipopt::OptionsList::OptionValue::AllowClobber
bool AllowClobber() const
True if the option can be overwritten.
Definition: IpOptionsList.hpp:107
Ipopt::OptionsList::OptionValue::allow_clobber_
bool allow_clobber_
True if the option can be overwritten.
Definition: IpOptionsList.hpp:132
Ipopt::OptionsList::OptionValue::Counter
Index Counter() const
Method for accessing current value of the request counter.
Definition: IpOptionsList.hpp:100
Ipopt::OptionsList::SetStringValueIfUnset
virtual bool SetStringValueIfUnset(const std::string &tag, const std::string &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::SetStringValue
virtual bool SetStringValue(const std::string &tag, const std::string &value, bool allow_clobber=true, bool dont_print=false)
Ipopt::OptionsList::lowercase_buffer_
std::string lowercase_buffer_
auxilliary string set by lowercase method
Definition: IpOptionsList.hpp:284
Ipopt::Index
int Index
Type of all indices of vectors, matrices etc.
Definition: IpTypes.hpp:19
IpReferenced.hpp
DBG_ASSERT
#define DBG_ASSERT(test)
Definition: IpDebug.hpp:38
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:115
Ipopt::OptionsList::OptionValue::initialized_
bool initialized_
for debugging
Definition: IpOptionsList.hpp:129
Ipopt::DECLARE_STD_EXCEPTION
DECLARE_STD_EXCEPTION(SUFFIX_EMPTY)
Ipopt::OptionsList::GetNumericValue
virtual bool GetNumericValue(const std::string &tag, Number &value, const std::string &prefix) const
Ipopt::OptionsList::SetRegisteredOptions
virtual void SetRegisteredOptions(const SmartPtr< RegisteredOptions > reg_options)
Definition: IpOptionsList.hpp:179
Ipopt::OptionsList::OptionValue
Class for storing the value and counter for each option in OptionsList.
Definition: IpOptionsList.hpp:36
Ipopt::Journalist
Class responsible for all message output.
Definition: IpJournalist.hpp:134
Ipopt::OptionsList::~OptionsList
virtual ~OptionsList()
Default destructor.
Definition: IpOptionsList.hpp:159
Ipopt::OptionsList::SetNumericValueIfUnset
virtual bool SetNumericValueIfUnset(const std::string &tag, Number value, bool allow_clobber=true, bool dont_print=false)
Ipopt::OptionsList::OptionValue::GetValue
std::string GetValue() const
Method for retrieving the value of an option.
Definition: IpOptionsList.hpp:84
Ipopt::OptionsList::jnlst_
SmartPtr< Journalist > jnlst_
Journalist for writing error messages, etc.
Definition: IpOptionsList.hpp:258
Ipopt::OptionsList::GetIntegerValue
virtual bool GetIntegerValue(const std::string &tag, Index &value, const std::string &prefix) const
Ipopt::OptionsList::lowercase
const std::string & lowercase(const std::string tag) const
auxilliary method for converting sting to all lower-case letters
Ipopt::OptionsList::OptionValue::OptionValue
OptionValue()
Default constructor (needed for the map)
Definition: IpOptionsList.hpp:42
Ipopt::OptionsList::OptionValue::operator=
void operator=(const OptionValue &copy)
Equals operator.
Definition: IpOptionsList.hpp:68
Ipopt::OptionsList::reg_options_
SmartPtr< RegisteredOptions > reg_options_
list of all the registered options to validate against
Definition: IpOptionsList.hpp:255
Ipopt::OptionsList::OptionValue::value_
std::string value_
Value for this option.
Definition: IpOptionsList.hpp:123
IpException.hpp
Ipopt::OptionsList::clear
virtual void clear()
Method for clearing all previously set options.
Definition: IpOptionsList.hpp:172
IpRegOptions.hpp