KiCad PCB EDA Suite
KIID Class Reference

#include <common.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
 

Private Attributes

boost::uuids::uuid m_uuid
 
timestamp_t m_cached_timestamp
 

Detailed Description

Definition at line 68 of file common.h.

Constructor & Destructor Documentation

◆ KIID() [1/4]

KIID::KIID ( )

Definition at line 64 of file common.cpp.

64  :
67 {
68 }
boost::uuids::uuid m_uuid
Definition: common.h:109
timestamp_t m_cached_timestamp
Definition: common.h:111
static boost::uuids::random_generator randomGenerator
Definition: common.cpp:46

◆ KIID() [2/4]

KIID::KIID ( int  null)

Definition at line 71 of file common.cpp.

71  :
72  m_uuid( nilGenerator() ),
74 {
75  wxASSERT( null == 0 );
76 }
boost::uuids::uuid m_uuid
Definition: common.h:109
static boost::uuids::nil_generator nilGenerator
Definition: common.cpp:50
timestamp_t m_cached_timestamp
Definition: common.h:111

◆ KIID() [3/4]

KIID::KIID ( const wxString &  aString)

Definition at line 79 of file common.cpp.

79  :
80  m_uuid(),
82 {
83  if( aString.length() == 8 )
84  {
85  // A legacy-timestamp-based UUID has only the last 4 octets filled in.
86  // Convert them individually to avoid stepping in the little-endian/big-endian
87  // doo-doo.
88  for( int i = 0; i < 4; ++i )
89  {
90  wxString octet = aString.substr( i * 2, 2 );
91  m_uuid.data[ i + 12 ] = strtol( octet.data(), NULL, 16 );
92  }
93 
94  m_cached_timestamp = strtol( aString.c_str(), NULL, 16 );
95  }
96  else
97  {
98  try
99  {
100  m_uuid = stringGenerator( aString.wc_str() );
101 
102  if( IsLegacyTimestamp() )
103  m_cached_timestamp = strtol( aString.substr( 28 ).c_str(), NULL, 16 );
104  }
105  catch( ... )
106  {
107  // Failed to parse string representation; best we can do is assign a new
108  // random one.
110  }
111  }
112 }
static boost::uuids::string_generator stringGenerator
Definition: common.cpp:49
boost::uuids::uuid m_uuid
Definition: common.h:109
bool IsLegacyTimestamp() const
Definition: common.cpp:132
timestamp_t m_cached_timestamp
Definition: common.h:111
#define NULL
static boost::uuids::random_generator randomGenerator
Definition: common.cpp:46

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

◆ KIID() [4/4]

KIID::KIID ( timestamp_t  aTimestamp)

Definition at line 115 of file common.cpp.

116 {
117  m_cached_timestamp = aTimestamp;
118 
119  // A legacy-timestamp-based UUID has only the last 4 octets filled in.
120  // Convert them individually to avoid stepping in the little-endian/big-endian
121  // doo-doo.
122  wxString str = AsLegacyTimestampString();
123 
124  for( int i = 0; i < 4; ++i )
125  {
126  wxString octet = str.substr( i * 2, 2 );
127  m_uuid.data[ i + 12 ] = strtol( octet.data(), NULL, 16 );
128  }
129 }
boost::uuids::uuid m_uuid
Definition: common.h:109
timestamp_t m_cached_timestamp
Definition: common.h:111
#define NULL
wxString AsLegacyTimestampString() const
Definition: common.cpp:171

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

Member Function Documentation

◆ AsLegacyTimestamp()

timestamp_t KIID::AsLegacyTimestamp ( ) const

Definition at line 138 of file common.cpp.

139 {
140  return m_cached_timestamp;
141 }
timestamp_t m_cached_timestamp
Definition: common.h:111

References m_cached_timestamp.

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

◆ AsLegacyTimestampString()

wxString KIID::AsLegacyTimestampString ( ) const

Definition at line 171 of file common.cpp.

172 {
173  return wxString::Format( "%8.8lX", (unsigned long) AsLegacyTimestamp() );
174 }
timestamp_t AsLegacyTimestamp() const
Definition: common.cpp:138
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:205

References AsLegacyTimestamp(), and Format().

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

◆ AsString()

◆ Clone()

void KIID::Clone ( const KIID aUUID)

Definition at line 158 of file common.cpp.

159 {
160  m_uuid = aUUID.m_uuid;
162 }
boost::uuids::uuid m_uuid
Definition: common.h:109
timestamp_t m_cached_timestamp
Definition: common.h:111

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 177 of file common.cpp.

178 {
179  if( !IsLegacyTimestamp() )
180  return;
181 
182  m_cached_timestamp = 0;
184 }
boost::uuids::uuid m_uuid
Definition: common.h:109
bool IsLegacyTimestamp() const
Definition: common.cpp:132
timestamp_t m_cached_timestamp
Definition: common.h:111
static boost::uuids::random_generator randomGenerator
Definition: common.cpp:46

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

◆ Hash()

size_t KIID::Hash ( ) const

Definition at line 144 of file common.cpp.

145 {
146  size_t hash = 0;
147 
148  // Note: this is NOT little-endian/big-endian safe, but as long as it's just used
149  // at runtime it won't matter.
150 
151  for( int i = 0; i < 4; ++i )
152  boost::hash_combine( hash, reinterpret_cast<const uint32_t*>( m_uuid.data )[i] );
153 
154  return hash;
155 }
boost::uuids::uuid m_uuid
Definition: common.h:109
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 132 of file common.cpp.

133 {
134  return !m_uuid.data[8] && !m_uuid.data[9] && !m_uuid.data[10] && !m_uuid.data[11];
135 }
boost::uuids::uuid m_uuid
Definition: common.h:109

References m_uuid.

Referenced by ConvertTimestampToUuid(), and KIID().

◆ operator!=()

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

Definition at line 98 of file common.h.

99  {
100  return m_uuid != rhs.m_uuid;
101  }
boost::uuids::uuid m_uuid
Definition: common.h:109

References m_uuid.

◆ operator<()

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

Definition at line 103 of file common.h.

104  {
105  return m_uuid < rhs.m_uuid;
106  }
boost::uuids::uuid m_uuid
Definition: common.h:109

References m_uuid.

◆ operator==()

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

Definition at line 93 of file common.h.

94  {
95  return m_uuid == rhs.m_uuid;
96  }
boost::uuids::uuid m_uuid
Definition: common.h:109

References m_uuid.

Member Data Documentation

◆ m_cached_timestamp

timestamp_t KIID::m_cached_timestamp
private

Definition at line 111 of file common.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: