/** * @file include/ActivMiddleware/ActivBase/GenericMessages/Detail/FieldMetaFunctions.h * * @brief Header for field metafunction classes used internally. */ #if (!defined ACTIV_BASE_GENERIC_MESSAGES_DETAIL_FIELD_META_FUNCTIONS_H) #define ACTIV_BASE_GENERIC_MESSAGES_DETAIL_FIELD_META_FUNCTIONS_H #include "ActivMiddleware/CxxYZ/type_traits.h" #include "ActivMiddleware/Misc/ContainerTraits.h" #include ACTIV_BOOST_INCLUDE(mpl/count_if.hpp) //! Activ namespace. namespace Activ { //! GenericMessages namespace. namespace GenericMessages { namespace Detail { //! Compare two field types for equality. template class IsFieldEqual : public MakeBoolConstant< (F1::id == F2::id) && CxxYZ::is_same::value && CxxYZ::is_same::value && CxxYZ::is_same::value> { }; // --------------------------------------------------------------------------------------------------------------------------------- template class TRANSFORM, typename T> class FieldTransform; // --------------------------------------------------------------------------------------------------------------------------------- // Transform a field's type. template class TRANSFORM, typename T, typename ENABLE = void> class FieldTransformImpl { public: typedef typename TRANSFORM::type type; }; // --------------------------------------------------------------------------------------------------------------------------------- // Specialization for a std::pair field. template class TRANSFORM, typename T1, typename T2> class FieldTransformImpl > { private: typedef typename FieldTransform::type firstType; typedef typename FieldTransform::type secondType; public: typedef std::pair type; }; // --------------------------------------------------------------------------------------------------------------------------------- #if (defined ACTIV_GM_HAS_STD_TUPLE_SUPPORT) // Specialization for a std::tuple field. template class TRANSFORM, typename... T> class FieldTransformImpl> { public: typedef std::tuple::type...> type; }; #endif // (defined ACTIV_GM_HAS_STD_TUPLE_SUPPORT) // --------------------------------------------------------------------------------------------------------------------------------- // Specialization for a container field. template class TRANSFORM, typename T> class FieldTransformImpl::value>::type> { public: typedef typename ContainerTraits::Rebind::type type; }; // --------------------------------------------------------------------------------------------------------------------------------- /** * @brief Transform a field's type. * * @tparam TRANSFORM the transform to apply (e.g. Definition -> Definition::Storage; Definition -> Definition::Reference). * @tparam T the field's type (as provided to a Field template). */ template class TRANSFORM, typename T> class FieldTransform : public FieldTransformImpl { }; // --------------------------------------------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------------------------------------------- // Transform a field's type to that suitable for a Message::Storage. template class FieldTypeToStorageTransformImpl { public: typedef T type; }; // --------------------------------------------------------------------------------------------------------------------------------- // Specialization for a field that is a Definition (i.e. field is a nested message). The storage type for the nested message field // is Definition::Storage. template class FieldTypeToStorageTransformImpl::value>::type> { public: typedef typename T::Storage type; }; // --------------------------------------------------------------------------------------------------------------------------------- /** * @brief Transform a field's type to one suitable for storage in a Definition::Storage type. * * @tparam T the field's type (as provided to a Field template). */ template class FieldTypeToStorageTransform : public FieldTypeToStorageTransformImpl { }; // --------------------------------------------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------------------------------------------- // Transform a field's type to that suitable for a Definition::Reference. template class FieldTypeToReferenceTransformImpl { public: typedef T type; }; // --------------------------------------------------------------------------------------------------------------------------------- // Specialization for a Definition field. template class FieldTypeToReferenceTransformImpl::value>::type> { public: typedef typename T::Reference type; }; // --------------------------------------------------------------------------------------------------------------------------------- /** * @brief Transform a field's type to one suitable for storage in a Definition::Reference type. * * @tparam T the field's type (as provided to a Field template). */ template class FieldTypeToReferenceTransform : public FieldTypeToReferenceTransformImpl { }; // --------------------------------------------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------------------------------------------- /** * @brief Metafunction to determine the underlying C++ class type for a field in a Definition::Storage::Reference. * * T is the field's type as provided to a Field template. */ // Transform a field's type to that suitable for a Definition::Storage::Reference. template class FieldTypeToClassTransformImpl { public: typedef T type; }; // --------------------------------------------------------------------------------------------------------------------------------- // Partial specialization for a Definition field. template class FieldTypeToClassTransformImpl::value>::type> { public: typedef typename T::Reference::Class type; }; // --------------------------------------------------------------------------------------------------------------------------------- /** * @brief Transform a field's type to one suitable for storage in a Definition::Storage::Reference type. * * @tparam T the field's type (as provided to a Field template). */ template class FieldTypeToClassTransform : public FieldTypeToClassTransformImpl { }; // --------------------------------------------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------------------------------------------- /** * @brief Metafunction to determine the suitable storage type for a field in a Definition::Storage. * * @tparam T the field's type (as provided to a Field template). */ template class FieldTypeToStorageType : public Detail::FieldTransform { }; // --------------------------------------------------------------------------------------------------------------------------------- /** * @brief Metafunction to determine the suitable reference type for a field in a MessageStorage::Reference. * * T is the field's type as provided to a Field template. */ template class FieldTypeToReferenceType : public Detail::FieldTransform { }; // --------------------------------------------------------------------------------------------------------------------------------- /** * @brief Metafunction to determine the underlying C++ class type for a field in a MessageStorage::Reference. * * T is the field's type as provided to a Field template. */ template class FieldTypeToClassType : public Detail::FieldTransform { }; // --------------------------------------------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------------------------------------------- //! Metafunction to determine the C++ class that a ClassField member pointer points to. template class ClassFieldToClass { public: typedef typename T::ClassMember::Class type; }; // --------------------------------------------------------------------------------------------------------------------------------- //! Metafunction to get the field id as an integral constant from a Field. template class FieldToFieldIdType : public Boost::mpl::integral_c { }; // --------------------------------------------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------------------------------------------- //! Is a Field mandatory? template class IsFieldMandatory : public MakeIntegralConstant > { }; // --------------------------------------------------------------------------------------------------------------------------------- //! Is a Field optional and defatuled? template class IsFieldDefaultedOptional : public MakeIntegralConstant > { }; // --------------------------------------------------------------------------------------------------------------------------------- //! Is a Field optional and non-defaulted? template class IsFieldNonDefaultedOptional : public MakeIntegralConstant > { }; // --------------------------------------------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------------------------------------------- /** * @brief Determine the type to be stored in a Field::Reference. * * For non-smart pointer fields, the type is most likely const T &, or const T for built in types. * * The exceptions are if T is a Definition, or a container containing a Definition, when T is mapped to the underlying * C++ class (if possible, by Definition using ClassField fields). */ template class TypeToFieldReferenceType { public: typedef typename Boost::call_traits::type>::param_type type; }; // --------------------------------------------------------------------------------------------------------------------------------- /** * @brief Determine the type to be stored in a Field::Reference. * * For smart pointer fields, the type is most likely const T *. This allows Field::References to be constructed by * smart pointer, raw pointer or reference to the pointed to type for convenience. * * The exceptions are if T is a Definition, or a container containing a Definition, when T is mapped to the underlying * C++ class (if possible, by Definition using ClassField fields). */ template class TypeToFieldReferenceType >::type> { public: typedef const typename Detail::FieldTypeToClassType::type>::type *type; }; } // namespace Detail } // namespace GenericMessages } // namespace Activ #endif // (!defined ACTIV_BASE_GENERIC_MESSAGES_DETAIL_FIELD_META_FUNCTIONS_H)