WinStd
Windows Win32 API using Standard C++
Loading...
Searching...
No Matches
winstd::handle< T, INVAL > Class Template Referenceabstract

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

#include <WinStd/Common.h>

Inheritance diagram for winstd::handle< T, INVAL >:
winstd::dplhandle< T *, NULL > winstd::dplhandle< T, INVAL > winstd::com_obj< T >

Public Types

typedef T handle_type
 Datatype of the object handle this template class handles.
 

Public Member Functions

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

Static Public Attributes

static const T invalid = INVAL
 Invalid handle value.
 

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

handle_type m_h
 Object handle.
 

Detailed Description

template<class T, const T INVAL>
class winstd::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>
winstd::handle< T, INVAL >::handle ( handle_type 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>
winstd::handle< T, INVAL >::handle ( handle< handle_type, 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 winstd::handle< T, INVAL >::attach ( handle_type 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>
handle_type winstd::handle< T, INVAL >::detach ( )
inline

Dismisses the object handle from this class.

Returns
Object handle

◆ free_internal()

◆ operator handle_type()

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

Auto-typecasting operator.

Returns
Object handle

◆ operator!()

template<class T , const T INVAL>
bool winstd::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 handle_type are polymorphed. Use !! to test if the object handle is valid.

◆ operator!=()

template<class T , const T INVAL>
bool winstd::handle< T, INVAL >::operator!= ( handle_type 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>
handle_type * winstd::handle< T, INVAL >::operator& ( )
inline

Returns the object handle reference.

Returns
Object handle reference

◆ operator*()

template<class T , const T INVAL>
handle_type *& winstd::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>
handle_type winstd::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 winstd::handle< T, INVAL >::operator< ( handle_type 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 winstd::handle< T, INVAL >::operator<= ( handle_type 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< handle_type, INVAL > & winstd::handle< T, INVAL >::operator= ( handle< handle_type, INVAL > && h)
inlinenoexcept

Move assignment.

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

◆ operator=() [2/2]

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

Attaches already available object handle.

Parameters
[in]hObject handle value

◆ operator==()

template<class T , const T INVAL>
bool winstd::handle< T, INVAL >::operator== ( handle_type 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 winstd::handle< T, INVAL >::operator> ( handle_type 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 winstd::handle< T, INVAL >::operator>= ( handle_type 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: