28#include <boost/uuid/uuid_generators.hpp>
29#include <boost/uuid/uuid_io.hpp>
30#include <boost/functional/hash.hpp>
32#if BOOST_VERSION >= 106700
33#include <boost/uuid/entropy_error.hpp>
36#include <nlohmann/json.hpp>
50static boost::mt19937
rng;
78#if BOOST_VERSION >= 106700
89 std::lock_guard<std::mutex> lock(
rng_mutex );
93#if BOOST_VERSION >= 106700
95 catch(
const boost::uuids::entropy_error& )
97 wxLogFatalError(
"A Boost UUID entropy exception was thrown in %s:%s.",
98 __FILE__, __FUNCTION__ );
106 m_cached_timestamp( 0 )
108 wxASSERT( null == 0 );
114 m_cached_timestamp( 0 )
116 if( aString.length() == 8
117 && std::all_of( aString.begin(), aString.end(),
118 [](
unsigned char c )
120 return std::isxdigit( c );
126 for(
int i = 0; i < 4; ++i )
128 std::string octet = aString.substr( i * 2, 2 );
129 m_uuid.data[i + 12] = strtol( octet.data(),
nullptr, 16 );
147#if BOOST_VERSION >= 106700
154#if BOOST_VERSION >= 106700
156 catch(
const boost::uuids::entropy_error& )
158 wxLogFatalError(
"A Boost UUID entropy exception was thrown in %s:%s.",
159 __FILE__, __FUNCTION__ );
174 KIID(
std::string( aString.ToUTF8() ) )
183 if( aCandidate.Length() != niluuidStr.Length() )
186 for( wxChar c : aCandidate )
188 if( c >=
'0' && c <=
'9' )
191 if( c >=
'a' && c <=
'f' )
194 if( c >=
'A' && c <=
'F' )
216 for(
int i = 0; i < 4; ++i )
218 wxString octet = str.substr( i * 2, 2 );
219 m_uuid.data[i + 12] = strtol( octet.data(),
nullptr, 16 );
243 for(
int i = 0; i < 4; ++i )
244 boost::hash_combine( hash,
reinterpret_cast<const uint32_t*
>(
m_uuid.data )[i] );
259 return boost::uuids::to_string(
m_uuid );
284 for(
int i = 15; i >= 0; --i )
309 for(
const wxString& pathStep : wxSplit( aString,
'/' ) )
311 if( !pathStep.empty() )
312 emplace_back(
KIID( pathStep ) );
322 if( aPath.size() >
copy.size() )
325 for(
size_t i = 0; i < aPath.size(); ++i )
327 if(
copy.at( i ).AsString() != aPath.at( i ).
AsString() )
331 for(
size_t i = aPath.size(); i <
copy.size(); ++i )
332 push_back(
copy.at( i ) );
340 if( aPath.size() > size() )
346 while( !copyThat.empty() )
348 if( *std::prev( copyThis.end() ) != *std::prev( copyThat.end() ) )
363 for(
const KIID& pathStep : *
this )
378 aKIID =
KIID( aJson.get<std::string>() );
bool EndsWith(const KIID_PATH &aPath) const
Test if aPath from the last path towards the first path.
bool MakeRelativeTo(const KIID_PATH &aPath)
wxString AsString() const
timestamp_t m_cached_timestamp
static void SeedGenerator(unsigned int aSeed)
Re-initialize the UUID generator with a given seed (for testing or QA purposes)
wxString AsString() const
boost::uuids::uuid m_uuid
void Increment()
Generates a deterministic replacement for a given ID.
wxString AsLegacyTimestampString() const
timestamp_t AsLegacyTimestamp() const
static void CreateNilUuids(bool aNil=true)
A performance optimization which disables/enables the generation of pseudo-random UUIDs.
static bool SniffTest(const wxString &aCandidate)
Returns true if a string has the correct formatting to be a KIID.
void Clone(const KIID &aUUID)
bool IsLegacyTimestamp() const
void ConvertTimestampToUuid()
Change an existing time stamp based UUID into a true UUID.
static boost::uuids::nil_generator nilGenerator
static bool g_createNilUuids
static std::mutex rng_mutex
static boost::mt19937 rng
void from_json(const nlohmann::json &aJson, KIID &aKIID)
static boost::uuids::string_generator stringGenerator
static boost::uuids::basic_random_generator< boost::mt19937 > randomGenerator
void to_json(nlohmann::json &aJson, const KIID &aKIID)
KICOMMON_API KIID niluuid
uint32_t timestamp_t
timestamp_t is our type to represent unique IDs for all kinds of elements; historically simply the ti...