简体   繁体   English

具有已定义的操作重载的c ++无类型值对象/变量库

[英]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), 我不知道如何定义我正在搜索的内容,但是,我在这里:由于库libjsoncpp存在并且让我们在“基于json”的对象中保存一个值,这意味着一个整数,一个无符号数,double,string或null ...(也可以看到数组和对象 - 或者我认为 - 作为基于指针的对象到其他对象),

... is there any kind of library in which we could operate with those data, more or less as we do in javascript? ...是否有任何类型的库我们可以使用这些数据,或多或少像我们在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?"). (...甚至“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. 实际上,我正在开发一个项目,该项目需要json处理的一部分来比较从串行协议中传输的基于部分的端口获得的值,与从基于json的配置文件获得的值进行比较。

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. 能够编码或预览未来场景变得困难,因为我们还必须预测来自基于JsonRPC的对象的传入值,因此生成或维护代码可能变得昂贵。

Do you know if there's any kind of library that implements this kind of "non-typed" type in C++? 你知道是否有任何类型的库在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++. 看看crow c ++。 its not just json stuff, its pretty much flask for c++. 它不仅仅是json的东西,它几乎是c ++的瓶子。 might be useful. 可能有用。 it's also just a header file, so no installation etc is needed 它也只是一个头文件,所以不需要安装等

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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