KiCad PCB EDA Suite
kiid.h
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2020 Ian McInerney <ian.s.mcinerney@ieee.org>
5  * Copyright (C) 2007-2014 Jean-Pierre Charras, jp.charras at wanadoo.fr
6  * Copyright (C) 1992-2020 KiCad Developers, see CHANGELOG.TXT for contributors.
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, you may find one here:
20  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21  * or you may search the http://www.gnu.org website for the version 2 license,
22  * or you may write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24  */
25 
26 #ifndef KIID_H
27 #define KIID_H
28 
29 #include <boost/uuid/uuid.hpp>
30 #include <macros_swig.h>
31 
32 class wxString;
33 
42 typedef uint32_t timestamp_t;
43 
44 class KIID
45 {
46 public:
47  KIID();
48  KIID( int null );
49  KIID( const wxString& aString );
50  KIID( timestamp_t aTimestamp );
51 
52  void Clone( const KIID& aUUID );
53 
54  size_t Hash() const;
55 
56  bool IsLegacyTimestamp() const;
58 
59  wxString AsString() const;
60  wxString AsLegacyTimestampString() const;
61 
62  static bool SniffTest( const wxString& aCandidate );
63 
64  static void CreateNilUuids( bool aNil = true );
65 
72 
73  bool operator==( KIID const& rhs ) const
74  {
75  return m_uuid == rhs.m_uuid;
76  }
77 
78  bool operator!=( KIID const& rhs ) const
79  {
80  return m_uuid != rhs.m_uuid;
81  }
82 
83  bool operator<( KIID const& rhs ) const
84  {
85  return m_uuid < rhs.m_uuid;
86  }
87 
88  bool operator>( KIID const& rhs ) const
89  {
90  return m_uuid > rhs.m_uuid;
91  }
92 
93 private:
94  boost::uuids::uuid m_uuid;
95 
97 };
98 
99 
100 extern KIID niluuid;
101 
102 KIID& NilUuid();
103 
104 // declare KIID_VECT_LIST as std::vector<KIID> both for c++ and swig:
105 DECL_VEC_FOR_SWIG( KIID_VECT_LIST, KIID )
106 
107 class KIID_PATH : public KIID_VECT_LIST
108 {
109 public:
111  {
112  }
113 
114  KIID_PATH( const wxString& aString );
115 
116  bool MakeRelativeTo( const KIID_PATH& aPath );
117 
118  wxString AsString() const;
119 
120  bool operator==( KIID_PATH const& rhs ) const
121  {
122  if( size() != rhs.size() )
123  return false;
124 
125  for( size_t i = 0; i < size(); ++i )
126  {
127  if( at( i ) != rhs.at( i ) )
128  return false;
129  }
130 
131  return true;
132  }
133 
134  bool operator<( KIID_PATH const& rhs ) const
135  {
136  if( size() != rhs.size() )
137  return size() < rhs.size();
138 
139  for( size_t i = 0; i < size(); ++i )
140  {
141  if( at( i ) < rhs.at( i ) )
142  return true;
143 
144  if( at( i ) != rhs.at( i ) )
145  return false;
146  }
147 
148  return false;
149  }
150 };
151 
152 #endif // KIID_H
KIID()
Definition: kiid.cpp:61
bool operator>(KIID const &rhs) const
Definition: kiid.h:88
bool operator!=(KIID const &rhs) const
Definition: kiid.h:78
bool operator==(KIID const &rhs) const
Definition: kiid.h:73
wxString AsString() const
Definition: kiid.cpp:218
boost::uuids::uuid m_uuid
Definition: kiid.h:94
KIID niluuid
bool operator==(KIID_PATH const &rhs) const
Definition: kiid.h:120
bool IsLegacyTimestamp() const
Definition: kiid.cpp:185
timestamp_t m_cached_timestamp
Definition: kiid.h:96
bool operator<(KIID const &rhs) const
Definition: kiid.h:83
Definition: kiid.h:44
size_t Hash() const
Definition: kiid.cpp:197
KIID & NilUuid()
Definition: kiid.cpp:54
KIID_PATH()
Definition: kiid.h:110
timestamp_t AsLegacyTimestamp() const
Definition: kiid.cpp:191
static bool SniffTest(const wxString &aCandidate)
Definition: kiid.cpp:140
_OUT_STRING AsString(const std::string &aString)
Definition: sexpr.h:130
void ConvertTimestampToUuid()
Change an existing time stamp based UUID into a true UUID.
Definition: kiid.cpp:230
uint32_t timestamp_t
timestamp_t is our type to represent unique IDs for all kinds of elements; historically simply the ti...
Definition: kiid.h:32
void Clone(const KIID &aUUID)
Definition: kiid.cpp:211
wxString AsLegacyTimestampString() const
Definition: kiid.cpp:224
static void CreateNilUuids(bool aNil=true)
Definition: kiid.cpp:240
This file contains macros just for swig binding.
#define DECL_VEC_FOR_SWIG(TypeName, MemberType)
Declare a std::vector but no swig template.
Definition: macros_swig.h:50
bool operator<(KIID_PATH const &rhs) const
Definition: kiid.h:134