libqi-api  2.8.7.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Classes | Namespaces | Macros | Functions
structtypeinterface.hxx File Reference
#include <map>
#include <boost/type_traits.hpp>
#include <boost/utility/enable_if.hpp>
#include <qi/api.hpp>
#include <qi/type/fwd.hpp>
#include <qi/type/detail/accessor.hxx>
#include <qi/type/typeinterface.hpp>
#include <qi/preproc.hpp>

Go to the source code of this file.

Classes

struct  qi::detail::StructVersioningDelegateAddFields< T >
 
struct  qi::detail::StructVersioningDelegateDropFields< T >
 
struct  qi::detail::StructVersioningDelegate< T >
 
class  qi::StructTypeInterfaceBouncer< T, TO >
 
class  qi::TypeImpl< std::pair< F, S > >
 

Namespaces

 qi
 Deprecated in 2.5. Use int8_t from <cstdint>.
 
 qi::detail
 

Macros

#define _QITYPE_DETAIL_TYPETUPLE_HXX_
 
#define QI_TYPE_STRUCT_EXTENSION_ADDED_FIELDS(name,...)
 
#define QI_TYPE_STRUCT_EXTENSION_DROPPED_FIELDS(name,...)
 
#define QI_TYPE_STRUCT_EXTENSION_CONVERT_HANDLERS(name, fromHandler, toHandler)
 
#define __QI_TYPE_STRUCT_DECLARE(name, extra)
 
#define __QI_TUPLE_TYPE(_, what, field)   res.push_back(::qi::typeOf(ptr->field));
 
#define __QI_TUPLE_GET(_, what, field)   if (i == index) return ::qi::typeOf(ptr->field)->initializeStorage(&ptr->field); i++;
 
#define __QI_TUPLE_SET(_, what, field)   if (i == index) ::qi::detail::setFromStorage(ptr->field, valueStorage); i++;
 
#define __QI_TUPLE_FIELD_NAME(_, what, field)   res.push_back(BOOST_PP_STRINGIZE(QI_DELAY(field)));
 
#define __QI_TYPE_STRUCT_IMPLEMENT(name, inl, onSet,...)
 
#define QI_STRUCT_HELPER(name, func)   (name, func, FUNC)
 Declare a struct field using an helper function. More...
 
#define QI_STRUCT_FIELD(name, field)   (name, field, FIELD)
 Declare a struct feld that is a member (member value or member accessor function) More...
 
#define __QI_STRUCT_ACCESS_FUNC(fname, field)   &field
 
#define __QI_STRUCT_ACCESS_FIELD(fname, field)   &ClassType::field
 
#define __QI_STRUCT_ACCESS_BOUNCE2(name, accessor, type)   QI_CAT(__QI_STRUCT_ACCESS_, type)(name, accessor)
 
#define __QI_STRUCT_ACCESS_BOUNCE1(x, y)   __QI_STRUCT_ACCESS_BOUNCE2(x, y, FIELD)
 
#define __QI_STRUCT_ACCESS_BOUNCE(...)   QI_CAT(__QI_STRUCT_ACCESS_BOUNCE, QI_LIST_VASIZE((__VA_ARGS__)))(__VA_ARGS__)
 
#define __QI_STRUCT_ACCESS(tuple)   QI_DELAY(__QI_STRUCT_ACCESS_BOUNCE)tuple
 
#define __QI_ATUPLE_TYPE(_, what, field)   res.push_back(::qi::detail::fieldType(__QI_STRUCT_ACCESS(field)));
 
#define __QI_ATUPLE_GET(_, what, field)   if (i == index) return ::qi::detail::fieldStorage(ptr, __QI_STRUCT_ACCESS(field)); i++;
 
#define __QI_ATUPLE_FIELD_NAME(_, what, field)   res.push_back(QI_PAIR_FIRST(field));
 
#define __QI_ATUPLE_FROMDATA(idx, what, field)   ::qi::detail::fieldValue(ptr, __QI_STRUCT_ACCESS(field), const_cast<void**>(&data[idx]))
 
#define __QI_TYPE_STRUCT_AGREGATE_CONSTRUCTOR_IMPLEMENT(name, inl, onSet,...)
 
#define QI_TYPE_STRUCT_PRIVATE_ACCESS(name)   friend class qi::TypeImpl<name>;
 Allow the QI_TYPE_STRUCT macro and variants to access private members. More...
 
#define QI_TYPE_STRUCT(name,...)
 
#define QI_TYPE_STRUCT_EX(name, onSet,...)
 
#define QI_TYPE_STRUCT_IMPLEMENT(name,...)   __QI_TYPE_STRUCT_IMPLEMENT(name, , , __VA_ARGS__)
 
#define QI_TYPE_STRUCT_AGREGATE_CONSTRUCTOR(name,...)
 
#define QI_TYPE_STRUCT_REGISTER(name,...)
 
#define QI_TYPE_STRUCT_AGREGATE_CONSTRUCTOR_REGISTER(name,...)
 
#define QI_TYPE_STRUCT_BOUNCE(name, bounceTo, conversion)
 
#define QI_TYPE_STRUCT_BOUNCE_REGISTER(name, bounceTo, conversion)
 

Functions

bool qi::detail::fillMissingFieldsWithDefaultValues (std::map< std::string,::qi::AnyValue > &fields, const std::vector< std::tuple< std::string, TypeInterface * >> &missing, const char **which=0, int whichLength=0)
 
std::string qi::detail::normalizeClassName (const std::string &name)
 
template<typename T >
void qi::detail::setFromStorage (T &ref, void *storage)
 
template<typename A >
TypeInterface * qi::detail::fieldType (A)
 
template<typename C , typename A >
void * qi::detail::fieldStorage (C *inst, A accessor)
 
template<typename C , typename A >
detail::Accessor< A >::value_type & qi::detail::fieldValue (C *instance, A accessor, void **data)
 

Macro Definition Documentation

#define __QI_ATUPLE_FIELD_NAME (   _,
  what,
  field 
)    res.push_back(QI_PAIR_FIRST(field));

Definition at line 323 of file structtypeinterface.hxx.

#define __QI_ATUPLE_FROMDATA (   idx,
  what,
  field 
)    ::qi::detail::fieldValue(ptr, __QI_STRUCT_ACCESS(field), const_cast<void**>(&data[idx]))

Definition at line 324 of file structtypeinterface.hxx.

#define __QI_ATUPLE_GET (   _,
  what,
  field 
)    if (i == index) return ::qi::detail::fieldStorage(ptr, __QI_STRUCT_ACCESS(field)); i++;

Definition at line 322 of file structtypeinterface.hxx.

#define __QI_ATUPLE_TYPE (   _,
  what,
  field 
)    res.push_back(::qi::detail::fieldType(__QI_STRUCT_ACCESS(field)));

Definition at line 321 of file structtypeinterface.hxx.

#define __QI_STRUCT_ACCESS (   tuple)    QI_DELAY(__QI_STRUCT_ACCESS_BOUNCE)tuple

Definition at line 318 of file structtypeinterface.hxx.

#define __QI_STRUCT_ACCESS_BOUNCE (   ...)    QI_CAT(__QI_STRUCT_ACCESS_BOUNCE, QI_LIST_VASIZE((__VA_ARGS__)))(__VA_ARGS__)

Definition at line 314 of file structtypeinterface.hxx.

#define __QI_STRUCT_ACCESS_BOUNCE1 (   x,
 
)    __QI_STRUCT_ACCESS_BOUNCE2(x, y, FIELD)

Definition at line 310 of file structtypeinterface.hxx.

#define __QI_STRUCT_ACCESS_BOUNCE2 (   name,
  accessor,
  type 
)    QI_CAT(__QI_STRUCT_ACCESS_, type)(name, accessor)

Definition at line 306 of file structtypeinterface.hxx.

#define __QI_STRUCT_ACCESS_FIELD (   fname,
  field 
)    &ClassType::field

Definition at line 303 of file structtypeinterface.hxx.

#define __QI_STRUCT_ACCESS_FUNC (   fname,
  field 
)    &field

Definition at line 301 of file structtypeinterface.hxx.

#define __QI_TUPLE_FIELD_NAME (   _,
  what,
  field 
)    res.push_back(BOOST_PP_STRINGIZE(QI_DELAY(field)));

Definition at line 242 of file structtypeinterface.hxx.

#define __QI_TUPLE_GET (   _,
  what,
  field 
)    if (i == index) return ::qi::typeOf(ptr->field)->initializeStorage(&ptr->field); i++;

