TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
G3D::Pointer< ValueType > Class Template Reference

#include <Pointer.h>

Classes

class  Accessor
 
class  FcnAccessor
 
class  IndirectValue
 
class  Interface
 
class  Memory
 
class  SharedAccessor
 

Public Member Functions

 Pointer ()
 
 Pointer (ValueType *v)
 
bool isNull () const
 
Pointeroperator= (const Pointer &r)
 
 Pointer (const Pointer &p)
 
template<class Class >
 Pointer (const shared_ptr< Class > &object, ValueType(Class::*getMethod)() const, void(Class::*setMethod)(ValueType))
 
template<class Class >
 Pointer (const shared_ptr< Class > &object, const ValueType &(Class::*getMethod)() const, void(Class::*setMethod)(ValueType))
 
 Pointer (ValueType(*getMethod)(), void(*setMethod)(ValueType))
 
 Pointer (const ValueType &(*getMethod)(), void(*setMethod)(ValueType))
 
template<class Class >
 Pointer (const shared_ptr< Class > &object, ValueType(Class::*getMethod)() const, void(Class::*setMethod)(const ValueType &))
 
template<class Class >
 Pointer (const shared_ptr< Class > &object, const ValueType &(Class::*getMethod)() const, void(Class::*setMethod)(const ValueType &))
 
template<class Class >
 Pointer (Class *object, const ValueType &(Class::*getMethod)() const, void(Class::*setMethod)(const ValueType &))
 
template<class Class >
 Pointer (Class *object, ValueType(Class::*getMethod)() const, void(Class::*setMethod)(const ValueType &))
 
template<class Class >
 Pointer (Class *object, const ValueType &(Class::*getMethod)() const, void(Class::*setMethod)(ValueType))
 
template<class Class >
 Pointer (Class *object, ValueType(Class::*getMethod)() const, void(Class::*setMethod)(ValueType))
 
 ~Pointer ()
 
const ValueType getValue () const
 
void setValue (const ValueType &v)
 Assign a value to the referenced element. If this Pointer was initialized with a NULL setMethod, the call is ignored. More...
 
IndirectValue operator* ()
 
const ValueType operator* () const
 

Private Attributes

Interfacem_interface
 

Detailed Description

template<typename ValueType>
class G3D::Pointer< ValueType >

Acts like a pointer to a value of type ValueType (i.e., ValueType*), but can operate through accessor methods as well as on a value in memory. This is useful for implementing scripting languages and other applications that need to connect existing APIs by reference.

Because the accessors require values to be passed by value (instead of by reference) this is primarily useful for objects whose memory size is small.

class Foo {
public:
void setEnabled(bool b);
bool getEnabled() const;
};
Foo f;
bool b;
Pointer<bool> p1(&b);
Pointer<bool> p2(&f, &Foo::getEnabled, &Foo::setEnabled);
*p1 = true;
*p2 = false;
*p2 = *p1; \/\/ Value assignment
p2 = p1; \/\/ Pointer aliasing
\/\/ Or, equivalently:
p1.setValue(true);
p2.setValue(false);
p2.setValue(p1.getValue());
p2 = p1;

Note: Because of the way that dereference is implemented, you cannot pass *p through a function that takes varargs (...), e.g., printf("%d", *p) will produce a compile-time error. Instead use printf("%d",(bool)*p) or printf("%d", p.getValue()).

[McGuire], GUIs for Real-time Programs, using Universal Pointers, SIGGRAPH 2008 Poster.

Constructor & Destructor Documentation

template<typename ValueType>
G3D::Pointer< ValueType >::Pointer ( )
inline
207 : m_interface(NULL) {};
arena_t NULL
Definition: jemalloc_internal.h:624
Interface * m_interface
Definition: Pointer.h:203
template<typename ValueType>
G3D::Pointer< ValueType >::Pointer ( ValueType *  v)
inline

Allows implicit cast from real pointer

210 : m_interface(new Memory(v)) {}
Interface * m_interface
Definition: Pointer.h:203
template<typename ValueType>
G3D::Pointer< ValueType >::Pointer ( const Pointer< ValueType > &  p)
inline
227  : m_interface(NULL) {
228  this[0] = p;
229  }
arena_t NULL
Definition: jemalloc_internal.h:624
Interface * m_interface
Definition: Pointer.h:203
template<typename ValueType>
template<class Class >
G3D::Pointer< ValueType >::Pointer ( const shared_ptr< Class > &  object,
ValueType(Class::*)() const  getMethod,
void(Class::*)(ValueType)  setMethod 
)
inline
Parameters
setMethodMay be NULL
236  :
237  m_interface(new SharedAccessor<Class, ValueType (Class::*)() const, void (Class::*)(ValueType)>(object, getMethod, setMethod)) {}
Interface * m_interface
Definition: Pointer.h:203
template<typename ValueType>
template<class Class >
G3D::Pointer< ValueType >::Pointer ( const shared_ptr< Class > &  object,
const ValueType &(Class::*)() const  getMethod,
void(Class::*)(ValueType)  setMethod 
)
inline
Parameters
setMethodMay be NULL
243  :
244  m_interface(new SharedAccessor<Class, const ValueType& (Class::*)() const, void (Class::*)(ValueType)>(object, getMethod, setMethod)) {}
Interface * m_interface
Definition: Pointer.h:203
template<typename ValueType>
G3D::Pointer< ValueType >::Pointer ( ValueType(*)()  getMethod,
void(*)(ValueType)  setMethod 
)
inline
Parameters
setMethodMay be NULL
249  :
250  m_interface(new FcnAccessor<ValueType (*)(), void (*)(ValueType)>(getMethod, setMethod)) {}
Interface * m_interface
Definition: Pointer.h:203
template<typename ValueType>
G3D::Pointer< ValueType >::Pointer ( const ValueType &(*)()  getMethod,
void(*)(ValueType)  setMethod 
)
inline
Parameters
setMethodMay be NULL
254  :
255  m_interface(new FcnAccessor<const ValueType& (*)(), void (*)(ValueType)>(getMethod, setMethod)) {}
Interface * m_interface
Definition: Pointer.h:203
template<typename ValueType>
template<class Class >
G3D::Pointer< ValueType >::Pointer ( const shared_ptr< Class > &  object,
ValueType(Class::*)() const  getMethod,
void(Class::*)(const ValueType &)  setMethod 
)
inline
Parameters
setMethodMay be NULL
262  :
263  m_interface(new SharedAccessor<Class, ValueType (Class::*)() const, void (Class::*)(const ValueType&)>(object, getMethod, setMethod)) {}
Interface * m_interface
Definition: Pointer.h:203
template<typename ValueType>
template<class Class >
G3D::Pointer< ValueType >::Pointer ( const shared_ptr< Class > &  object,
const ValueType &(Class::*)() const  getMethod,
void(Class::*)(const ValueType &)  setMethod 
)
inline
Parameters
setMethodMay be NULL
269  :
270  m_interface(new SharedAccessor<Class, const ValueType& (Class::*)() const, void (Class::*)(const ValueType&)>(object, getMethod, setMethod)) {}
Interface * m_interface
Definition: Pointer.h:203
template<typename ValueType>
template<class Class >
G3D::Pointer< ValueType >::Pointer ( Class *  object,
const ValueType &(Class::*)() const  getMethod,
void(Class::*)(const ValueType &)  setMethod 
)
inline
Parameters
setMethodMay be NULL
276  :
277  m_interface(new Accessor<Class, const ValueType& (Class::*)() const, void (Class::*)(const ValueType&)>(object, getMethod, setMethod)) {}
Interface * m_interface
Definition: Pointer.h:203
template<typename ValueType>
template<class Class >
G3D::Pointer< ValueType >::Pointer ( Class *  object,
ValueType(Class::*)() const  getMethod,
void(Class::*)(const ValueType &)  setMethod 
)
inline
Parameters
setMethodMay be NULL
283  :
284  m_interface(new Accessor<Class, ValueType (Class::*)() const, void (Class::*)(const ValueType&)>(object, getMethod, setMethod)) {}
Interface * m_interface
Definition: Pointer.h:203
template<typename ValueType>
template<class Class >
G3D::Pointer< ValueType >::Pointer ( Class *  object,
const ValueType &(Class::*)() const  getMethod,
void(Class::*)(ValueType)  setMethod 
)
inline
Parameters
setMethodMay be NULL
290  :
291  m_interface(new Accessor<Class, const ValueType& (Class::*)() const, void (Class::*)(ValueType)>(object, getMethod, setMethod)) {}
Interface * m_interface
Definition: Pointer.h:203
template<typename ValueType>
template<class Class >
G3D::Pointer< ValueType >::Pointer ( Class *  object,
ValueType(Class::*)() const  getMethod,
void(Class::*)(ValueType)  setMethod 
)
inline
Parameters
setMethodMay be NULL
297  :
298  m_interface(new Accessor<Class, ValueType (Class::*)() const, void (Class::*)(ValueType)>(object, getMethod, setMethod)) {}
Interface * m_interface
Definition: Pointer.h:203
template<typename ValueType>
G3D::Pointer< ValueType >::~Pointer ( )
inline
300  {
301  delete m_interface;
302  }
Interface * m_interface
Definition: Pointer.h:203

Member Function Documentation

template<typename ValueType>
const ValueType G3D::Pointer< ValueType >::getValue ( ) const
inline
304  {
306  return m_interface->get();
307  }
arena_t NULL
Definition: jemalloc_internal.h:624
virtual ValueType get() const =0
#define debugAssert(exp)
Definition: debugAssert.h:160
Interface * m_interface
Definition: Pointer.h:203

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename ValueType>
bool G3D::Pointer< ValueType >::isNull ( ) const
inline
212  {
213  return (m_interface == NULL) || m_interface->isNull();
214  }
arena_t NULL
Definition: jemalloc_internal.h:624
virtual bool isNull() const =0
Interface * m_interface
Definition: Pointer.h:203

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename ValueType>
IndirectValue G3D::Pointer< ValueType >::operator* ( )
inline
335  {
336  return IndirectValue(this);
337  }
template<typename ValueType>
const ValueType G3D::Pointer< ValueType >::operator* ( ) const
inline
339  {
340  return getValue();
341  }
const ValueType getValue() const
Definition: Pointer.h:304

+ Here is the call graph for this function:

template<typename ValueType>
Pointer& G3D::Pointer< ValueType >::operator= ( const Pointer< ValueType > &  r)
inline
217  {
218  delete m_interface;
219  if (r.m_interface != NULL) {
220  m_interface = r.m_interface->clone();
221  } else {
222  m_interface = NULL;
223  }
224  return this[0];
225  }
virtual Interface * clone() const =0
arena_t NULL
Definition: jemalloc_internal.h:624
Interface * m_interface
Definition: Pointer.h:203

+ Here is the call graph for this function:

template<typename ValueType>
void G3D::Pointer< ValueType >::setValue ( const ValueType &  v)
inline

Assign a value to the referenced element. If this Pointer was initialized with a NULL setMethod, the call is ignored.

311  {
313  m_interface->set(v);
314  }
arena_t NULL
Definition: jemalloc_internal.h:624
#define debugAssert(exp)
Definition: debugAssert.h:160
Interface * m_interface
Definition: Pointer.h:203
virtual void set(ValueType b)=0

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Member Data Documentation

template<typename ValueType>
Interface* G3D::Pointer< ValueType >::m_interface
private

The documentation for this class was generated from the following file: