• Main Page
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

/tmp/buildd/coinor-ipopt-3.8.3/Ipopt/src/Common/IpRegOptions.hpp

Go to the documentation of this file.
00001 // Copyright (C) 2004, 2007 International Business Machines and others.
00002 // All Rights Reserved.
00003 // This code is published under the Common Public License.
00004 //
00005 // $Id: IpRegOptions.hpp 1692 2010-06-21 19:10:07Z andreasw $
00006 //
00007 // Authors:  Carl Laird, Andreas Waechter     IBM    2005-06-18
00008 
00009 #ifndef __IPREGOPTIONS_HPP__
00010 #define __IPREGOPTIONS_HPP__
00011 
00012 #include "IpUtils.hpp"
00013 #include "IpReferenced.hpp"
00014 #include "IpException.hpp"
00015 #include "IpSmartPtr.hpp"
00016 
00017 #include <map>
00018 
00019 namespace Ipopt
00020 {
00021 
00022   enum RegisteredOptionType
00023   {
00024     OT_Number,
00025     OT_Integer,
00026     OT_String,
00027     OT_Unknown
00028   };
00029 
00033   class RegisteredOption : public ReferencedObject
00034   {
00035   public:
00037     class string_entry
00038     {
00039     public:
00040       string_entry(const std::string& value, const std::string& description)
00041           : value_(value), description_(description)
00042       {}
00043       std::string value_;
00044       std::string description_;
00045     };
00046 
00049     RegisteredOption()
00050         :
00051         type_(OT_Unknown),
00052         has_lower_(false),
00053         has_upper_(false),
00054         counter_(0)
00055     {}
00056 
00057     RegisteredOption(const std::string& name,
00058                      const std::string& short_description,
00059                      const std::string& long_description,
00060                      const std::string& registering_category)
00061         :
00062         name_(name),
00063         short_description_(short_description),
00064         long_description_(long_description),
00065         registering_category_(registering_category),
00066         type_(OT_Unknown),
00067         has_lower_(false),
00068         has_upper_(false),
00069         counter_(next_counter_++)
00070     {}
00071 
00072     RegisteredOption(const RegisteredOption& copy)
00073         :
00074         name_(copy.name_),
00075         short_description_(copy.short_description_),
00076         long_description_(copy.long_description_),
00077         registering_category_(copy.registering_category_),
00078         type_(copy.type_),
00079         has_lower_(copy.has_lower_),
00080         lower_(copy.lower_),
00081         has_upper_(copy.has_upper_),
00082         upper_(copy.upper_),
00083         valid_strings_(copy.valid_strings_),
00084         counter_(copy.counter_)
00085     {}
00086 
00087     virtual ~RegisteredOption()
00088     {}
00090 
00091     DECLARE_STD_EXCEPTION(ERROR_CONVERTING_STRING_TO_ENUM);
00092 
00096     virtual const std::string& Name() const
00097     {
00098       return name_;
00099     }
00101     virtual void SetName(const std::string& name)
00102     {
00103       name_ = name;
00104     }
00106     virtual const std::string& ShortDescription() const
00107     {
00108       return short_description_;
00109     }
00111     virtual const std::string& LongDescription() const
00112     {
00113       return long_description_;
00114     }
00116     virtual void SetShortDescription(const std::string& short_description)
00117     {
00118       short_description_ = short_description;
00119     }
00121     virtual void SetLongDescription(const std::string& long_description)
00122     {
00123       long_description_ = long_description;
00124     }
00126     virtual const std::string& RegisteringCategory() const
00127     {
00128       return registering_category_;
00129     }
00131     virtual void SetRegisteringCategory(const std::string& registering_category)
00132     {
00133       registering_category_ = registering_category;
00134     }
00136     virtual const RegisteredOptionType& Type() const
00137     {
00138       return type_;
00139     }
00141     virtual void SetType(const RegisteredOptionType& type)
00142     {
00143       type_ = type;
00144     }
00146     virtual Index Counter() const
00147     {
00148       return counter_;
00149     }
00151 
00158     virtual const bool& HasLower() const
00159     {
00160       DBG_ASSERT(type_ == OT_Number || type_ == OT_Integer);
00161       return has_lower_;
00162     }
00165     virtual const bool& LowerStrict() const
00166     {
00167       DBG_ASSERT(type_ == OT_Number && has_lower_ == true);
00168       return lower_strict_;
00169     }
00172     virtual Number LowerNumber() const
00173     {
00174       DBG_ASSERT(has_lower_ == true && type_ == OT_Number);
00175       return lower_;
00176     }
00179     virtual void SetLowerNumber(const Number& lower, const bool& strict)
00180     {
00181       DBG_ASSERT(type_ == OT_Number);
00182       lower_ = lower;
00183       lower_strict_ = strict, has_lower_ = true;
00184     }
00187     virtual Index LowerInteger() const
00188     {
00189       DBG_ASSERT(has_lower_ == true && type_ == OT_Integer);
00190       return (Index)lower_;
00191     }
00194     virtual void SetLowerInteger(const Index& lower)
00195     {
00196       DBG_ASSERT(type_ == OT_Integer);
00197       lower_ = (Number)lower;
00198       has_lower_ = true;
00199     }
00202     virtual const bool& HasUpper() const
00203     {
00204       DBG_ASSERT(type_ == OT_Number || type_ == OT_Integer);
00205       return has_upper_;
00206     }
00209     virtual const bool& UpperStrict() const
00210     {
00211       DBG_ASSERT(type_ == OT_Number && has_upper_ == true);
00212       return upper_strict_;
00213     }
00216     virtual Number UpperNumber() const
00217     {
00218       DBG_ASSERT(has_upper_ == true && type_ == OT_Number);
00219       return upper_;
00220     }
00223     virtual void SetUpperNumber(const Number& upper, const bool& strict)
00224     {
00225       DBG_ASSERT(type_ == OT_Number);
00226       upper_ = upper;
00227       upper_strict_ = strict;
00228       has_upper_ = true;
00229     }
00232     virtual Index UpperInteger() const
00233     {
00234       DBG_ASSERT(has_upper_ == true && type_ == OT_Integer);
00235       return (Index)upper_;
00236     }
00239     virtual void SetUpperInteger(const Index& upper)
00240     {
00241       DBG_ASSERT(type_ == OT_Integer);
00242       upper_ = (Number)upper;
00243       has_upper_ = true;
00244     }
00247     virtual void AddValidStringSetting(const std::string value,
00248                                        const std::string description)
00249     {
00250       DBG_ASSERT(type_ == OT_String);
00251       valid_strings_.push_back(string_entry(value, description));
00252     }
00254     virtual Number DefaultNumber() const
00255     {
00256       DBG_ASSERT(type_ == OT_Number);
00257       return default_number_;
00258     }
00260     virtual void SetDefaultNumber(const Number& default_value)
00261     {
00262       DBG_ASSERT(type_ == OT_Number);
00263       default_number_ = default_value;
00264     }
00266     virtual Index DefaultInteger() const
00267     {
00268       DBG_ASSERT(type_ == OT_Integer);
00269       return (Index)default_number_;
00270     }
00273     virtual void SetDefaultInteger(const Index& default_value)
00274     {
00275       DBG_ASSERT(type_ == OT_Integer);
00276       default_number_ = (Number)default_value;
00277     }
00279     virtual std::string DefaultString() const
00280     {
00281       DBG_ASSERT(type_ == OT_String);
00282       return default_string_;
00283     }
00287     virtual Index DefaultStringAsEnum() const
00288     {
00289       DBG_ASSERT(type_ == OT_String);
00290       return MapStringSettingToEnum(default_string_);
00291     }
00293     virtual void SetDefaultString(const std::string& default_value)
00294     {
00295       DBG_ASSERT(type_ == OT_String);
00296       default_string_ = default_value;
00297     }
00299     virtual std::vector<string_entry> GetValidStrings() const
00300     {
00301       DBG_ASSERT(type_ == OT_String);
00302       return valid_strings_;
00303     }
00306     virtual bool IsValidNumberSetting(const Number& value) const
00307     {
00308       DBG_ASSERT(type_ == OT_Number);
00309       if (has_lower_ && ((lower_strict_ == true && value <= lower_) ||
00310                          (lower_strict_ == false && value < lower_))) {
00311         return false;
00312       }
00313       if (has_upper_ && ((upper_strict_ == true && value >= upper_) ||
00314                          (upper_strict_ == false && value > upper_))) {
00315         return false;
00316       }
00317       return true;
00318     }
00321     virtual bool IsValidIntegerSetting(const Index& value) const
00322     {
00323       DBG_ASSERT(type_ == OT_Integer);
00324       if (has_lower_ && value < lower_) {
00325         return false;
00326       }
00327       if (has_upper_ && value > upper_) {
00328         return false;
00329       }
00330       return true;
00331     }
00334     virtual bool IsValidStringSetting(const std::string& value) const;
00335 
00339     virtual std::string MapStringSetting(const std::string& value) const;
00340 
00345     virtual Index MapStringSettingToEnum(const std::string& value) const;
00347 
00349     virtual void OutputDescription(const Journalist& jnlst) const;
00351     virtual void OutputShortDescription(const Journalist& jnlst) const;
00353     virtual void OutputLatexDescription(const Journalist& jnlst) const;
00354 
00355   private:
00356     std::string name_;
00357     std::string short_description_;
00358     std::string long_description_;
00359     std::string registering_category_;
00360     RegisteredOptionType type_;
00361 
00362     bool has_lower_;
00363     bool lower_strict_;
00364     Number lower_;
00365     bool has_upper_;
00366     bool upper_strict_;
00367     Number upper_;
00368     Number default_number_;
00369 
00370     void MakeValidLatexString(std::string source, std::string& dest) const;
00371     std::string MakeValidLatexNumber(Number value) const;
00372 
00375     bool string_equal_insensitive(const std::string& s1,
00376                                   const std::string& s2) const;
00377 
00378     std::vector<string_entry> valid_strings_;
00379     std::string default_string_;
00380 
00383     const Index counter_;
00384 
00385     static Index next_counter_;
00386   };
00387 
00391   class RegisteredOptions : public ReferencedObject
00392   {
00393   public:
00397     RegisteredOptions()
00398         :
00399         current_registering_category_("Uncategorized")
00400     {}
00401 
00403     virtual ~RegisteredOptions()
00404     {}
00406 
00407     DECLARE_STD_EXCEPTION(OPTION_ALREADY_REGISTERED);
00408 
00413     virtual void SetRegisteringCategory(const std::string& registering_category)
00414     {
00415       current_registering_category_ = registering_category;
00416     }
00417 
00419     virtual std::string RegisteringCategory()
00420     {
00421       return current_registering_category_;
00422     }
00423 
00425     virtual void AddNumberOption(const std::string& name,
00426                                  const std::string& short_description,
00427                                  Number default_value,
00428                                  const std::string& long_description="");
00430     virtual void AddLowerBoundedNumberOption(const std::string& name,
00431         const std::string& short_description,
00432         Number lower, bool strict,
00433         Number default_value,
00434         const std::string& long_description="");
00436     virtual void AddUpperBoundedNumberOption(const std::string& name,
00437         const std::string& short_description,
00438         Number upper, bool strict,
00439         Number default_value,
00440         const std::string& long_description="");
00442     virtual void AddBoundedNumberOption(const std::string& name,
00443                                         const std::string& short_description,
00444                                         Number lower, bool lower_strict,
00445                                         Number upper, bool upper_strict,
00446                                         Number default_value,
00447                                         const std::string& long_description="");
00449     virtual void AddIntegerOption(const std::string& name,
00450                                   const std::string& short_description,
00451                                   Index default_value,
00452                                   const std::string& long_description="");
00454     virtual void AddLowerBoundedIntegerOption(const std::string& name,
00455         const std::string& short_description,
00456         Index lower, Index default_value,
00457         const std::string& long_description="");
00459     virtual void AddUpperBoundedIntegerOption(const std::string& name,
00460         const std::string& short_description,
00461         Index upper, Index default_value,
00462         const std::string& long_description="");
00464     virtual void AddBoundedIntegerOption(const std::string& name,
00465                                          const std::string& short_description,
00466                                          Index lower, Index upper,
00467                                          Index default_value,
00468                                          const std::string& long_description="");
00469 
00471     virtual void AddStringOption(const std::string& name,
00472                                  const std::string& short_description,
00473                                  const std::string& default_value,
00474                                  const std::vector<std::string>& settings,
00475                                  const std::vector<std::string>& descriptions,
00476                                  const std::string& long_description="");
00479     virtual void AddStringOption1(const std::string& name,
00480                                   const std::string& short_description,
00481                                   const std::string& default_value,
00482                                   const std::string& setting1,
00483                                   const std::string& description1,
00484                                   const std::string& long_description="");
00485     virtual void AddStringOption2(const std::string& name,
00486                                   const std::string& short_description,
00487                                   const std::string& default_value,
00488                                   const std::string& setting1,
00489                                   const std::string& description1,
00490                                   const std::string& setting2,
00491                                   const std::string& description2,
00492                                   const std::string& long_description="");
00493     virtual void AddStringOption3(const std::string& name,
00494                                   const std::string& short_description,
00495                                   const std::string& default_value,
00496                                   const std::string& setting1,
00497                                   const std::string& description1,
00498                                   const std::string& setting2,
00499                                   const std::string& description2,
00500                                   const std::string& setting3,
00501                                   const std::string& description3,
00502                                   const std::string& long_description="");
00503     virtual void AddStringOption4(const std::string& name,
00504                                   const std::string& short_description,
00505                                   const std::string& default_value,
00506                                   const std::string& setting1,
00507                                   const std::string& description1,
00508                                   const std::string& setting2,
00509                                   const std::string& description2,
00510                                   const std::string& setting3,
00511                                   const std::string& description3,
00512                                   const std::string& setting4,
00513                                   const std::string& description4,
00514                                   const std::string& long_description="");
00515     virtual void AddStringOption5(const std::string& name,
00516                                   const std::string& short_description,
00517                                   const std::string& default_value,
00518                                   const std::string& setting1,
00519                                   const std::string& description1,
00520                                   const std::string& setting2,
00521                                   const std::string& description2,
00522                                   const std::string& setting3,
00523                                   const std::string& description3,
00524                                   const std::string& setting4,
00525                                   const std::string& description4,
00526                                   const std::string& setting5,
00527                                   const std::string& description5,
00528                                   const std::string& long_description="");
00529     virtual void AddStringOption6(const std::string& name,
00530                                   const std::string& short_description,
00531                                   const std::string& default_value,
00532                                   const std::string& setting1,
00533                                   const std::string& description1,
00534                                   const std::string& setting2,
00535                                   const std::string& description2,
00536                                   const std::string& setting3,
00537                                   const std::string& description3,
00538                                   const std::string& setting4,
00539                                   const std::string& description4,
00540                                   const std::string& setting5,
00541                                   const std::string& description5,
00542                                   const std::string& setting6,
00543                                   const std::string& description6,
00544                                   const std::string& long_description="");
00545     virtual void AddStringOption7(const std::string& name,
00546                                   const std::string& short_description,
00547                                   const std::string& default_value,
00548                                   const std::string& setting1,
00549                                   const std::string& description1,
00550                                   const std::string& setting2,
00551                                   const std::string& description2,
00552                                   const std::string& setting3,
00553                                   const std::string& description3,
00554                                   const std::string& setting4,
00555                                   const std::string& description4,
00556                                   const std::string& setting5,
00557                                   const std::string& description5,
00558                                   const std::string& setting6,
00559                                   const std::string& description6,
00560                                   const std::string& setting7,
00561                                   const std::string& description7,
00562                                   const std::string& long_description="");
00563     virtual void AddStringOption8(const std::string& name,
00564                                   const std::string& short_description,
00565                                   const std::string& default_value,
00566                                   const std::string& setting1,
00567                                   const std::string& description1,
00568                                   const std::string& setting2,
00569                                   const std::string& description2,
00570                                   const std::string& setting3,
00571                                   const std::string& description3,
00572                                   const std::string& setting4,
00573                                   const std::string& description4,
00574                                   const std::string& setting5,
00575                                   const std::string& description5,
00576                                   const std::string& setting6,
00577                                   const std::string& description6,
00578                                   const std::string& setting7,
00579                                   const std::string& description7,
00580                                   const std::string& setting8,
00581                                   const std::string& description8,
00582                                   const std::string& long_description="");
00583     virtual void AddStringOption9(const std::string& name,
00584                                   const std::string& short_description,
00585                                   const std::string& default_value,
00586                                   const std::string& setting1,
00587                                   const std::string& description1,
00588                                   const std::string& setting2,
00589                                   const std::string& description2,
00590                                   const std::string& setting3,
00591                                   const std::string& description3,
00592                                   const std::string& setting4,
00593                                   const std::string& description4,
00594                                   const std::string& setting5,
00595                                   const std::string& description5,
00596                                   const std::string& setting6,
00597                                   const std::string& description6,
00598                                   const std::string& setting7,
00599                                   const std::string& description7,
00600                                   const std::string& setting8,
00601                                   const std::string& description8,
00602                                   const std::string& setting9,
00603                                   const std::string& description9,
00604                                   const std::string& long_description="");
00605     virtual void AddStringOption10(const std::string& name,
00606                                    const std::string& short_description,
00607                                    const std::string& default_value,
00608                                    const std::string& setting1,
00609                                    const std::string& description1,
00610                                    const std::string& setting2,
00611                                    const std::string& description2,
00612                                    const std::string& setting3,
00613                                    const std::string& description3,
00614                                    const std::string& setting4,
00615                                    const std::string& description4,
00616                                    const std::string& setting5,
00617                                    const std::string& description5,
00618                                    const std::string& setting6,
00619                                    const std::string& description6,
00620                                    const std::string& setting7,
00621                                    const std::string& description7,
00622                                    const std::string& setting8,
00623                                    const std::string& description8,
00624                                    const std::string& setting9,
00625                                    const std::string& description9,
00626                                    const std::string& setting10,
00627                                    const std::string& description10,
00628                                    const std::string& long_description="");
00629 
00632     virtual SmartPtr<const RegisteredOption> GetOption(const std::string& name);
00633 
00636     virtual void OutputOptionDocumentation(const Journalist& jnlst, std::list<std::string>& categories);
00637 
00639     virtual void OutputLatexOptionDocumentation(const Journalist& jnlst, std::list<std::string>& categories);
00641 
00642     typedef std::map<std::string, SmartPtr<RegisteredOption> > RegOptionsList;
00643 
00646     virtual const RegOptionsList& RegisteredOptionsList () const
00647     {
00648       return registered_options_;
00649     }
00650 
00651   private:
00652     std::string current_registering_category_;
00653     std::map<std::string, SmartPtr<RegisteredOption> > registered_options_;
00654   };
00655 } // namespace Ipopt
00656 
00657 #endif

Generated on Thu Jul 29 2010 19:56:08 by  doxygen 1.7.1