Definition at line 240 of file structtypeinterface.hxx.

#define __QI_TUPLE_SET (   _,
  what,
  field 
)    if (i == index) ::qi::detail::setFromStorage(ptr->field, valueStorage); i++;

Definition at line 241 of file structtypeinterface.hxx.

#define __QI_TUPLE_TYPE (   _,
  what,
  field 
)    res.push_back(::qi::typeOf(ptr->field));

Definition at line 239 of file structtypeinterface.hxx.

#define __QI_TYPE_STRUCT_AGREGATE_CONSTRUCTOR_IMPLEMENT (   name,
  inl,
  onSet,
  ... 
)

Definition at line 325 of file structtypeinterface.hxx.

#define __QI_TYPE_STRUCT_DECLARE (   name,
  extra 
)
Value:
namespace qi \
{ \
template <> \
struct TypeImpl<name> : public ::qi::StructTypeInterface \
{ \
public: \
using ClassType = name; \
TypeImpl(); \
std::vector<::qi::TypeInterface*> memberTypes() override; \
std::vector<std::string> elementsName() override; \
std::string className() override; \
void* get(void* storage, unsigned int index) override; \
void set(void** storage, unsigned int index, void* valStorage) override; \
virtual bool convertFrom(std::map<std::string, ::qi::AnyValue>& fields, \
const std::vector<std::tuple<std::string, TypeInterface*>>& missing, \
const std::map<std::string, ::qi::AnyReference>& dropfields) override; \
virtual bool convertTo(std::map<std::string, ::qi::AnyValue>& fields, \
const std::vector<std::tuple<std::string, TypeInterface*>>& missing, \
const std::map<std::string, ::qi::AnyReference>& dropfields) override; \
}; \
}
#define _QI_BOUNCE_TYPE_METHODS(Bounce)
Implement all methods of Type as bouncers to Bouncer.
Definition: typeimpl.hxx:273

Definition at line 214 of file structtypeinterface.hxx.

#define __QI_TYPE_STRUCT_IMPLEMENT (   name,
  inl,
  onSet,
  ... 
)

Definition at line 243 of file structtypeinterface.hxx.

#define _QITYPE_DETAIL_TYPETUPLE_HXX_

Definition at line 8 of file structtypeinterface.hxx.

#define QI_STRUCT_FIELD (   name,
  field 
)    (name, field, FIELD)

Declare a struct feld that is a member (member value or member accessor function)

Definition at line 298 of file structtypeinterface.hxx.

#define QI_STRUCT_HELPER (   name,
  func 
)    (name, func, FUNC)

Declare a struct field using an helper function.

Definition at line 296 of file structtypeinterface.hxx.

#define QI_TYPE_STRUCT (   name,
  ... 
)
Value:
__QI_TYPE_STRUCT_IMPLEMENT(name, inline, , __VA_ARGS__)
#define QI_TYPE_STRUCT_DECLARE(name)
#define __QI_TYPE_STRUCT_IMPLEMENT(name, inl, onSet,...)

Declare a simple struct to the type system. First argument is the structure name. Remaining arguments are the structure fields. This macro must be called outside any namespace. This macro should be called in the header file defining the structure 'name', or in a header included by all source files using the structure. See QI_TYPE_STRUCT_REGISTER for a similar macro that can be called from a single source file.

Definition at line 396 of file structtypeinterface.hxx.

#define QI_TYPE_STRUCT_AGREGATE_CONSTRUCTOR (   name,
  ... 
)
Value:
void set(void** storage, const std::vector<void*>&) override;) \
#define __QI_TYPE_STRUCT_AGREGATE_CONSTRUCTOR_IMPLEMENT(name, inl, onSet,...)
#define __QI_TYPE_STRUCT_DECLARE(name, extra)

Register a struct with member field/function getters, and constructor setter

Call like that: QI_TYPE_STRUCT_AGREGATE_CONSTRUCTOR(Point, ("x", getX), ("y", y))

The first macro argument is the class full name including namespace. Remaining arguments can be:

The class must provide a constructor that accepts all fields as argument, in the order in which they are declared in the macro.

Must be called outside any namespace.

Definition at line 432 of file structtypeinterface.hxx.

