@@ -180,7 +180,7 @@ void YAMLConfigParser::displayMap(const YAML::Node &map, int level)
180180
181181}
182182
183- bool YAMLConfigParser::parseAndInsert (const std::string& configName, const std::string& ymlString, const std::string &pathStr, std::map< std::string, Configuration >& subConfigs)
183+ bool YAMLConfigParser::parseAndInsert (const std::string& configName, const std::string& ymlString, std::map< std::string, Configuration >& subConfigs)
184184{
185185 std::string afterInsertion = applyStringVariableInsertions (ymlString);
186186
@@ -191,7 +191,7 @@ bool YAMLConfigParser::parseAndInsert(const std::string& configName, const std::
191191 return false ;
192192 } catch (std::runtime_error &e)
193193 {
194- std::cout << " Error loading sub config << '" << configName << " ' of file " << pathStr << std::endl << " " << e.what () << std::endl;
194+ std::cout << " Error loading sub config << '" << configName << std::endl << " " << e.what () << std::endl;
195195 std::cout << " YML of subconfig was :" << std::endl << afterInsertion << std::endl;
196196 return false ;
197197 }
@@ -202,41 +202,54 @@ bool YAMLConfigParser::parseAndInsert(const std::string& configName, const std::
202202
203203bool YAMLConfigParser::loadConfigFile (const std::string& pathStr, std::map<std::string, Configuration> &subConfigs)
204204{
205- subConfigs.clear ();
206205 using namespace boost ::filesystem;
207-
208206 path path (pathStr);
209-
210207 if (!exists (path))
211208 {
212209 throw std::runtime_error (std::string (" Error, could not find config file " ) + path.c_str ());
213210 }
214211
215- // as this is non standard yml, we need to load and parse the config file first
216212 std::ifstream fin (path.c_str ());
213+ bool st = loadConfig (fin, subConfigs);
214+ fin.close ();
215+ return st;
216+ }
217+
218+ bool libConfig::YAMLConfigParser::loadConfigString (const std::string &yamlstring, std::map<std::string, libConfig::Configuration> &subConfigs)
219+ {
220+ std::istringstream ss;
221+ ss.str (yamlstring);
222+ return loadConfig (ss, subConfigs);
223+ }
224+ template <typename T>
225+ bool libConfig::YAMLConfigParser::loadConfig (T &stream, std::map<std::string, libConfig::Configuration> &subConfigs)
226+ {
227+ subConfigs.clear ();
228+
229+ // as this is non standard yml, we need to load and parse the config file first
217230 std::string line;
218-
231+
219232 std::string buffer;
220-
233+
221234 std::string configName;
222-
223- while (std::getline (fin , line))
235+
236+ while (std::getline (stream , line))
224237 {
225238 if (line.size () >= 3 && line.at (0 ) == ' -' && line.at (1 ) == ' -' && line.at (2 ) == ' -' )
226239 {
227240 // found new subsection
228241// std::cout << "found subsection " << line << std::endl;
229-
242+
230243 std::string searched (" --- name:" );
231244 if (!line.compare (0 , searched.size (), searched))
232245 {
233246 if (!configName.empty ())
234247 {
235- if (!parseAndInsert (configName, buffer, pathStr, subConfigs))
248+ if (!parseAndInsert (configName, buffer, subConfigs))
236249 return false ;
237250 buffer.clear ();
238251 }
239-
252+
240253 configName = line.substr (searched.size (), line.size ());
241254
242255// std::cout << "Found new configuration " << curConfig.name << std::endl;
@@ -253,10 +266,10 @@ bool YAMLConfigParser::loadConfigFile(const std::string& pathStr, std::map<std::
253266 buffer.append (" \n " );
254267 }
255268 }
256-
269+
257270 if (!configName.empty ())
258271 {
259- if (!parseAndInsert (configName, buffer, pathStr, subConfigs))
272+ if (!parseAndInsert (configName, buffer, subConfigs))
260273 return false ;
261274 }
262275
@@ -265,7 +278,7 @@ bool YAMLConfigParser::loadConfigFile(const std::string& pathStr, std::map<std::
265278// std::cout << "Cur conf \"" << it->first << "\"" << std::endl;
266279// displayConfiguration(it->second);
267280// }
268-
281+
269282 return true ;
270283}
271284
0 commit comments