-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Do not bother caching previously used Ids, just a simple increment will do
- Loading branch information
Showing
17 changed files
with
109 additions
and
279 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#pragma once | ||
|
||
#include <cstdint> | ||
#include <type_traits> | ||
|
||
#define DYN_DEFINE_ID_TYPE(T) using T = struct T##_t * | ||
|
||
namespace Dynamo { | ||
/** | ||
* @brief Generate typesafe handles. | ||
* | ||
* @tparam Id | ||
*/ | ||
template <typename Id> | ||
class IdGenerator { | ||
static_assert(std::is_pointer<Id>::value, "Id must be a valid handle type (opaque pointer)."); | ||
static_assert(sizeof(Id) == sizeof(uintptr_t), "Id and its integer mode must be the same size."); | ||
static inline uintptr_t _counter = 0; | ||
|
||
public: | ||
/** | ||
* @brief Generate an id. | ||
* | ||
* @return Id | ||
*/ | ||
static inline Id generate() { return reinterpret_cast<Id>(_counter++); } | ||
|
||
/** | ||
* @brief Get the key of the id. | ||
* | ||
* @param id | ||
* @return uintptr_t | ||
*/ | ||
static inline uintptr_t key(Id id) { return reinterpret_cast<uintptr_t>(id); } | ||
}; | ||
} // namespace Dynamo |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.