Skip to content

Conversation

@marc1uk
Copy link
Contributor

@marc1uk marc1uk commented Dec 13, 2024

pretty much just boilerplate code, but it enables the possibility to Set and Get a Store into another Store without intermediate strings, which may address the underlying issue with #20 .

Test code:

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

using namespace ToolFramework;

int main(){
	int a = 99;
	float b = 55.5;
	std::string s{"potato"};
	
	Store inner;
	inner.Set("a",a);
	inner.Set("b",b);
	inner.Set("s",s);
	
	std::string innerjson;
	inner >> innerjson;
	
	Store outer;
	outer.Set("inner",inner);
	
	std::string outerjson;
	outer >> outerjson;
	
	std::cout<<"Inner:\n-----"<<std::endl;
	inner.Print();
	std::cout<<"------\nAs json: '"<<innerjson<<"'\n"<<std::endl;
	
	std::cout<<"Outer:\n-----"<<std::endl;
	outer.Print();
	std::cout<<"------\nAs json: '"<<outerjson<<"'\n"<<std::endl;
	
	Store innerget;
	outer.Get("inner",innerget);
	
	std::string innergetjson;
	innerget >> innergetjson;
	
	std::cout<<"InnerGet:\n-----"<<std::endl;
	innerget.Print();
	std::cout<<"------\nAs json: '"<<innergetjson<<"'"<<std::endl;
	
	// =====================
	std::cout<<"\n==========\n"<<std::endl;
	
	
	Store outer2;
	outer2.Set("innerjson",innerjson);
	
	std::string outer2json;
	outer2 >> outer2json;
	
	std::cout<<"Outer2:\n-----"<<std::endl;
	outer2.Print();
	std::cout<<"------\nAs json: '"<<outer2json<<"'\n"<<std::endl;
	
	std::string innerjsonget;
	outer2.Get("innerjson",innerjsonget);
	
	Store innerget2;
	innerget2.JsonParser(innerjsonget);
	
	std::string inner2json;
	innerget2 >> inner2json;
	
	std::cout<<"Inner2:\n-----"<<std::endl;
	innerget2.Print();
	std::cout<<"-----\nAs json: '"<<inner2json<<"'"<<std::endl;
	
	return 0;
}

Output:

Inner:
-----
a => 99
b => 55.5
s => "potato"
------
As json: '{"a":99 ,"b":55.5 ,"s":"potato" }'

Outer:
-----
inner => {"a":99 ,"b":55.5 ,"s":"potato" }
------
As json: '{"inner":{"a":99 ,"b":55.5 ,"s":"potato" } }'

InnerGet:
-----
a => 99
b => 55.5
s => "potato"
------
As json: '{"a":99 ,"b":55.5 ,"s":"potato" }'

==========

Outer2:
-----
innerjson => "{"a":99 ,"b":55.5 ,"s":"potato" }"
------
As json: '{"innerjson":"{"a":99 ,"b":55.5 ,"s":"potato" }" }'

Inner2:
-----
a => 99
b => 55.5
s => "potato"
-----
As json: '{"a":99 ,"b":55.5 ,"s":"potato" }'

@brichards64 brichards64 merged commit 01d76a1 into ToolFramework:main Dec 13, 2024
3 of 4 checks passed
@marc1uk marc1uk deleted the insertionoperator branch December 13, 2024 16:12
tdealtry added a commit to tdealtry/ToolFrameworkCore that referenced this pull request Dec 16, 2024
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