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-2020 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  LIB_ID() {}
55 
56  // NOTE: don't define any constructors which call Parse() on their arguments. We want it
57  // to be obvious to callers that parsing is involved (and that valid IDs are guaranteed in
58  // the presence of disallowed characters, malformed ids, etc.).
59 
69  LIB_ID( const wxString& aLibraryName, const wxString& aItemName );
70 
85  int Parse( const UTF8& aId, bool aFix = false );
86 
90  const UTF8& GetLibNickname() const { return m_libraryName; }
91 
99  int SetLibNickname( const UTF8& aNickname );
100 
104  const UTF8& GetLibItemName() const { return m_itemName; }
105 
114  const wxString GetUniStringLibItemName() const { return m_itemName.wx_str(); }
115 
123  int SetLibItemName( const UTF8& aLibItemName );
124 
128  UTF8 Format() const;
129 
134  wxString GetUniStringLibId() const
135  {
136  return Format().wx_str();
137  }
138 
145  static UTF8 Format( const UTF8& aLibraryName, const UTF8& aLibItemName );
146 
159  bool IsValid() const
160  {
161  return !m_libraryName.empty() && !m_itemName.empty();
162  }
163 
167  bool IsLegacy() const
168  {
169  return m_libraryName.empty() && !m_itemName.empty();
170  }
171 
175  void clear();
176 
180  bool empty() const
181  {
182  return m_libraryName.empty() && m_itemName.empty();
183  }
184 
192  int compare( const LIB_ID& aLibId ) const;
193 
194  bool operator < ( const LIB_ID& aLibId ) const { return this->compare( aLibId ) < 0; }
195  bool operator > ( const LIB_ID& aLibId ) const { return this->compare( aLibId ) > 0; }
196  bool operator ==( const LIB_ID& aLibId ) const { return this->compare( aLibId ) == 0; }
197  bool operator !=( const LIB_ID& aLibId ) const { return !(*this == aLibId); }
198 
205  static int HasIllegalChars( const UTF8& aLibItemName );
206 
214  static UTF8 FixIllegalChars( const UTF8& aLibItemName, bool aLib );
215 
222  static unsigned FindIllegalLibraryNameChar( const UTF8& aLibraryName );
223 
224 protected:
248  static bool isLegalChar( unsigned aUniChar );
249 
256  static bool isLegalLibraryNameChar( unsigned aUniChar );
257 
260 };
261 
262 
263 #endif // _LIB_ID_H_
An 8 bit string that is assuredly encoded in UTF8, and supplies special conversion support to and fro...
Definition: utf8.h:70
const UTF8 & GetLibItemName() const
Definition: lib_id.h:104
static UTF8 FixIllegalChars(const UTF8 &aLibItemName, bool aLib)
Replace illegal LIB_ID item name characters with underscores '_'.
Definition: lib_id.cpp:189
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:51
bool IsValid() const
Check if this LID_ID is valid.
Definition: lib_id.h:159
static bool isLegalLibraryNameChar(unsigned aUniChar)
Tests whether a Unicode character is a legal LIB_ID library nickname character.
Definition: lib_id.cpp:252
static bool isLegalChar(unsigned aUniChar)
Tests whether a Unicode character is a legal LIB_ID item name character.
Definition: lib_id.cpp:206
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:158
bool empty() const
Definition: lib_id.h:180
bool operator !=(const LIB_ID &aLibId) const
Definition: lib_id.h:197
bool operator >(const LIB_ID &aLibId) const
Definition: lib_id.h:195
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
Definition: lib_id.h:90
int SetLibItemName(const UTF8 &aLibItemName)
Override the library item name portion of the LIB_ID to aLibItemName.
Definition: lib_id.cpp:108
void clear()
Clear the contents of the library nickname, library entry name, and revision strings.
Definition: lib_id.cpp:42
UTF8 m_libraryName
The nickname of the library or empty.
Definition: lib_id.h:258
UTF8 Format() const
Definition: lib_id.cpp:116
int SetLibNickname(const UTF8 &aNickname)
Override the logical library name portion of the LIB_ID to aNickname.
Definition: lib_id.cpp:97
LIB_ID()
Definition: lib_id.h:54
int Parse(const UTF8 &aId, bool aFix=false)
Parse LIB_ID with the information from aId.
Definition: lib_id.cpp:49
static int HasIllegalChars(const UTF8 &aLibItemName)
Examine aLibItemName for invalid LIB_ID item name characters.
Definition: lib_id.cpp:173
wxString wx_str() const
Definition: utf8.cpp:46
bool operator<(const LIB_ID &aLibId) const
Definition: lib_id.h:194
UTF8 m_itemName
The name of the entry in the logical library.
Definition: lib_id.h:259
wxString GetUniStringLibId() const
Definition: lib_id.h:134
bool IsLegacy() const
Definition: lib_id.h:167
const wxString GetUniStringLibItemName() const
Get strings for display messages in dialogs.
Definition: lib_id.h:114
bool operator==(const LIB_ID &aLibId) const
Definition: lib_id.h:196
bool empty() const
Definition: utf8.h:103
static unsigned FindIllegalLibraryNameChar(const UTF8 &aLibraryName)
Looks for characters that are illegal in library nicknames.
Definition: lib_id.cpp:240