Robowflex  v0.1
Making MoveIt Easy
id.h
Go to the documentation of this file.
1 /* Author Zachary Kingston */
2 
3 #ifndef ROBOWFLEX_ID_
4 #define ROBOWFLEX_ID_
5 
6 #include <atomic>
7 #include <string>
8 
10 
11 namespace robowflex
12 {
13  /** \cond IGNORE */
15  /** \endcond */
16 
17  /** \class robowflex::IDPtr
18  \brief A shared pointer wrapper for robowflex::ID. */
19 
20  /** \class robowflex::IDConstPtr
21  \brief A const shared pointer wrapper for robowflex::ID. */
22 
23  /** \brief Adds functionality to uniquely ID a specific class as well as the "version" of that class,
24  * managed by an incrementing counter.
25  */
26  class ID
27  {
28  public:
29  /** \brief A snapshot of the state of an ID. Can be compared against another ID.
30  */
32 
33  /** \brief Get a null key for initialization.
34  * \return The null key.
35  */
36  static Key getNullKey();
37 
38  /** \brief Constructor.
39  */
40  ID();
41 
42  /** \brief Get the unique ID for this object.
43  * \return The unique ID.
44  */
45  const std::string &getID() const;
46 
47  /** \brief Get the current version of this object.
48  * \return The version number.
49  */
50  std::size_t getVersion() const;
51 
52  /** \brief Get this ID as a Key.
53  * \return The ID as a Key.
54  */
55  Key getKey() const;
56 
57  /** \brief Compare with another ID object.
58  * \param[in] b Object to compare against.
59  * \return True if the same, false otherwise.
60  */
61  bool operator==(const ID &b) const;
62 
63  /** \brief Compare with an ID Key.
64  * \param[in] b Key to compare against.
65  * \return True if the same, false otherwise.
66  */
67  bool operator==(const Key &b) const;
68 
69  protected:
70  /** \brief Increment the version number of this object.
71  */
72  void incrementVersion();
73 
74  private:
75  const std::string id_; ///< Unique object ID
76  std::atomic_size_t version_; ///< Version number.
77  };
78 
79  /** \brief Compare two ID objects.
80  * \param[in] a First object to compare.
81  * \param[in] b Second object to compare.
82  * \return True if \a a and \a b are the same, false otherwise.
83  */
84  bool compareIDs(const ID &a, const ID &b);
85 
86  /** \brief Compare two ID objects.
87  * \param[in] a First object to compare.
88  * \param[in] b Second object to compare.
89  * \return True if \a a and \a b are the same, false otherwise.
90  */
91  bool compareIDs(const IDPtr &a, const IDPtr &b);
92 
93  /** \brief Compare two ID objects.
94  * \param[in] a First object to compare.
95  * \param[in] b Second object to compare.
96  * \return True if \a a and \a b are the same, false otherwise.
97  */
98  bool compareIDs(const IDConstPtr &a, const IDConstPtr &b);
99 
100  /** \brief Compare an ID object to a key.
101  * \param[in] a Object to compare.
102  * \param[in] b Key to compare against.
103  * \return True if \a a and \a b are the same, false otherwise.
104  */
105  bool compareIDs(const ID &a, const ID::Key &b);
106 
107  /** \brief Compare an ID object to a key.
108  * \param[in] a Object to compare.
109  * \param[in] b Key to compare against.
110  * \return True if \a a and \a b are the same, false otherwise.
111  */
112  bool compareIDs(const IDPtr &a, const ID::Key &b);
113 
114  /** \brief Compare an ID object to a key.
115  * \param[in] a Object to compare.
116  * \param[in] b Key to compare against.
117  * \return True if \a a and \a b are the same, false otherwise.
118  */
119  bool compareIDs(const IDConstPtr &a, const ID::Key &b);
120 
121  /** \brief Compare an ID object to a key.
122  * \param[in] a Key to compare.
123  * \param[in] b Key to compare against.
124  * \return True if \a a and \a b are the same, false otherwise.
125  */
126  bool compareIDs(const ID::Key &a, const ID::Key &b);
127 } // namespace robowflex
128 
129 #endif
#define ROBOWFLEX_CLASS_FORWARD(C)
Macro that forward declares a class and defines two shared ptrs types:
Definition: class_forward.h:16
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
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