IpRegOptions.hpp
Go to the documentation of this file.
1 // Copyright (C) 2004, 2007 International Business Machines and others.
2 // All Rights Reserved.
3 // This code is published under the Eclipse Public License.
4 //
5 // $Id: IpRegOptions.hpp 1861 2010-12-21 21:34:47Z andreasw $
6 //
7 // Authors: Carl Laird, Andreas Waechter IBM 2005-06-18
8 
9 #ifndef __IPREGOPTIONS_HPP__
10 #define __IPREGOPTIONS_HPP__
11 
12 #include "IpUtils.hpp"
13 #include "IpReferenced.hpp"
14 #include "IpException.hpp"
15 #include "IpSmartPtr.hpp"
16 
17 #include <map>
18 
19 namespace Ipopt
20 {
21 
23  {
28  };
29 
34  {
35  public:
38  {
39  public:
40  string_entry(const std::string& value, const std::string& description)
41  : value_(value), description_(description)
42  {}
43  std::string value_;
44  std::string description_;
45  };
46 
50  :
52  has_lower_(false),
53  has_upper_(false),
54  counter_(0)
55  {}
56 
57  RegisteredOption(const std::string& name,
58  const std::string& short_description,
59  const std::string& long_description,
60  const std::string& registering_category)
61  :
62  name_(name),
63  short_description_(short_description),
64  long_description_(long_description),
65  registering_category_(registering_category),
67  has_lower_(false),
68  has_upper_(false),
70  {}
71 
73  :
74  name_(copy.name_),
78  type_(copy.type_),
79  has_lower_(copy.has_lower_),
80  lower_(copy.lower_),
81  has_upper_(copy.has_upper_),
82  upper_(copy.upper_),
84  counter_(copy.counter_)
85  {}
86 
88  {}
90 
91  DECLARE_STD_EXCEPTION(ERROR_CONVERTING_STRING_TO_ENUM);
92 
96  virtual const std::string& Name() const
97  {
98  return name_;
99  }
101  virtual void SetName(const std::string& name)
102  {
103  name_ = name;
104  }
106  virtual const std::string& ShortDescription() const
107  {
108  return short_description_;
109  }
111  virtual const std::string& LongDescription() const
112  {
113  return long_description_;
114  }
116  virtual void SetShortDescription(const std::string& short_description)
117  {
118  short_description_ = short_description;
119  }
121  virtual void SetLongDescription(const std::string& long_description)
122  {
123  long_description_ = long_description;
124  }
126  virtual const std::string& RegisteringCategory() const
127  {
128  return registering_category_;
129  }
131  virtual void SetRegisteringCategory(const std::string& registering_category)
132  {
133  registering_category_ = registering_category;
134  }
136  virtual const RegisteredOptionType& Type() const
137  {
138  return type_;
139  }
141  virtual void SetType(const RegisteredOptionType& type)
142  {
143  type_ = type;
144  }
146  virtual Index Counter() const
147  {
148  return counter_;
149  }
151 
158  virtual const bool& HasLower() const
159  {
161  return has_lower_;
162  }
165  virtual const bool& LowerStrict() const
166  {
167  DBG_ASSERT(type_ == OT_Number && has_lower_ == true);
168  return lower_strict_;
169  }
172  virtual Number LowerNumber() const
173  {
174  DBG_ASSERT(has_lower_ == true && type_ == OT_Number);
175  return lower_;
176  }
179  virtual void SetLowerNumber(const Number& lower, const bool& strict)
180  {
182  lower_ = lower;
183  lower_strict_ = strict, has_lower_ = true;
184  }
187  virtual Index LowerInteger() const
188  {
189  DBG_ASSERT(has_lower_ == true && type_ == OT_Integer);
190  return (Index)lower_;
191  }
194  virtual void SetLowerInteger(const Index& lower)
195  {
197  lower_ = (Number)lower;
198  has_lower_ = true;
199  }
202  virtual const bool& HasUpper() const
203  {
205  return has_upper_;
206  }
209  virtual const bool& UpperStrict() const
210  {
211  DBG_ASSERT(type_ == OT_Number && has_upper_ == true);
212  return upper_strict_;
213  }
216  virtual Number UpperNumber() const
217  {
218  DBG_ASSERT(has_upper_ == true && type_ == OT_Number);
219  return upper_;
220  }
223  virtual void SetUpperNumber(const Number& upper, const bool& strict)
224  {
226  upper_ = upper;
227  upper_strict_ = strict;
228  has_upper_ = true;
229  }
232  virtual Index UpperInteger() const
233  {
234  DBG_ASSERT(has_upper_ == true && type_ == OT_Integer);
235  return (Index)upper_;
236  }
239  virtual void SetUpperInteger(const Index& upper)
240  {
242  upper_ = (Number)upper;
243  has_upper_ = true;
244  }
247  virtual void AddValidStringSetting(const std::string value,
248  const std::string description)
249  {
251  valid_strings_.push_back(string_entry(value, description));
252  }
254  virtual Number DefaultNumber() const
255  {
257  return default_number_;
258  }
260  virtual void SetDefaultNumber(const Number& default_value)
261  {
263  default_number_ = default_value;
264  }
266  virtual Index DefaultInteger() const
267  {
269  return (Index)default_number_;
270  }
273  virtual void SetDefaultInteger(const Index& default_value)
274  {
276  default_number_ = (Number)default_value;
277  }
279  virtual std::string DefaultString() const
280  {
282  return default_string_;
283  }
287  virtual Index DefaultStringAsEnum() const
288  {
291  }
293  virtual void SetDefaultString(const std::string& default_value)
294  {
296  default_string_ = default_value;
297  }
299  virtual std::vector<string_entry> GetValidStrings() const
300  {
302  return valid_strings_;
303  }
306  virtual bool IsValidNumberSetting(const Number& value) const
307  {
309  if (has_lower_ && ((lower_strict_ == true && value <= lower_) ||
310  (lower_strict_ == false && value < lower_))) {
311  return false;
312  }
313  if (has_upper_ && ((upper_strict_ == true && value >= upper_) ||
314  (upper_strict_ == false && value > upper_))) {
315  return false;
316  }
317  return true;
318  }
321  virtual bool IsValidIntegerSetting(const Index& value) const
322  {
324  if (has_lower_ && value < lower_) {
325  return false;
326  }
327  if (has_upper_ && value > upper_) {
328  return false;
329  }
330  return true;
331  }
334  virtual bool IsValidStringSetting(const std::string& value) const;
335 
339  virtual std::string MapStringSetting(const std::string& value) const;
340 
345  virtual Index MapStringSettingToEnum(const std::string& value) const;
347 
349  virtual void OutputDescription(const Journalist& jnlst) const;
351  virtual void OutputShortDescription(const Journalist& jnlst) const;
353  virtual void OutputLatexDescription(const Journalist& jnlst) const;
354 
355  private:
356  std::string name_;
357  std::string short_description_;
358  std::string long_description_;
361 
369 
370  void MakeValidLatexString(std::string source, std::string& dest) const;
371  std::string MakeValidLatexNumber(Number value) const;
372 
375  bool string_equal_insensitive(const std::string& s1,
376  const std::string& s2) const;
377 
378  std::vector<string_entry> valid_strings_;
379  std::string default_string_;
380 
384 
386  };
387 
392  {
393  public:
398  :
399  current_registering_category_("Uncategorized")
400  {}
401 
404  {}
406 
407  DECLARE_STD_EXCEPTION(OPTION_ALREADY_REGISTERED);
408 
413  virtual void SetRegisteringCategory(const std::string& registering_category)
414  {
415  current_registering_category_ = registering_category;
416  }
417 
419  virtual std::string RegisteringCategory()
420  {
422  }
423 
425  virtual void AddNumberOption(const std::string& name,
426  const std::string& short_description,
427  Number default_value,
428  const std::string& long_description="");
430  virtual void AddLowerBoundedNumberOption(const std::string& name,
431  const std::string& short_description,
432  Number lower, bool strict,
433  Number default_value,
434  const std::string& long_description="");
436  virtual void AddUpperBoundedNumberOption(const std::string& name,
437  const std::string& short_description,
438  Number upper, bool strict,
439  Number default_value,
440  const std::string& long_description="");
442  virtual void AddBoundedNumberOption(const std::string& name,
443  const std::string& short_description,
444  Number lower, bool lower_strict,
445  Number upper, bool upper_strict,
446  Number default_value,
447  const std::string& long_description="");
449  virtual void AddIntegerOption(const std::string& name,
450  const std::string& short_description,
451  Index default_value,
452  const std::string& long_description="");
454  virtual void AddLowerBoundedIntegerOption(const std::string& name,
455  const std::string& short_description,
456  Index lower, Index default_value,
457  const std::string& long_description="");
459  virtual void AddUpperBoundedIntegerOption(const std::string& name,
460  const std::string& short_description,
461  Index upper, Index default_value,
462  const std::string& long_description="");
464  virtual void AddBoundedIntegerOption(const std::string& name,
465  const std::string& short_description,
466  Index lower, Index upper,
467  Index default_value,
468  const std::string& long_description="");
469 
471  virtual void AddStringOption(const std::string& name,
472  const std::string& short_description,
473  const std::string& default_value,
474  const std::vector<std::string>& settings,
475  const std::vector<std::string>& descriptions,
476  const std::string& long_description="");
479  virtual void AddStringOption1(const std::string& name,
480  const std::string& short_description,
481  const std::string& default_value,
482  const std::string& setting1,
483  const std::string& description1,
484  const std::string& long_description="");
485  virtual void AddStringOption2(const std::string& name,
486  const std::string& short_description,
487  const std::string& default_value,
488  const std::string& setting1,
489  const std::string& description1,
490  const std::string& setting2,
491  const std::string& description2,
492  const std::string& long_description="");
493  virtual void AddStringOption3(const std::string& name,
494  const std::string& short_description,
495  const std::string& default_value,
496  const std::string& setting1,
497  const std::string& description1,
498  const std::string& setting2,
499  const std::string& description2,
500  const std::string& setting3,
501  const std::string& description3,
502  const std::string& long_description="");
503  virtual void AddStringOption4(const std::string& name,
504  const std::string& short_description,
505  const std::string& default_value,
506  const std::string& setting1,
507  const std::string& description1,
508  const std::string& setting2,
509  const std::string& description2,
510  const std::string& setting3,
511  const std::string& description3,
512  const std::string& setting4,
513  const std::string& description4,
514  const std::string& long_description="");
515  virtual void AddStringOption5(const std::string& name,
516  const std::string& short_description,
517  const std::string& default_value,
518  const std::string& setting1,
519  const std::string& description1,
520  const std::string& setting2,
521  const std::string& description2,
522  const std::string& setting3,
523  const std::string& description3,
524  const std::string& setting4,
525  const std::string& description4,
526  const std::string& setting5,
527  const std::string& description5,
528  const std::string& long_description="");
529  virtual void AddStringOption6(const std::string& name,
530  const std::string& short_description,
531  const std::string& default_value,
532  const std::string& setting1,
533  const std::string& description1,
534  const std::string& setting2,
535  const std::string& description2,
536  const std::string& setting3,
537  const std::string& description3,
538  const std::string& setting4,
539  const std::string& description4,
540  const std::string& setting5,
541  const std::string& description5,
542  const std::string& setting6,
543  const std::string& description6,
544  const std::string& long_description="");
545  virtual void AddStringOption7(const std::string& name,
546  const std::string& short_description,
547  const std::string& default_value,
548  const std::string& setting1,
549  const std::string& description1,
550  const std::string& setting2,
551  const std::string& description2,
552  const std::string& setting3,
553  const std::string& description3,
554  const std::string& setting4,
555  const std::string& description4,
556  const std::string& setting5,
557  const std::string& description5,
558  const std::string& setting6,
559  const std::string& description6,
560  const std::string& setting7,
561  const std::string& description7,
562  const std::string& long_description="");
563  virtual void AddStringOption8(const std::string& name,
564  const std::string& short_description,
565  const std::string& default_value,
566  const std::string& setting1,
567  const std::string& description1,
568  const std::string& setting2,
569  const std::string& description2,
570  const std::string& setting3,
571  const std::string& description3,
572  const std::string& setting4,
573  const std::string& description4,
574  const std::string& setting5,
575  const std::string& description5,
576  const std::string& setting6,
577  const std::string& description6,
578  const std::string& setting7,
579  const std::string& description7,
580  const std::string& setting8,
581  const std::string& description8,
582  const std::string& long_description="");
583  virtual void AddStringOption9(const std::string& name,
584  const std::string& short_description,
585  const std::string& default_value,
586  const std::string& setting1,
587  const std::string& description1,
588  const std::string& setting2,
589  const std::string& description2,
590  const std::string& setting3,
591  const std::string& description3,
592  const std::string& setting4,
593  const std::string& description4,
594  const std::string& setting5,
595  const std::string& description5,
596  const std::string& setting6,
597  const std::string& description6,
598  const std::string& setting7,
599  const std::string& description7,
600  const std::string& setting8,
601  const std::string& description8,
602  const std::string& setting9,
603  const std::string& description9,
604  const std::string& long_description="");
605  virtual void AddStringOption10(const std::string& name,
606  const std::string& short_description,
607  const std::string& default_value,
608  const std::string& setting1,
609  const std::string& description1,
610  const std::string& setting2,
611  const std::string& description2,
612  const std::string& setting3,
613  const std::string& description3,
614  const std::string& setting4,
615  const std::string& description4,
616  const std::string& setting5,
617  const std::string& description5,
618  const std::string& setting6,
619  const std::string& description6,
620  const std::string& setting7,
621  const std::string& description7,
622  const std::string& setting8,
623  const std::string& description8,
624  const std::string& setting9,
625  const std::string& description9,
626  const std::string& setting10,
627  const std::string& description10,
628  const std::string& long_description="");
629 
632  virtual SmartPtr<const RegisteredOption> GetOption(const std::string& name);
633 
636  virtual void OutputOptionDocumentation(const Journalist& jnlst, std::list<std::string>& categories);
637 
639  virtual void OutputLatexOptionDocumentation(const Journalist& jnlst, std::list<std::string>& categories);
641 
642  typedef std::map<std::string, SmartPtr<RegisteredOption> > RegOptionsList;
643 
646  virtual const RegOptionsList& RegisteredOptionsList () const
647  {
648  return registered_options_;
649  }
650 
651  private:
653  std::map<std::string, SmartPtr<RegisteredOption> > registered_options_;
654  };
655 } // namespace Ipopt
656 
657 #endif