KiCad PCB EDA Suite
KIID_PATH Class Reference

#include <kiid.h>

Inheritance diagram for KIID_PATH:

Public Member Functions

 KIID_PATH ()
 
 KIID_PATH (const wxString &aString)
 
bool MakeRelativeTo (const KIID_PATH &aPath)
 
bool EndsWith (const KIID_PATH &aPath) const
 Test if aPath from the last path towards the first path. More...
 
wxString AsString () const
 
bool operator== (KIID_PATH const &rhs) const
 
bool operator< (KIID_PATH const &rhs) const
 

Detailed Description

Definition at line 139 of file kiid.h.

Constructor & Destructor Documentation

◆ KIID_PATH() [1/2]

KIID_PATH::KIID_PATH ( )
inline

Definition at line 142 of file kiid.h.

143 {
144 }

◆ KIID_PATH() [2/2]

KIID_PATH::KIID_PATH ( const wxString &  aString)

Definition at line 307 of file kiid.cpp.

308{
309 for( const wxString& pathStep : wxSplit( aString, '/' ) )
310 {
311 if( !pathStep.empty() )
312 emplace_back( KIID( pathStep ) );
313 }
314}
Definition: kiid.h:48

Member Function Documentation

◆ AsString()

◆ EndsWith()

bool KIID_PATH::EndsWith ( const KIID_PATH aPath) const

Test if aPath from the last path towards the first path.

This is useful for testing for existing schematic symbol and sheet instances when copying or adding a new sheet that is lower in the hierarchy than the current path.

Parameters
aPathis the path to compare this path against.
Returns
true if this path ends with aPath or false if it does not.

Definition at line 338 of file kiid.cpp.

339{
340 if( aPath.size() > size() )
341 return false; // this path can not end aPath
342
343 KIID_PATH copyThis = *this;
344 KIID_PATH copyThat = aPath;
345
346 while( !copyThat.empty() )
347 {
348 if( *std::prev( copyThis.end() ) != *std::prev( copyThat.end() ) )
349 return false;
350
351 copyThis.pop_back();
352 copyThat.pop_back();
353 }
354
355 return true;
356}

Referenced by BOOST_AUTO_TEST_CASE().

◆ MakeRelativeTo()

bool KIID_PATH::MakeRelativeTo ( const KIID_PATH aPath)

Definition at line 317 of file kiid.cpp.

318{
319 KIID_PATH copy = *this;
320 clear();
321
322 if( aPath.size() > copy.size() )
323 return false; // this path is not contained within aPath
324
325 for( size_t i = 0; i < aPath.size(); ++i )
326 {
327 if( copy.at( i ).AsString() != aPath.at( i ).AsString() )
328 return false; // this path is not contained within aPath
329 }
330
331 for( size_t i = aPath.size(); i < copy.size(); ++i )
332 push_back( copy.at( i ) );
333
334 return true;
335}
wxString AsString() const
Definition: kiid.cpp:359

References AsString(), and copy.

◆ operator<()

bool KIID_PATH::operator< ( KIID_PATH const &  rhs) const
inline

Definition at line 177 of file kiid.h.

178 {
179 if( size() != rhs.size() )
180 return size() < rhs.size();
181
182 for( size_t i = 0; i < size(); ++i )
183 {
184 if( at( i ) < rhs.at( i ) )
185 return true;
186
187 if( at( i ) != rhs.at( i ) )
188 return false;
189 }
190
191 return false;
192 }

◆ operator==()

bool KIID_PATH::operator== ( KIID_PATH const &  rhs) const
inline

Definition at line 163 of file kiid.h.

164 {
165 if( size() != rhs.size() )
166 return false;
167
168 for( size_t i = 0; i < size(); ++i )
169 {
170 if( at( i ) != rhs.at( i ) )
171 return false;
172 }
173
174 return true;
175 }

The documentation for this class was generated from the following files: