MIRA
UUID.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 by
3  * MetraLabs GmbH (MLAB), GERMANY
4  * and
5  * Neuroinformatics and Cognitive Robotics Labs (NICR) at TU Ilmenau, GERMANY
6  * All rights reserved.
7  *
8  * Contact: info@mira-project.org
9  *
10  * Commercial Usage:
11  * Licensees holding valid commercial licenses may use this file in
12  * accordance with the commercial license agreement provided with the
13  * software or, alternatively, in accordance with the terms contained in
14  * a written agreement between you and MLAB or NICR.
15  *
16  * GNU General Public License Usage:
17  * Alternatively, this file may be used under the terms of the GNU
18  * General Public License version 3.0 as published by the Free Software
19  * Foundation and appearing in the file LICENSE.GPL3 included in the
20  * packaging of this file. Please review the following information to
21  * ensure the GNU General Public License version 3.0 requirements will be
22  * met: http://www.gnu.org/copyleft/gpl.html.
23  * Alternatively you may (at your option) use any later version of the GNU
24  * General Public License if such license has been publicly approved by
25  * MLAB and NICR (or its successors, if any).
26  *
27  * IN NO EVENT SHALL "MLAB" OR "NICR" BE LIABLE TO ANY PARTY FOR DIRECT,
28  * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF
29  * THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF "MLAB" OR
30  * "NICR" HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *
32  * "MLAB" AND "NICR" SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING,
33  * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
34  * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
35  * ON AN "AS IS" BASIS, AND "MLAB" AND "NICR" HAVE NO OBLIGATION TO
36  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS OR MODIFICATIONS.
37  */
38 
47 #ifndef _MIRA_UUID_H_
48 #define _MIRA_UUID_H_
49 
50 #ifndef Q_MOC_RUN
51 #include <boost/uuid/uuid.hpp>
52 #include <boost/uuid/uuid_generators.hpp>
53 #include <boost/uuid/uuid_io.hpp>
54 #endif
55 
56 #include <json/JSON.h>
57 
59 #include <stream/BinaryStream.h>
60 
61 #include <utils/ToString.h>
62 #include <utils/IsCheapToCopy.h>
63 
64 namespace mira {
65 
67 
69 typedef boost::uuids::uuid UUID;
70 
72 template <typename StreamUnderlay>
73 BinaryOstream<StreamUnderlay>& operator<<(BinaryOstream<StreamUnderlay>& s,
74  const UUID& uuid)
75 {
76 #if BOOST_VERSION < 108600
77  const char* buffer = reinterpret_cast<const char*>(uuid.data);
78 #else
79  const char* buffer = reinterpret_cast<const char*>(uuid.data());
80 #endif
81  s.write(buffer, UUID::static_size());
82  return s;
83 }
84 
86 template <typename StreamUnderlay>
88  UUID& uuid)
89 {
90 #if BOOST_VERSION < 108600
91  char* buffer = reinterpret_cast<char*>(uuid.data);
92 #else
93  char* buffer = reinterpret_cast<char*>(uuid.data());
94 #endif
95  s.read(buffer, UUID::static_size());
96 
97  return s;
98 }
99 
100 template<>
101 class IsAtomicSerializable<UUID> : public std::true_type {};
102 
104 template<>
105 inline std::string toString<UUID>(const UUID& value, int precision)
106 {
107  std::stringstream ss;
108  ss << value;
109  return ss.str();
110 }
111 
113 template <>
114 inline UUID fromString<UUID>(const std::string& str)
115 {
116  std::stringstream ss(str);
117  UUID uuid;
118  ss >> uuid;
119  return uuid;
120 }
121 
122 namespace json
123 {
124  MIRA_JSON_TRAIT(std::string, UUID)
125 
126  template<>
127  inline std::string cast<UUID>(const UUID& value)
128  {
129  return toString(value);
130  }
131 
132  template<>
133  inline UUID reverse_cast<UUID>(const std::string& value)
134  {
135  return fromString<UUID>(value);
136  }
137 }
138 
140 
141 template <>
142 class IsCheapToCopy<UUID> : public std::true_type {};
143 
145 
146 }
147 
148 #endif
std::string toString< UUID >(const UUID &value, int precision)
specialization for toString
Definition: UUID.h:105
specialize cv::DataType for our ImgPixel and inherit from cv::DataType<Vec>
Definition: IOService.h:67
void read(T *data, std::size_t count)
Definition: BinaryStream.h:602
Contains toString and fromString functions for converting data types to strings and the other way rou...
Type trait that indicates whether a type can be serialized as an atomic value.
Definition: IsAtomicSerializable.h:83
MIRA_BASE_EXPORT std::istream & operator>>(std::istream &stream, RSAKey &key)
The &#39;>>&#39; operator for RSAKey.
std::string toString(const T &value, int precision=-1)
Converts any data type to string (the data type must support the stream << operator).
Definition: ToString.h:256
Output stream adapter that can be assigned to any output stream and allows binary output using the <<...
Definition: BinaryStream.h:293
By default, IsCheapToCopy<T>::value evaluates to true for fundamental types T, false for all other ty...
Definition: IsCheapToCopy.h:63
Type trait to define if a class is cheap to copy.
std::string cast< UUID >(const UUID &value)
Definition: UUID.h:127
Input stream adapter that can be assigned to any input stream and allows binary input using the >> st...
Definition: BinaryStream.h:523
Contains the BinaryIStream and BinaryOStream classes for fast and efficient streaming of binary data...
Provides type trait that indicates whether a type can be serialized as atomic value.
void write(const T *data, std::size_t count)
Definition: BinaryStream.h:370
PropertyHint precision(int p)
Sets the attribute "precision".
Definition: PropertyHint.h:285
UUID fromString< UUID >(const std::string &str)
specialization for fromString
Definition: UUID.h:114
boost::uuids::uuid UUID
Shorter name for boost uuid.
Definition: UUID.h:69
Wrappers for JSON.