RSB  0.9.6
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
EventId.cpp
Go to the documentation of this file.
1 /* ============================================================
2  *
3  * This file is a part of the RSB project.
4  *
5  * Copyright (C) 2011 by Johannes Wienke <jwienke at techfak dot uni-bielefeld dot de>
6  *
7  * This file may be licensed under the terms of the
8  * GNU Lesser General Public License Version 3 (the ``LGPL''),
9  * or (at your option) any later version.
10  *
11  * Software distributed under the License is distributed
12  * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
13  * express or implied. See the LGPL for the specific language
14  * governing rights and limitations.
15  *
16  * You should have received a copy of the LGPL along with this
17  * program. If not, go to http://www.gnu.org/licenses/lgpl.html
18  * or write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  * The development of this software was supported by:
22  * CoR-Lab, Research Institute for Cognition and Robotics
23  * Bielefeld University
24  *
25  * ============================================================ */
26 
27 #include "EventId.h"
28 
29 #include <boost/format.hpp>
30 
31 using namespace std;
32 
33 namespace rsb {
34 
35 EventId::EventId(const rsc::misc::UUID& participantId,
36  const boost::uint32_t& sequenceNumber) :
37  participantId(participantId), sequenceNumber(sequenceNumber) {
38 }
39 
41 }
42 
43 rsc::misc::UUID EventId::getParticipantId() const {
44  return participantId;
45 }
46 
47 boost::uint32_t EventId::getSequenceNumber() const {
48  return sequenceNumber;
49 }
50 
51 rsc::misc::UUID EventId::getAsUUID() const {
52  // this does not need locking as in the worst case it may only be set twice
53  // and reading a shared pointer is not affected by this because it is
54  // thread-safe.
55  if (!id) {
56  id.reset(
57  new rsc::misc::UUID(
59  boost::str(
60  boost::format("%1$08x")
61  % this->sequenceNumber)));
62  }
63  return *id;
64 }
65 
66 bool EventId::operator==(const EventId& other) const {
67  // first compare the sequence number which is most likely already different
68  return (sequenceNumber == other.sequenceNumber)
69  && (participantId == other.participantId);
70 }
71 
72 bool EventId::operator<(const EventId& other) const {
73  if (sequenceNumber < other.sequenceNumber) {
74  return true;
75  } else if (sequenceNumber > other.sequenceNumber) {
76  return false;
77  } else {
78  return participantId < other.participantId;
79  }
80 }
81 
82 string EventId::getClassName() const {
83  return "EventId";
84 }
85 
86 void EventId::printContents(ostream& stream) const {
87  stream << "participantId = " << participantId << ", sequenceNumber = "
88  << sequenceNumber;
89 }
90 
91 }
bool operator==(const EventId &other) const
Definition: EventId.cpp:66
std::string getClassName() const
Definition: EventId.cpp:82
boost::uint32_t sequenceNumber
Definition: EventId.h:73
boost::uint32_t getSequenceNumber() const
Definition: EventId.cpp:47
virtual ~EventId()
Definition: EventId.cpp:40
rsc::misc::UUID getAsUUID() const
Definition: EventId.cpp:51
rsc::misc::UUIDPtr id
A cache for the generated uuid.
Definition: EventId.h:78
bool operator<(const EventId &other) const
Definition: EventId.cpp:72
rsc::misc::UUID participantId
The id of the sending participant.
Definition: EventId.h:72
void printContents(std::ostream &stream) const
Definition: EventId.cpp:86
rsc::misc::UUID getParticipantId() const
Definition: EventId.cpp:43
A unique ID for events in RSB.
Definition: EventId.h:48