I'm a c++ noob trying to build a personal finance websocket server that tracks all of my assets and liabilities in real-time.
I've found that I can make map
s of map
s to have a multi-dimensional system of key-value pairs.
I've also found that boost::any
and boost::variant
can be used to store multiple types for a values. My problem is that some levels aren't very complex compared to others. For example, a bank account will only have a value, the amount in the account, while a brokerage account will have many types of investments and characteristics, so I'd like to do something like (in json):
{
'bankAccount': 100.00,
'brokerageAccount': {
'stocks': {
'companyName': 'Stack Exchange',
'ticker': 'STAK',
'pps': bazillion
...
Where bankAccount
and brokerageAccount
can be insert
ed and erase
d when needed and discarded as necessary.
I don't really know where to go from here. When I try to put
map<string, boost::any> accounts;
accounts["cash"] = 100;
accounts["brokerageAccount"] = map<string, boost::any>;
in the private
section of broadcast_server
in this websocket server, gcc
with these flags -I ~/websocketpp-master/ -std=c++0x -D_WEBSOCKETPP_CPP11_STL_ -D_WEBSOCKETPP_NO_CPP11_REGEX_ -lboost_regex -lboost_system -L/usr/lib -pthread -O0 -ljson_spirit
gives error: ‘accounts’ does not name a type
for the last two lines.
How best can I store data in a json type way above, with the ability to add and delete keys and values anywhere?