Skip to content

Commit 5a19174

Browse files
committed
1. Add Input_Item::values_type. Update Input_Process::check_transform() and Input_Process::out()
1 parent ac8b358 commit 5a19174

File tree

5 files changed

+38
-9
lines changed

5 files changed

+38
-9
lines changed

source/src_io/read_txt_input-general.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,6 @@ namespace Read_Txt_Input
5252
Input_Item item("symmetry");
5353
item.default_1(false);
5454
item.annotation = "turn symmetry on or off";
55-
item.check_transform = [](Input_Item &self)
56-
{
57-
if(!Read_Txt_Tools::in_set( self.values[0].gets(), Read_Txt_Tools::Preset::Bool))
58-
throw std::invalid_argument("symmetry must be bool");
59-
};
6055
item.convert = [](const Input_Item &self)
6156
{
6257
ModuleSymmetry::Symmetry::symm_flag = self.values[0].getb();

source/src_io/read_txt_input-pw.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace Read_Txt_Input
1717
{
1818
{
1919
Input_Item item("ecutwfc");
20-
item.default_1(100,"eV");
20+
item.default_1(100.0,"eV");
2121
item.annotation = "energy cutoff for wave functions";
2222
item.check_transform = [](Input_Item &self)
2323
{

source/src_io/read_txt_input_item-template.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,34 +28,39 @@ namespace Read_Txt_Input
2828
{
2929
this->values.push_back({});
3030
this->values.back().setb(b);
31+
this->values_type.push_back("b");
3132
}
3233

3334
template<>
3435
void Input_Item::set_value(const int &i)
3536
{
3637
this->values.push_back({});
3738
this->values.back().seti(i);
39+
this->values_type.push_back("i");
3840
}
3941

4042
template<>
4143
void Input_Item::set_value(const double &d)
4244
{
4345
this->values.push_back({});
4446
this->values.back().setd(d);
47+
this->values_type.push_back("d");
4548
}
4649

4750
template<>
4851
void Input_Item::set_value(const std::string &s)
4952
{
5053
this->values.push_back({});
5154
this->values.back().sets(s);
55+
this->values_type.push_back("s");
5256
}
5357

5458
template<>
5559
void Input_Item::set_value(const char*const &s)
5660
{
5761
this->values.push_back({});
5862
this->values.back().sets(std::string(s));
63+
this->values_type.push_back("s");
5964
}
6065
}
6166

source/src_io/read_txt_input_item.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ namespace Read_Txt_Input
4343
private:
4444
std::string label;
4545
//int value_read_size = -1;
46+
std::vector<std::string> values_type;
4647

4748
friend class Input_List;
4849
friend class Input_Process;

source/src_io/read_txt_input_process.cpp

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,18 @@ namespace Read_Txt_Input
5656
void Input_Process::check_transform()
5757
{
5858
for(auto &item : input.list)
59+
{
5960
item.second.check_transform(item.second);
61+
62+
for(size_t i=0; i<item.second.values.size(); ++i)
63+
{
64+
if(item.second.values_type[i]=="b")
65+
{
66+
if(!Read_Txt_Tools::in_set( item.second.values[i].gets(), Read_Txt_Tools::Preset::Bool))
67+
throw std::invalid_argument("INPUT "+item.second.label+" must be bool");
68+
}
69+
}
70+
}
6071
}
6172

6273
void Input_Process::default2()
@@ -71,9 +82,26 @@ namespace Read_Txt_Input
7182
for(const std::string &label : input.add_order)
7283
{
7384
ofs<<label<<"\t";
74-
for(const Input_Value &value : input.list.at(label).values)
75-
ofs<<value.gets()<<" ";
76-
ofs<<"\t# "<<input.list.at(label).annotation<<std::endl;
85+
const Read_Txt_Input::Input_Item &item = input.list.at(label);
86+
for(size_t i=0; i<item.values.size(); ++i)
87+
{
88+
if(item.values_type[i]=="s")
89+
ofs<<item.values[i].gets()<<" ";
90+
else if(item.values_type[i]=="d")
91+
ofs<<std::to_string(item.values[i].getd())<<" ";
92+
else if(item.values_type[i]=="i")
93+
ofs<<std::to_string(item.values[i].geti())<<" ";
94+
else if(item.values_type[i]=="b")
95+
{
96+
if(item.values[i].getb())
97+
ofs<<"true"<<" ";
98+
else
99+
ofs<<"false"<<" ";
100+
}
101+
else
102+
throw invalid_argument("Input_Process::out() value_type["+std::to_string(i)+"]="+item.values_type[i]);
103+
}
104+
ofs<<"\t# "<<item.annotation<<std::endl;
77105
}
78106
}
79107

0 commit comments

Comments
 (0)