#include <baseref.h>
This is a general template for references of any kind. The characteristic feature of it is that special actions are triggered whenever the reference is set, cleared, changed or destructed. For example, a reference to a reference-counted object has to increase the reference count of the pointee when the pointer is set, and to decrease the count when the reference is cleared. Another example of reference is a unique reference which simply frees the pointee when it is cleared or destructed.
BaseRef delegates the specific behaviour to static members of the template parameter HANDLER. There are several implementations available to be used as HANDLER:
So if you want to have a reference to an object of type MyType with reference counting and copy-on-write semantics, you could use BaseRef<const MyType, StrongCOWRefHandler> which is equivalent to StrongCOWRef<MyType>.
T | Type of the referenced object. |
HANDLER | Base class for BaseRef. This implements the specific behaviour whenever a reference is changed to point to another object, see above. |
Public Types | |
using | ReferencedType = T |
using | ConstReferencedType = typename ConstIf< T, Bool(HANDLER::KIND &VALUEKIND::DEEP_CONSTNESS)>::type |
using | DirectlyReferencedType = T |
using | SelfType = BaseRef< T, HANDLER > |
template<typename D > | |
using | IsGenericBaseOf = std::true_type |
using | Handler = HANDLER |
using | RefCompareType = RefCompare< MAXON_IS_COW_KIND(HANDLER::KIND), IsInterfaceType< T >::value > |
Public Member Functions | |
T * | GetPointer () |
ConstReferencedType * | GetPointer () const |
T * | operator-> () |
ConstReferencedType * | operator-> () const |
std::conditional< std::is_void< T >::value, DeleteReturnType01, T >::type & | operator* () |
std::conditional< std::is_void< ConstReferencedType >::value, DeleteReturnType01, T >::type & | operator* () const |
operator T* () | |
operator ConstReferencedType * () const | |
operator Bool () const | |
operator Bool () | |
const std::conditional< std::is_void< T >::value, DeleteReturnType01, T >::type & | operator[] (Int) const =delete |
ResultRef< typename std::remove_const< T >::type > | MakeWritable (Bool resetOnError=true) |
ResultRef< typename std::remove_const< T >::type > | MakeWritableDontCopy () |
Bool | HasMultipleReferences () const |
std::conditional< std::is_void< T >::value, DeleteReturnType01, T >::type & | GetOrDefault () const |
BaseRef () | |
MAXON_IMPLICIT | BaseRef (std::nullptr_t)=delete |
MAXON_IMPLICIT | BaseRef (T *o) |
template<typename PTR > | |
BaseRef (ForwardResultPtr< PTR > o) | |
BaseRef (ResultPtr< T > o, Int) | |
BaseRef (const BaseRef &src) | |
template<typename REF , typename = typename std::enable_if<!STD_IS_REPLACEMENT(base_of, BaseRef, REF) && maxon::HasErasedBase<typename REF::ReferencedType, ReferencedType>::value>::type> | |
MAXON_IMPLICIT | BaseRef (const REF &src) |
template<typename REF , typename = typename std::enable_if<!STD_IS_REPLACEMENT(base_of, BaseRef, REF) && maxon::HasErasedBase<typename REF::ReferencedType, ReferencedType>::value>::type> | |
MAXON_IMPLICIT | BaseRef (REF &src) |
BaseRef & | operator= (T *src) |
BaseRef & | operator= (std::nullptr_t src) |
BaseRef & | operator= (const BaseRef &src) |
template<typename REF , typename = typename std::enable_if<!STD_IS_REPLACEMENT(base_of, BaseRef, REF) && maxon::HasErasedBase<typename REF::ReferencedType, ReferencedType>::value>::type> | |
BaseRef & | operator= (const REF &src) |
template<typename REF , typename = typename std::enable_if<!STD_IS_REPLACEMENT(base_of, BaseRef, REF) && maxon::HasErasedBase<typename REF::ReferencedType, ReferencedType>::value>::type> | |
BaseRef & | operator= (REF &src) |
BaseRef (BaseRef &&src) | |
template<typename REF , typename = typename std::enable_if<!STD_IS_REPLACEMENT(const, REF) && !STD_IS_REPLACEMENT(base_of, BaseRef, REF) && maxon::HasErasedBase<typename REF::ReferencedType, ReferencedType>::value>::type> | |
MAXON_IMPLICIT | BaseRef (REF &&src) |
BaseRef & | operator= (BaseRef &&src) |
template<typename REF , typename = typename std::enable_if<!STD_IS_REPLACEMENT(const, REF) && !STD_IS_REPLACEMENT(base_of, BaseRef, REF) && maxon::HasErasedBase<typename REF::ReferencedType, ReferencedType>::value>::type> | |
BaseRef & | operator= (REF &&src) |
~BaseRef () | |
Bool | operator== (const BaseRef &b) const |
Bool | operator!= (const BaseRef &b) const |
Bool | operator< (const BaseRef &b) const |
MAXON_OPERATOR_INEQUALITY (BaseRef) | |
Bool | operator== (const T *b) const |
Bool | operator!= (const T *b) const |
Bool | operator== (typename std::remove_const< T >::type *b) const |
Bool | operator!= (typename std::remove_const< T >::type *b) const |
Bool | operator== (std::nullptr_t) const |
Bool | operator!= (std::nullptr_t) const |
HashInt | GetHashCode () const |
UniqueHash | GetUniqueHashCode () const |
std::conditional< Bool(HANDLER::KIND &VALUEKIND::COW_MASK), typename std::remove_const< T >::type, T >::type * | Disconnect () |
void | PrivateSetTarget (ResultPtr< T > src) |
void | PrivateSetPointer (T *ptr) |
Static Public Member Functions | |
static void | PrivateLookupFn () |
static std::false_type | GenericVarianceCheck (const void *) |
template<typename... ARGS> | |
static MAXON_ATTRIBUTE_FORCE_INLINE ResultMemT< BaseRef > | Create (ARGS &&... args) |
static const BaseRef & | DefaultValueRef () |
static std::conditional< Bool(HANDLER::KIND &VALUEKIND::UNIQUE_REFERENCE), BaseRef, const BaseRef & >::type | DefaultValue () |
Static Public Attributes | |
static constexpr Bool | DIRECT_REF |
Protected Attributes | |
union { | |
T * _object | |
const void * _impl | |
}; | |
Private Member Functions | |
void | operator+ (Int) const |
void | operator- (Int) const |
void | operator- (const BaseRef &) const |
Static Private Member Functions | |
static const BaseRef & | PrivateDefaultValue (std::false_type *) |
static BaseRef | PrivateDefaultValue (std::true_type *) |
Friends | |
template<typename , typename > | |
class | BaseRef |
using ReferencedType = T |
A type alias for the type the BaseRef points to.
using ConstReferencedType = typename ConstIf<T, Bool(HANDLER::KIND & VALUEKIND::DEEP_CONSTNESS)>::type |
using DirectlyReferencedType = T |
using IsGenericBaseOf = std::true_type |
using Handler = HANDLER |
using RefCompareType = RefCompare<MAXON_IS_COW_KIND(HANDLER::KIND), IsInterfaceType<T>::value> |
BaseRef | ( | ) |
|
delete |
MAXON_IMPLICIT BaseRef | ( | T * | o | ) |
|
explicit |
MAXON_IMPLICIT BaseRef | ( | const REF & | src | ) |
MAXON_IMPLICIT BaseRef | ( | REF & | src | ) |
MAXON_IMPLICIT BaseRef | ( | REF && | src | ) |
|
static |
|
static |
T* GetPointer | ( | ) |
ConstReferencedType* GetPointer | ( | ) | const |
T* operator-> | ( | ) |
Allows direct access to the members of the pointee. You have to check for a nullptr before.
ConstReferencedType* operator-> | ( | ) | const |
Allows direct access to the members of the pointee. You have to check for a nullptr before.
Dereferences the BaseRef. This yields the pointee as a reference. You have to check for a nullptr before.
std::conditional<std::is_void<ConstReferencedType>::value, DeleteReturnType01, T>::type& operator* | ( | ) | const |
Dereferences the BaseRef. This yields the pointee as a reference. You have to check for a nullptr before.
operator T* | ( | ) |
User-defined conversion to T*, unpacking the internal pointer.
operator ConstReferencedType * | ( | ) | const |
User-defined conversion to T*, unpacking the internal pointer.
|
explicit |
Checks if the pointer is valid (i.e., not a nullptr).
|
explicit |
|
delete |
Superscript operator is not available.
Makes the pointee writable. Depending on the argument for the template parameter HANDLER, this may just return the original pointer, or it may replace the pointer by a new one pointing to a copy of the original pointee, and return the new pointer. The latter is the case for copy-on-write semantics if there is more than one reference to the pointee.
[in] | resetOnError | If true (the default), the reference will be reset when the copy fails. If false, the reference will stay the same, but the function returns nullptr. |
Makes the pointee writable. Depending on the argument for the template parameter HANDLER, this may just return the original pointer, or it may replace the pointer by a new one and return the new pointer. The latter is the case for copy-on-write semantics if there is more than one reference to the pointee. Unlike MakeWritable this function doesn't copy the contents of the original pointee if a new object is created. This is useful when you overwrite the content in the sequel anyway.
Bool HasMultipleReferences | ( | ) | const |
Returns whether the referenced object has more than this single reference. For a null reference it will return false. For an object with one strong reference it will return false. For an object with a single strong reference and weak references it will return true. For an object with two strong references it will return true.
|
static |
Creates the referenced type.
[in] | args | Arguments for the construcor. |
ARGS | Parameter types. |
BaseRef& operator= | ( | T * | src | ) |
Lets the BaseRef point to another object. This performs the necessary operations for removing the reference to the current pointee and adding the reference to the new pointee.
[in] | src | New pointer, may be nullptr. |
BaseRef& operator= | ( | std::nullptr_t | src | ) |
Resets the internal pointer to nullptr, which includes the proper release of the reference.
BaseRef& operator= | ( | const REF & | src | ) |
Lets the BaseRef point to the object of another reference object. This performs the necessary operations for removing the reference to the current pointee and adding the reference to the new pointee.
[in] | src | Another reference of which the pointer will be used. |
BaseRef& operator= | ( | REF & | src | ) |
BaseRef& operator= | ( | REF && | src | ) |
Returns true when this and b are equal as determined by RefCompare.
[in] | b | Reference to compare with. |
Returns true when this and b are not equal as determined by RefCompare.
[in] | b | Reference to compare with. |
Returns true when this is less than b as determined by RefCompare.
[in] | b | Reference to compare with. |
MAXON_OPERATOR_INEQUALITY | ( | BaseRef< T, HANDLER > | ) |
Bool operator== | ( | const T * | b | ) | const |
Returns true when this and b are equal as determined by RefCompare.
[in] | b | Pointer to compare with. |
Bool operator!= | ( | const T * | b | ) | const |
Returns true when this and b are not equal as determined by RefCompare.
[in] | b | Reference to compare with. |
Returns true when this and b are equal as determined by RefCompare.
[in] | b | Pointer to compare with. |
Returns true when this and b are not equal as determined by RefCompare.
[in] | b | Reference to compare with. |
Bool operator== | ( | std::nullptr_t | ) | const |
Returns true when this and a null reference are equal as determined by RefCompare.
Bool operator!= | ( | std::nullptr_t | ) | const |
Returns true when this and a null reference are not equal as determined by RefCompare.
HashInt GetHashCode | ( | ) | const |
Returns the hash code of the reference. For COW references this is the hash code of the referenced object, otherwise it's the hash code of the pointer.
UniqueHash GetUniqueHashCode | ( | ) | const |
Returns the hash value of the reference. For COW references this is the hash value of the referenced object, otherwise it's the hash value of the pointer.
|
static |
|
static |
std::conditional<Bool(HANDLER::KIND & VALUEKIND::COW_MASK), typename std::remove_const<T>::type, T>::type* Disconnect | ( | ) |
Sets the internal pointer to nullptr and returns its previous value. This moves the ownership of the object from this BaseRef to the invoking code, so you have to take care of proper deallocation once the object isn't needed any longer.
If this BaseRef is a strong reference, the reference count must be exactly 1 before the call, otherwise a nullptr will be returned.
void PrivateSetTarget | ( | ResultPtr< T > | src | ) |
Lets the BaseRef point to another freshly allocated object. This performs the necessary operations for removing the reference to the current pointee and adding the reference to the new pointee.
[in] | src | New pointer, may be nullptr. |
void PrivateSetPointer | ( | T * | ptr | ) |
|
private |
|
private |
|
private |
|
staticprivate |
|
staticprivate |
|
friend |
|
staticconstexpr |
T* _object |
const void* _impl |
union { ... } |