diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2020-07-30 12:12:13 +0300 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2020-07-31 12:24:03 +0300 |
commit | de21ddf821ce073031aa0154874cebcfad7cb481 (patch) | |
tree | 8b76d624c393e789abc15455e021062cd9ab7609 /source/blender/blenlib/BLI_session_uuid.h | |
parent | cd579c49960510b9979842284b94b35c9175e059 (diff) |
BLI: Initial implementation of generic session UUID API
Covers basics like generation of new UUID.
Also contains code needed to use the SessionUUID as a key in the Map.
Diffstat (limited to 'source/blender/blenlib/BLI_session_uuid.h')
-rw-r--r-- | source/blender/blenlib/BLI_session_uuid.h | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/source/blender/blenlib/BLI_session_uuid.h b/source/blender/blenlib/BLI_session_uuid.h new file mode 100644 index 00000000000..35d358b8e7c --- /dev/null +++ b/source/blender/blenlib/BLI_session_uuid.h @@ -0,0 +1,71 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef __BLI_SESSION_UUID_H__ +#define __BLI_SESSION_UUID_H__ + +/** \file + * \ingroup bli + */ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "DNA_session_uuid_types.h" + +/* Generate new UUID which is unique throughout the Blender session. */ +SessionUUID BLI_session_uuid_generate(void); + +/* Check whether the UUID is properly generated. */ +bool BLI_session_uuid_is_generated(const SessionUUID *uuid); + +/* Check whether two UUIDs are identical. */ +bool BLI_session_uuid_is_equal(const SessionUUID *lhs, const SessionUUID *rhs); + +uint64_t BLI_session_uuid_hash_uint64(const SessionUUID *uuid); + +/* Utility functions to make it possible to create GHash/GSet with UUID as a key. */ +uint BLI_session_uuid_ghash_hash(const void *uuid_v); +bool BLI_session_uuid_ghash_compare(const void *lhs_v, const void *rhs_v); + +#ifdef __cplusplus +} +#endif + +#ifdef __cplusplus + +namespace blender { + +inline const bool operator==(const SessionUUID &lhs, const SessionUUID &rhs) +{ + return BLI_session_uuid_is_equal(&lhs, &rhs); +} + +template<typename T> struct DefaultHash; + +template<> struct DefaultHash<SessionUUID> { + uint64_t operator()(const SessionUUID &value) const + { + return BLI_session_uuid_hash_uint64(&value); + } +}; + +} // namespace blender + +#endif + +#endif /* __BLI_SESSION_UUID_H__ */ |