Skip to content

Commit da30ea2

Browse files
committed
1. add namespace Read_Txt_Tools::Preset
1 parent faf8bb5 commit da30ea2

File tree

4 files changed

+49
-12
lines changed

4 files changed

+49
-12
lines changed

source/src_io/read_txt_input-general.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ namespace Read_Txt_Input
1818
item.check_transform = [](Input_Item &self)
1919
{
2020
Input_List::check_value_size(self, 1);
21-
if(!Read_Txt_Tools::in_set(self.values[0].gets(), {"1","2","4"}))
21+
if(!Read_Txt_Tools::in_set(self.values[0].geti(), {1,2,4}))
2222
throw std::invalid_argument("nspin must be 1,2,4");
2323
};
2424
item.convert = [](const Input_Item &self)
@@ -44,5 +44,22 @@ namespace Read_Txt_Input
4444
};
4545
this->add_item(item);
4646
}
47+
48+
{
49+
Input_Item item("symmetry");
50+
item.default_1(false);
51+
item.annotation = "turn symmetry on or off";
52+
item.check_transform = [](Input_Item &self)
53+
{
54+
Input_List::check_value_size(self, 1);
55+
if(!Read_Txt_Tools::in_set( self.values[0].gets(), Read_Txt_Tools::Preset::Bool))
56+
throw std::invalid_argument("symmetry must be bool");
57+
};
58+
item.convert = [](const Input_Item &self)
59+
{
60+
ModuleSymmetry::Symmetry::symm_flag = self.values[0].getb();
61+
};
62+
this->add_item(item);
63+
}
4764
}
4865
}

source/src_io/read_txt_input_value.cpp

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "read_txt_input_value.h"
22

3+
#include "src_io/read_txt_tools.h"
34
#include <stdexcept>
45

56
namespace Read_Txt_Input
@@ -30,16 +31,28 @@ namespace Read_Txt_Input
3031

3132
void Input_Value::sets(const std::string &s_in)
3233
{
33-
try
34+
this->s = s_in;
35+
if(Read_Txt_Tools::in_set(s_in, Read_Txt_Tools::Preset::True))
3436
{
35-
this->s = s_in;
36-
this->d = std::stod(s_in);
37-
this->i = std::stoi(s_in);
38-
this->b = static_cast<bool>(std::stoi(s_in));
37+
this->b = true;
38+
this->i = 1;
39+
this->d = 1.0;
3940
}
40-
catch(const std::invalid_argument &e)
41+
else if(Read_Txt_Tools::in_set(s_in, Read_Txt_Tools::Preset::False))
4142
{
42-
this->s = s_in;
43+
this->b = false;
44+
this->i = 0;
45+
this->d = 0.0;
46+
}
47+
else
48+
{
49+
try
50+
{
51+
this->d = std::stod(s_in);
52+
this->i = std::stoi(s_in);
53+
this->b = static_cast<bool>(std::stoi(s_in));
54+
}
55+
catch(const std::invalid_argument &e){}
4356
}
4457
}
4558
}

source/src_io/read_txt_input_value.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ namespace Read_Txt_Input
2323
void sets(const std::string &s_in);
2424

2525
private:
26-
bool b;
27-
int i;
28-
double d;
26+
bool b = false;
27+
int i = 0;
28+
double d = 0.0;
2929
std::string s;
3030

3131
#ifdef USE_CEREAL_SERIALIZATION

source/src_io/read_txt_tools.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,14 @@ namespace Read_Txt_Tools
6969
bool in_set(const T &value, const std::set<T> &set_check)
7070
{
7171
return set_check.find(value)!=set_check.end();
72-
}
72+
}
73+
74+
namespace Preset
75+
{
76+
const std::set<std::string> True = {"1","T","t","TRUE","True","true"};
77+
const std::set<std::string> False = {"0","F","f","FALSE","False","false"};
78+
const std::set<std::string> Bool = {"1","T","t","TRUE","True","true","0","F","f","FALSE","False","false"};
79+
}
7380
}
7481

7582
#endif

0 commit comments

Comments
 (0)