Skip to content

Commit 9d631a5

Browse files
committed
1. add INPUT duplicated checking in Read_Txt_Tools
1 parent e7e7629 commit 9d631a5

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

source/src_io/read_txt_input_process.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ namespace Read_Txt_Input
3434
void Input_Process::read(const std::string &file_name)
3535
{
3636
const std::map<std::string, std::vector<std::string>> inputs_read
37-
= Read_Txt_Tools::read_file_to_map(file_name, {"#","\\"});
37+
= Read_Txt_Tools::read_file_to_map(file_name, {"#","\\"}, true);
3838
for(const auto & input_read : inputs_read)
3939
{
4040
const auto ptr = input.list.find(input_read.first);

source/src_io/read_txt_tools.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <fstream>
99
#include <sstream>
1010
#include <algorithm>
11+
#include <stdexcept>
1112

1213
namespace Read_Txt_Tools
1314
{
@@ -17,7 +18,8 @@ namespace Read_Txt_Tools
1718
// }
1819
std::map<std::string, std::vector<std::string>> read_file_to_map(
1920
const std::string &file_name,
20-
const std::set<std::string> &comment_seps)
21+
const std::set<std::string> &comment_seps,
22+
const bool flag_check_duplicate)
2123
{
2224
std::string str;
2325
std::ifstream ifs(file_name);
@@ -27,7 +29,12 @@ namespace Read_Txt_Tools
2729
std::getline(ifs,str);
2830
const std::vector<std::string> vec = Read_Txt_Tools::split_whitespace(Read_Txt_Tools::ignore_comment(str, comment_seps));
2931
if(vec.size()>0)
32+
{
33+
if(flag_check_duplicate)
34+
if(m.find(vec[0])!=m.end())
35+
throw std::invalid_argument(vec[0]+" is duplicated in INPUT");
3036
m[vec[0]] = std::vector<std::string>(vec.begin()+1, vec.end());
37+
}
3138
}
3239
return m;
3340
}

source/src_io/read_txt_tools.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ namespace Read_Txt_Tools
1919
// }
2020
std::map<std::string, std::vector<std::string>> read_file_to_map(
2121
const std::string &file_name,
22-
const std::set<std::string> &comment_seps);
22+
const std::set<std::string> &comment_seps,
23+
const bool flag_check_duplicate);
2324

2425

2526
// [

0 commit comments

Comments
 (0)