Robowflex  v0.1
Making MoveIt Easy
id.cpp
Go to the documentation of this file.
1 /* Author: Zachary Kingston */
2 
3 #include <robowflex_library/id.h>
4 #include <robowflex_library/io.h>
5 
6 using namespace robowflex;
7 
8 ID::ID() : id_(IO::generateUUID()), version_(0)
9 {
10 }
11 
12 const std::string &ID::getID() const
13 {
14  return id_;
15 }
16 
18 {
19  return version_.load();
20 }
21 
23 {
24  return {getID(), getVersion()};
25 }
26 
28 {
29  return {"NULL", 0};
30 }
31 
32 bool ID::operator==(const ID &b) const
33 {
34  return getID() == b.getID() and getVersion() == b.getVersion();
35 }
36 
37 bool ID::operator==(const ID::Key &b) const
38 {
39  return getID() == b.first and getVersion() == b.second;
40 }
41 
43 {
44  version_++;
45 }
46 
47 bool robowflex::compareIDs(const ID &a, const ID &b)
48 {
49  return a == b;
50 }
51 
52 bool robowflex::compareIDs(const IDPtr &a, const IDPtr &b)
53 {
54  return compareIDs(*a, *b);
55 }
56 
58 {
59  return compareIDs(*a, *b);
60 }
61 
62 bool robowflex::compareIDs(const ID &a, const ID::Key &b)
63 {
64  return a == b;
65 }
66 
67 bool robowflex::compareIDs(const IDPtr &a, const ID::Key &b)
68 {
69  return compareIDs(*a, b);
70 }
71 
72 bool robowflex::compareIDs(const IDConstPtr &a, const ID::Key &b)
73 {
74  return compareIDs(*a, b);
75 }
76 
77 bool robowflex::compareIDs(const ID::Key &a, const ID::Key &b)
78 {
79  return a == b;
80 }
A const shared pointer wrapper for robowflex::ID.
A shared pointer wrapper for robowflex::ID.
Adds functionality to uniquely ID a specific class as well as the "version" of that class,...
Definition: id.h:27
const std::string id_
Unique object ID.
Definition: id.h:75
std::atomic_size_t version_
Version number.
Definition: id.h:76
void incrementVersion()
Increment the version number of this object.
Definition: id.cpp:42
const std::string & getID() const
Get the unique ID for this object.
Definition: id.cpp:12
bool operator==(const ID &b) const
Compare with another ID object.
Definition: id.cpp:32
std::size_t getVersion() const
Get the current version of this object.
Definition: id.cpp:17
ID()
Constructor.
Definition: id.cpp:8
static Key getNullKey()
Get a null key for initialization.
Definition: id.cpp:27
Key getKey() const
Get this ID as a Key.
Definition: id.cpp:22
std::string generateUUID()
Generates a UUID.
Main namespace. Contains all library classes and functions.
Definition: scene.cpp:25
bool compareIDs(const ID &a, const ID &b)
Compare two ID objects.
Definition: id.cpp:47