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)
 
static void CreateNilUuids (bool aNil=true)
 

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

62 {
64 
65 #if BOOST_VERSION >= 106700
66  try
67  {
68 #endif
69 
70  if( createNilUuids )
71  m_uuid = nilGenerator();
72  else
74 
75 #if BOOST_VERSION >= 106700
76  }
77  catch( const boost::uuids::entropy_error& )
78  {
79  wxLogFatalError( "A Boost UUID entropy exception was thrown in %s:%s.",
80  __FILE__, __FUNCTION__ );
81  }
82 #endif
83 }
boost::uuids::uuid m_uuid
Definition: kiid.h:94
timestamp_t m_cached_timestamp
Definition: kiid.h:96
static boost::uuids::nil_generator nilGenerator
Definition: kiid.cpp:44
static boost::uuids::random_generator randomGenerator
Definition: kiid.cpp:40
static bool createNilUuids
Definition: kiid.cpp:50

References createNilUuids, m_cached_timestamp, m_uuid, nilGenerator, and randomGenerator.

◆ KIID() [2/4]

KIID::KIID ( int  null)

Definition at line 86 of file kiid.cpp.

87 {
88  wxASSERT( null == 0 );
89 }
boost::uuids::uuid m_uuid
Definition: kiid.h:94
timestamp_t m_cached_timestamp
Definition: kiid.h:96
static boost::uuids::nil_generator nilGenerator
Definition: kiid.cpp:44

◆ KIID() [3/4]

KIID::KIID ( const wxString &  aString)

Definition at line 92 of file kiid.cpp.

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

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

◆ KIID() [4/4]

KIID::KIID ( timestamp_t  aTimestamp)

Definition at line 168 of file kiid.cpp.

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

References AsLegacyTimestampString(), m_cached_timestamp, and m_uuid.

Member Function Documentation

◆ AsLegacyTimestamp()

timestamp_t KIID::AsLegacyTimestamp ( ) const

Definition at line 191 of file kiid.cpp.

192 {
193  return m_cached_timestamp;
194 }
timestamp_t m_cached_timestamp
Definition: kiid.h:96

References m_cached_timestamp.

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

◆ AsLegacyTimestampString()

wxString KIID::AsLegacyTimestampString ( ) const

Definition at line 224 of file kiid.cpp.

225 {
226  return wxString::Format( "%8.8lX", (unsigned long) AsLegacyTimestamp() );
227 }
timestamp_t AsLegacyTimestamp() const
Definition: kiid.cpp:191
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::saveSymbol().

◆ AsString()

◆ Clone()

void KIID::Clone ( const KIID aUUID)

Definition at line 211 of file kiid.cpp.

212 {
213  m_uuid = aUUID.m_uuid;
215 }
boost::uuids::uuid m_uuid
Definition: kiid.h:94
timestamp_t m_cached_timestamp
Definition: kiid.h:96

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

231 {
232  if( !IsLegacyTimestamp() )
233  return;
234 
235  m_cached_timestamp = 0;
237 }
boost::uuids::uuid m_uuid
Definition: kiid.h:94
bool IsLegacyTimestamp() const
Definition: kiid.cpp:185
timestamp_t m_cached_timestamp
Definition: kiid.h:96
static boost::uuids::random_generator randomGenerator
Definition: kiid.cpp:40

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

◆ CreateNilUuids()

void KIID::CreateNilUuids ( bool  aNil = true)
static

Definition at line 240 of file kiid.cpp.

241 {
242  createNilUuids = aNil;
243 }
static bool createNilUuids
Definition: kiid.cpp:50

References createNilUuids.

Referenced by FOOTPRINT_ASYNC_LOADER::Abort(), SYMBOL_TREE_MODEL_ADAPTER::AddLibraries(), and FOOTPRINT_ASYNC_LOADER::Start().

◆ Hash()

size_t KIID::Hash ( ) const

Definition at line 197 of file kiid.cpp.

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

186 {
187  return !m_uuid.data[8] && !m_uuid.data[9] && !m_uuid.data[10] && !m_uuid.data[11];
188 }
boost::uuids::uuid m_uuid
Definition: kiid.h:94

References m_uuid.

Referenced by ConvertTimestampToUuid(), and KIID().

◆ operator!=()

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

Definition at line 78 of file kiid.h.

79  {
80  return m_uuid != rhs.m_uuid;
81  }
boost::uuids::uuid m_uuid
Definition: kiid.h:94

References m_uuid.

◆ operator<()

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

Definition at line 83 of file kiid.h.

84  {
85  return m_uuid < rhs.m_uuid;
86  }
boost::uuids::uuid m_uuid
Definition: kiid.h:94

References m_uuid.

◆ operator==()

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

Definition at line 73 of file kiid.h.

74  {
75  return m_uuid == rhs.m_uuid;
76  }
boost::uuids::uuid m_uuid
Definition: kiid.h:94

References m_uuid.

◆ operator>()

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

Definition at line 88 of file kiid.h.

89  {
90  return m_uuid > rhs.m_uuid;
91  }
boost::uuids::uuid m_uuid
Definition: kiid.h:94

References m_uuid.

◆ SniffTest()

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

Definition at line 140 of file kiid.cpp.

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

References AsString(), and niluuid.

Referenced by insideArea().

Member Data Documentation

◆ m_cached_timestamp

timestamp_t KIID::m_cached_timestamp
private

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