Debian Codegraph @

FaCT++.Python/lib/Kernel/ifOptions.cpp

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 #include <ostream>
21
22 #include "ifOptions.h"
23 #include "configure.h"
24
25 bool ifOption :: setAValue ( const std::string& s )
26 {
27 if ( type == iotBool ) // check possible boolean values
28 {
29 if ( s == "0" || s == "off" || s == "no" || s == "false" )
30 bValue = false;
31 else if ( s == "1" || s == "on" || s == "yes" || s == "true" )
32 bValue = true;
33 else
34 return true;
35 }
36 else if ( type == iotInt ) // check possible integer values
37 {
38 if ( !isdigit (s[0]) )
39 return true;
40 else
41 iValue = stoi(s);
42 }
43 else // text values
44 tValue = s;
45
46 return false;
47 }
48
49 /// output in the form of config file
50 void ifOption :: printConfString ( std::ostream& o ) const
51 {
52 // name and type
53 o << "\n;---\n;--- Option '" << optionName << "': ";
54 if ( type == iotBool )
55 o << "boolean";
56 else if ( type == iotInt )
57 o << "integer";
58 else if ( type == iotText )
59 o << "text";
60 else // sanity check
61 fpp_unreachable();
62
63 // description, default, name
64 o << " ---\n;---\n;* " << optionDescription << "\n;* Default value: '"
65 << defaultValue << "'\n\n; " << optionName << " = ";
66
67 // value
68 if ( type == iotBool )
69 o << getBool ();
70 else if ( type == iotInt )
71 o << getInt ();
72 else if ( type == iotText )
73 o << getText();
74 else // sanity check
75 fpp_unreachable();
76
77 o << "\n";
78 }
79
80 bool ifOptionSet :: initByConfigure ( Configuration& Config, const std::string& Section )
81 {
82 // try to load given config section
83 if ( Config.useSection ( Section ) )
84 return true;
85
86 // for all registered options
87 for ( const auto& p: Base )
88 if ( !Config.checkValue(p.first) ) // if option located in config file
89 if ( p.second->setAValue(Config.getValue())) // ... set up its value
90 return true; // can't set value
91
92 // all done without errors
93 return false;
94 }
95
96 /// output in the form of config file
97 void ifOptionSet :: printConfig ( std::ostream& o ) const
98 {
99 // print LeveLogger info
100 o << "[LeveLogger]\n\n;--- Logging file name\n file = reasoning.log\n"
101 ";--- Logging level (the less level you give, the less information will be logged)\n allowedLevel = 0\n\n";
102
103 // print header
104 o << "\n[Tuning]\n";
105
106 for ( const auto& opt: Base )
107 opt.second->printConfString(o);
108 o << std::endl;
109 }