Support Forum       G3D Web Page     
Classes | Public Member Functions | List of all members
G3D::Pointer< ValueType > Class Template Reference

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

Classes

class  IndirectValue
 

Public Member Functions

 Pointer ()
 
 Pointer (ValueType *v)
 Allows implicit cast from real pointer. More...
 
 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 (std::function< ValueType(void)> getMethod)
 
 Pointer (std::function< ValueType(void)> getMethod, std::function< void(ValueType)> setMethod)
 
 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
 
bool isNull () const
 
IndirectValue operator* ()
 
IndirectValue operator* () const
 
Pointeroperator= (const Pointer &r)
 
void setValue (const ValueType &v) const
 Assign a value to the referenced element. More...
 

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()).

Referenced Code: McGuire, GUIs for Real-time Programs, using Universal Pointers, SIGGRAPH 2008 Poster.

Constructor & Destructor Documentation

◆ Pointer() [1/15]

template<typename ValueType>
G3D::Pointer< ValueType >::Pointer ( )
inline

◆ Pointer() [2/15]

template<typename ValueType>
G3D::Pointer< ValueType >::Pointer ( ValueType *  v)
inline

Allows implicit cast from real pointer.

◆ Pointer() [3/15]

template<typename ValueType>
G3D::Pointer< ValueType >::Pointer ( const Pointer< ValueType > &  p)
inline

◆ Pointer() [4/15]

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 nullptr

◆ Pointer() [5/15]

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 nullptr

◆ Pointer() [6/15]

template<typename ValueType>
G3D::Pointer< ValueType >::Pointer ( ValueType(*)()  getMethod,
void(*)(ValueType)  setMethod 
)
inline
Parameters
setMethodMay be nullptr

◆ Pointer() [7/15]

template<typename ValueType>
G3D::Pointer< ValueType >::Pointer ( std::function< ValueType(void)>  getMethod)
inline

◆ Pointer() [8/15]

template<typename ValueType>
G3D::Pointer< ValueType >::Pointer ( std::function< ValueType(void)>  getMethod,
std::function< void(ValueType)>  setMethod 
)
inline

◆ Pointer() [9/15]

template<typename ValueType>
G3D::Pointer< ValueType >::Pointer ( const ValueType &(*)()  getMethod,
void(*)(ValueType)  setMethod 
)
inline
Parameters
setMethodMay be nullptr

◆ Pointer() [10/15]

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 nullptr

◆ Pointer() [11/15]

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 nullptr

◆ Pointer() [12/15]

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 nullptr

◆ Pointer() [13/15]

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 nullptr

◆ Pointer() [14/15]

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 nullptr

◆ Pointer() [15/15]

template<typename ValueType>
template<class Class >
G3D::Pointer< ValueType >::Pointer ( Class *  object,
ValueType(Class::*)() const  getMethod,
void(Class::*)(ValueType)  setMethod 
)
inline
Parameters
setMethodMay be nullptr

◆ ~Pointer()

template<typename ValueType>
G3D::Pointer< ValueType >::~Pointer ( )
inline

Member Function Documentation

◆ getValue()

template<typename ValueType>
const ValueType G3D::Pointer< ValueType >::getValue ( ) const
inline

◆ isNull()

template<typename ValueType>
bool G3D::Pointer< ValueType >::isNull ( ) const
inline

Referenced by G3D::isNull(), and G3D::notNull().

◆ operator*() [1/2]

template<typename ValueType>
IndirectValue G3D::Pointer< ValueType >::operator* ( )
inline

◆ operator*() [2/2]

template<typename ValueType>
IndirectValue G3D::Pointer< ValueType >::operator* ( ) const
inline

◆ operator=()

template<typename ValueType>
Pointer& G3D::Pointer< ValueType >::operator= ( const Pointer< ValueType > &  r)
inline

◆ setValue()

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

Assign a value to the referenced element.

If this Pointer was initialized with a nullptr setMethod, the call is ignored

Referenced by G3D::Pointer< ValueType >::IndirectValue::operator=().


documentation generated on Wed Nov 24 2021 08:01:59 using doxygen 1.8.15