14 #ifndef WIBBLE_AMORPH_H
15 #define WIBBLE_AMORPH_H
19 template<
typename _T >
29 template<
typename F,
typename R >
32 typename F::argument_type a )
39 template<
typename F >
41 inline Unit call(
typename F::argument_type a )
50 static const bool value =
false;
58 template<
typename T >
67 template<
typename F >
90 template<
typename Interface >
94 virtual void destroy(
unsigned int available = 0 ) = 0;
101 void *
operator new(
size_t bytes,
void *where,
unsigned available ) {
102 if ( bytes > available || where == 0 ) {
103 where = ::operator
new( bytes );
108 void *
operator new(
size_t bytes ) {
109 return ::operator
new( bytes );
113 template<
typename W,
typename Interface >
117 template<
typename _W >
122 template<
typename _W >
129 return virtualBase< W >();
140 template<
typename Self,
typename W,
typename Interface >
149 const Self &
self()
const {
return *
static_cast< const Self *
>( this ); }
157 const Morph *o =
dynamic_cast< const Morph *
>( _o );
159 if (
typeid(
Morph ).before(
typeid( _o ) ) )
168 void *where,
unsigned int available )
const
170 return new( where, available ) Self(
self() );
173 virtual void destroy(
unsigned int available ) {
174 if (
sizeof(
Morph ) <= available ) {
260 #ifndef WIBBLE_AMORPH_PADDING
261 #define WIBBLE_AMORPH_PADDING 0
265 int m_padding[ Padding1 ];
271 template<
typename Self,
typename _Interface,
int Padding = WIBBLE_AMORPH_PADDING >
295 const Self &
self()
const {
296 return *
static_cast< const Self *
>( this );
300 return *
static_cast<Self *
>( this );
303 bool leq(
const Self &i )
const {
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;
356 return rt::Just( func(*ptr) );
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 );
405 unsigned int reservedSize() {
return sizeof( m_padding ) +
sizeof( m_impl ); }
406 AmorphPadder<Padding> m_padding;
407 MorphInterface< Interface > *m_impl;
412 template<
typename T,
typename X >
413 typename X::template Convert<T>::type &
downcast(
const X &a )
415 return *a.template impl< T >();