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

Go to the source code of this file.

Classes

struct  qi::detail::StructVersioningDelegateDrop< T >
 
struct  qi::detail::StructVersioningDelegateFill< T >
 
class  qi::StructTypeInterfaceBouncer< T, TO >
 
class  qi::TypeImpl< std::pair< F, S > >
 

Namespaces

 qi
 
 qi::detail
 

Macros

#define _QITYPE_DETAILS_TYPETUPLE_HXX_
 
#define QI_TYPE_STRUCT_EXTENSION_FILL_FIELDS(name,...)
 
#define QI_TYPE_STRUCT_EXTENSION_FILL_ALL(name,...)
 Allow filling any missing field with default value. More...
 
#define QI_TYPE_STRUCT_EXTENSION_DROP_ALL(name)
 Declare struct as extension of previous versions, allowing all fields to be dropped. More...
 
#define QI_TYPE_STRUCT_EXTENSION_DROP_FIELDS(name,...)
 Declare struct as extension of previous versions, allowing given fields to be dropped. More...
 
#define QI_TYPE_STRUCT_EXTENSION_DROP_HANDLER(name, f)
 
#define QI_TYPE_STRUCT_EXTENSION_FILL_HANDLER(name, f)
 
#define QI_TYPE_STRUCT_EXTENSION_ALL(name)
 
#define QI_TYPE_STRUCT_EXTENSION_FIELDS(name,...)
 Declare a versionned struct that accepts dropping/filling-with-default given fields. More...
 
#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 (StructTypeInterface *type, std::map< std::string,::qi::AnyValue > &fields, const std::vector< std::string > &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 239 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 240 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 238 of file structtypeinterface.hxx.

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

Definition at line 237 of file structtypeinterface.hxx.

#define __QI_STRUCT_ACCESS (   tuple)    QI_DELAY(__QI_STRUCT_ACCESS_BOUNCE)tuple

Definition at line 234 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 230 of file structtypeinterface.hxx.

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

Definition at line 226 of file structtypeinterface.hxx.

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

Definition at line 222 of file structtypeinterface.hxx.

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

Definition at line 219 of file structtypeinterface.hxx.

#define __QI_STRUCT_ACCESS_FUNC (   fname,
  field 
)    &field

Definition at line 217 of file structtypeinterface.hxx.

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

Definition at line 168 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 166 of file structtypeinterface.hxx.

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

Definition at line 167 of file structtypeinterface.hxx.

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

Definition at line 165 of file structtypeinterface.hxx.

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

Definition at line 241 of file structtypeinterface.hxx.

#define __QI_TYPE_STRUCT_DECLARE (   name,
  extra 
)
Value:
namespace qi { \
template<> struct TypeImpl<name>: public ::qi::StructTypeInterface \
{ \
public: \
typedef name ClassType; \
TypeImpl(); \
virtual std::vector< ::qi::TypeInterface*> memberTypes(); \
virtual std::vector<std::string> elementsName(); \
virtual std::string className(); \
virtual void* get(void* storage, unsigned int index); \
virtual void set(void** storage, unsigned int index, void* valStorage); \
virtual bool canDropFields(void* storage, const std::vector<std::string>& fieldNames); \
virtual bool fillMissingFields(std::map<std::string, ::qi::AnyValue>& fields, const std::vector<std::string>& missing); \
extra \
typedef ::qi::DefaultTypeImplMethods<name, ::qi::TypeByPointerPOD<name> > Impl; \
}; }
#define _QI_BOUNCE_TYPE_METHODS(Bounce)
Implement all methods of Type as bouncers to Bouncer.
Definition: typeimpl.hxx:275

Definition at line 145 of file structtypeinterface.hxx.

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

Definition at line 169 of file structtypeinterface.hxx.

#define _QITYPE_DETAILS_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 214 of file structtypeinterface.hxx.

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

Declare a struct field using an helper function.

Definition at line 212 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 301 of file structtypeinterface.hxx.

#define QI_TYPE_STRUCT_AGREGATE_CONSTRUCTOR (   name,
  ... 
)
Value:
virtual void set(void** storage, const std::vector<void*>&);) \
#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 337 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 359 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() \
{ \
return ::qi::detail::normalizeClassName(BOOST_PP_STRINGIZE(name)); \
} \
};}
std::string normalizeClassName(const std::string &name)
virtual void * ptrFromStorage(void **s)
Definition: typeimpl.hxx:294

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 372 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 392 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 308 of file structtypeinterface.hxx.

#define QI_TYPE_STRUCT_EXTENSION_ALL (   name)
Value:
#define QI_TYPE_STRUCT_EXTENSION_DROP_ALL(name)
Declare struct as extension of previous versions, allowing all fields to be dropped.
#define QI_TYPE_STRUCT_EXTENSION_FILL_ALL(name,...)
Allow filling any missing field with default value.

Allow converting this struct to/from anything. Dropping unmatched fields, and filling non-present ones with the default value for the matching type.

Warning
This will allow conversion between completely unrelated types, use with caution.

Definition at line 102 of file structtypeinterface.hxx.

#define QI_TYPE_STRUCT_EXTENSION_DROP_ALL (   name)
Value:
namespace qi { namespace detail { template<> struct StructVersioningDelegateDrop<name> { \
static bool canDropFields(void*, const std::vector<std::string>&) { return true;} \
};}}
static bool canDropFields(void *, const std::vector< std::string > &)

Declare struct as extension of previous versions, allowing all fields to be dropped.

Definition at line 56 of file structtypeinterface.hxx.

#define QI_TYPE_STRUCT_EXTENSION_DROP_FIELDS (   name,
  ... 
)
Value:
namespace qi { namespace detail { template<> struct StructVersioningDelegateDrop<name> { \
static bool canDropFields(void*, const std::vector<std::string>& fields) { \
const char* okFields[] = {__VA_ARGS__ }; \
int count = sizeof(okFields) / sizeof(char*); \
for (unsigned i=0; i<fields.size(); ++i) \
if (std::find(okFields, okFields+count, fields[i]) == okFields+count) return false; \
return true; \
} \
};}}
static bool canDropFields(void *, const std::vector< std::string > &)

Declare struct as extension of previous versions, allowing given fields to be dropped.

Definition at line 62 of file structtypeinterface.hxx.

#define QI_TYPE_STRUCT_EXTENSION_DROP_HANDLER (   name,
  f 
)
Value:
namespace qi { namespace detail { template<> struct StructVersioningDelegateDrop<name> { \
static bool canDropFields(void* store, const std::vector<std::string>& fields) { \
return f((name*)store, fields);} \
};}}
static bool canDropFields(void *, const std::vector< std::string > &)

Define callable f as drop handler for struct name will be invoked as f(name* nameInstance, const std::vector<std::string>& fields) and must return true to allow the drop, or false to deny the conversion.

Definition at line 77 of file structtypeinterface.hxx.

#define QI_TYPE_STRUCT_EXTENSION_FIELDS (   name,
  ... 
)
Value:
#define QI_TYPE_STRUCT_EXTENSION_DROP_FIELDS(name,...)
Declare struct as extension of previous versions, allowing given fields to be dropped.
#define QI_TYPE_STRUCT_EXTENSION_FILL_FIELDS(name,...)

Declare a versionned struct that accepts dropping/filling-with-default given fields.

Definition at line 107 of file structtypeinterface.hxx.

#define QI_TYPE_STRUCT_EXTENSION_FILL_ALL (   name,
  ... 
)
Value:
namespace qi { namespace detail { template<> struct StructVersioningDelegateFill<name> { \
static bool fillMissingFields(StructTypeInterface* type, std::map<std::string, ::qi::AnyValue>& fields, const std::vector<std::string>& missing) \
{ \
return fillMissingFieldsWithDefaultValues(type, fields, missing); \
} \
};}}
bool fillMissingFieldsWithDefaultValues(StructTypeInterface *type, std::map< std::string,::qi::AnyValue > &fields, const std::vector< std::string > &missing, const char **which=0, int whichLength=0)
static bool fillMissingFields(StructTypeInterface *type, std::map< std::string,::qi::AnyValue > &fields, const std::vector< std::string > &missing)

Allow filling any missing field with default value.

Definition at line 48 of file structtypeinterface.hxx.

#define QI_TYPE_STRUCT_EXTENSION_FILL_FIELDS (   name,
  ... 
)
Value:
namespace qi { namespace detail { template<> struct StructVersioningDelegateFill<name> { \
static bool fillMissingFields(StructTypeInterface* type, std::map<std::string, ::qi::AnyValue>& fields, const std::vector<std::string>& missing) \
{ \
const char* which[] = {__VA_ARGS__ }; \
int count = sizeof(which) / sizeof(char*); \
return fillMissingFieldsWithDefaultValues(type, fields, missing, which, count); \
} \
};}}
bool fillMissingFieldsWithDefaultValues(StructTypeInterface *type, std::map< std::string,::qi::AnyValue > &fields, const std::vector< std::string > &missing, const char **which=0, int whichLength=0)
static bool fillMissingFields(StructTypeInterface *type, std::map< std::string,::qi::AnyValue > &fields, const std::vector< std::string > &missing)

Allow filling given struct field names with the default value, if converting from a previous struct version.

Warning
any value set by the default constructor will be overriden with the default value for the field type (0 for int).

Definition at line 38 of file structtypeinterface.hxx.

#define QI_TYPE_STRUCT_EXTENSION_FILL_HANDLER (   name,
  f 
)
Value:
namespace qi { namespace detail { template<> struct StructVersioningDelegateFill<name> { \
static bool fillMissingFields(StructTypeInterface* type, std::map<std::string, ::qi::AnyValue>& fields, const std::vector<std::string>& missing) \
{ \
return f(fields, missing) ; \
}};}}
static bool fillMissingFields(StructTypeInterface *type, std::map< std::string,::qi::AnyValue > &fields, const std::vector< std::string > &missing)

Define callable f as handler when a default value is needed for some fields of name. Will be invoked as f(std::map<string, AnyValue>& content, const vector<string>& missingFields) It must return false to indicate a failure, or fill content with a value for all the missing fields and return true.

Definition at line 89 of file structtypeinterface.hxx.

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

Definition at line 312 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 289 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 348 of file structtypeinterface.hxx.