unique_id.h
Go to the documentation of this file.
1 /* -*- mode: C++ -*- */
2 /*********************************************************************
3 * Software License Agreement (BSD License)
4 *
5 * Copyright (C) 2012 Jack O'Quin
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * * Redistributions in binary form must reproduce the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer in the documentation and/or other materials provided
17 * with the distribution.
18 * * Neither the name of the author nor other contributors may be
19 * used to endorse or promote products derived from this software
20 * without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 * POSSIBILITY OF SUCH DAMAGE.
34 *********************************************************************/
35 
36 #ifndef _UNIQUE_ID_H_
37 #define _UNIQUE_ID_H_ 1
38 
46 #include <string>
47 
48 #include <boost/uuid/uuid.hpp>
49 #include <boost/uuid/uuid_io.hpp>
50 
51 #include <ros/ros.h>
52 #include <uuid_msgs/UniqueID.h>
53 
54 #include <unique_id/impl/unique_id.h> // private implementation details
55 
77 namespace unique_id
78 {
79 
86 {
87  boost::uuids::uuid uu{};
88  std::copy(msg.uuid.begin(), msg.uuid.end(), uu.begin());
89  return uu;
90 }
91 
100 static inline boost::uuids::uuid fromRandom(void)
101 {
102  return impl::genRandom();
103 }
104 
125 static inline boost::uuids::uuid fromHexString(std::string const &str)
126 {
127  return impl::genString(str);
128 }
129 
151 static inline boost::uuids::uuid fromURL(std::string const &url)
152 {
153  return impl::genURL(url);
154 }
155 
167 static inline boost::uuids::uuid fromTime(ros::Time timestamp, uint64_t hw_addr)
168 {
169  return impl::genTime(timestamp, hw_addr);
170 }
171 
178 {
180  std::copy(uu.begin(), uu.end(), msg.uuid.begin());
181  return msg;
182 }
183 
192 static inline std::string toHexString(boost::uuids::uuid const &uu)
193 {
194  return boost::uuids::to_string(uu);
195 }
196 
202 static inline std::string toHexString(uuid_msgs::UniqueID const &msg)
203 {
204  return boost::uuids::to_string(fromMsg(msg));
205 }
206 
207 } // end namespace unique_id
208 
209 #endif // _UNIQUE_ID_H_
static boost::uuids::uuid fromRandom(void)
Generate a random UUID object.
Definition: unique_id.h:100
static boost::uuids::uuid fromMsg(uuid_msgs::UniqueID const &msg)
Create UUID object from UniqueID message.
Definition: unique_id.h:85
C++ namespace for unique_id helper functions.
static boost::uuids::random_generator genRandom
static boost::uuids::uuid genTime(ros::Time uuid_time, uint64_t hw_addr)
static boost::uuids::string_generator genString
static boost::uuids::uuid fromTime(ros::Time timestamp, uint64_t hw_addr)
Generate a Time Based UUID object. Users are recommended to seed the random number generator using sr...
Definition: unique_id.h:167
uuid_msgs::UniqueID UniqueID
static std::string toHexString(boost::uuids::uuid const &uu)
Get the canonical string representation for a boost UUID.
Definition: unique_id.h:192
boost::uuids::uuid uuid
Private implementation details for C++ unique_id interface.
static boost::uuids::uuid fromURL(std::string const &url)
Generate UUID from Uniform Resource Identifier.
Definition: unique_id.h:151
static boost::uuids::name_generator genURL(url_namespace_uuid)
static uuid_msgs::UniqueID toMsg(boost::uuids::uuid const &uu)
Create a UniqueID message from a UUID object.
Definition: unique_id.h:177
static boost::uuids::uuid fromHexString(std::string const &str)
Generate UUID from canonical hex string.
Definition: unique_id.h:125


unique_id
Author(s): Jack O'Quin
autogenerated on Mon Mar 6 2023 03:18:07