Ipopt Documentation  
 
Loading...
Searching...
No Matches
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
18namespace Ipopt
19{
21DECLARE_STD_EXCEPTION(OPTION_INVALID);
22
33{
36 {
37 public:
40
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
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
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
135
138
141
145 };
146
147public:
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
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
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
318private:
329
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
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
#define DBG_ASSERT(test)
Definition: IpDebug.hpp:27
#define DECLARE_STD_EXCEPTION(__except_type)
Class responsible for all message output.
Class for storing the value and counter for each option in OptionsList.
std::string GetValue() const
Method for retrieving the value of an option.
bool dont_print_
True if this option is not to show up in the print_user_options output.
bool DontPrint() const
True if this option is not to show up in the print_user_options output.
bool AllowClobber() const
True if the option can be overwritten.
Index counter_
Counter for requests.
std::string value_
Value for this option.
OptionValue(const OptionValue &copy)
Copy Constructor.
std::string Value() const
Method for retrieving the value without increasing the counter.
Index Counter() const
Method for accessing current value of the request counter.
bool allow_clobber_
True if the option can be overwritten.
OptionValue()
Default constructor.
~OptionValue()
Default Destructor.
void operator=(const OptionValue &copy)
Equals operator.
OptionValue(std::string value, bool allow_clobber, bool dont_print)
Constructor given the value.
This class stores a list of user set options.
std::string lowercase_buffer_
auxiliary string set by lowercase method
virtual bool GetBoolValue(const std::string &tag, bool &value, const std::string &prefix) const
virtual bool SetNumericValueIfUnset(const std::string &tag, Number value, bool allow_clobber=true, bool dont_print=false)
virtual ~OptionsList()
Destructor.
virtual bool GetStringValue(const std::string &tag, std::string &value, const std::string &prefix) const
virtual bool GetNumericValue(const std::string &tag, Number &value, const std::string &prefix) const
virtual void PrintUserOptions(std::string &list) const
Get a string with the list of all options set by the user (tag, value, used/notused).
virtual bool GetIntegerValue(const std::string &tag, Index &value, const std::string &prefix) const
bool readnexttoken(std::istream &is, std::string &token)
read the next token from stream is
std::map< std::string, OptionValue > options_
Default Constructor.
virtual void SetJournalist(const SmartPtr< Journalist > jnlst)
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
virtual bool SetIntegerValue(const std::string &tag, Index value, bool allow_clobber=true, bool dont_print=false)
virtual void SetRegisteredOptions(const SmartPtr< RegisteredOptions > reg_options)
virtual void operator=(const OptionsList &source)
Default Assignment Operator.
virtual bool GetEnumValue(const std::string &tag, Index &value, const std::string &prefix) const
bool will_allow_clobber(const std::string &tag) const
tells whether or not we can clobber a particular option
const std::string & lowercase(const std::string tag) const
auxiliary method for converting sting to all lower-case letters
virtual bool ReadFromStream(const Journalist &jnlst, std::istream &is, bool allow_clobber=false)
Read options from the stream is.
virtual bool SetIntegerValueIfUnset(const std::string &tag, Index value, bool allow_clobber=true, bool dont_print=false)
virtual bool SetStringValue(const std::string &tag, const std::string &value, bool allow_clobber=true, bool dont_print=false)
virtual void PrintList(std::string &list) const
Get a string with the list of all options (tag, value, counter)
OptionsList(SmartPtr< RegisteredOptions > reg_options, SmartPtr< Journalist > jnlst)
SmartPtr< RegisteredOptions > reg_options_
list of all the registered options to validate against
virtual bool SetNumericValue(const std::string &tag, Number value, bool allow_clobber=true, bool dont_print=false)
virtual void clear()
Method for clearing all previously set options.
virtual bool SetStringValueIfUnset(const std::string &tag, const std::string &value, bool allow_clobber=true, bool dont_print=false)
SmartPtr< Journalist > jnlst_
Journalist for writing error messages, etc.
OptionsList(const OptionsList &copy)
Copy Constructor.
Storing the reference count of all the smart pointers that currently reference it.
Template class for Smart Pointers.
Definition: IpSmartPtr.hpp:172
#define IPOPTLIB_EXPORT
This file contains a base class for all exceptions and a set of macros to help with exceptions.
int Index
Type of all indices of vectors, matrices etc.
Definition: IpTypes.hpp:17
double Number
Type of all numbers.
Definition: IpTypes.hpp:15