11#include " config.hpp"
22
33#include " file.hpp"
4- #include " jute.h"
54#include " log.hpp"
65#include " setup.hpp"
76
87bool ConfigLoader::MAINTAINANCE_MODE = false ;
98
10- int64_t get_jint (jute::jValue &v, const std::string &key, int64_t def) {
11- if (v[key].get_type () == jute::jType::JNUMBER) {
12- return v[key].as_int ();
13- }
14- return def;
15- }
16-
17- double get_jdouble (jute::jValue &v, const std::string &key, double def) {
18- if (v[key].get_type () == jute::jType::JNUMBER) {
19- return v[key].as_double ();
20- }
21- return def;
22- }
23-
24- bool get_jbool (jute::jValue &v, const std::string &key, bool def) {
25- if (v[key].get_type () == jute::jType::JBOOLEAN) {
26- return v[key].as_bool ();
27- }
28- return def;
29- }
30-
319std::string get_template (std::string t) {
3210 static const std::string h (
3311 " $LODA_HOME/programs/" ); // TODO: use proper variable replacing
@@ -52,15 +30,15 @@ std::vector<Generator::Config> loadGeneratorConfigs(
5230 continue ;
5331 }
5432 Generator::Config c;
55- c.version = get_jint (g, " version" , 1 );
33+ c.version = getJInt (g, " version" , 1 );
5634 c.miner = miner;
57- c.length = get_jint (g, " length" , 20 );
58- c.max_constant = get_jint (g, " maxConstant" , 4 );
59- c.max_index = get_jint (g, " maxIndex" , 4 );
60- c.mutation_rate = get_jdouble (g, " mutationRate" , 0.3 );
61- c.loops = get_jbool (g, " loops" , true );
62- c.calls = get_jbool (g, " calls" , true );
63- c.indirect_access = get_jbool (g, " indirectAccess" , false );
35+ c.length = getJInt (g, " length" , 20 );
36+ c.max_constant = getJInt (g, " maxConstant" , 4 );
37+ c.max_index = getJInt (g, " maxIndex" , 4 );
38+ c.mutation_rate = getJDouble (g, " mutationRate" , 0.3 );
39+ c.loops = getJBool (g, " loops" , true );
40+ c.calls = getJBool (g, " calls" , true );
41+ c.indirect_access = getJBool (g, " indirectAccess" , false );
6442 auto t = g[" template" ].get_type ();
6543 switch (t) {
6644 case jute::jType::JSTRING: {
@@ -140,7 +118,7 @@ Miner::Config ConfigLoader::load(const Settings &settings) {
140118 }
141119
142120 // load matcher configs
143- bool backoff = get_jbool (m, " backoff" , true );
121+ bool backoff = getJBool (m, " backoff" , true );
144122 auto matchers = m[" matchers" ];
145123 for (int j = 0 ; j < matchers.size (); j++) {
146124 Matcher::Config mc;
0 commit comments