Skip to content

Latest commit

 

History

16 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

roamer

roamer is a C++ helper library, split from my another repo: https://github.com/TSSDorg/tssdcc roamer supports deep copy object, deep compare, random object, print object

features

  • API simple effective: parse with reflect once, run without reflect
  • Support rich C++ types: class with private data/struct, STL(vector, list, set,map, unordered_map, shared_ptr/unique_ptr)
  • less depenency: depend third library google-test only, which for test. but require C++ reflection feture(GCC-16.1)

quick start

build step:

if you want run UTs: (require google-test)

  • $make test
// the complete demo code: test/main.cc
// support nested class/struct
struct Student {
    string name;
    std::uint16_t age;
};

// support class with private data
class ObjectTest {
    bool  bv;
    int8_t vint8;
public:
    void Set(bool b, int8_t vint8) {
        this->bv = b;
        this->vint8 = vint8;
    }
    uint8_t  vint16_t[5];
    string  s1[2];
    vector<unsigned char> vc;
    vector<std::byte> vb;
    list<int32_t> li;
    set<int16_t> si;
    map<string, Student> students;
    std::shared_ptr<string> sps;
    std::unique_ptr<std::int64_t> ups;
    timespec ts;
    std::chrono::time_point<std::chrono::system_clock,
                            std::chrono::nanoseconds> t;
};

void demo()
{
    ObjectTest ot1, ot2;
    // create a roamer
    tssd::Roamer<ObjectTest> roamer;

    //generator random content for ot1
    roamer.Random(ot1);

    //print ot1 in stdout, also support print in FIlE*
    roamer.Print(ot1, stdout);

    // deep copy a object ot1 to anoer ot2;
    roamer.Copy(ot1, ot2);

    // deep compare ot1 with ot2, if they equal or not
    auto ret = roamer.Equal(ot1, ot2);
    std::println("ot1==ot2 is {}", ret);
}
/** demo output like this:
ObjectTest(fields:13):
        bv bool: true
        vint8 signed char: L
        vint16_t unsigned char[5]: [0xB3, 0x9C, 0x8D, 0xF5, 0x95, ]
        s1 std::string[2]: ["X5","kJQYNVa",]
        vc std::vector<unsigned char>(size:4): [0x4D, 0xF3, 0x6F, 0xFF, ]
        vb std::vector<std::byte>(size:5): [0xD0, 0xB0, 0x3D, 0x9, 0x14, ]
        li std::list<int>(size:1): [2779114738, ]
        si std::set<short int>(size:0): []
        students std::map<std::string, Student>(size:2): [
                std::string: "L"
                :
                Student(fields:2):
                        name std::string: "Uyk"
                        age short unsigned int: 8293

                std::string: "V44"
                :
                Student(fields:2):
                        name std::string: "kcY"
                        age short unsigned int: 26516

        ]
        sps std::shared_ptr<std::string>: ["VYPK",]
        ups std::shared_ptr<long int>: [3051425111676637924, ]
        ts timespec: 1971-06-11T05:04:49.968625479Z
        t std::chrono::time_point: 2246-06-12T00:27:25.427737193Z

ot1==ot2 is true
**/

About

CPP, C++ deep copy, deep compare, object print, random object

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages