RefleX
Build DDS Applications in Modern C++ without IDL
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros Pages
Macros
adapt_macros.h File Reference

Macros to adapt user-defined types (classes, structs, and enums) to allow RefleX to extract type-specific information at compile-time. More...

Go to the source code of this file.

Macros

#define REFLEX_STATIC_STRING_BOUND
 Static bound for string types. Default 256. More...
 
#define REFLEX_STATIC_CONTAINER_BOUND
 Static bound for container types. Default 256. More...
 
#define REFLEX_ENUM_DEF_CUSTOM(EnumType, Name, Size)
 Adapt and customize a C++ native enumeration for use with RefleX. More...
 
#define REFLEX_ENUM_MEMBER_DEF_CUSTOM(EnumType, Index, Name, Ordinal)
 Adapt and customize a C++ native enumeration item names and ordinals for use with RefleX. More...
 
#define REFLEX_STRUCT_NAME_DEF_CUSTOM(FullyQualifiedType, Name)
 Adapt and customize a std::tuple type for use with RefleX. More...
 
#define REFLEX_STRUCT_MEMBER_DEF_CUSTOM(FullyQualifiedType, Index, Name, Flags)
 Adapt and customize members of a std::tuple type for use with RefleX. More...
 
#define REFLEX_ADAPT_ENUM(EnumType, Attributes)
 Adapt a C++ native enumeration for use with RefleX. More...
 
#define REFLEX_ADAPT_STRUCT(Type, Attributes)
 Adapt a native C++ struct/class for use with RefleX. More...
 
#define REFLEX_ADAPT_VALUETYPE(Type, Base, Attributes)
 Adapt a C++ struct/class hierarchy for use with RefleX. More...
 
#define REFLEX_OPTIONAL   (DDS_TYPECODE_NONKEY_MEMBER)
 Indicate in REFLEX_ADAPT_STRUCT that a member is optional. More...
 
#define REFLEX_KEY   (DDS_TYPECODE_KEY_MEMBER)
 Indicate in REFLEX_ADAPT_STRUCT that a member is key. More...
 
#define REFLEX_REQUIRED   (DDS_TYPECODE_NONKEY_REQUIRED_MEMBER)
 Indicate in REFLEX_ADAPT_STRUCT that a member is required. More...
 
#define REFLEX_EXTENDS(X)   X
 Indicate the base struct/class in REFLEX_ADAPT_VALUETYPE. More...
 

Detailed Description

Macros to adapt user-defined types (classes, structs, and enums) to allow RefleX to extract type-specific information at compile-time.

Macro Definition Documentation

#define REFLEX_ADAPT_ENUM (   EnumType,
  Attributes 
)
Value:
namespace reflex { namespace codegen { \
template <> \
struct EnumDef<EnumType> \
{ \
static const char *name() { \
return \
detail::NameHelper::basename \
(#EnumType); \
} \
\
enum { is_enum = true }; \
\
static const unsigned int size = \
BOOST_PP_SEQ_SIZE(RTI_PARENTHESIZE(Attributes)); \
\
template <unsigned Index> \
struct EnumMember { \
static MemberInfo info(); \
}; \
}; \
} } /* namespace reflex::detail */ \
BOOST_PP_SEQ_FOR_EACH_I(RTI_ENUM_MEMBER_INFO_INTERNAL, \
EnumType, \
RTI_PARENTHESIZE(Attributes))

Adapt a C++ native enumeration for use with RefleX.

Consider the following native C++ enumeration called FillKind.

enum ShapeFillKind { SOLID_FILL=10, TRANSPARENT_FILL=11, HORIZONTAL_HATCH_FILL=12, VERTICAL_HATCH_FILL=13 };

It may be adapted as follows.

FillKind,
(SOLID_FILL, 10)
(TRANSPARENT_FILL, 11)
(HORIZONTAL_HATCH_FILL, 12)
(VERTICAL_HATCH_FILL, 13))

The above declarations results into an X-Types typecode representing an enumeration named FillKind that matches the C++ native declaration.

Parameters
EnumTypeThe fully qualified type of the native C++ enumeration.
AttributesA list of parenthesis describing the enumeration items and their ordinals. Parenthesis are not separated by comma.
See Also
REFLEX_ENUM_MEMBER_DEF_CUSTOM
REFLEX_ENUM_DEF_CUSTOM
#define REFLEX_ADAPT_STRUCT (   Type,
  Attributes 
)
Value:
RTI_STRUCT_NAME_DEF_INTERNAL(Type) \
RTI_MEMBER_TRAITS(Type, Attributes) \
BOOST_FUSION_ADAPT_STRUCT(Type, RTI_TRANSFORM_TRIPLETS_TO_PAIRS(Attributes))

Adapt a native C++ struct/class for use with RefleX.

Consider the following native C++ struct called ShapeType.

namespace geometry {
struct ShapeType {
std::string color;
int x;
int y;
int shapesize;
};
} // namespace geometry

It may be adapted as follows.

geometry::ShapeType,
(std::string, color)
(int, x)
(int, y)
(int, shapesize))

The above declarations results into an X-Types typecode representing an struct type named ShapeType that matches the C++ native declaration. The namespaces are ignored and the resulting typecode has EXTENSIBLE_EXTENSIBILITY. The default bounds for strings and containers are REFLEX_STATIC_STRING_BOUND and REFLEX_STATIC_CONTAINER_BOUND.

If the type of a member contains a comma, such as in std::pair or std::tuple, such types must be typedef-ed so that commas are no longer needed.

If the type is a class, getters may be used instead of the actual member names. The name of the getter is used to define the member name. The getter name should include the trailing parenthesis as in color(), x(), y(), and shapesize().

Parameters
TypeThe fully qualified type of the native C++ struct/class.
AttributesA list of parenthesis describing the members (the type and the member name). Parenthesis are not separated by comma.
See Also
REFLEX_STRUCT_MEMBER_DEF_CUSTOM
REFLEX_STRUCT_NAME_DEF_CUSTOM
#define REFLEX_ADAPT_VALUETYPE (   Type,
  Base,
  Attributes 
)
Value:
RTI_INHERITANCE_TRAITS(Type, Base) \
REFLEX_ADAPT_STRUCT(Type, Attributes)
#define REFLEX_ADAPT_STRUCT(Type, Attributes)
Adapt a native C++ struct/class for use with RefleX.
Definition: adapt_macros.h:302

Adapt a C++ struct/class hierarchy for use with RefleX.

Parameters
TypeThe fully qualified type of the C++ struct/class.
BaseThe fully qualified type of the C++ struct/class that Type inherits from.
AttributesA list of parenthesis describing the members (the type and the member name). Parenthesis are not separated by comma.
See Also
REFLEX_ADAPT_STRUCT
#define REFLEX_ENUM_DEF_CUSTOM (   EnumType,
  Name,
  Size 
)
Value:
namespace reflex { namespace codegen { \
template <> \
struct EnumDef<EnumType> \
{ \
static const char *name() { \
return Name; \
} \
\
enum { is_enum = true }; \
static const unsigned int size = Size; \
\
template <unsigned Index> \
struct EnumMember { \
static MemberInfo info(); \
}; \
}; \
} }

Adapt and customize a C++ native enumeration for use with RefleX.

REFLEX_ENUM_DEF_CUSTOM and REFLEX_ENUM_MEMBER_DEF_CUSTOM are always used together and they allow customization of enumeration type-name, item names and ordinals that are not possible with REFLEX_ADAPT_ENUM .

Consider the following native C++ enumeration called FillKind.

enum FillKind { SOLID_FILL=10, TRANSPARENT_FILL=11, HORIZONTAL_HATCH_FILL=12, VERTICAL_HATCH_FILL=13 };

REFLEX_ENUM_DEF_CUSTOM and REFLEX_ENUM_MEMBER_DEF_CUSTOM may be used as follows.

REFLEX_ENUM_DEF_CUSTOM(FillKind, "FillKindStyle", 4)
REFLEX_ENUM_MEMBER_DEF_CUSTOM(FillKind, 0, "SOLID_FILL_STYLE", 10)
REFLEX_ENUM_MEMBER_DEF_CUSTOM(FillKind, 1, "TRANSPARENT_FILL_STYLE", 11)
REFLEX_ENUM_MEMBER_DEF_CUSTOM(FillKind, 2, "HORIZONTAL_HATCH_FILL_STYLE", 12)
REFLEX_ENUM_MEMBER_DEF_CUSTOM(FillKind, 3, "VERTICAL_HATCH_FILL_STYLE", 13)

The above declarations results in to an X-Types typecode representing an enumeration named FillKindStyle as follows.

enum FillKindStyle { SOLID_FILL_STYLE=10, TRANSPARENT_FILL_STYLE=11, HORIZONTAL_HATCH_FILL_STYLE=12, VERTICAL_HATCH_FILL_STYLE=13 };
Parameters
EnumTypeFully qualified type of the native C++ enumeration.
NameThe target name of the enumeration. This may be different from the name of the native C++ enumeration.
SizeThe number of items in the C++ native enumeration.
See Also
REFLEX_ENUM_MEMBER_DEF_CUSTOM
REFLEX_ADAPT_ENUM
#define REFLEX_ENUM_MEMBER_DEF_CUSTOM (   EnumType,
  Index,
  Name,
  Ordinal 
)
Value:
namespace reflex { namespace codegen { \
template<> \
inline MemberInfo \
EnumDef<EnumType>::EnumMember<Index>::info() \
{ \
return MemberInfo(Name, Ordinal); \
} \
} }