#define QI_TYPE_STRUCT_AGREGATE_CONSTRUCTOR_REGISTER (   name,
  ... 
)
Value:
namespace _qi_ { \
} \
#define QI_TYPE_STRUCT_AGREGATE_CONSTRUCTOR(name,...)
#define QI_TYPE_REGISTER_CUSTOM(type, typeimpl)

Similar to QI_TYPE_STRUCT_AGREGATE_CONSTRUCTOR, but using the runtime factory instead of the compile-time template.

Definition at line 454 of file structtypeinterface.hxx.

#define QI_TYPE_STRUCT_BOUNCE (   name,
  bounceTo,
  conversion 
)
Value:
namespace qi { \
template<> class TypeImpl<name>: public ::qi::StructTypeInterfaceBouncer<name, bounceTo> \
{ \
public: \
void adaptStorage(void** storage, void** adapted) \
{ \
name* ptr = (name*)ptrFromStorage(storage); \
bounceTo * tptr = conversion(ptr); \
*adapted = bounceType()->initializeStorage(tptr); \
} \
std::string className() \
{ \
} \
};}
void * ptrFromStorage(void **s) override
Definition: typeimpl.hxx:292
std::string normalizeClassName(const std::string &name)

Declares that name is equivalent to type bounceTo, and that instances can be converted using the conversion function with signature 'bounceTo* (name*)'. This macro should be called in a header included by all code using the 'name' class. See QI_TYPE_STRUCT_BOUNCE_REGISTER for a similar macro that can be called from a single source file.

Definition at line 467 of file structtypeinterface.hxx.

#define QI_TYPE_STRUCT_BOUNCE_REGISTER (   name,
  bounceTo,
  conversion 
)
Value:
namespace _qi_ { \
QI_TYPE_STRUCT_BOUNCE(name, bounceTo, conversion); \
} \
#define QI_TYPE_STRUCT_BOUNCE(name, bounceTo, conversion)
#define QI_TYPE_REGISTER_CUSTOM(type, typeimpl)

Similar to QI_TYPE_STRUCT_BOUNCE, but using the runtime factory instead of the compile-time template.

Definition at line 487 of file structtypeinterface.hxx.

#define QI_TYPE_STRUCT_EX (   name,
  onSet,
  ... 
)
Value:
__QI_TYPE_STRUCT_IMPLEMENT(name, inline, onSet, __VA_ARGS__)
#define QI_TYPE_STRUCT_DECLARE(name)
#define __QI_TYPE_STRUCT_IMPLEMENT(name, inl, onSet,...)

Similar to QI_TYPE_STRUCT, but evaluates 'onSet' after writting to an instance. The instance is accessible through the variable 'ptr'.

Definition at line 403 of file structtypeinterface.hxx.

#define QI_TYPE_STRUCT_EXTENSION_ADDED_FIELDS (   name,
  ... 
)
Value:
namespace qi \
{ \
namespace detail \
{ \
template <> \
struct StructVersioningDelegateAddFields<name> \
{ \
static bool convertFrom(StructTypeInterface* type, \
std::map<std::string, ::qi::AnyValue>& fields, \
const std::vector<std::tuple<std::string, TypeInterface*>>& missing) \
{ \
static const char* which[] = {__VA_ARGS__}; \
const int count = sizeof(which) / sizeof(char*); \
return fillMissingFieldsWithDefaultValues(fields, missing, which, count); \
} \
static bool convertTo(const std::map<std::string, ::qi::AnyReference>& todrop) \
{ \
static const char* which[] = {__VA_ARGS__}; \
const int count = sizeof(which) / sizeof(char*); \
for (const auto& field : todrop) \
if (std::find(which, which + count, field.first) == which + count) \
return false; \
return true; \
} \
}; \
} \
}
bool fillMissingFieldsWithDefaultValues(std::map< std::string,::qi::AnyValue > &fields, const std::vector< std::tuple< std::string, TypeInterface * >> &missing, const char **which=0, int whichLength=0)

Declare that some fields have been added in this structure. They will be filled with default values upon conversion to this structure.

Definition at line 81 of file structtypeinterface.hxx.

#define QI_TYPE_STRUCT_EXTENSION_CONVERT_HANDLERS (   name,
  fromHandler,
  toHandler 
)
Value:
namespace qi \
{ \
namespace detail \
{ \
template <> \
struct StructVersioningDelegate<name> \
{ \
static bool convertFrom(StructTypeInterface* type, \
std::map<std::string, ::qi::AnyValue>& fields, \
const std::vector<std::tuple<std::string, TypeInterface*>>& missing, \
const std::map<std::string, ::qi::AnyReference>& dropfields) \
{ \
return fromHandler(fields, missing, dropfields); \
} \
static bool convertTo(StructTypeInterface* type, \
std::map<std::string, ::qi::AnyValue>& fields, \
const std::vector<std::tuple<std::string, TypeInterface*>>& missing, \
const std::map<std::string, ::qi::AnyReference>& dropfields) \
{ \
return toHandler(fields, missing, dropfields); \
} \
}; \
} \
}

Declare handlers for structure conversion from and to old version.

Parameters
namethe name of the structure
fromHandlera handler that will be called when converting from old structure to this one. It should have the following signature: bool convertFrom(StructTypeInterface* type, std::map<std::string, ::qi::AnyValue>& fields, const std::vector<std::tuple<std::string, TypeInterface*>>& missing, const std::map<std::string, ::qi::AnyReference>& dropfields). The method receives the structure to convert from as a map and it must fill in the fields given in the missing argument. It must return true upon successful conversion.
toHandlera handler that will be called when converting from this structure to the old one. It should have the following signature: bool convertFrom(StructTypeInterface* type, std::map<std::string, ::qi::AnyValue>& fields, const std::vector<std::tuple<std::string>& missing, const std::map<std::string, ::qi::AnyReference>& dropfields). The method receives the structure to convert from as a map and it must fill in the fields given in the missing argument. It must return true upon successful conversion.

Definition at line 155 of file structtypeinterface.hxx.

#define QI_TYPE_STRUCT_EXTENSION_DROPPED_FIELDS (   name,
  ... 
)
Value:
namespace qi \
{ \
namespace detail \
{ \
template <> \
struct StructVersioningDelegateDropFields<name> \
{ \
static bool convertTo(StructTypeInterface* type, \
std::map<std::string, ::qi::AnyValue>& fields, \
const std::vector<std::tuple<std::string, TypeInterface*>>& missing) \
{ \
static const char* which[] = {__VA_ARGS__}; \
const int count = sizeof(which) / sizeof(char*); \
return fillMissingFieldsWithDefaultValues(fields, missing, which, count); \
} \
static bool convertFrom(const std::map<std::string, ::qi::AnyReference>& todrop) \
{ \
static const char* which[] = {__VA_ARGS__}; \
const int count = sizeof(which) / sizeof(char*); \
for (const auto& field : todrop) \
if (std::find(which, which + count, field.first) == which + count) \
return false; \
return true; \
} \
}; \
} \
}
bool fillMissingFieldsWithDefaultValues(std::map< std::string,::qi::AnyValue > &fields, const std::vector< std::tuple< std::string, TypeInterface * >> &missing, const char **which=0, int whichLength=0)

Declare that some fields have been dropped in this structure. They will be filled with default values upon conversion to the old structure.

Definition at line 112 of file structtypeinterface.hxx.

#define QI_TYPE_STRUCT_IMPLEMENT (   name,
  ... 
)    __QI_TYPE_STRUCT_IMPLEMENT(name, , , __VA_ARGS__)

Definition at line 407 of file structtypeinterface.hxx.

#define QI_TYPE_STRUCT_PRIVATE_ACCESS (   name)    friend class qi::TypeImpl<name>;

Allow the QI_TYPE_STRUCT macro and variants to access private members.

Definition at line 384 of file structtypeinterface.hxx.

#define QI_TYPE_STRUCT_REGISTER (   name,
  ... 
)
Value:
namespace _qi_ { \
QI_TYPE_STRUCT(name, __VA_ARGS__) \
} \
#define QI_TYPE_REGISTER_CUSTOM(type, typeimpl)
#define QI_TYPE_STRUCT(name,...)

Similar to QI_TYPE_STRUCT, but using the runtime factory instead of the compile-time template. This macro will register the struct at static initialization time, and thus should only be called from one compilation unit. To ensure this, the simplest option is to use this macro from a .cpp source file. It should not be used in a header.

Definition at line 443 of file structtypeinterface.hxx.