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
 
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 59 of file kiid.cpp.

60 {
62 
63 #if BOOST_VERSION >= 106700
64  try
65  {
66 #endif
67 
69 
70 #if BOOST_VERSION >= 106700
71  }
72  catch( const boost::uuids::entropy_error& )
73  {
74  wxLogFatalError( "A Boost UUID entropy exception was thrown in %s:%s.",
75  __FILE__, __FUNCTION__ );
76  }
77 #endif
78 }
boost::uuids::uuid m_uuid
Definition: kiid.h:92
timestamp_t m_cached_timestamp
Definition: kiid.h:94
static boost::uuids::random_generator randomGenerator
Definition: kiid.cpp:41

References m_cached_timestamp, m_uuid, and randomGenerator.

◆ KIID() [2/4]

KIID::KIID ( int  null)

Definition at line 81 of file kiid.cpp.

82 {
83  wxASSERT( null == 0 );
84 }
boost::uuids::uuid m_uuid
Definition: kiid.h:92
timestamp_t m_cached_timestamp
Definition: kiid.h:94
static boost::uuids::nil_generator nilGenerator
Definition: kiid.cpp:45

◆ KIID() [3/4]

KIID::KIID ( const wxString &  aString)

Definition at line 87 of file kiid.cpp.

87  : m_uuid(), m_cached_timestamp( 0 )
88 {
89  if( aString.length() == 8 )
90  {
91  // A legacy-timestamp-based UUID has only the last 4 octets filled in.
92  // Convert them individually to avoid stepping in the little-endian/big-endian
93  // doo-doo.
94  for( int i = 0; i < 4; ++i )
95  {
96  wxString octet = aString.substr( i * 2, 2 );
97  m_uuid.data[i + 12] = strtol( octet.data(), NULL, 16 );
98  }
99 
100  m_cached_timestamp = strtol( aString.c_str(), NULL, 16 );
101  }
102  else
103  {
104  try
105  {
106  m_uuid = stringGenerator( aString.wc_str() );
107 
108  if( IsLegacyTimestamp() )
109  m_cached_timestamp = strtol( aString.substr( 28 ).c_str(), NULL, 16 );
110  }
111  catch( ... )
112  {
113  // Failed to parse string representation; best we can do is assign a new
114  // random one.
115 #if BOOST_VERSION >= 106700
116  try
117  {
118 #endif
119 
121 
122 #if BOOST_VERSION >= 106700
123  }
124  catch( const boost::uuids::entropy_error& )
125  {
126  wxLogFatalError( "A Boost UUID entropy exception was thrown in %s:%s.",
127  __FILE__, __FUNCTION__ );
128  }
129 #endif
130  }
131  }
132 }
boost::uuids::uuid m_uuid
Definition: kiid.h:92
bool IsLegacyTimestamp() const
Definition: kiid.cpp:180
timestamp_t m_cached_timestamp
Definition: kiid.h:94
#define NULL
static boost::uuids::random_generator randomGenerator
Definition: kiid.cpp:41
static boost::uuids::string_generator stringGenerator
Definition: kiid.cpp:44

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

◆ KIID() [4/4]

KIID::KIID ( timestamp_t  aTimestamp)

Definition at line 163 of file kiid.cpp.

164 {
165  m_cached_timestamp = aTimestamp;
166 
167  // A legacy-timestamp-based UUID has only the last 4 octets filled in.
168  // Convert them individually to avoid stepping in the little-endian/big-endian
169  // doo-doo.
170  wxString str = AsLegacyTimestampString();
171 
172  for( int i = 0; i < 4; ++i )
173  {
174  wxString octet = str.substr( i * 2, 2 );
175  m_uuid.data[i + 12] = strtol( octet.data(), NULL, 16 );
176  }
177 }
boost::uuids::uuid m_uuid
Definition: kiid.h:92
timestamp_t m_cached_timestamp
Definition: kiid.h:94
#define NULL
wxString AsLegacyTimestampString() const
Definition: kiid.cpp:219

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

Member Function Documentation

◆ AsLegacyTimestamp()

timestamp_t KIID::AsLegacyTimestamp ( ) const

Definition at line 186 of file kiid.cpp.

187 {
188  return m_cached_timestamp;
189 }
timestamp_t m_cached_timestamp
Definition: kiid.h:94

References m_cached_timestamp.

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

◆ AsLegacyTimestampString()

wxString KIID::AsLegacyTimestampString ( ) const

Definition at line 219 of file kiid.cpp.

220 {
221  return wxString::Format( "%8.8lX", (unsigned long) AsLegacyTimestamp() );
222 }
timestamp_t AsLegacyTimestamp() const
Definition: kiid.cpp:186
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200

References AsLegacyTimestamp(), and Format().

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

◆ AsString()

◆ Clone()

void KIID::Clone ( const KIID aUUID)

Definition at line 206 of file kiid.cpp.

207 {
208  m_uuid = aUUID.m_uuid;
210 }
boost::uuids::uuid m_uuid
Definition: kiid.h:92
timestamp_t m_cached_timestamp
Definition: kiid.h:94

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 225 of file kiid.cpp.

226 {
227  if( !IsLegacyTimestamp() )
228  return;
229 
230  m_cached_timestamp = 0;
232 }
boost::uuids::uuid m_uuid
Definition: kiid.h:92
bool IsLegacyTimestamp() const
Definition: kiid.cpp:180
timestamp_t m_cached_timestamp
Definition: kiid.h:94
static boost::uuids::random_generator randomGenerator
Definition: kiid.cpp:41

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

◆ Hash()

size_t KIID::Hash ( ) const

Definition at line 192 of file kiid.cpp.

193 {
194  size_t hash = 0;
195 
196  // Note: this is NOT little-endian/big-endian safe, but as long as it's just used
197  // at runtime it won't matter.
198 
199  for( int i = 0; i < 4; ++i )
200  boost::hash_combine( hash, reinterpret_cast<const uint32_t*>( m_uuid.data )[i] );
201 
202  return hash;
203 }
boost::uuids::uuid m_uuid
Definition: kiid.h:92
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:67

References hash_combine(), and m_uuid.

◆ IsLegacyTimestamp()

bool KIID::IsLegacyTimestamp ( ) const

Definition at line 180 of file kiid.cpp.

181 {
182  return !m_uuid.data[8] && !m_uuid.data[9] && !m_uuid.data[10] && !m_uuid.data[11];
183 }
boost::uuids::uuid m_uuid
Definition: kiid.h:92

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:92

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:92

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:92

References m_uuid.

◆ operator>()

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

Definition at line 86 of file kiid.h.

87  {
88  return m_uuid > rhs.m_uuid;
89  }
boost::uuids::uuid m_uuid
Definition: kiid.h:92

References m_uuid.

◆ SniffTest()

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

Definition at line 135 of file kiid.cpp.

136 {
137  static wxString niluuidStr = niluuid.AsString();
138 
139  if( aCandidate.Length() != niluuidStr.Length() )
140  return false;
141 
142  for( wxChar c : aCandidate )
143  {
144  if( c >= '0' && c <= '9' )
145  continue;
146 
147  if( c >= 'a' && c <= 'f' )
148  continue;
149 
150  if( c >= 'A' && c <= 'F' )
151  continue;
152 
153  if( c == '-' )
154  continue;
155 
156  return false;
157  }
158 
159  return true;
160 }
KIID niluuid(0)
wxString AsString() const
Definition: kiid.cpp:213

References AsString(), and niluuid.

Referenced by insideArea().

Member Data Documentation

◆ m_cached_timestamp

timestamp_t KIID::m_cached_timestamp
private

Definition at line 94 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: