Class LPID (aka GUID) is a Logical Part ID and consists of various portions much like a URI. More...
#include <sch_lpid.h>
Inheritance diagram for SCH::LPID:Public Member Functions | |
| LPID (const STRING &aLPID) throw ( PARSE_ERROR ) | |
| Constructor LPID takes aLPID string and parses it. | |
| int | Parse (const STRING &aLPID) |
| Function Parse [re-]stuffs this LPID with the information from aLPID. | |
| const STRING & | GetLogicalLib () const |
| Function GetLogicalLib returns the logical library portion of a LPID. | |
| int | SetLogicalLib (const STRING &aLogical) |
| Function SetCategory overrides the logical lib name portion of the LPID to aLogical, and can be empty. | |
| const STRING & | GetCategory () const |
| Function GetCategory returns the category of this part id, "passives" in the example at the top of the class description. | |
| int | SetCategory (const STRING &aCategory) |
| Function SetCategory overrides the category portion of the LPID to aCategory and is typically either the empty string or a single word like "passives". | |
| const STRING & | GetBaseName () const |
| Function GetBaseName returns the part name without the category. | |
| int | SetBaseName (const STRING &aBaseName) |
| Function SetBaseName overrides the base name portion of the LPID to aBaseName. | |
| const STRING & | GetPartName () const |
| Function GetPartName returns the part name, i.e. | |
| STRING | GetPartNameAndRev () const |
| Function GetPartNameAndRev returns the part name with revision if any, i.e. | |
| int | SetPartName (const STRING &aPartName) |
| Function SetPartName overrides the part name portion of the LPID to aPartName. | |
| const STRING & | GetRevision () const |
| Function GetRevision returns the revision portion of the LPID. | |
| int | SetRevision (const STRING &aRevision) |
| Function SetRevision overrides the revision portion of the LPID to aRevision and must be in the form "rev<num>" where "<num>" is "1", "2", etc. | |
| STRING | Format () const |
| Function Format returns the full text of the LPID. | |
Static Public Member Functions | |
| static STRING | Format (const STRING &aLogicalLib, const STRING &aPartName, const STRING &aRevision="") throw ( PARSE_ERROR ) |
| Function Format returns a STRING in the proper format as an LPID for a combination of aLogicalLib, aPartName, and aRevision. | |
Protected Attributes | |
| STRING | logical |
| logical lib name or empty | |
| STRING | category |
| or empty | |
| STRING | baseName |
| without category | |
| STRING | revision |
| "revN[N..]" or empty | |
| STRING | partName |
| cannot be set directory, set via SetBaseName() & SetCategory() | |
Class LPID (aka GUID) is a Logical Part ID and consists of various portions much like a URI.
It is a container for the separated portions of a logical part id STRING so they can be accessed individually. The various portions of an LPID are: logicalLibraryName, category, baseName, and revision. Only the baseName is mandatory. There is another construct called "partName" which consists of [category/]baseName. That is the category followed by a slash, but only if the category is not empty.
partName = [category/]baseName
Example LPID string: "kicad:passives/R/rev6".
Definition at line 59 of file sch_lpid.h.
| LPID::LPID | ( | const STRING & | aLPID | ) | throw ( PARSE_ERROR ) |
Constructor LPID takes aLPID string and parses it.
A typical LPID string uses a logical library name followed by a part name. e.g.: "kicad:passives/R/rev2", or e.g.: "mylib:R33"
Definition at line 201 of file sch_lpid.cpp.
{
int offset = Parse( aLPID );
if( offset != -1 )
{
THROW_PARSE_ERROR(
_( "Illegal character found in LPID string" ),
wxString::FromUTF8( aLPID.c_str() ),
aLPID.c_str(),
0,
offset
);
}
}
| int LPID::Parse | ( | const STRING & | aLPID | ) |
Function Parse [re-]stuffs this LPID with the information from aLPID.
Definition at line 136 of file sch_lpid.cpp.
References revision, SetBaseName(), SetCategory(), and SetLogicalLib().
{
clear();
const char* rev = EndsWithRev( aLPID );
size_t revNdx;
size_t partNdx;
size_t baseNdx;
int offset;
//=====<revision>=========================================
if( rev )
{
revNdx = rev - aLPID.c_str();
// no need to check revision, EndsWithRev did that.
revision = aLPID.substr( revNdx );
--revNdx; // back up to omit the '/' which preceeds the rev
}
else
revNdx = aLPID.size();
//=====<logical>==========================================
if( ( partNdx = aLPID.find( ':' ) ) != aLPID.npos )
{
offset = SetLogicalLib( aLPID.substr( 0, partNdx ) );
if( offset > -1 )
{
return offset;
}
++partNdx; // skip ':'
}
else
partNdx = 0;
//=====<rawName && category>==============================
// "length limited" search:
const char* base = (const char*) memchr( aLPID.c_str() + partNdx, '/', revNdx - partNdx );
if( base )
{
baseNdx = base - aLPID.c_str();
offset = SetCategory( aLPID.substr( partNdx, baseNdx - partNdx ) );
if( offset > -1 )
{
return offset + partNdx;
}
++baseNdx; // skip '/'
}
else
{
baseNdx = partNdx;
}
//=====<baseName>==========================================
offset = SetBaseName( aLPID.substr( baseNdx, revNdx - baseNdx ) );
if( offset > -1 )
{
return offset + baseNdx;
}
return -1;
}
| const STRING& SCH::LPID::GetLogicalLib | ( | ) | const [inline] |
Function GetLogicalLib returns the logical library portion of a LPID.
There is not Set accessor for this portion since it comes from the library table and is considered read only here.
Definition at line 88 of file sch_lpid.h.
References logical.
{
return logical;
}
| int LPID::SetLogicalLib | ( | const STRING & | aLogical | ) |
Function SetCategory overrides the logical lib name portion of the LPID to aLogical, and can be empty.
Definition at line 218 of file sch_lpid.cpp.
References logical.
Referenced by Parse().
{
int offset = okLogical( aLogical );
if( offset == -1 )
{
logical = aLogical;
}
return offset;
}
| int LPID::SetCategory | ( | const STRING & | aCategory | ) |
Function SetCategory overrides the category portion of the LPID to aCategory and is typically either the empty string or a single word like "passives".
Definition at line 229 of file sch_lpid.cpp.
References baseName, category, and partName.
Referenced by Parse(), and SetPartName().
| int LPID::SetBaseName | ( | const STRING & | aBaseName | ) |
Function SetBaseName overrides the base name portion of the LPID to aBaseName.
Definition at line 251 of file sch_lpid.cpp.
References baseName, category, and partName.
Referenced by Parse(), and SetPartName().
| const STRING& SCH::LPID::GetPartName | ( | ) | const [inline] |
Function GetPartName returns the part name, i.e.
category/baseName without revision.
Definition at line 144 of file sch_lpid.h.
References partName.
{
return partName;
}
| STRING LPID::GetPartNameAndRev | ( | ) | const |
Function GetPartNameAndRev returns the part name with revision if any, i.e.
[category/]baseName[/revN..]
Definition at line 341 of file sch_lpid.cpp.
| int LPID::SetPartName | ( | const STRING & | aPartName | ) |
Function SetPartName overrides the part name portion of the LPID to aPartName.
Definition at line 272 of file sch_lpid.cpp.
References category, SetBaseName(), and SetCategory().
{
STRING category;
STRING base;
int offset;
int separation = int( aPartName.find_first_of( "/" ) );
if( separation != -1 )
{
category = aPartName.substr( 0, separation );
base = aPartName.substr( separation+1 );
}
else
{
// leave category empty
base = aPartName;
}
if( (offset = SetCategory( category )) != -1 )
return offset;
if( (offset = SetBaseName( base )) != -1 )
{
return offset + separation + 1;
}
return -1;
}
| int LPID::SetRevision | ( | const STRING & | aRevision | ) |
Function SetRevision overrides the revision portion of the LPID to aRevision and must be in the form "rev<num>" where "<num>" is "1", "2", etc.
Definition at line 302 of file sch_lpid.cpp.
References revision.
{
int offset = okRevision( aRevision );
if( offset == -1 )
{
revision = aRevision;
}
return offset;
}
| STRING LPID::Format | ( | const STRING & | aLogicalLib, | |
| const STRING & | aPartName, | |||
| const STRING & | aRevision = "" | |||
| ) | throw ( PARSE_ERROR ) [static] |
Function Format returns a STRING in the proper format as an LPID for a combination of aLogicalLib, aPartName, and aRevision.
| PARSE_ERROR | if any of the pieces are illegal. |
Definition at line 363 of file sch_lpid.cpp.
{
STRING ret;
int offset;
if( aLogicalLib.size() )
{
offset = okLogical( aLogicalLib );
if( offset != -1 )
{
THROW_PARSE_ERROR(
_( "Illegal character found in logical lib name" ),
wxString::FromUTF8( aLogicalLib.c_str() ),
aLogicalLib.c_str(),
0,
offset
);
}
ret += aLogicalLib;
ret += ':';
}
{
STRING category;
STRING base;
int separation = int( aPartName.find_first_of( "/" ) );
if( separation != -1 )
{
category = aPartName.substr( 0, separation );
base = aPartName.substr( separation+1 );
}
else
{
// leave category empty
base = aPartName;
}
if( (offset = okCategory( category )) != -1 )
{
THROW_PARSE_ERROR(
_( "Illegal character found in category" ),
wxString::FromUTF8( aRevision.c_str() ),
aRevision.c_str(),
0,
offset
);
}
if( (offset = okBase( base )) != -1 )
{
THROW_PARSE_ERROR(
_( "Illegal character found in base name" ),
wxString::FromUTF8( aRevision.c_str() ),
aRevision.c_str(),
0,
offset + separation + 1
);
}
if( category.size() )
{
ret += category;
ret += '/';
}
ret += base;
}
if( aRevision.size() )
{
offset = okRevision( aRevision );
if( offset != -1 )
{
THROW_PARSE_ERROR(
_( "Illegal character found in revision" ),
wxString::FromUTF8( aRevision.c_str() ),
aRevision.c_str(),
0,
offset
);
}
ret += '/';
ret += aRevision;
}
return ret;
}
1.7.1