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>
58 #include <stream/BinaryStream.h>
59 #include <utils/ToString.h>
60 
61 namespace mira {
62 
64 
66 typedef boost::uuids::uuid UUID;
67 
69 template <typename StreamUnderlay>
70 BinaryOstream<StreamUnderlay>& operator<<(BinaryOstream<StreamUnderlay>& s,
71  const UUID& uuid)
72 {
73  const char* buffer = reinterpret_cast<const char*>(uuid.data);
74  s.write(buffer, UUID::static_size());
75  return s;
76 }
77 
79 template <typename StreamUnderlay>
81  UUID& uuid)
82 {
83  char* buffer = reinterpret_cast<char*>(uuid.data);
84  s.read(buffer, UUID::static_size());
85  return s;
86 }
87 
88 template<>
89 class IsAtomicSerializable<UUID> : public std::true_type {};
90 
92 template<>
93 inline std::string toString<UUID>(const UUID& value, int precision)
94 {
95  std::stringstream ss;
96  ss << value;
97  return ss.str();
98 }
99 
101 template <>
102 inline UUID fromString<UUID>(const std::string& str)
103 {
104  std::stringstream ss(str);
105  UUID uuid;
106  ss >> uuid;
107  return uuid;
108 }
109 
110 namespace json
111 {
112  MIRA_JSON_TRAIT(std::string, UUID)
113 
114  template<>
115  inline std::string cast<UUID>(const UUID& value)
116  {
117  return toString(value);
118  }
119 
120  template<>
121  inline UUID reverse_cast<UUID>(const std::string& value)
122  {
123  return fromString<UUID>(value);
124  }
125 }
126 
128 
129 }
130 
131 #endif
std::string toString< UUID >(const UUID &value, int precision)
specialization for toString
Definition: UUID.h:93
IStream & operator>>(IStream &is, JSONValue &value)
Definition: JSON.h:389
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:71
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
std::string cast< UUID >(const UUID &value)
Definition: UUID.h:115
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:102
boost::uuids::uuid UUID
Shorter name for boost uuid.
Definition: UUID.h:66
Wrappers for JSON.