Debian Codegraph @

Kernel/ifOptions.h

raw symbols SCIP
1 /* This file is part of the FaCT++ DL reasoner
2 Copyright (C) 2003-2015 Dmitry Tsarkov and The University of Manchester
3 Copyright (C) 2015-2017 Dmitry Tsarkov
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20 #ifndef IFOPTIONS_H
21 #define IFOPTIONS_Hcxx . . $ `Kernel/ifOptions.h:21:9`!
22
23 /********************************************************\
24 |* Interface for the options management for the FaCT++ *|
25 \********************************************************/
26
27 #include <string>
28 #include <map>
29 #include <iosfwd>
30
31 #include "fpp_assert.h"cxx . . $ `<file>/Kernel/fpp_assert.h`/
32
33 class Configurationcxx . . $ Configuration#;
34
35 /// class for working with general options with boolean, integer or text values
36 class ifOptioncxx . . $ ifOption#
37 {
38 public: // type interface
39 /// type of an option
40 enum ioTypecxx . . $ ifOption#ioType# { iotBoolcxx . . $ ifOption#iotBool., iotIntcxx . . $ ifOption#iotInt., iotTextcxx . . $ ifOption#iotText. };
41
42 protected: // members
43 /// option name
44 stdcxx . . $ std/::stringcxx . . $ std/string# optionNamecxx . . $ ifOption#optionName.;
45 /// informal description
46 stdcxx . . $ std/::stringcxx . . $ std/string# optionDescriptioncxx . . $ ifOption#optionDescription.;
47 /// default value (name of type)
48 stdcxx . . $ std/::stringcxx . . $ std/string# defaultValuecxx . . $ ifOption#defaultValue.;
49 /// textual value [relevant iff (type == iotText)]
50 stdcxx . . $ std/::stringcxx . . $ std/string# tValuecxx . . $ ifOption#tValue.;
51 /// type of value: bool, int or text
52 ioTypecxx . . $ ifOption#ioType# typecxx . . $ ifOption#type.;
53 /// integer value [relevant iff (type == iotInt)]
54 int iValuecxx . . $ ifOption#iValue. = 0;
55 /// boolean value [relevant iff (type == iotBool)]
56 bool bValuecxx . . $ ifOption#bValue. = 0;
57
58 public: // interface
59 /// c'tor (init all values including proper ?Value)
60 ifOptioncxx . . $ ifOption#ifOption(fee78f722aa49a4d). ( const stdcxx . . $ std/::stringcxx . . $ std/string#& name, const stdcxx . . $ std/::stringcxx . . $ std/string#& desc, ioTypecxx . . $ ifOption#ioType# t, const stdcxx . . $ std/::stringcxx . . $ std/string#& defVal );
61 /// no empty c'tor
62 ifOptioncxx . . $ ifOption#ifOption(49f6e7a06ebc5aa8). ( void ) = delete;
63 /// no copy c'tor
64 ifOptioncxx . . $ ifOption#ifOption(1ef75d9fe056b4c2). ( const ifOptioncxx . . $ ifOption#& ) = delete;
65 /// no assignment
66 ifOptioncxx . . $ ifOption#& operatorcxx . . $ ifOption#`operator=`(534a4ee168ad6f69). = ( const ifOptioncxx . . $ ifOption#& ) = delete;
67
68 // write methods
69
70 /// set boolean value; @return false in case of error
71 bool setValuecxx . . $ ifOption#setValue(efaadfb7dc14930a). ( bool b ) { bValuecxx . . $ ifOption#bValue. = b; return (typecxx . . $ ifOption#type. != iotBoolcxx . . $ ifOption#iotBool.); }
72 /// set integer value; @return false in case of error
73 bool setValuecxx . . $ ifOption#setValue(83c267b20bac841a). ( int i ) { iValuecxx . . $ ifOption#iValue. = i; return (typecxx . . $ ifOption#type. != iotIntcxx . . $ ifOption#iotInt.); }
74 /// set string value; @return false in case of error
75 bool setValuecxx . . $ ifOption#setValue(7c222eea44a24d43). ( const stdcxx . . $ std/::stringcxx . . $ std/string#& t ) { tValuecxx . . $ ifOption#tValue. =cxx . . $ std/__cxx11/basic_string#`operator=`(c0b47be1fddc0e75). t; return (typecxx . . $ ifOption#type. != iotTextcxx . . $ ifOption#iotText.); }
76 /// set textually given value of current type; @return false in case of error
77 bool setAValuecxx . . $ ifOption#setAValue(7c222eea44a24d43). ( const stdcxx . . $ std/::stringcxx . . $ std/string#& s );
78
79 // access methods
80 /// get value of a Boolean option
81 bool getBoolcxx . . $ ifOption#getBool(50ce9a9e25b4a850). ( void ) const { fpp_assertcxx . . $ EFPPAssertion# ( type == iotBool ); return bValuecxx . . $ ifOption#bValue.; }
82 /// get value of an integer option
83 int getIntcxx . . $ ifOption#getInt(455f465bc33b4cdf). ( void ) const { fpp_assertcxx . . $ EFPPAssertion#EFPPAssertion(85c52e162fed56f9). ( type == iotInt ); return iValuecxx . . $ ifOption#iValue.; }
84 /// get value of a string option
85 const stdcxx . . $ std/::stringcxx . . $ std/string#& getTextcxx . . $ ifOption#getText(f4fff0029955a25f). ( void ) const { fpp_assertcxx . . $ ifOption#iotText. ( type == iotText ); return tValuecxx . . $ ifOption#tValue.; }
86
87 /// output in the form of config file
88 void printConfStringcxx . . $ ifOption#printConfString(490063bd7e6d8d5d). ( stdcxx . . $ std/::ostreamcxx . . $ std/ostream#& o ) const;
89 }; // ifOption
90
91 // implementation of class ifOption
92
93 inline ifOptioncxx . . $ ifOption# :: ifOptioncxx . . $ ifOption#ifOption(fee78f722aa49a4d). ( const stdcxx . . $ std/::stringcxx . . $ std/string#& name, const stdcxx . . $ std/::stringcxx . . $ std/string#& desc, ioTypecxx . . $ ifOption#ioType# t, const stdcxx . . $ std/::stringcxx . . $ std/string#& defVal )
94 : optionNamecxx . . $ std/__cxx11/basic_string#basic_string(a47f53d4115f6ce5).(name)
95 , optionDescriptioncxx . . $ ifOption#optionDescription.(desc)
96 , defaultValuecxx . . $ std/__cxx11/basic_string#basic_string(a47f53d4115f6ce5).(defVal)
97 , typecxx . . $ ifOption#type.(t)
98 {
99 setAValuecxx . . $ ifOption#setAValue(7c222eea44a24d43). (defVal);
100 }
101
102 /// set of options with access by name
103 class ifOptionSetcxx . . $ ifOptionSet#
104 {
105 protected: // internal type definitions
106 /// base internal type
107 typedef stdcxx . . $ std/::mapcxx . . $ std/map#<stdcxx . . $ std/::stringcxx . . $ std/string#,ifOptioncxx . . $ ifOption#*> OptionSetcxx . . $ ifOptionSet#OptionSet#;
108
109 protected: // members
110 /// set of all available (given) options
111 OptionSetcxx . . $ ifOptionSet#OptionSet# Basecxx . . $ ifOptionSet#Base.;
112
113 protected: // methods
114 /// get access option structure by name; @return NULL if no such option was registered
115 const ifOptioncxx . . $ ifOption#* locateOptioncxx . . $ ifOptionSet#locateOption(3a1da25d2f3c5c7f). ( const stdcxx . . $ std/::stringcxx . . $ std/string#& name ) const
116 {
117 auto p = Basecxx . . $ ifOptionSet#Base..findcxx . . $ std/map#find(7b3585bb5da8f7d).(name);
118 return p ==cxx . . $ std/`operator==`(7e1308a0738ea758). Basecxx . . $ ifOptionSet#Base..endcxx . . $ std/map#end(646659518938a4d6).() ? nullptr : p->cxx . . $ std/_Rb_tree_const_iterator#`operator->`(1016ee5406d91ab9).secondcxx . . $ std/pair#second.;
119 }
120
121 public: // interface
122 /// empty c'tor
123 ifOptionSetcxx . . $ ifOptionSet#ifOptionSet(49f6e7a06ebc5aa8).() = default;
124 /// d'tor (delete all registered options)
125 ~cxx . . $ ifOptionSet#`~ifOptionSet`(49f6e7a06ebc5aa8).ifOptionSetcxx . . $ ifOptionSet#()
126 {
127 for ( auto& p: Basecxx . . $ ifOptionSet#Base. )
128 delete p.secondcxx . . $ std/pair#second.;
129 }
130
131 /// register an option with given name, description, type and default. @return true iff such option exists
132 bool RegisterOptioncxx . . $ ifOptionSet#RegisterOption(10eeaca43a3c48cb). (
133 const stdcxx . . $ std/::stringcxx . . $ std/string#& name,
134 const stdcxx . . $ std/::stringcxx . . $ std/string#& desc,
135 ifOptioncxx . . $ ifOption#::ioTypecxx . . $ ifOption#ioType# t,
136 const stdcxx . . $ std/::stringcxx . . $ std/string#& defVal )
137 {
138 if ( locateOptioncxx . . $ ifOptionSet#locateOption(3a1da25d2f3c5c7f). (name) != nullptr )
139 return true;
140 Basecxx . . $ ifOptionSet#Base.[cxx . . $ std/map#`operator[]`(bbd415b616967878).name] = new ifOptioncxx . . $ ifOption#ifOption(fee78f722aa49a4d). ( name, desc, t, defVal );
141 return false;
142 }
143 /// init all registered option using given section of given configuration
144 bool initByConfigurecxx . . $ ifOptionSet#initByConfigure(bb2da3fc04b58aa3). ( Configurationcxx . . $ Configuration#& conf, const stdcxx . . $ std/::stringcxx . . $ std/string#& Section );
145
146 bool setOptioncxx . . $ ifOptionSet#setOption(1667653f663d0d88).( const stdcxx . . $ std/::stringcxx . . $ std/string#& optionName, const stdcxx . . $ std/::stringcxx . . $ std/string#& optionValue)
147 {
148 auto p = Basecxx . . $ ifOptionSet#Base..findcxx . . $ std/map#find(36f8d56706583706).(optionName);
149 if ( p ==cxx . . $ std/`operator==`(84f83906d8995b82). Basecxx . . $ ifOptionSet#Base..endcxx . . $ std/map#end(fbe2f8c57595edf).() )
150 return true;
151 if ( p->cxx . . $ std/_Rb_tree_iterator#`operator->`(5a2a78a048fb49a8).secondcxx . . $ std/pair#second.->setAValuecxx . . $ ifOption#setAValue(7c222eea44a24d43).(optionValue)) // ... set up its value
152 return true; // can't set value
153 return false;
154 }
155
156 // read access
157
158 /// get Boolean value of given option
159 bool getBoolcxx . . $ ifOptionSet#getBool(13a55b95a0133754). ( const stdcxx . . $ std/::stringcxx . . $ std/string#& optionName ) const
160 {
161 const ifOptioncxx . . $ ifOption#* p = locateOptioncxx . . $ ifOptionSet#locateOption(3a1da25d2f3c5c7f). ( optionName );
162 fpp_assertcxx . . $ EFPPAssertion#EFPPAssertion(85c52e162fed56f9). ( p != nullptr );
163 return p->getBoolcxx . . $ ifOption#getBool(50ce9a9e25b4a850). ();
164 }
165 /// get integral value of given option
166 int getIntcxx . . $ ifOptionSet#getInt(22cc3a531165f6b0). ( const stdcxx . . $ std/::stringcxx . . $ std/string#& optionName ) const
167 {
168 const ifOptioncxx . . $ ifOption#* p = locateOptioncxx . . $ ifOptionSet#locateOption(3a1da25d2f3c5c7f). ( optionName );
169 fpp_assertcxx . . $ `Kernel/fpp_assert.h:46:10`! ( p != nullptr );
170 return p->getIntcxx . . $ ifOption#getInt(455f465bc33b4cdf). ();
171 }
172 /// get string value of given option
173 const stdcxx . . $ std/::stringcxx . . $ std/string#& getTextcxx . . $ ifOptionSet#getText(d33e27454d79bb74). ( const stdcxx . . $ std/::stringcxx . . $ std/string#& optionName ) const
174 {
175 const ifOptioncxx . . $ ifOption#* p = locateOptioncxx . . $ ifOptionSet#locateOption(3a1da25d2f3c5c7f). ( optionName );
176 fpp_assertcxx . . $ `Kernel/fpp_assert.h:46:10`! ( p != nullptr );
177 return p->getTextcxx . . $ ifOption#getText(f4fff0029955a25f). ();
178 }
179
180 /// output option set in the form of config file
181 void printConfigcxx . . $ ifOptionSet#printConfig(490063bd7e6d8d5d). ( stdcxx . . $ std/::ostreamcxx . . $ std/ostream#& o ) const;
182 }; // ifOptionSet
183
184 #endif