4 Copyright (c) 2014 Graeme Hill (http://graemehill.ca)
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to deal
8 in the Software without restriction, including without limitation the rights
9 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
37 // Class to represent a GUID/UUID. Each instance acts as a wrapper around a
38 // 16 byte value that can be passed around by value. It also supports
39 // conversion to string (via the stream operator <<) and conversion from a
40 // string via constructor.
45 // create a guid from vector of bytes
46 Guid(const std::vector<unsigned char> &bytes);
48 // create a guid from array of bytes
49 Guid(const unsigned char *bytes);
51 // Create a guid from array of words.
52 Guid(const uint16_t *bytes, bool reverse);
54 // create a guid from string
55 Guid(const std::string &fromString);
61 Guid(const Guid &other);
63 // overload assignment operator
64 Guid &operator=(const Guid &other);
66 // overload equality and inequality operator
67 bool operator==(const Guid &other) const;
68 bool operator!=(const Guid &other) const;
70 const std::string toString() const;
71 std::vector<unsigned char>::const_iterator begin() { return _bytes.begin(); }
72 std::vector<unsigned char>::const_iterator end() { return _bytes.end(); }
73 std::vector<unsigned char>::const_reverse_iterator rbegin() { return _bytes.rbegin(); }
74 std::vector<unsigned char>::const_reverse_iterator rend() { return _bytes.rend(); }
80 std::vector<unsigned char> _bytes;
82 // make the << operator a friend so it can access _bytes
83 friend std::ostream &operator<<(std::ostream &s, const Guid &guid);
86 // Class that can create new guids. The only reason this exists instead of
87 // just a global "newGuid" function is because some platforms will require
88 // that there is some attached context. In the case of android, we need to
89 // know what JNIEnv is being used to call back to Java, but the newGuid()
90 // function would no longer be cross-platform if we parameterized the android
91 // version. Instead, construction of the GuidGenerator may be different on
92 // each platform, but the use of newGuid is uniform.
97 GuidGenerator(JNIEnv *env);
108 jmethodID _newGuidMethod;
109 jmethodID _mostSignificantBitsMethod;
110 jmethodID _leastSignificantBitsMethod;