KiCad PCB EDA Suite
lib_id.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) 2010-2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
5  * Copyright (C) 2012-2017 Wayne Stambaugh <stambaughw@verizon.net>
6  * Copyright (C) 2010-2017 KiCad Developers, see change_log.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 _LIB_ID_H_
27 #define _LIB_ID_H_
28 
29 #include <richio.h>
30 #include <utf8.h>
31 
56 class LIB_ID
57 {
58 public:
59 
60  LIB_ID() {}
61 
73  LIB_ID( const UTF8& aId );
74 
75  LIB_ID( const wxString& aId );
76 
87  LIB_ID( const wxString& aLibName, const wxString& aLibItemName,
88  const wxString& aRevision = wxEmptyString );
89 
100  int Parse( const UTF8& aId );
101 
102 
108  const UTF8& GetLibNickname() const
109  {
110  return nickname;
111  }
112 
122  int SetLibNickname( const UTF8& aNickname );
123 
129  const UTF8& GetLibItemName() const { return item_name; }
130 
140  int SetLibItemName( const UTF8& aLibItemName, bool aTestForRev = true );
141 
142  int SetRevision( const UTF8& aRevision );
143 
144  const UTF8& GetRevision() const { return revision; }
145 
146  UTF8 GetLibItemNameAndRev() const;
147 
153  UTF8 Format() const;
154 
163  static UTF8 Format( const UTF8& aLibNickname, const UTF8& aLibItemName,
164  const UTF8& aRevision = "" );
165 
177  bool IsValid() const { return !nickname.empty() && !item_name.empty(); }
178 
184  bool IsLegacy() const { return nickname.empty() && !item_name.empty() && revision.empty(); }
185 
191  void clear();
192 
198  bool empty() const { return nickname.empty() && item_name.empty() && revision.empty(); }
199 
208  int compare( const LIB_ID& aLibId ) const;
209 
210  bool operator < ( const LIB_ID& aLibId ) const { return this->compare( aLibId ) < 0; }
211  bool operator > ( const LIB_ID& aLibId ) const { return this->compare( aLibId ) > 0; }
212  bool operator ==( const LIB_ID& aLibId ) const { return this->compare( aLibId ) == 0; }
213  bool operator !=( const LIB_ID& aLibId ) const { return !(*this == aLibId); }
214 
215 #if defined(DEBUG)
216  static void Test();
217 #endif
218 
219 protected:
223 };
224 
225 
226 #endif // _LIB_ID_H_
int compare(const LIB_ID &aLibId) const
Compare the contents of LIB_ID objects by performing a std::string comparison of the library nickname...
Definition: lib_id.cpp:342
bool IsValid() const
Function IsValid.
Definition: lib_id.h:177
bool operator>(const LIB_ID &aLibId) const
Definition: lib_id.h:211
Class UTF8 is an 8 bit string that is assuredly encoded in UTF8, and supplies special conversion supp...
Definition: utf8.h:73
bool empty() const
Function empty.
Definition: lib_id.h:198
UTF8 revision
The revision of the entry.
Definition: lib_id.h:222
bool operator!=(const LIB_ID &aLibId) const
Definition: lib_id.h:213
bool operator<(const LIB_ID &aLibId) const
Definition: lib_id.h:210
bool IsLegacy() const
Function IsLegacy.
Definition: lib_id.h:184
int Parse(const UTF8 &aId)
Function Parse.
Definition: lib_id.cpp:122
Class LIB_ID.
Definition: lib_id.h:56
UTF8 GetLibItemNameAndRev() const
Definition: lib_id.cpp:285
const UTF8 & GetRevision() const
Definition: lib_id.h:144
bool operator==(const LIB_ID &aLibId) const
Definition: lib_id.h:212
bool empty() const
Definition: utf8.h:108
const UTF8 & GetLibItemName() const
Function GetLibItemName.
Definition: lib_id.h:129
UTF8 item_name
The name of the entry in the logical library.
Definition: lib_id.h:221
int SetRevision(const UTF8 &aRevision)
Definition: lib_id.cpp:250
UTF8 nickname
The nickname of the library or empty.
Definition: lib_id.h:220
void clear()
Function clear.
Definition: lib_id.cpp:114
int SetLibItemName(const UTF8 &aLibItemName, bool aTestForRev=true)
Function SetLibItemName.
Definition: lib_id.cpp:232
int SetLibNickname(const UTF8 &aNickname)
Function SetLibNickname.
Definition: lib_id.cpp:219
LIB_ID()
Definition: lib_id.h:60
UTF8 Format() const
Function Format.
Definition: lib_id.cpp:263
const UTF8 & GetLibNickname() const
Function GetLibNickname.
Definition: lib_id.h:108