Adapt and customize a C++ native enumeration item names and ordinals for use with RefleX.

See REFLEX_ENUM_DEF_CUSTOM and REFLEX_ENUM_MEMBER_DEF_CUSTOM for more information.

Parameters
EnumTypeThe fully qualified type of the enumeration to be adapted.
IndexThe index of the member. Starts at 0.
NameThe target name of the member
OrdinalThe integer value of the enumeration item.
#define REFLEX_EXTENDS (   X)    X

Indicate the base struct/class in REFLEX_ADAPT_VALUETYPE.

#define REFLEX_KEY   (DDS_TYPECODE_KEY_MEMBER)

Indicate in REFLEX_ADAPT_STRUCT that a member is key.

#define REFLEX_OPTIONAL   (DDS_TYPECODE_NONKEY_MEMBER)

Indicate in REFLEX_ADAPT_STRUCT that a member is optional.

#define REFLEX_REQUIRED   (DDS_TYPECODE_NONKEY_REQUIRED_MEMBER)

Indicate in REFLEX_ADAPT_STRUCT that a member is required.

#define REFLEX_STATIC_CONTAINER_BOUND

Static bound for container types. Default 256.

See Also
REFLEX_STATIC_STRING_BOUND
#define REFLEX_STATIC_STRING_BOUND

Static bound for string types. Default 256.

See Also
REFLEX_STATIC_CONTAINER_BOUND
#define REFLEX_STRUCT_MEMBER_DEF_CUSTOM (   FullyQualifiedType,
  Index,
  Name,
  Flags 
)
Value:
namespace reflex { namespace codegen { \
template <> \
struct MemberTraits<FullyQualifiedType, Index> \
{ \
static MemberInfo member_info() \
{ \
return MemberInfo(Name, Flags); \
} \
}; \
} }

Adapt and customize members of a std::tuple type for use with RefleX.

See REFLEX_STRUCT_NAME_DEF_CUSTOM and REFLEX_ADAPT_STRUCT for more information.

Parameters
FullyQualifiedTypeThe fully qualified type of the type to be adapted.
IndexThe index of the member. Starts at 0.
NameThe target name of the member
FlagsOne of REFLEX_KEY, REFLEX_REQUIRED, and REFLEX_OPTIONAL
#define REFLEX_STRUCT_NAME_DEF_CUSTOM (   FullyQualifiedType,
  Name 
)
Value:
namespace reflex { namespace codegen { \
template <> \
struct StructName<FullyQualifiedType> \
{ \
static std::string get() { \
return Name; \
} \
}; \
} }

Adapt and customize a std::tuple type for use with RefleX.

By default, std::tuple types do not require any adaptations to use with RefleX. Adaptations might be desirable to allow more descriptive (human-readable) names for tuple types and members.

Without customization, a std::tuple maps to "DefaultTupleNameN" where N is unique for each std::tuple type. The member names default to "m0", "m1", "m2" etc. REFLEX_STRUCT_NAME_DEF_CUSTOM and REFLEX_STRUCT_MEMBER_DEF_CUSTOM allow customization of the typename and member names. They are always used together.

Consider the following std::tuple definition.

typedef std::tuple<std::string, int, int, int> ShapeTypeTuple;

Without any customization, ShapeTypeTuple maps to the following X-Types struct type. Note that there is no key attribute specified.

struct DefaultTupleName0 {
string<REFLEX_STATIC_STRING_BOUND> m0;
long m1;
long m2;
long m3;
};

With REFLEX_STRUCT_NAME_DEF_CUSTOM and REFLEX_STRUCT_MEMBER_DEF_CUSTOM the name and the members of the ShapeTypeTuple can be easily customized.

REFLEX_STRUCT_NAME_DEF_CUSTOM(ShapeTypeTuple, "ShapeType")
REFLEX_STRUCT_MEMBER_DEF_CUSTOM(ShapeTypeTuple, 0, "color", REFLEX_KEY);
REFLEX_STRUCT_MEMBER_DEF_CUSTOM(ShapeTypeTuple, 2, "y", REFLEX_REQUIRED);
REFLEX_STRUCT_MEMBER_DEF_CUSTOM(ShapeTypeTuple, 3, "shapesize", REFLEX_REQUIRED);

The above declarations results in to an X-Types typecode representing a struct named ShapeType as follows.

struct ShapeType {
string<REFLEX_STATIC_STRING_BOUND> color; //@key
long x;
long y;
long shapesize;
};
Parameters
FullyQualifiedTypeThe fully qualified type of the C++ tuple type.
NameThe target name of the tuple type.
See Also
REFLEX_ADAPT_STRUCT