/home/coin/SVN-release/Ipopt-3.2.4/Ipopt/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 Common Public License.
00004 //
00005 // $Id: IpOptionsList.hpp 759 2006-07-07 03:07:08Z 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     void operator=(const OptionsList& source)
00164     {
00165       options_ = source.options_;
00166     }
00168 
00171     void SetRegisteredOptions(const SmartPtr<RegisteredOptions> reg_options)
00172     {
00173       reg_options_ = reg_options;
00174     }
00175     void SetJournalist(const SmartPtr<Journalist> jnlst)
00176     {
00177       jnlst_ = jnlst;
00178     }
00180 
00182     bool SetStringValue(const std::string& tag, const std::string& value,
00183                         bool allow_clobber = true, bool dont_print = false);
00184     bool SetNumericValue(const std::string& tag, Number value,
00185                          bool allow_clobber = true, bool dont_print = false);
00186     bool SetIntegerValue(const std::string& tag, Index value,
00187                          bool allow_clobber = true, bool dont_print = false);
00189 
00194     bool GetStringValue(const std::string& tag, std::string& value,
00195                         const std::string& prefix) const;
00196     bool GetEnumValue(const std::string& tag, Index& value,
00197                       const std::string& prefix) const;
00198     bool GetBoolValue(const std::string& tag, bool& value,
00199                       const std::string& prefix) const;
00200     bool GetNumericValue(const std::string& tag, Number& value,
00201                          const std::string& prefix) const;
00202     bool GetIntegerValue(const std::string& tag, Index& value,
00203                          const std::string& prefix) const;
00205 
00207     void PrintList(std::string& list) const;
00208 
00212     void PrintUserOptions(std::string& list) const;
00213 
00216     bool ReadFromStream(const Journalist& jnlst, std::istream& is);
00217 
00218   private:
00228     //    OptionsList();
00229 
00231 
00233     std::map< std::string, OptionValue > options_;
00234 
00236     SmartPtr<RegisteredOptions> reg_options_;
00237 
00239     SmartPtr<Journalist> jnlst_;
00240 
00243     const std::string& lowercase(const std::string tag) const;
00244 
00251     bool find_tag(const std::string& tag, const std::string& prefix,
00252                   std::string& value) const;
00253 
00258     bool will_allow_clobber(const std::string& tag) const;
00259 
00262     bool readnexttoken(std::istream& is, std::string& token);
00263 
00265     mutable std::string lowercase_buffer_;
00266   };
00267 
00268 } // namespace Ipopt
00269 
00270 #endif

Generated on Thu May 15 22:23:37 2008 by  doxygen 1.4.7