14#ifndef WIBBLE_AMORPH_H
15#define WIBBLE_AMORPH_H
19template<
typename _T >
29template<
typename F,
typename R >
32 typename F::argument_type a )
41 inline Unit call(
typename F::argument_type a )
50 static const bool value =
false;
90template<
typename Interface >
103 where = ::operator
new(
bytes );
108 void *
operator new(
size_t bytes ) {
109 return ::operator
new(
bytes );
113template<
typename W,
typename Interface >
117 template<
typename _W >
122 template<
typename _W >
140template<
typename Self,
typename W,
typename Interface >
152 return wrapped().operator<=(
o.wrapped() );
159 if (
typeid(
Morph ).before(
typeid(
_o ) ) )
168 void *where,
unsigned int available )
const
260#ifndef WIBBLE_AMORPH_PADDING
261#define WIBBLE_AMORPH_PADDING 0
271template<
typename Self,
typename _Interface,
int Padding = WIBBLE_AMORPH_PADDING >
296 return *
static_cast< const Self *
>(
this );
300 return *
static_cast<Self *
>(
this );
305 if ( i.morphInterface() )
310 return !i.morphInterface();
327 &m_padding,
sizeof( m_padding ) );
337 m_impl = i->constructCopy( &m_padding,
sizeof( m_padding ) );
350 template<
typename F >
352 typedef typename F::argument_type T;
358 return rt::Nothing();
363 return static_cast< const Interface *
>( m_impl );
368 return static_cast< Interface *
>( m_impl );
384 template<
typename T >
391 template<
typename T >
393 T *
p =
dynamic_cast< T *
>( m_impl );
396 if (
m )
p = &(
m->wrapped());
405 unsigned int reservedSize() {
return sizeof( m_padding ) +
sizeof( m_impl ); }
406 AmorphPadder<Padding> m_padding;
407 MorphInterface< Interface > *m_impl;
412template<
typename T,
typename X >
X::template Convert< T >::type & downcast(const X &a)
Definition amorph.h:413
T type
Definition amorph.h:277
Amorph(const Amorph &a)
Definition amorph.h:288
Interface & wrapped()
Definition amorph.h:380
bool leq(const Self &i) const
Definition amorph.h:303
Interface * implementation()
Definition amorph.h:366
Maybe< typename F::result_type > ifType(F func)
Definition amorph.h:351
Amorph & operator=(const Amorph &i)
Definition amorph.h:340
~Amorph()
Definition amorph.h:345
const Interface * implementation() const
Definition amorph.h:361
Self & self()
Definition amorph.h:299
Amorph()
Definition amorph.h:293
MorphInterface< Interface > * morphInterface() const
Definition amorph.h:371
void setInterfacePointer(const Interface *i)
Definition amorph.h:316
bool isVoid() const
Definition amorph.h:389
bool operator<=(const Self &i) const
Definition amorph.h:314
T * impl() const
Definition amorph.h:392
const Self & self() const
Definition amorph.h:295
_Interface Interface
Definition amorph.h:273
void setMorphInterfacePointer(const MorphInterface< Interface > *i)
Definition amorph.h:332
Amorph(const MorphInterface< Interface > &b)
Definition amorph.h:284
bool is() const
Definition amorph.h:385
const Interface & wrapped() const
Definition amorph.h:376
static const bool value
Definition amorph.h:64
static const bool value
Definition amorph.h:50
custom allocator for morph classes
Definition amorph.h:100
W & wrapped()
Definition amorph.h:132
W m_wrapped
Definition amorph.h:137
EnableIf< TNot< IsPolymorphic< _W > >, VirtualBase * >::T virtualBase()
Definition amorph.h:124
MorphBase(const W &w)
Definition amorph.h:115
EnableIf< IsPolymorphic< _W >, VirtualBase * >::T virtualBase()
Definition amorph.h:118
virtual VirtualBase * virtualBase()
Definition amorph.h:128
An interface implemented by all morph classes.
Definition amorph.h:91
virtual MorphInterface * constructCopy(void *where=0, unsigned int available=0) const =0
virtual ~MorphInterface()
Definition amorph.h:95
virtual VirtualBase * virtualBase()
Definition amorph.h:92
virtual bool leq(const MorphInterface *) const =0
virtual void destroy(unsigned int available=0)=0
W Wrapped
Definition amorph.h:145
const Self & self() const
Definition amorph.h:149
Wrapped & wrapped()
Definition amorph.h:185
bool operator<=(const Morph &o) const
Definition amorph.h:151
virtual ~Morph()
Definition amorph.h:189
Morph(const Wrapped &w)
Definition amorph.h:147
const Wrapped & wrapped() const
Definition amorph.h:181
virtual MorphInterface< Interface > * constructCopy(void *where, unsigned int available) const
Definition amorph.h:167
virtual bool leq(const MorphInterface< Interface > *_o) const
Definition amorph.h:156
virtual void destroy(unsigned int available)
Definition amorph.h:173
Unit T
Definition amorph.h:26
_T T
Definition amorph.h:21
ReturnType< typenameF::result_type >::T result_type
Definition amorph.h:70
result_type operator()(typename F::argument_type a)
Definition amorph.h:72
SanitizeResultType(F _f)
Definition amorph.h:69
F f
Definition amorph.h:77
Unit call(typename F::argument_type a)
Definition amorph.h:41
ReturnType< R >::T call(typename F::argument_type a)
Definition amorph.h:31
virtual ~VirtualBase()
Definition amorph.h:84