Git Product home page Git Product logo

kcfg's Introduction

kcfg

A C++ json config mapping library.

Dependency

rapidjson

Limit

  • Only works with GCC
  • Max 256 fields in a struct/class

Example

#include "kcfg.hpp"

struct ConfigItem
{
        int v0;
        int y0;
        KCFG_DEFINE_FIELDS(v0, y0);
};

struct Config
{
        int64_t x;
        int y;
        float z;
        std::string aa;
        std::map<std::string, int> m1;
        std::vector<std::string> v2;
        std::vector<ConfigItem> v3;
        KCFG_DEFINE_FIELDS(x, y, z, aa, m1, v2, v3)
        Config()
                : x(0), y(0), z(0)
        {
        }
};


int main(int argc, char *argv[])
{

    std::string json = "{\"x\":1, \"y\":101, \"z\":2.1, \"aa\":\"val\", \"m1\":{\"k1\":102}, \"v2\":[\"v0\"]}";

    Config cfg;
    kcfg::ParseFromJsonString(json, cfg);

    cfg.v2.push_back("testa");
    cfg.v2.push_back("testv");
    cfg.v3.resize(2);
    cfg.v3[0].v0 = 101;
    cfg.v3[1].y0 = 987;
    std::string kstr;
    kcfg::WriteToJsonString(cfg, kstr);
    printf("%s\n",kstr.c_str());

    return 0;
}

kcfg's People

Contributors

yinqiwen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

wjd6910502 corcpp

kcfg's Issues

MSVC支持?!

你好同学,我十分需要你的解析json配置库来完成一个作业,但我的代码需要运行在windows MSVC上。
我尝试在MSVC上编译你的代码时发现KCFG_DEFINE_FIELDS宏无法被MSVC正常识别,似乎是宏嵌套在MSVC中表现不正常。
而且我使用MSVC(VS2019)似乎最多只能支持127个宏参数,所以我对你的KCFG_ARG_N宏和其他宏也进行了对应改动。

我现在仍然不知道如何解KCFG_DEFINE_FIELDS的问题,恳请作者有空帮我看一下,万分感谢!!!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.