VisualIB  1.0
IBExpress library for making use of Borland IBExpress outside of C++Builder
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros
VIB::Property< T > Class Template Reference

Property implements Borland Delphi-style properties using standard C++11 mechanisms. More...

#include <VIBProperties.h>

Inheritance diagram for VIB::Property< T >:
VIB::ArrayProperty< T, A >

Public Member Functions

 Property ()
 Default constructor, you must initialize get and set later.
 
 Property (const Getter &pGet, const Setter &pSet)
 Full constructor.
 
void initCallbacks (const Getter &pGet, const Setter &pSet)
 Late-initialize the callbacks, or change their values at runtime.
 
 operator T ()
 Cast operator, invokes get() and returns its value.
 
Property< T > & operator= (const T &nv)
 Assignment operator, invokes set with the provided value, returns this object.
 
operator-> ()
 Invokes get, assuming it returns a pointer that can be used with the deref-access arrow operator.
 

Protected Types

typedef std::function< T(void)> Getter
 The type of a Property Getter method.
 
typedef std::function< void(const
T &)> 
Setter
 The type of a Property Setter method.
 

Protected Attributes

Getter get
 The getter method; typically, a this-capturing lambda function.
 
Setter set
 The setter method; typically, a this-capturing lambda function.
 

Detailed Description

template<typename T>
class VIB::Property< T >

Property implements Borland Delphi-style properties using standard C++11 mechanisms.

Implementation of proper message forwarding to the parent object of the property is accomplished through use of lambda functions as get/set callbacks, which capture the "this" pointer by reference during their construction. Both callbacks are optional; leaving one unimplemented will cause a std::exception to be thrown if a call is attempted. This can be used to create read-only or even write-only properties.

Template Parameters
TBasic type or structure/class type to wrap.

Constructor & Destructor Documentation

template<typename T>
VIB::Property< T >::Property ( )
inline

Default constructor, you must initialize get and set later.

Typical use case.

template<typename T>
VIB::Property< T >::Property ( const Getter pGet,
const Setter pSet 
)
inline

Full constructor.

Provide get and set callbacks at instantiation.

Parameters
[in]pGetPointer to a T (void) getter function; typically, a this-capturing lambda.
[in]pSetPointer to a void (const T &) setter function; typically, a this-capturing lambda.

Member Function Documentation

template<typename T>
void VIB::Property< T >::initCallbacks ( const Getter pGet,
const Setter pSet 
)
inline

Late-initialize the callbacks, or change their values at runtime.

Parameters
[in]pGetPointer to a T (void) getter function; typically, a this-capturing lambda.
[in]pSetPointer to a void (const T &) setter function; typically, a this-capturing lambda.
template<typename T>
VIB::Property< T >::operator T ( )
inline

Cast operator, invokes get() and returns its value.

Allows treating an instance of Property like an rvalue of its underlying type in most contexts.

Returns
Value returned by the getter callback function.
template<typename T>
T VIB::Property< T >::operator-> ( )
inline

Invokes get, assuming it returns a pointer that can be used with the deref-access arrow operator.

If not, you will cause a compile-time error by trying to use it.

Returns
Value returned by the getter callback function. Ensure that the underlying type is a pointer when using this.
template<typename T>
Property<T>& VIB::Property< T >::operator= ( const T &  nv)
inline

Assignment operator, invokes set with the provided value, returns this object.

Parameters
[in]nvNew value of the underlying type to assign to the property via the setter callback function.
Returns
Reference to the Property instance. Allows use in consecutive assignment expressions with the expected normal language semantics.

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