KiCad PCB EDA Suite
KIID Class Reference

#include <kiid.h>

Public Member Functions

 KIID ()
 
 KIID (int null)
 
 KIID (const wxString &aString)
 
 KIID (timestamp_t aTimestamp)
 
void Clone (const KIID &aUUID)
 
size_t Hash () const
 
bool IsLegacyTimestamp () const
 
timestamp_t AsLegacyTimestamp () const
 
wxString AsString () const
 
wxString AsLegacyTimestampString () const
 
void ConvertTimestampToUuid ()
 Change an existing time stamp based UUID into a true UUID. More...
 
bool operator== (KIID const &rhs) const
 
bool operator!= (KIID const &rhs) const
 
bool operator< (KIID const &rhs) const
 

Static Public Member Functions

static bool SniffTest (const wxString &aCandidate)
 

Private Attributes

boost::uuids::uuid m_uuid
 
timestamp_t m_cached_timestamp
 

Detailed Description

Definition at line 44 of file kiid.h.

Constructor & Destructor Documentation

◆ KIID() [1/4]

KIID::KIID ( )

Definition at line 51 of file kiid.cpp.

52 {
53 }
boost::uuids::uuid m_uuid
Definition: kiid.h:87
timestamp_t m_cached_timestamp
Definition: kiid.h:89
static boost::uuids::random_generator randomGenerator
Definition: kiid.cpp:34

◆ KIID() [2/4]

KIID::KIID ( int  null)

Definition at line 56 of file kiid.cpp.

57 {
58  wxASSERT( null == 0 );
59 }
boost::uuids::uuid m_uuid
Definition: kiid.h:87
timestamp_t m_cached_timestamp
Definition: kiid.h:89
static boost::uuids::nil_generator nilGenerator
Definition: kiid.cpp:38

◆ KIID() [3/4]

KIID::KIID ( const wxString &  aString)

Definition at line 62 of file kiid.cpp.

62  : m_uuid(), m_cached_timestamp( 0 )
63 {
64  if( aString.length() == 8 )
65  {
66  // A legacy-timestamp-based UUID has only the last 4 octets filled in.
67  // Convert them individually to avoid stepping in the little-endian/big-endian
68  // doo-doo.
69  for( int i = 0; i < 4; ++i )
70  {
71  wxString octet = aString.substr( i * 2, 2 );
72  m_uuid.data[i + 12] = strtol( octet.data(), NULL, 16 );
73  }
74 
75  m_cached_timestamp = strtol( aString.c_str(), NULL, 16 );
76  }
77  else
78  {
79  try
80  {
81  m_uuid = stringGenerator( aString.wc_str() );
82 
83  if( IsLegacyTimestamp() )
84  m_cached_timestamp = strtol( aString.substr( 28 ).c_str(), NULL, 16 );
85  }
86  catch( ... )
87  {
88  // Failed to parse string representation; best we can do is assign a new
89  // random one.
91  }
92  }
93 }
boost::uuids::uuid m_uuid
Definition: kiid.h:87
bool IsLegacyTimestamp() const
Definition: kiid.cpp:141
timestamp_t m_cached_timestamp
Definition: kiid.h:89
#define NULL
static boost::uuids::random_generator randomGenerator
Definition: kiid.cpp:34
static boost::uuids::string_generator stringGenerator
Definition: kiid.cpp:37

References IsLegacyTimestamp(), m_cached_timestamp, m_uuid, NULL, randomGenerator, and stringGenerator.

◆ KIID() [4/4]

KIID::KIID ( timestamp_t  aTimestamp)

Definition at line 124 of file kiid.cpp.

125 {
126  m_cached_timestamp = aTimestamp;
127 
128  // A legacy-timestamp-based UUID has only the last 4 octets filled in.
129  // Convert them individually to avoid stepping in the little-endian/big-endian
130  // doo-doo.
131  wxString str = AsLegacyTimestampString();
132 
133  for( int i = 0; i < 4; ++i )
134  {
135  wxString octet = str.substr( i * 2, 2 );
136  m_uuid.data[i + 12] = strtol( octet.data(), NULL, 16 );
137  }
138 }
boost::uuids::uuid m_uuid
Definition: kiid.h:87
timestamp_t m_cached_timestamp
Definition: kiid.h:89
#define NULL
wxString AsLegacyTimestampString() const
Definition: kiid.cpp:180

References AsLegacyTimestampString(), m_cached_timestamp, m_uuid, and NULL.

Member Function Documentation

◆ AsLegacyTimestamp()

timestamp_t KIID::AsLegacyTimestamp ( ) const

Definition at line 147 of file kiid.cpp.

148 {
149  return m_cached_timestamp;
150 }
timestamp_t m_cached_timestamp
Definition: kiid.h:89

References m_cached_timestamp.

Referenced by AsLegacyTimestampString(), SCH_LEGACY_PLUGIN::saveComponent(), and SCH_LEGACY_PLUGIN::saveSheet().

◆ AsLegacyTimestampString()

wxString KIID::AsLegacyTimestampString ( ) const

Definition at line 180 of file kiid.cpp.

181 {
182  return wxString::Format( "%8.8lX", (unsigned long) AsLegacyTimestamp() );
183 }
timestamp_t AsLegacyTimestamp() const
Definition: kiid.cpp:147
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:201

References AsLegacyTimestamp(), and Format().

Referenced by KIID(), and SCH_LEGACY_PLUGIN::saveComponent().

◆ AsString()

◆ Clone()

void KIID::Clone ( const KIID aUUID)

Definition at line 167 of file kiid.cpp.

168 {
169  m_uuid = aUUID.m_uuid;
171 }
boost::uuids::uuid m_uuid
Definition: kiid.h:87
timestamp_t m_cached_timestamp
Definition: kiid.h:89

References m_cached_timestamp, and m_uuid.

◆ ConvertTimestampToUuid()

void KIID::ConvertTimestampToUuid ( )

Change an existing time stamp based UUID into a true UUID.

If this is not a time stamp based UUID, then no change is made.

Definition at line 186 of file kiid.cpp.

187 {
188  if( !IsLegacyTimestamp() )
189  return;
190 
191  m_cached_timestamp = 0;
193 }
boost::uuids::uuid m_uuid
Definition: kiid.h:87
bool IsLegacyTimestamp() const
Definition: kiid.cpp:141
timestamp_t m_cached_timestamp
Definition: kiid.h:89
static boost::uuids::random_generator randomGenerator
Definition: kiid.cpp:34

References IsLegacyTimestamp(), m_cached_timestamp, m_uuid, and randomGenerator.

◆ Hash()

size_t KIID::Hash ( ) const

Definition at line 153 of file kiid.cpp.

154 {
155  size_t hash = 0;
156 
157  // Note: this is NOT little-endian/big-endian safe, but as long as it's just used
158  // at runtime it won't matter.
159 
160  for( int i = 0; i < 4; ++i )
161  boost::hash_combine( hash, reinterpret_cast<const uint32_t*>( m_uuid.data )[i] );
162 
163  return hash;
164 }
boost::uuids::uuid m_uuid
Definition: kiid.h:87
static void hash_combine(std::size_t &seed)
This is a dummy function to take the final case of hash_combine below.
Definition: hash_eda.h:64

References hash_combine(), and m_uuid.

◆ IsLegacyTimestamp()

bool KIID::IsLegacyTimestamp ( ) const

Definition at line 141 of file kiid.cpp.

142 {
143  return !m_uuid.data[8] && !m_uuid.data[9] && !m_uuid.data[10] && !m_uuid.data[11];
144 }
boost::uuids::uuid m_uuid
Definition: kiid.h:87

References m_uuid.

Referenced by ConvertTimestampToUuid(), and KIID().

◆ operator!=()

bool KIID::operator!= ( KIID const &  rhs) const
inline

Definition at line 76 of file kiid.h.

77  {
78  return m_uuid != rhs.m_uuid;
79  }
boost::uuids::uuid m_uuid
Definition: kiid.h:87

References m_uuid.

◆ operator<()

bool KIID::operator< ( KIID const &  rhs) const
inline

Definition at line 81 of file kiid.h.

82  {
83  return m_uuid < rhs.m_uuid;
84  }
boost::uuids::uuid m_uuid
Definition: kiid.h:87

References m_uuid.

◆ operator==()

bool KIID::operator== ( KIID const &  rhs) const
inline

Definition at line 71 of file kiid.h.

72  {
73  return m_uuid == rhs.m_uuid;
74  }
boost::uuids::uuid m_uuid
Definition: kiid.h:87

References m_uuid.

◆ SniffTest()

bool KIID::SniffTest ( const wxString &  aCandidate)
static

Definition at line 96 of file kiid.cpp.

97 {
98  static wxString niluuidStr = niluuid.AsString();
99 
100  if( aCandidate.Length() != niluuidStr.Length() )
101  return false;
102 
103  for( wxChar c : aCandidate )
104  {
105  if( c >= '0' && c <= '9' )
106  continue;
107 
108  if( c >= 'a' && c <= 'f' )
109  continue;
110 
111  if( c >= 'A' && c <= 'F' )
112  continue;
113 
114  if( c == '-' )
115  continue;
116 
117  return false;
118  }
119 
120  return true;
121 }
KIID niluuid(0)
wxString AsString() const
Definition: kiid.cpp:174

References AsString(), and niluuid.

Referenced by insideArea().

Member Data Documentation

◆ m_cached_timestamp

timestamp_t KIID::m_cached_timestamp
private

Definition at line 89 of file kiid.h.

Referenced by AsLegacyTimestamp(), Clone(), ConvertTimestampToUuid(), and KIID().

◆ m_uuid

boost::uuids::uuid KIID::m_uuid
private

The documentation for this class was generated from the following files: