Fork Vasum on GitHub Official Vasum Wiki on Tizen.org
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
fields-union.hpp File Reference

Macros for declare cargo fields. More...

#include "cargo/fields.hpp"
#include "cargo/exception.hpp"
#include <utility>
#include <boost/any.hpp>

Go to the source code of this file.

Classes

class  DisableMoveAnyWrapper
 

Macros

#define CARGO_DECLARE_UNION(...)
 Use this macro to declare and register cargo fields. More...
 
#define GENERATE_CODE(MACRO,...)   BOOST_PP_LIST_FOR_EACH(MACRO, _, BOOST_PP_VARIADIC_TO_LIST(__VA_ARGS__))
 
#define GENERATE_UNION_VISIT__(r, _, TYPE_)
 
#define GENERATE_UNION_VISIT_CONST__(r, _, TYPE_)
 
#define GENERATE_UNION_NAME__(r, _, TYPE_)
 

Detailed Description

Macros for declare cargo fields.

Author
Mateusz Malicki (m.mal.nosp@m.icki.nosp@m.2@sam.nosp@m.sung.nosp@m..com)

Macro Definition Documentation

#define CARGO_DECLARE_UNION (   ...)

Use this macro to declare and register cargo fields.

Example of fields registration:

struct Foo {
std::string bar;
(
bar,
)
};
struct Config
{
(
Foo,
int
)
};

Example of valid configuration:

1. {
"type": "Foo",
"value": { "bar": "some string" }
}
2. {
"type": "int",
"value": 1
}

Usage of existing bindings:

Config config;
// ...
if (config.isSet()) {
if (config.is<Foo>()) {
Foo& foo = config.as<Foo>();
// ...
}
if (config.is<int>())) {
int field = config.as<int>();
// ...
}
} else {
// Config is not set
Foo foo({"some string"});
config.set(foo);
config.set(std::move(foo)); //< copy sic!
config.set(Foo({"some string"}));
}
#define GENERATE_CODE (   MACRO,
  ... 
)    BOOST_PP_LIST_FOR_EACH(MACRO, _, BOOST_PP_VARIADIC_TO_LIST(__VA_ARGS__))
#define GENERATE_UNION_NAME__ (   r,
  _,
  TYPE_ 
)
Value:
if (is<TYPE_>()) { \
return #TYPE_; \
}
#define GENERATE_UNION_VISIT__ (   r,
  _,
  TYPE_ 
)
Value:
if (#TYPE_ == name) { \
v.visit("value", set(std::move(TYPE_()))); \
return; \
}
#define GENERATE_UNION_VISIT_CONST__ (   r,
  _,
  TYPE_ 
)
Value:
if (#TYPE_ == name) { \
v.visit("value", as<const TYPE_>()); \
return; \
}