MCPcopy Create free account
hub / github.com/OAID/Tengine / Load

Method Load

core/lib/tengine_config.cpp:52–95  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

50}
51
52bool TEngineConfig::Load(const std::string filename, const char delimiter, const char comment)
53{
54 std::fstream cfgfile(filename.c_str());
55 if(!cfgfile)
56 {
57 LOG_ERROR() << "Can not open the config file: " << filename << "\n";
58 LOG_ERROR() << "Please cp ./etc/config.example ./etc/config\n";
59 return false;
60 }
61
62 // Set the seperators
63 delim_ch = delimiter;
64 commt_ch = comment;
65
66 // Read the keys and values from the config file
67 typedef std::string::size_type pos;
68 ConfManager* manager = GetConfManager();
69 while(!cfgfile.eof())
70 {
71 std::string line;
72 getline(cfgfile, line);
73
74 // Ignore comments
75 line = line.substr(0, line.find(commt_ch));
76 if(!line.length())
77 continue;
78
79 // Parse the line if it contains a delimiter
80 pos delim_pos = line.find(delim_ch);
81 if(delim_pos != std::string::npos)
82 {
83 // Get the key and the value
84 std::string key = line.substr(0, delim_pos);
85 line.replace(0, delim_pos + 1, "");
86 // Remove the leading and trailing whitespaces
87 Trim(key);
88 Trim(line);
89 // Store the key and the value, overwrites if the key is repeated
90 // Set the config manager
91 manager->SetAttr(key, line);
92 }
93 }
94 return true;
95}
96
97void TEngineConfig::Remove(const std::string& key)
98{

Callers 3

LoadPluginMethod · 0.45
load_tengine_pluginFunction · 0.45
hclcpu_plugin_initFunction · 0.45

Calls 4

TrimFunction · 0.85
lengthMethod · 0.80
c_strMethod · 0.45
SetAttrMethod · 0.45

Tested by

no test coverage detected