- Main Page
- Classes
- Files

- File List
- File Members

# src/Common/IpOptionsList.hpp

Go to the documentation of this file.

    00001 // Copyright (C) 2004, 2006 International Business Machines and others.
    00002 // All Rights Reserved.
    00003 // This code is published under the Eclipse Public License.
    00004 //
    00005 // $Id: IpOptionsList.hpp 1861 2010-12-21 21:34:47Z andreasw $
    00006 //
    00007 // Authors:  Carl Laird, Andreas Waechter     IBM    2004-08-13
    00008
    00009 #ifndef __IPOPTLIST_HPP__
    00010 #define __IPOPTLIST_HPP__
    00011
    00012 #include "IpUtils.hpp"
    00013 #include "IpReferenced.hpp"
    00014 #include "IpException.hpp"
    00015 #include "IpRegOptions.hpp"
    00016
    00017 #include <iostream>
    00018 #include <map>
    00019
    00020 namespace Ipopt
    00021 {
    00023   DECLARE_STD_EXCEPTION(OPTION_INVALID);
    00024
    00032   class OptionsList : public ReferencedObject
    00033   {
    00036     class OptionValue
    00037     {
    00038     public:
    00042       OptionValue()
    00043           :
    00044           initialized_(false)
    00045       {}
    00046
    00048       OptionValue(std::string value, bool allow_clobber, bool dont_print)
    00049           :
    00050           value_(value),
    00051           counter_(0),
    00052           initialized_(true),
    00053           allow_clobber_(allow_clobber),
    00054           dont_print_(dont_print)
    00055       {}
    00056
    00058       OptionValue(const OptionValue& copy)
    00059           :
    00060           value_(copy.value_),
    00061           counter_(copy.counter_),
    00062           initialized_(copy.initialized_),
    00063           allow_clobber_(copy.allow_clobber_),
    00064           dont_print_(copy.dont_print_)
    00065       {}
    00066
    00068       void operator=(const OptionValue& copy)
    00069       {
    00070         value_=copy.value_;
    00071         counter_=copy.counter_;
    00072         initialized_=copy.initialized_;
    00073         allow_clobber_=copy.allow_clobber_;
    00074         dont_print_=copy.dont_print_;
    00075       }
    00076
    00078       ~OptionValue()
    00079       {}
    00081
    00084       std::string GetValue() const
    00085       {
    00086         DBG_ASSERT(initialized_);
    00087         counter_++;
    00088         return value_;
    00089       }
    00090
    00093       std::string Value() const
    00094       {
    00095         DBG_ASSERT(initialized_);
    00096         return value_;
    00097       }
    00098
    00100       Index Counter() const
    00101       {
    00102         DBG_ASSERT(initialized_);
    00103         return counter_;
    00104       }
    00105
    00107       bool AllowClobber() const
    00108       {
    00109         DBG_ASSERT(initialized_);
    00110         return allow_clobber_;
    00111       }
    00112
    00115       bool DontPrint() const
    00116       {
    00117         DBG_ASSERT(initialized_);
    00118         return dont_print_;
    00119       }
    00120
    00121     private:
    00123       std::string value_;
    00124
    00126       mutable Index counter_;
    00127
    00129       bool initialized_;
    00130
    00132       bool allow_clobber_;
    00133
    00136       bool dont_print_;
    00137     };
    00138
    00139   public:
    00142     OptionsList(SmartPtr<RegisteredOptions> reg_options, SmartPtr<Journalist> jnlst)
    00143         : reg_options_(reg_options), jnlst_(jnlst)
    00144     {}
    00145
    00146     OptionsList()
    00147     {}
    00148
    00150     OptionsList(const OptionsList& copy)
    00151     {
    00152       // copy all the option strings and values
    00153       options_ = copy.options_;
    00154       // copy the registered options pointer
    00155       reg_options_ = copy.reg_options_;
    00156     }
    00157
    00159     virtual ~OptionsList()
    00160     {}
    00161
    00163     virtual void operator=(const OptionsList& source)
    00164     {
    00165       options_ = source.options_;
    00166       reg_options_ = source.reg_options_;
    00167       jnlst_ = source.jnlst_;
    00168     }
    00170
    00172     virtual void clear()
    00173     {
    00174       options_.clear();
    00175     }
    00176
    00179     virtual void SetRegisteredOptions(const SmartPtr<RegisteredOptions> reg_options)
    00180     {
    00181       reg_options_ = reg_options;
    00182     }
    00183     virtual void SetJournalist(const SmartPtr<Journalist> jnlst)
    00184     {
    00185       jnlst_ = jnlst;
    00186     }
    00188
    00190     virtual bool SetStringValue(const std::string& tag, const std::string& value,
    00191                                 bool allow_clobber = true, bool dont_print = false);
    00192     virtual bool SetNumericValue(const std::string& tag, Number value,
    00193                                  bool allow_clobber = true, bool dont_print = false);
    00194     virtual bool SetIntegerValue(const std::string& tag, Index value,
    00195                                  bool allow_clobber = true, bool dont_print = false);
    00197
    00201     virtual bool SetStringValueIfUnset(const std::string& tag, const std::string& value,
    00202                                        bool allow_clobber = true, bool dont_print = false);
    00203     virtual bool SetNumericValueIfUnset(const std::string& tag, Number value,
    00204                                         bool allow_clobber = true, bool dont_print = false);
    00205     virtual bool SetIntegerValueIfUnset(const std::string& tag, Index value,
    00206                                         bool allow_clobber = true, bool dont_print = false);
    00208
    00213     virtual bool GetStringValue(const std::string& tag, std::string& value,
    00214                                 const std::string& prefix) const;
    00215     virtual bool GetEnumValue(const std::string& tag, Index& value,
    00216                               const std::string& prefix) const;
    00217     virtual bool GetBoolValue(const std::string& tag, bool& value,
    00218                               const std::string& prefix) const;
    00219     virtual bool GetNumericValue(const std::string& tag, Number& value,
    00220                                  const std::string& prefix) const;
    00221     virtual bool GetIntegerValue(const std::string& tag, Index& value,
    00222                                  const std::string& prefix) const;
    00224
    00226     virtual void PrintList(std::string& list) const;
    00227
    00231     virtual void PrintUserOptions(std::string& list) const;
    00232
    00235     virtual bool ReadFromStream(const Journalist& jnlst, std::istream& is);
    00236
    00237   private:
    00247     //    OptionsList();
    00248
    00250
    00252     std::map< std::string, OptionValue > options_;
    00253
    00255     SmartPtr<RegisteredOptions> reg_options_;
    00256
    00258     SmartPtr<Journalist> jnlst_;
    00259
    00262     const std::string& lowercase(const std::string tag) const;
    00263
    00270     bool find_tag(const std::string& tag, const std::string& prefix,
    00271                   std::string& value) const;
    00272
    00277     bool will_allow_clobber(const std::string& tag) const;
    00278
    00281     bool readnexttoken(std::istream& is, std::string& token);
    00282
    00284     mutable std::string lowercase_buffer_;
    00285   };
    00286
    00287 } // namespace Ipopt
    00288
    00289 #endif

All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines