简体   繁体   中英

c++ untyped value object/variable library with defined operation overloads

I don't know exactly how to define what I am searching, but, here I go: Since the library libjsoncpp exists and lets us hold a value in an object that is "json based", which means, an integer, an unsigned number, double, string or null... (also arrays and objects that can be seen -or I perceive- as pointer based objects to other objects),

... is there any kind of library in which we could operate with those data, more or less as we do in javascript?

#include "somemagiclib.h"

magicnamespace::jsonlike_o value1=10;
int integervalue=15;
magicnamespace::jsonlike_o value2="hello_world";
std::string anything="anything";
magicnamespace::jsonlike_o value3="10.3";
magicnamespace::jsonlike_b result;

value3=value2+value1;
std::cout << "value3 is: " << value3.asString() << std::endl;
   /*value3 is: 21*/
std::cout << (value2+value1).asString() << std::endl;
   /*hello_world10*/
std::cout << (value1+value3).asString() << std::endl;
   /*20*/
std::cout << (value3+value1).asString() << std::endl;
   /*10.310*/
std::cout << (value1<value3).asString() << std::endl;
   /*true*/
std::cout << (value1+integervalue).asString() << std::endl;
   /*25*/
std::cout << (value1+anything).asString() << std::endl;
   /*18*/
std::cout << (value1>=integervalue).asString() << std::endl;
   /*false*/
std::cout << (value2+integervalue).asString() << std::endl;
   /*hello_world15*/
std::cout << (value2+anything).asString() << std::endl;
   /*hello_worldanything*/

We could easily reach to the ask "what for?" (...or even "wtf for?"). In fact, I am working on a project that requires a part of json processing to compare values that are obtained from part based ports transmitting in serial protocols, compared with values that are obtained from json based configured files.

Being able to code or preview the future scenarios is becoming difficult, since we also have to preview incoming values from JsonRPC based objects, so the code may become expensive to generate or to maintain.

Do you know if there's any kind of library that implements this kind of "non-typed" type in C++? In case of not knowing, do you think that this kind of library deserves the efforts to be created?

Thank you very much for your attention.

Look into crow c++. its not just json stuff, its pretty much flask for c++. might be useful. it's also just a header file, so no installation etc is needed

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM