The Vish Visualization Shell 0.3
Vish
Public Types | Public Member Functions | Static Public Member Functions | List of all members
MemCore::interface_cast< InterfaceType > Class Template Reference

Interface cast: Given an Intercube, retrive the an interface object which is stored there. More...

#include <elementary/memcore/Interface.hpp>

Public Types

typedef InterfaceType::InterfaceDomain_t InterfaceDomain_t
 The domain type, i.e.
 

Public Member Functions

 interface_cast (const Intercube &IC)
 Construct a temporary interface_cast<> object.
 
template<class IntercubeType >
 interface_cast (const WeakPtr< IntercubeType > &IT)
 Construct an interface_cast<> object from a pointer to some arbitrary class which is convertible to an Intercube.
 
 operator RefPtr< InterfaceType > () const
 Conversion operator to reference pointer of interface implementation.
 
InterfaceType & operator() () const
 Provide an interface object for the requested type, returning an existing one or creating a new one.
 
template<class ... InitType>
InterfaceType & operator() (InitType... args) const
 Provide an interface object for the requested type, returning an existing one or creating a new one with the given parameter as constructor argument.
 

Static Public Member Functions

static RefPtr< InterfaceType > findInterface (const Intercube &IC)
 Static member function alternative.
 

Detailed Description

template<class InterfaceType>
class MemCore::interface_cast< InterfaceType >

Interface cast: Given an Intercube, retrive the an interface object which is stored there.

Example:

struct myInterface : Interface<int>
{
int i;
};
int InterfaceExample()
{
Intercube Alpha;
Alpha.addInterface( new myInterface() );
RefPtr<myInterface> m = Alpha.getInterface( typeid(int) );
return 0;
}
A container that holds many Interfaces.
Definition Interface.hpp:151
void addInterface(const RefPtr< InterfaceBase > &I) const
Add an interface class object.
Definition Interface.cpp:97
RefPtr< InterfaceBase > getInterface(const type_info &t)
Retrieve an interface object from a certain type.
Definition Interface.cpp:151
Interface template.
Definition Interface.hpp:74
A reference counting pointer class which keeps objects alive as long as strong pointers to these obje...
Definition RefPtr.hpp:405
Interface cast: Given an Intercube, retrive the an interface object which is stored there.
Definition Interface.hpp:471
Definition InterfaceExample.cpp:15
Note
interface_cast<> is implemented via an temporary C++ object. Make sure that the lifetime of this object is shorted than the Intercube object for which it is used, otherwise an invalid reference is used. This should be quite safe if never an object of type interface_cast<> is created explicitly.

Member Typedef Documentation

◆ InterfaceDomain_t

template<class InterfaceType >
typedef InterfaceType::InterfaceDomain_t MemCore::interface_cast< InterfaceType >::InterfaceDomain_t

The domain type, i.e.

a possible base class of the given interface type, which is used to look up a certain interface. The returned interface may be an implementation of the InterfaceDomain_t.

Member Function Documentation

◆ operator()() [1/2]

template<class InterfaceType >
InterfaceType & MemCore::interface_cast< InterfaceType >::operator() ( ) const
inline

Provide an interface object for the requested type, returning an existing one or creating a new one.

struct X : Interface<X> {};
X&z = interface_cast<X>(I)();
Definition OmegaPtrCheck.cpp:14
Warning
The Intercube object may be modified hereby!

References MemCore::Intercube::findInterface().

◆ operator()() [2/2]

template<class InterfaceType >
template<class ... InitType>
InterfaceType & MemCore::interface_cast< InterfaceType >::operator() ( InitType...  args) const
inline

Provide an interface object for the requested type, returning an existing one or creating a new one with the given parameter as constructor argument.

struct X : Interface<X> { X(int) {} };
Intercube I;
RefPtr<X> z = interface_cast<X>(I)(42);
Warning
The Intercube object may be modified hereby!

References MemCore::Intercube::findInterface().