Robowflex  v0.1
Making MoveIt Easy
robowflex::ID Class Reference

Adds functionality to uniquely ID a specific class as well as the "version" of that class, managed by an incrementing counter. More...

#include <id.h>

+ Inheritance diagram for robowflex::ID:

Public Types

using Key = std::pair< std::string, std::size_t >
 A snapshot of the state of an ID. Can be compared against another ID. More...
 

Public Member Functions

 ID ()
 Constructor. More...
 
const std::stringgetID () const
 Get the unique ID for this object. More...
 
std::size_t getVersion () const
 Get the current version of this object. More...
 
Key getKey () const
 Get this ID as a Key. More...
 
bool operator== (const ID &b) const
 Compare with another ID object. More...
 
bool operator== (const Key &b) const
 Compare with an ID Key. More...
 

Static Public Member Functions

static Key getNullKey ()
 Get a null key for initialization. More...
 

Protected Member Functions

void incrementVersion ()
 Increment the version number of this object. More...
 

Private Attributes

const std::string id_
 Unique object ID. More...
 
std::atomic_size_t version_
 Version number. More...
 

Detailed Description

Adds functionality to uniquely ID a specific class as well as the "version" of that class, managed by an incrementing counter.

Definition at line 26 of file id.h.

Member Typedef Documentation

◆ Key

A snapshot of the state of an ID. Can be compared against another ID.

Definition at line 31 of file id.h.

Constructor & Destructor Documentation

◆ ID()

ID::ID ( )

Constructor.

Definition at line 8 of file id.cpp.

9 {
10 }
const std::string id_
Unique object ID.
Definition: id.h:75
std::atomic_size_t version_
Version number.
Definition: id.h:76
std::string generateUUID()
Generates a UUID.

Member Function Documentation

◆ getID()

const std::string & ID::getID ( ) const

Get the unique ID for this object.

Returns
The unique ID.

Definition at line 12 of file id.cpp.

13 {
14  return id_;
15 }

◆ getKey()

ID::Key ID::getKey ( ) const

Get this ID as a Key.

Returns
The ID as a Key.

Definition at line 22 of file id.cpp.

23 {
24  return {getID(), getVersion()};
25 }
const std::string & getID() const
Get the unique ID for this object.
Definition: id.cpp:12
std::size_t getVersion() const
Get the current version of this object.
Definition: id.cpp:17

◆ getNullKey()

ID::Key ID::getNullKey ( )
static

Get a null key for initialization.

Returns
The null key.

Definition at line 27 of file id.cpp.

28 {
29  return {"NULL", 0};
30 }

◆ getVersion()

std::size_t ID::getVersion ( ) const

Get the current version of this object.

Returns
The version number.

Definition at line 17 of file id.cpp.

18 {
19  return version_.load();
20 }

◆ incrementVersion()

void ID::incrementVersion ( )
protected

Increment the version number of this object.

Definition at line 42 of file id.cpp.

43 {
44  version_++;
45 }

◆ operator==() [1/2]

bool ID::operator== ( const ID b) const

Compare with another ID object.

Parameters
[in]bObject to compare against.
Returns
True if the same, false otherwise.

Definition at line 32 of file id.cpp.

33 {
34  return getID() == b.getID() and getVersion() == b.getVersion();
35 }

◆ operator==() [2/2]

bool ID::operator== ( const Key b) const

Compare with an ID Key.

Parameters
[in]bKey to compare against.
Returns
True if the same, false otherwise.

Definition at line 37 of file id.cpp.

38 {
39  return getID() == b.first and getVersion() == b.second;
40 }

Member Data Documentation

◆ id_

const std::string robowflex::ID::id_
private

Unique object ID.

Definition at line 75 of file id.h.

◆ version_

std::atomic_size_t robowflex::ID::version_
private

Version number.

Definition at line 76 of file id.h.


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