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...
|
| 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 |
|
Pointer & | operator= (const Pointer &r) |
|
void | setValue (const ValueType &v) const |
| Assign a value to the referenced element. More...
|
|
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
\/\/ 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.