nlib
nn::nlib::HandleMaker< HBODY > Class Template Reference

A class supporting the implementation of handles with a 32-bit integer value. More...

#include "nn/nlib/HandleMaker.h"

Public Member Functions

 HandleMaker (HandleTable< HBODY > *ptr) noexcept
 Instantiates the object. A pointer to the table needs to be passed.
 
errno_t AttachHandleBody (int *handle, HBODY *body) noexcept
 Gets a handle that should be associated with the handle instance. More...
 
errno_t GetHandleAccess (int handle, HandleAccess< HBODY > *access) noexcept
 Obtains access from a handle to the handle instance. More...
 

Detailed Description

template<class HBODY>
class nn::nlib::HandleMaker< HBODY >

A class supporting the implementation of handles with a 32-bit integer value.

Template Parameters
HBODYHandle instance type.
Description
A class providing a mechanism to associate a 32-bit integer value (a handle) with an object (a handle instance). Using HandleMaker enables you to easily provide handles with the following features:
  • Access to the handle instance through the handle is thread safe.
  • Even if you use the handle after closing it (i.e. the handle is no longer valid), an error (generally, EBADF) can be returned without causing a crash.
  • The above features apply also for cases where the handle is closed from a different thread.
  • Since an integer value that acts as a handle will not be reused immediately, you can avoid unintentional access to the handle instance.
  • -1, 0, 1, 2, or 3 will not be assigned as a handle value.
Examples:
misc/handlemaker/handlemaker.cpp.

Definition at line 93 of file HandleMaker.h.

Member Function Documentation

◆ AttachHandleBody()

template<class HBODY >
nn::nlib::HandleMaker< HBODY >::AttachHandleBody ( int *  handle,
HBODY *  body 
)
noexcept

Gets a handle that should be associated with the handle instance.

Parameters
[out]handlePointer to the handle associated with body.
[in]bodyHandle instance to be associated with the handle.
Return values
0Success.
ENFILENo handle is available that can be assigned.

Definition at line 195 of file HandleMaker.h.

◆ GetHandleAccess()

template<class HBODY >
nn::nlib::HandleMaker< HBODY >::GetHandleAccess ( int  handle,
HandleAccess< HBODY > *  access 
)
noexcept

Obtains access from a handle to the handle instance.

Parameters
[in]handleHandle obtained with AttachHandleBody().
[out]accessAccessor to an instance corresponding to the handle.
Return values
0Success.
EBADFThe handle is not valid.

Definition at line 262 of file HandleMaker.h.


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