Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

Class template generic_parameter

boost::reflections::generic_parameter — A container for a single item - similar to boost::any.

Synopsis

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 *) ;
};

Description

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 construct/copy/destruct

  1. generic_parameter(void * value);
  2. ~generic_parameter();

    The destructor cleans up the converters contained in this generic_parameter.

generic_parameter public member functions

  1. TypeInfo type() const;

    Return the TypeInfo for the primary type of this generic_parameter.

  2. 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.

  3. 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.

  4. template<typename T> void cast(T * dest) ;

    Identical to T cast(), but takes a pointer to T instead.


PrevUpHomeNext