MCPcopy Create free account
hub / github.com/Tencent/embedx / LoadConfigFromFile

Function LoadConfigFromFile

src/io/io_util.cc:61–103  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

59}
60
61static bool LoadConfigFromFile(const std::string& file, uint16_t* ns_size,
62 id_name_t* id_name_map) {
63 deepx_core::AutoInputFileStream ifs;
64 if (!ifs.Open(file)) {
65 DXERROR("Failed to open file: %s.", file.c_str());
66 return false;
67 }
68
69 std::string line;
70 std::istringstream iss;
71 std::string ns_name;
72 uint16_t ns_id = 0, max_ns_id = 0;
73
74 id_name_map->clear();
75 while (GetLine(ifs, line)) {
76 if (line.find("#") != std::string::npos ||
77 line.find("//") != std::string::npos) {
78 continue;
79 }
80
81 iss.clear();
82 iss.str(line);
83 if (!(iss >> ns_name >> ns_id)) {
84 continue;
85 }
86
87 if (id_name_map->find(ns_id) != id_name_map->end()) {
88 DXERROR("Duplicate namespace id: %d.", (int)ns_id);
89 return false;
90 }
91
92 id_name_map->emplace(ns_id, ns_name);
93 if (ns_id > max_ns_id) {
94 max_ns_id = ns_id;
95 }
96 }
97
98 DXINFO("Loaded %d namespaces, max namespace id is: %d",
99 (int)id_name_map->size(), max_ns_id);
100
101 *ns_size = max_ns_id + 1;
102 return !id_name_map->empty();
103}
104
105bool LoadConfig(const std::string& file, uint16_t* max_ns_id,
106 id_name_t* id_name_map) {

Callers 1

LoadConfigFunction · 0.85

Calls 3

emplaceMethod · 0.80
OpenMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected