Skip to content

Conversation

marc1uk
Copy link
Contributor

@marc1uk marc1uk commented Apr 27, 2023

add Store::Initialise based on stringstream as well as string filename. Return false on failure to parse a config file line (which isn't a comment or empty), rather than silently ignoring it

@brichards64
Copy link
Contributor

update resolving conflicts and avoid repition one call the other

…me. Return false on failure to parse a config file line (which isn't a comment or empty), rather than silently ignoring it
@marc1uk
Copy link
Contributor Author

marc1uk commented Dec 13, 2024

Done, tested with the following code:

// g++ -g storetest.cpp -I include/ -L lib/ -lStore -o sstest
#include <iostream>
#include "Store.h"

using namespace ToolFramework;

int main(){
	bool ok=true;
	Store s1;
	std::cout<<"initing file"<<std::endl;
	ok = s1.Initialise("testconfig.txt");
	std::cout<<"ok = "<<ok<<", contents: "<<std::endl;
	s1.Print();
	std::cout<<"---"<<std::endl;
	
	std::stringstream ss;
	std::string tmp{
"var1 99 \n\
    var2 3.33 \n\
	var3 potato \n\
\n\
var4 cat dog fish \n\
var5 onemore \n\
#commentline \n\
var6 trailingcomment # potato \n\
var7 lastone \n"
	};
	
	std::clog<<"config string is:\n'"<<tmp<<"'"<<std::endl;
	ss.str(tmp);
	Store s2;
	std::cout<<"initing stringstream"<<std::endl;
	ok = s2.Initialise(ss);
	std::cout<<"ok = "<<ok<<", contents: "<<std::endl;
	s2.Print();
	std::cout<<"---"<<std::endl;
	
	return 0;
}

and testconfig.txt contents:

var1 99
var2 3.33
var3 potato

var4 cat dog fish
var5 onemore
#commentline
var6 trailingcomment # potato
var7 lastone

with output as follows:

initing file
ok = 1, contents: 
var1 => "99"
var2 => "3.33"
var3 => "potato"
var4 => "cat dog fish"
var5 => "onemore"
var6 => "trailingcomment"
var7 => "lastone"
---
config string is:
'var1 99 
    var2 3.33 
	var3 potato 

var4 cat dog fish 
var5 onemore 
#commentline 
var6 trailingcomment # potato 
var7 lastone 
'
initing stringstream
ok = 1, contents: 
var1 => "99"
var2 => "3.33"
var3 => "potato"
var4 => "cat dog fish"
var5 => "onemore"
var6 => "trailingcomment"
var7 => "lastone"
---

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants