![]() |
Home | Libraries | People | FAQ | More |
boost::reflections::generic_parameter — A container for a single item - similar to boost::any.
template<typename TypeInfo = extensions::default_type_info> class generic_parameter { public: // types typedef void(* FunctionPtr; class basic_converter { public: // construct/copy/destruct ~basic_converter(); // public member functions void convert(void *, void *) const; }; // construct/copy/destruct generic_parameter(void *); ~generic_parameter(); // public member functions TypeInfo type() const; template<typename T> bool can_cast() const; template<typename T> T cast() const; template<typename T> void cast(T *) ; };
The primary difference between generic_parameter and boost::any is that a generic_parameter can be declared to be convertible to arbitrary types, in addition to the base type that it holds. This allows an object to also be accessible through pointers to its base types, for example.
generic_parameter public member functionsTypeInfo type() const;
Return the TypeInfo for the primary type of this generic_parameter.
template<typename T> bool can_cast() const;
Given a type T, this function returns true if the generic_parameter can convert its value to T.
| Returns: | true if the conversion is possible. |
template<typename T> T cast() const;
This will attempt to convert the generic_parameter to type T. If it fails, it will throw an exception. To avoid the exception, the can_cast function can be called first.
| Requires: | can_cast<T>() == true |
| Postconditions: | None. |
| Returns: | A value of T that was converted from the generic_parameter. |
template<typename T> void cast(T * dest) ;
Identical to T cast(), but takes a pointer to T instead.