Fork Vasum on GitHub Official Vasum Wiki on Tizen.org
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
libcargo

C++ library for handling serialization. More...

Macros

#define CARGO_REGISTER_EMPTY
 Register empty cargo class. More...
 
#define CARGO_REGISTER(...)
 Registers cargo fields within class. More...
 
#define CARGO_EXTEND(BASE)
 Registers new cargo fields within child class. More...
 

Detailed Description

C++ library for handling serialization.

cargo libraries usage example

#include "cargo/fields.hpp"
#include <iostream>
#include <cstdio>
struct Foo
{
std::string bar = "plain-text";
std::vector<int> tab = std::vector<int>{1, 2, 4, 8};
double number = 3.14;
(
bar,
tab,
number
)
};
int main()
{
Foo foo;
const std::string jsonString = cargo::saveToJsonString(foo);
cargo::loadFromJsonString(jsonString, foo);
const GVariant* gVariantPointer = cargo::saveToGVariant(foo);
cargo::loadFromGVariant(gVariantPointer, foo);
g_variant_unref(gVariantPointer);
constexpr std::string jsonFile = "foo.json";
cargo::saveToJsonFile(jsonFile, foo);
cargo::loadFromJsonFile(jsonFile, foo);
constexpr std::string kvDBPath = "kvdb";
constexpr std::string key = "foo";
cargo::saveToKVStore(kvDBPath, foo, key);
cargo::loadFromKVStore(kvDBPath, foo, key);
cargo::loadFromKVStoreWithJson(kvDBPath, jsonString, foo, key);
cargo::loadFromKVStoreWithJsonFile(kvDBPath, jsonFile, foo, key);
FILE* file = fopen("blob", "wb");
if (!file)
{
return EXIT_FAILURE;
}
const int fd = ::fileno(file);
cargo::saveToFD(fd, foo);
::fclose(file);
file = ::fopen("blob", "rb");
if(!file) {
return EXIT_FAILURE;
}
::fclose(file);
return 0;
}

Macro Definition Documentation

#define CARGO_EXTEND (   BASE)
Value:
typedef BASE ParentVisitor; \
#define __CARGO_EXTEND(...)
Definition: fields.hpp:129

Registers new cargo fields within child class.

CARGO_REGISTER doesn't preserve cargo fields registered in the base class. Use this macro instead.

Example:

struct Foo
{
std::string bar;
std::vector<int> tab;
// SubConfigA must also register config fields
SubConfigA sub_a;
// SubConfigB must also register config fields
std::vector<SubConfigB> tab_sub;
(
bar,
tab,
sub_a
)
};
struct FooChild : Foo
{
std::string newField;
(
newField
)
};
#define CARGO_REGISTER (   ...)
Value:
template<typename Visitor> \
void accept(Visitor v) { \
GENERATE_ELEMENTS__(__VA_ARGS__) \
} \
template<typename Visitor> \
void accept(Visitor v) const { \
GENERATE_ELEMENTS__(__VA_ARGS__) \
} \
#define GENERATE_ELEMENTS__(...)
Definition: fields.hpp:141

Registers cargo fields within class.

Example:

struct Foo
{
std::string bar;
std::vector<int> tab;
// SubConfigA must also register config fields
SubConfigA sub_a;
// SubConfigB must also register config fields
std::vector<SubConfigB> tab_sub;
(
bar,
tab,
sub_a
)
};
#define CARGO_REGISTER_EMPTY
Value:
template<typename Visitor> \
static void accept(Visitor ) { \
} \

Register empty cargo class.