![]() |
4S Device Communication Module Collection
Version 0.6-SNAPSHOT
Full documentation of the modules in the 4SDC collection (aimed at 4SDC module developers)
|
|
Class that holds and assigns handles. More...
#include <handle.h>
Public Member Functions | |
Handle (void) | |
Default constructor. More... | |
Handle (Handle &ref) | |
Copy constructor for handle object. More... | |
Handle (const Handle &ref) | |
Copy constructor for handle object. More... | |
Handle & | operator= (Handle const &theOtherOne) |
bool | operator== (Handle const &compareTo) const |
Equality comparator. More... | |
bool | operator!= (Handle const &compareTo) const |
Not equalify operator. More... | |
bool | operator> (Handle const &compareTo) const |
Greater than operator ('>') More... | |
bool | operator< (Handle const &compareTo) const |
Less than operator ('<') More... | |
Static Public Member Functions | |
static Handle & | broadCastHandle (void) |
Generic broadcast handle. More... | |
static Handle & | null (void) |
The null handle. More... | |
Private Member Functions | |
int64_t | getNextHandle (void) |
Function to generate a unique handle. More... | |
Private Attributes | |
int64_t | handle |
The actual value of the handle. | |
If you instantiate this class with the default constructor then it will represent a unique handle, if you copy the object, the copy will contain the same handle.
It is possible to compare handles with the '!=', '==', '<' and '>' operators, you should not rely on any special meaning of the '<' and '>' operators, as future implemenations might change the order of created handles.
Two special handels are exposed by the class - the "null" and "broadcast" handles - you can not rely on how these two handles are ordered compared to other handles (e.g. null() will not always compare smaller to other handles, nor will null() compare equal to 0.
|
inline |
Using the default constructor will assign a unique handle to this object.
If you do not wish to have new handle assigned, then you can get a more efficient program by initializing the handle to the null handle. This will prevent a global mutex lock to be taken.
is more efficient than:
The most efficient is thou:
|
inline |
ref | The handle that should be copied |
|
inline |
ref | The handle that should be copied |
|
static |
The meaning of this handle is specified by its use, from the handle class's point of view, it is just a unique handle.
|
private |
This function will generate a unique handle, it will do this by returning a 64 bit handle - after all ~10¹⁹ handles with a positive value are used the function will assert, if a millon handles are used a second, this is not estimated to happen within the lifetime of a single instance of the application.
|
static |
The null handle is the handle that doesn't represent a valid handle.
Two null handles will compare equal to each other, and not equal to other handles.
The null handle does not compare equal to the integer value 0, you should consider it equally likely that it compares smaller or greater to any other specific handle, and because it compares smaller to one handle, it doesn't mean that it compares smaller to evey other handle.
The actuall value of the handle, will be dependend on a number of factors both compile time and excecution time wise.
|
inline |
Operator will return true if the two handles are different, e.g. not copies of each other.
comparTo | The handle this handle should be compared to |
|
inline |
If the greater than operator ('>') returns true for a relationship between A and B, then this function will return true when the arguments are swapped. So if A > B evaluates to true, then B < A will also evaluate to true.
compareTo | The handle that this handle should be compared to |
|
inline |
Operator will return true if the two handles are copies of each other
compareTo | The handle this handle should be compared to |
|
inline |
While handles don't have any meaning relation ship between them, except equality or not equality it is still helpfull for certian algorithms / data structures to be able to order them.
You should not rely on any connection between the creation order of the handles and how they compare to each other.
The only thing you can rely on is that if we you have three handles A, B and C - and A > B evaluates to true and B > C evaluates to true then A > C will also evaluate to true and in that case B > A, C > B and C > A will also all evaluate to false.
compareTo | The handle that should be compared to this handle |