MacStd
OS X API using Standard C++
Loading...
Searching...
No Matches
macstd::handle< T, INVAL > Class Template Referenceabstract

Base abstract template class to support generic object handle keeping. More...

#include <MacStd/common.hpp>

Inheritance diagram for macstd::handle< T, INVAL >:
macstd::dplhandle< T, INVAL >

Public Member Functions

 handle () noexcept
 Initializes a new class instance with the object handle set to INVAL.
 
 handle (T h) noexcept
 Initializes a new class instance with an already available object handle.
 
 handle (handle< T, INVAL > &&h) noexcept
 Move constructor.
 
handle< T, INVAL > & operator= (T h) noexcept
 Attaches already available object handle.
 
handle< T, INVAL > & operator= (handle< T, INVAL > &&h) noexcept
 Move assignment.
 
 operator T () const
 Auto-typecasting operator.
 
T *& operator* () const
 Returns the object handle value when the object handle is a pointer to a value (class, struct, etc.).
 
T * operator& ()
 Returns the object handle reference.
 
operator-> () const
 Provides object handle member access when the object handle is a pointer to a class or struct.
 
bool operator! () const
 Tests if the object handle is invalid.
 
bool operator< (T h) const
 Is handle less than?
 
bool operator<= (T h) const
 Is handle less than or equal to?
 
bool operator>= (T h) const
 Is handle greater than or equal to?
 
bool operator> (T h) const
 Is handle greater than?
 
bool operator!= (T h) const
 Is handle not equal to?
 
bool operator== (T h) const
 Is handle equal to?
 
void attach (T h) noexcept
 Sets a new object handle for the class.
 
detach ()
 Dismisses the object handle from this class.
 
void free ()
 Destroys the object.
 

Protected Member Functions

virtual void free_internal () noexcept=0
 Abstract member function that must be implemented by child classes to do the actual object destruction.
 

Protected Attributes

m_h
 Object handle.
 

Detailed Description

template<class T, const T INVAL>
class macstd::handle< T, INVAL >

Base abstract template class to support generic object handle keeping.

It provides basic operators and methods common to all descendands of this class establishing a base to ease the replacement of native object handle type with classes in object-oriented approach.

Constructor & Destructor Documentation

◆ handle() [1/2]

template<class T , const T INVAL>
macstd::handle< T, INVAL >::handle ( T h)
inlinenoexcept

Initializes a new class instance with an already available object handle.

Parameters
[in]hInitial object handle value

◆ handle() [2/2]

template<class T , const T INVAL>
macstd::handle< T, INVAL >::handle ( handle< T, INVAL > && h)
inlinenoexcept

Move constructor.

Parameters
[in,out]hA rvalue reference of another object

Member Function Documentation

◆ attach()

template<class T , const T INVAL>
void macstd::handle< T, INVAL >::attach ( T h)
inlinenoexcept

Sets a new object handle for the class.

When the current object handle of the class is non-INVAL, the object is destroyed first.

Parameters
[in]hNew object handle

◆ detach()

template<class T , const T INVAL>
T macstd::handle< T, INVAL >::detach ( )
inline

Dismisses the object handle from this class.

Returns
Object handle

◆ free_internal()

template<class T , const T INVAL>
virtual void macstd::handle< T, INVAL >::free_internal ( )
protectedpure virtualnoexcept

Abstract member function that must be implemented by child classes to do the actual object destruction.

Implemented in macstd::io_object< T >.

◆ operator T()

template<class T , const T INVAL>
macstd::handle< T, INVAL >::operator T ( ) const
inline

Auto-typecasting operator.

Returns
Object handle

◆ operator!()

template<class T , const T INVAL>
bool macstd::handle< T, INVAL >::operator! ( ) const
inline

Tests if the object handle is invalid.

Returns
  • Non zero when object handle is invalid;
  • Zero otherwise.
Note
Implementing operator bool() const would be correct C++ approach here. Unfortunately, it would produce ambiguities where bool and T are polymorphed. Use !! to test if the object handle is valid.

◆ operator!=()

template<class T , const T INVAL>
bool macstd::handle< T, INVAL >::operator!= ( T h) const
inline

Is handle not equal to?

Parameters
[in]hObject handle to compare against
Returns
  • Non zero when object handle is not equal to h;
  • Zero otherwise.

◆ operator&()

template<class T , const T INVAL>
T * macstd::handle< T, INVAL >::operator& ( )
inline

Returns the object handle reference.

Returns
Object handle reference

◆ operator*()

template<class T , const T INVAL>
T *& macstd::handle< T, INVAL >::operator* ( ) const
inline

Returns the object handle value when the object handle is a pointer to a value (class, struct, etc.).

Returns
Object handle value

◆ operator->()

template<class T , const T INVAL>
T macstd::handle< T, INVAL >::operator-> ( ) const
inline

Provides object handle member access when the object handle is a pointer to a class or struct.

Returns
Object handle

◆ operator<()

template<class T , const T INVAL>
bool macstd::handle< T, INVAL >::operator< ( T h) const
inline

Is handle less than?

Parameters
[in]hObject handle to compare against
Returns
  • Non zero when object handle is less than h;
  • Zero otherwise.

◆ operator<=()

template<class T , const T INVAL>
bool macstd::handle< T, INVAL >::operator<= ( T h) const
inline

Is handle less than or equal to?

Parameters
[in]hObject handle to compare against
Returns
  • Non zero when object handle is less than or equal to h;
  • Zero otherwise.

◆ operator=() [1/2]

template<class T , const T INVAL>
handle< T, INVAL > & macstd::handle< T, INVAL >::operator= ( handle< T, INVAL > && h)
inlinenoexcept

Move assignment.

Parameters
[in,out]hA rvalue reference of another object

◆ operator=() [2/2]

template<class T , const T INVAL>
handle< T, INVAL > & macstd::handle< T, INVAL >::operator= ( T h)
inlinenoexcept

Attaches already available object handle.

Parameters
[in]hObject handle value

◆ operator==()

template<class T , const T INVAL>
bool macstd::handle< T, INVAL >::operator== ( T h) const
inline

Is handle equal to?

Parameters
[in]hObject handle to compare against
Returns
  • Non zero when object handle is equal to h;
  • Zero otherwise.

◆ operator>()

template<class T , const T INVAL>
bool macstd::handle< T, INVAL >::operator> ( T h) const
inline

Is handle greater than?

Parameters
[in]hObject handle to compare against
Returns
  • Non zero when object handle is greater than h;
  • Zero otherwise.

◆ operator>=()

template<class T , const T INVAL>
bool macstd::handle< T, INVAL >::operator>= ( T h) const
inline

Is handle greater than or equal to?

Parameters
[in]hObject handle to compare against
Returns
  • Non zero when object handle is greater than or equal to h;
  • Zero otherwise.

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