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

56  :
59 {
60 }
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 63 of file common.cpp.

63  :
64  m_uuid( nilGenerator() ),
66 {
67  wxASSERT( null == 0 );
68 }
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 71 of file common.cpp.

71  :
72  m_uuid(),
74 {
75  if( aString.length() == 8 )
76  {
77  // A legacy-timestamp-based UUID has only the last 4 octets filled in.
78  // Convert them individually to avoid stepping in the little-endian/big-endian
79  // doo-doo.
80  for( int i = 0; i < 4; ++i )
81  {
82  wxString octet = aString.substr( i * 2, 2 );
83  m_uuid.data[ i + 12 ] = strtol( octet.data(), NULL, 16 );
84  }
85 
86  m_cached_timestamp = strtol( aString.c_str(), NULL, 16 );
87  }
88  else
89  {
90  try
91  {
92  m_uuid = stringGenerator( aString.wc_str() );
93 
94  if( IsLegacyTimestamp() )
95  m_cached_timestamp = strtol( aString.substr( 28 ).c_str(), NULL, 16 );
96  }
97  catch( ... )
98  {
99  // Failed to parse string representation; best we can do is assign a new
100  // random one.
102  }
103  }
104 }
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:124
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 107 of file common.cpp.

108 {
109  m_cached_timestamp = aTimestamp;
110 
111  // A legacy-timestamp-based UUID has only the last 4 octets filled in.
112  // Convert them individually to avoid stepping in the little-endian/big-endian
113  // doo-doo.
114  wxString str = AsLegacyTimestampString();
115 
116  for( int i = 0; i < 4; ++i )
117  {
118  wxString octet = str.substr( i * 2, 2 );
119  m_uuid.data[ i + 12 ] = strtol( octet.data(), NULL, 16 );
120  }
121 }
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:163

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

Member Function Documentation

◆ AsLegacyTimestamp()

timestamp_t KIID::AsLegacyTimestamp ( ) const

Definition at line 130 of file common.cpp.

131 {
132  return m_cached_timestamp;
133 }
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 163 of file common.cpp.

164 {
165  return wxString::Format( "%8.8lX", (unsigned long) AsLegacyTimestamp() );
166 }
timestamp_t AsLegacyTimestamp() const
Definition: common.cpp:130
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 150 of file common.cpp.

151 {
152  m_uuid = aUUID.m_uuid;
154 }
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 169 of file common.cpp.

170 {
171  if( !IsLegacyTimestamp() )
172  return;
173 
174  m_cached_timestamp = 0;
176 }
boost::uuids::uuid m_uuid
Definition: common.h:109
bool IsLegacyTimestamp() const
Definition: common.cpp:124
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 136 of file common.cpp.

137 {
138  size_t hash = 0;
139 
140  // Note: this is NOT little-endian/big-endian safe, but as long as it's just used
141  // at runtime it won't matter.
142 
143  for( int i = 0; i < 4; ++i )
144  boost::hash_combine( hash, reinterpret_cast<const uint32_t*>( m_uuid.data )[i] );
145 
146  return hash;
147 }
boost::uuids::uuid m_uuid
Definition: common.h:109

References m_uuid.

◆ IsLegacyTimestamp()

bool KIID::IsLegacyTimestamp ( ) const

Definition at line 124 of file common.cpp.

125 {
126  return !m_uuid.data[8] && !m_uuid.data[9] && !m_uuid.data[10] && !m_uuid.data[11];
127 }
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: