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-2016 Wayne Stambaugh <stambaughw@verizon.net>
6  * Copyright (C) 2010-2016 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 std::string& aId ) throw( PARSE_ERROR );
74 
75  LIB_ID( const wxString& aId ) throw( PARSE_ERROR );
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 
178  bool IsValid() const { return !nickname.empty() && !item_name.empty(); }
179 
185  bool IsLegacy() const { return nickname.empty() && !item_name.empty() && revision.empty(); }
186 
192  void clear();
193 
199  bool empty() const { return nickname.empty() && item_name.empty() && revision.empty(); }
200 
211  int compare( const LIB_ID& aLIB_ID ) const;
212 
213  bool operator < ( const LIB_ID& aLibId ) const { return this->compare( aLibId ) < 0; }
214  bool operator > ( const LIB_ID& aLibId ) const { return this->compare( aLibId ) > 0; }
215  bool operator ==( const LIB_ID& aLibId ) const { return this->compare( aLibId ) == 0; }
216  bool operator !=( const LIB_ID& aLibId ) const { return !(*this == aLibId); }
217 
218 #if defined(DEBUG)
219  static void Test();
220 #endif
221 
222 protected:
226 };
227 
228 
229 #endif // _LIB_ID_H_
bool IsValid() const
Function Format.
Definition: lib_id.h:178
bool operator>(const LIB_ID &aLibId) const
Definition: lib_id.h:214
Class UTF8 is an 8 bit std::string that is assuredly encoded in UTF8, and supplies special conversion...
Definition: utf8.h:53
bool empty() const
Function empty.
Definition: lib_id.h:199
UTF8 revision
The revision of the entry.
Definition: lib_id.h:225
bool operator!=(const LIB_ID &aLibId) const
Definition: lib_id.h:216
bool operator<(const LIB_ID &aLibId) const
Definition: lib_id.h:213
bool IsLegacy() const
Function IsLegacy.
Definition: lib_id.h:185
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:215
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:224
int SetRevision(const UTF8 &aRevision)
Definition: lib_id.cpp:250
UTF8 nickname
The nickname of the library or empty.
Definition: lib_id.h:223
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 compare(const LIB_ID &aLIB_ID) const
Function Compare.
Definition: lib_id.cpp:346
int SetLibNickname(const UTF8 &aNickname)
Function SetLibNickname.
Definition: lib_id.cpp:219
LIB_ID()
Definition: lib_id.h:60
Struct PARSE_ERROR contains a filename or source description, a problem input line, a line number, a byte offset, and an error message which contains the the caller's report and his call site information: CPP source file, function, and line number.
Definition: ki_exception.h:94
UTF8 Format() const
Function Format.
Definition: lib_id.cpp:263
const UTF8 & GetLibNickname() const
Function GetLibNickname.
Definition: lib_id.h:108