C ++ untyped value object / variable library with certain operational overloads

I don't know exactly how to determine what I'm looking for, but, here I go: Since the libjsoncpp library exists and allows us to hold a value in a "json based" object, which means integer, unsigned, 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 library where we could work with this data, more or less the same as 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 get to the "why?" Question. (... or even "wtf for?"). Actually, I am working on a project that requires some of the json processing to compare values ​​obtained from ports based on details transmitted in serial protocols versus values ​​obtained from configured json based files.

Being able to code or preview future scripts becomes difficult as we also have to view the input values ​​from JsonRPC based objects, so the code can become expensive to build or maintain.

Do you know if there is any library that implements this type of "non-printable" type in C ++? If you don't know, do you think such a library is worth the effort to create?

Thank you very much for your attention.

+3


source to share


1 answer


Have a look at C ++ Raven. its not just json stuff, its a big flask for c ++. might be helpful. it is also just a header file, so installation etc. not required



0


source







All Articles