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{
22
33{
36 {
37 public:
40
42 : initialized_(false)
43 { }
44
47 const 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 return *this;
82 }
83
86 { }
88
93 std::string GetValue() const
94 {
95 DBG_ASSERT(initialized_);
96 counter_++;
97 return value_;
98 }
99
101 std::string Value() const
102 {
103 DBG_ASSERT(initialized_);
104 return value_;
105 }
106
109 {
110 DBG_ASSERT(initialized_);
111 return counter_;
112 }
113
115 bool AllowClobber() const
116 {
117 DBG_ASSERT(initialized_);
118 return allow_clobber_;
119 }
120
124 bool DontPrint() const
125 {
126 DBG_ASSERT(initialized_);
127 return dont_print_;
128 }
129
130 private:
132 std::string value_;
133
136
139
142
146 };
147
148public:
154 )
155 : reg_options_(reg_options),
156 jnlst_(jnlst)
157 { }
158
160 { }
161
164 const OptionsList& copy
165 )
166 : options_(copy.options_), // copy all the option strings and values
167 reg_options_(copy.reg_options_) // copy the registered options pointer
168 { }
169
171 virtual ~OptionsList()
172 { }
173
176 const OptionsList& source
177 )
178 {
179 options_ = source.options_;
180 reg_options_ = source.reg_options_;
181 jnlst_ = source.jnlst_;
182 return *this;
183 }
185
187 virtual void clear()
188 {
189 options_.clear();
190 }
191
196 )
197 {
198 reg_options_ = reg_options;
199 }
200
201 virtual void SetJournalist(
203 )
204 {
205 jnlst_ = jnlst;
206 }
207
209
211 virtual bool SetStringValue(
212 const std::string& tag,
213 const std::string& value,
214 bool allow_clobber = true,
215 bool dont_print = false
216 );
217
218 virtual bool SetNumericValue(
219 const std::string& tag,
221 bool allow_clobber = true,
222 bool dont_print = false
223 );
224
225 virtual bool SetIntegerValue(
226 const std::string& tag,
227 Index value,
228 bool allow_clobber = true,
229 bool dont_print = false
230 );
231
233 virtual bool SetBoolValue(
234 const std::string& tag,
235 bool value,
236 bool allow_clobber = true,
237 bool dont_print = false
238 )
239 {
240 return SetStringValue(tag, value ? "yes" : "no", allow_clobber, dont_print);
241 }
242
247 virtual bool UnsetValue(
248 const std::string& tag
249 );
251
255 const std::string& tag,
256 const std::string& value,
257 bool allow_clobber = true,
258 bool dont_print = false
259 );
260
262 const std::string& tag,
264 bool allow_clobber = true,
265 bool dont_print = false
266 );
267
269 const std::string& tag,
270 Index value,
271 bool allow_clobber = true,
272 bool dont_print = false
273 );
274
277 const std::string& tag,
278 bool value,
279 bool allow_clobber = true,
280 bool dont_print = false
281 )
282 {
283 return SetStringValueIfUnset(tag, value ? "yes" : "no", allow_clobber, dont_print);
284 }
286
292 virtual bool GetStringValue(
293 const std::string& tag,
294 std::string& value,
295 const std::string& prefix
296 ) const;
297
298 virtual bool GetEnumValue(
299 const std::string& tag,
300 Index& value,
301 const std::string& prefix
302 ) const;
303
304 virtual bool GetBoolValue(
305 const std::string& tag,
306 bool& value,
307 const std::string& prefix
308 ) const;
309
310 virtual bool GetNumericValue(
311 const std::string& tag,
312 Number& value,
313 const std::string& prefix
314 ) const;
315
316 virtual bool GetIntegerValue(
317 const std::string& tag,
318 Index& value,
319 const std::string& prefix
320 ) const;
322
324 virtual void PrintList(
325 std::string& list
326 ) const;
327
333 virtual void PrintUserOptions(
334 std::string& list
335 ) const;
336
341 virtual bool ReadFromStream(
342 const Journalist& jnlst,
343 std::istream& is,
344 bool allow_clobber = false
345 );
346
347private:
358
359 // OptionsList();
361
362 std::map<std::string, OptionValue> options_;
363
366
369
371 const std::string& lowercase(
372 const std::string& tag
373 ) const;
374
384 const std::string& tag,
385 const std::string& prefix,
386 std::string& value
387 ) const;
388
394 const std::string& tag
395 ) const;
396
402 std::istream& is,
403 std::string& token
404 );
405
407 mutable std::string lowercase_buffer_;
408};
409
410} // namespace Ipopt
411
412#endif
#define DBG_ASSERT(test)
Definition IpDebug.hpp:27
#define DECLARE_STD_EXCEPTION(__except_type)
Templated class which stores one entry for the CachedResult class.
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.
OptionValue & operator=(const OptionValue &copy)
Equals operator.
std::string value_
Value for this option.
OptionValue(const OptionValue &copy)
Copy Constructor.
OptionValue(const std::string &value, bool allow_clobber, bool dont_print)
Constructor given the value.
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.
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 UnsetValue(const std::string &tag)
Resets an option to its default value, if clobber is allowed.
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 bool SetBoolValue(const std::string &tag, bool value, bool allow_clobber=true, bool dont_print=false)
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
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 bool SetBoolValueIfUnset(const std::string &tag, bool 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)
const std::string & lowercase(const std::string &tag) const
auxiliary method for converting sting to all lower-case letters
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.
virtual OptionsList & operator=(const OptionsList &source)
Default Assignment Operator.
OptionsList(const OptionsList &copy)
Copy Constructor.
Storing the reference count of all the smart pointers that currently reference it.
#define IPOPTLIB_EXPORT
This file contains a base class for all exceptions and a set of macros to help with exceptions.
ipindex Index
Type of all indices of vectors, matrices etc.
Definition IpTypes.hpp:20
ipnumber Number
Type of all numbers.
Definition IpTypes.hpp:17