Base Framework
Public Member Functions | List of all members
Indirect< TYPE > Class Template Reference

Automation pointer for direct values. More...

#include <base/mem/Indirect.h>

Public Member Functions

 Indirect () noexcept
 
 Indirect (const TYPE &_value)
 
 Indirect (const Indirect &copy)
 
template<class POLY >
Indirect< POLY > cast ()
 
Indirectoperator= (const Indirect &assign)
 
template<class POLY >
Indirectoperator= (const Indirect< POLY > &assign) noexcept
 
bool isValid () const noexcept
 
bool operator== (const Indirect &compare) const noexcept
 
bool operator!= (const Indirect &compare) const noexcept
 
template<class POLY >
bool isType () const noexcept
 
const TYPE & getValue () const
 
template<class POLY >
POLY getValue () const
 
TYPE * operator-> ()
 
const TYPE * operator-> () const
 
 operator bool () const noexcept
 
unsigned long getHash () const noexcept
 
 ~Indirect ()
 

Detailed Description

template<class TYPE>
class Indirect< TYPE >

Automation pointer for direct values.

Automation pointer which provides polymorphic behavior for non-polymorphic objects (direct objects). This is accomplished by copying the object to the heap using the default copy constructor and referencing the object through a pointer. This automation pointer is intended for objects such as Socket which use internal reference counting and thus normally are accessed through their value and not through some pointer. The Indirect automation pointer is relocateable. Accessing the object through this automation object results in an overhead because an additional pointer must be dereferenced. However, the overhead can be avoided by doing a dynamic cast and then copying the "new" object onto the stack. This automation pointer only makes sense if the type in question is itself some pointer.

class MyClass : public Object {
private:
Array<Indirect> sockets;
public:
void add(Indirect<Socket> socket) {
sockets.append(socket);
}
void add(ServerSocket socket) {
sockets.append(socket);
}
void add(StreamSocket socket) {
sockets.append(socket);
}
void add(Socket socket) {
sockets.append(socket);
}
};
See also
Reference
Version
1.0

Constructor & Destructor Documentation

◆ Indirect() [1/3]

template<class TYPE >
Indirect< TYPE >::Indirect ( )
inlinenoexcept

Initializes an automation pointer as invalid (i.e. nullptr).

◆ Indirect() [2/3]

template<class TYPE >
Indirect< TYPE >::Indirect ( const TYPE &  _value)
inline

Initializes reference with the specified pointer value. The automation pointer may be implicitly initialized.

Parameters
valueThe desired pointer value.

◆ Indirect() [3/3]

template<class TYPE >
Indirect< TYPE >::Indirect ( const Indirect< TYPE > &  copy)
inline

Initialization of automation pointer by automation pointer.

◆ ~Indirect()

template<class TYPE >
Indirect< TYPE >::~Indirect ( )
inline

Destroys the automation pointer.

Member Function Documentation

◆ cast()

template<class TYPE >
template<class POLY >
Indirect<POLY> Indirect< TYPE >::cast ( )
inline

Dynamic cast to the specified type.

Returns
nullptr if cast is not possible.

◆ getHash()

template<class TYPE >
unsigned long Indirect< TYPE >::getHash ( ) const
inlinenoexcept

Returns the hash value of the pointer.

◆ getValue() [1/2]

template<class TYPE >
const TYPE& Indirect< TYPE >::getValue ( ) const
inline

Returns the value.

◆ getValue() [2/2]

template<class TYPE >
template<class POLY >
POLY Indirect< TYPE >::getValue ( ) const
inline

Casts the object to the specified object type. Raises CastException if the cast failed.

◆ isType()

template<class TYPE >
template<class POLY >
bool Indirect< TYPE >::isType ( ) const
inlinenoexcept

Returns true if the object may be cast to the specified type.

◆ isValid()

template<class TYPE >
bool Indirect< TYPE >::isValid ( ) const
inlinenoexcept

Returns true if the automation pointer is valid (i.e. it is pointing to an object).

◆ operator bool()

template<class TYPE >
Indirect< TYPE >::operator bool ( ) const
inlinenoexcept

Returns true if the automation pointer is valid.

◆ operator!=()

template<class TYPE >
bool Indirect< TYPE >::operator!= ( const Indirect< TYPE > &  compare) const
inlinenoexcept

Returns true if the references are non-equal.

◆ operator->() [1/2]

template<class TYPE >
TYPE* Indirect< TYPE >::operator-> ( )
inline

Dereferences the automation pointer.

◆ operator->() [2/2]

template<class TYPE >
const TYPE* Indirect< TYPE >::operator-> ( ) const
inline

Dereferences the automation pointer.

◆ operator=() [1/2]

template<class TYPE >
Indirect& Indirect< TYPE >::operator= ( const Indirect< TYPE > &  assign)
inline

Initialization of automation pointer from other automation pointer using compile time polymorphism. Assignment of automation pointer by automation pointer.

◆ operator=() [2/2]

template<class TYPE >
template<class POLY >
Indirect& Indirect< TYPE >::operator= ( const Indirect< POLY > &  assign)
inlinenoexcept

Assignment of automation pointer by automation pointer using compile time polymorphism.

◆ operator==()

template<class TYPE >
bool Indirect< TYPE >::operator== ( const Indirect< TYPE > &  compare) const
inlinenoexcept

Returns true if the references are equal.

StreamSocket
Stream socket.
Definition: StreamSocket.h:33
Array::append
void append(const Value &value)
Definition: Array.h:499
Object
Object.
Definition: Object.h:28
ServerSocket
Server socket.
Definition: ServerSocket.h:30
Socket
Socket.
Definition: Socket.h:44
Indirect
Automation pointer for direct values.
Definition: Indirect.h:68
Array
Array collection.
Definition: Array.h:40