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 Wayne Stambaugh <stambaughw@gmail.com>
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 
51 class LIB_ID
52 {
53 public:
54 
55  LIB_ID() {}
56 
67  LIB_ID( const UTF8& aId );
68 
69  LIB_ID( const wxString& aId );
70 
73 
84  LIB_ID( const wxString& aLibName, const wxString& aLibItemName,
85  const wxString& aRevision = wxEmptyString );
86 
95  int Parse( const UTF8& aId );
96 
97 
101  const UTF8& GetLibNickname() const
102  {
103  return nickname;
104  }
105 
113  int SetLibNickname( const UTF8& aNickname );
114 
118  const UTF8& GetLibItemName() const { return item_name; }
119 
125  const wxString GetUniStringLibItemName() const { return item_name.wx_str(); }
126 
134  int SetLibItemName( const UTF8& aLibItemName, bool aTestForRev = true );
135 
136  int SetRevision( const UTF8& aRevision );
137 
138  const UTF8& GetRevision() const { return revision; }
139 
140  UTF8 GetLibItemNameAndRev() const;
141 
145  UTF8 Format() const;
146 
152  wxString GetUniStringLibId() const
153  {
154  return Format().wx_str();
155  }
156 
163  static UTF8 Format( const UTF8& aLibNickname, const UTF8& aLibItemName,
164  const UTF8& aRevision = "" );
165 
175  bool IsValid() const { return !nickname.empty() && !item_name.empty(); }
176 
180  bool IsLegacy() const { return nickname.empty() && !item_name.empty() && revision.empty(); }
181 
185  void clear();
186 
190  bool empty() const { return nickname.empty() && item_name.empty() && revision.empty(); }
191 
200  int compare( const LIB_ID& aLibId ) const;
201 
202  bool operator < ( const LIB_ID& aLibId ) const { return this->compare( aLibId ) < 0; }
203  bool operator > ( const LIB_ID& aLibId ) const { return this->compare( aLibId ) > 0; }
204  bool operator ==( const LIB_ID& aLibId ) const { return this->compare( aLibId ) == 0; }
205  bool operator !=( const LIB_ID& aLibId ) const { return !(*this == aLibId); }
206 
214  static bool HasIllegalChars( const UTF8& aLibItemName, LIB_ID_TYPE aType );
215 
223  static UTF8 FixIllegalChars( const UTF8& aLibItemName, LIB_ID_TYPE aType );
224 
232  static unsigned FindIllegalChar( const UTF8& aNickname, LIB_ID_TYPE aType );
233 
234 #if defined(DEBUG)
235  static void Test();
236 #endif
237 
238 protected:
243  static bool isLegalChar( unsigned aUniChar, LIB_ID_TYPE aType );
244 
248 };
249 
250 
251 #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
Definition: lib_id.h:175
bool operator>(const LIB_ID &aLibId) const
Definition: lib_id.h:203
Class UTF8 is an 8 bit string that is assuredly encoded in UTF8, and supplies special conversion supp...
Definition: utf8.h:73
const wxString GetUniStringLibItemName() const
Definition: lib_id.h:125
bool empty() const
Definition: lib_id.h:190
UTF8 revision
The revision of the entry.
Definition: lib_id.h:247
bool operator!=(const LIB_ID &aLibId) const
Definition: lib_id.h:205
bool operator<(const LIB_ID &aLibId) const
Definition: lib_id.h:202
static bool isLegalChar(unsigned aUniChar, LIB_ID_TYPE aType)
Tests whether a unicode character is a legal LIB_ID character note: aUniChar is expected to be a unic...
Definition: lib_id.cpp:406
bool IsLegacy() const
Definition: lib_id.h:180
int Parse(const UTF8 &aId)
Parse LIB_ID with the information from aId.
Definition: lib_id.cpp:122
static UTF8 FixIllegalChars(const UTF8 &aLibItemName, LIB_ID_TYPE aType)
Replace illegal LIB_ID item name characters with underscores &#39;_&#39;.
Definition: lib_id.cpp:374
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:51
UTF8 GetLibItemNameAndRev() const
Definition: lib_id.cpp:285
wxString GetUniStringLibId() const
Definition: lib_id.h:152
static unsigned FindIllegalChar(const UTF8 &aNickname, LIB_ID_TYPE aType)
Looks for characters that are illegal in library and item names.
Definition: lib_id.cpp:388
static bool HasIllegalChars(const UTF8 &aLibItemName, LIB_ID_TYPE aType)
Examine aLibItemName for invalid LIB_ID item name characters.
Definition: lib_id.cpp:362
const UTF8 & GetRevision() const
Definition: lib_id.h:138
wxString wx_str() const
Definition: utf8.cpp:48
bool operator==(const LIB_ID &aLibId) const
Definition: lib_id.h:204
bool empty() const
Definition: utf8.h:108
const UTF8 & GetLibItemName() const
Definition: lib_id.h:118
UTF8 item_name
The name of the entry in the logical library.
Definition: lib_id.h:246
int SetRevision(const UTF8 &aRevision)
Definition: lib_id.cpp:250
UTF8 nickname
The nickname of the library or empty.
Definition: lib_id.h:245
void clear()
Clear the contents of the library nickname, library entry name, and revision strings.
Definition: lib_id.cpp:114
int SetLibItemName(const UTF8 &aLibItemName, bool aTestForRev=true)
Override the library item name portion of the LIB_ID to aLibItemName.
Definition: lib_id.cpp:232
int SetLibNickname(const UTF8 &aNickname)
Override the logical library name portion of the LIB_ID to aNickname.
Definition: lib_id.cpp:219
LIB_ID_TYPE
Types of library identifiers
Definition: lib_id.h:72
LIB_ID()
Definition: lib_id.h:55
UTF8 Format() const
Definition: lib_id.cpp:263
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
Definition: lib_id.h:101