KiCad PCB EDA Suite
WX_FILENAME Class Reference

A wrapper around a wxFileName which is much more performant with a subset of the API. More...

#include <wx_filename.h>

Public Member Functions

 WX_FILENAME (const wxString &aPath, const wxString &aFilename)
 
void SetFullName (const wxString &aFileNameAndExtension)
 
wxString GetName () const
 
wxString GetFullName () const
 
wxString GetPath () const
 
wxString GetFullPath () const
 
long long GetTimestamp ()
 

Static Public Member Functions

static void ResolvePossibleSymlinks (wxFileName &aFilename)
 

Private Member Functions

void resolve ()
 

Private Attributes

wxFileName m_fn
 
wxString m_path
 
wxString m_fullName
 

Detailed Description

A wrapper around a wxFileName which is much more performant with a subset of the API.

A wrapper around a wxFileName which avoids expensive calls to wxFileName::SplitPath() and string concatenations by caching the path and filename locally and only resolving the wxFileName when it has to.

Definition at line 36 of file wx_filename.h.

Constructor & Destructor Documentation

◆ WX_FILENAME()

WX_FILENAME::WX_FILENAME ( const wxString &  aPath,
const wxString &  aFilename 
)

Definition at line 28 of file wx_filename.cpp.

29  : m_fn( aPath, aFilename ), m_path( aPath ), m_fullName( aFilename )
30 {
31 }
wxString m_path
Definition: wx_filename.h:59
wxFileName m_fn
Definition: wx_filename.h:58
wxString m_fullName
Definition: wx_filename.h:60

Member Function Documentation

◆ GetFullName()

wxString WX_FILENAME::GetFullName ( ) const

Definition at line 47 of file wx_filename.cpp.

48 {
49  return m_fullName;
50 }
wxString m_fullName
Definition: wx_filename.h:60

References m_fullName.

Referenced by BOOST_AUTO_TEST_CASE().

◆ GetFullPath()

wxString WX_FILENAME::GetFullPath ( ) const

Definition at line 59 of file wx_filename.cpp.

60 {
61  return m_path + wxT( '/' ) + m_fullName;
62 }
wxString m_path
Definition: wx_filename.h:59
wxString m_fullName
Definition: wx_filename.h:60

References m_fullName, and m_path.

Referenced by BOOST_AUTO_TEST_CASE(), FP_CACHE::Load(), and FP_CACHE::Save().

◆ GetName()

wxString WX_FILENAME::GetName ( void  ) const

Definition at line 40 of file wx_filename.cpp.

41 {
42  size_t dot = m_fullName.find_last_of( wxT( '.' ) );
43  return m_fullName.substr( 0, dot );
44 }
wxString m_fullName
Definition: wx_filename.h:60

References m_fullName.

Referenced by BOOST_AUTO_TEST_CASE(), and FP_CACHE::Load().

◆ GetPath()

wxString WX_FILENAME::GetPath ( ) const

Definition at line 53 of file wx_filename.cpp.

54 {
55  return m_path;
56 }
wxString m_path
Definition: wx_filename.h:59

References m_path.

Referenced by BOOST_AUTO_TEST_CASE(), and FP_CACHE::Save().

◆ GetTimestamp()

long long WX_FILENAME::GetTimestamp ( )

Definition at line 74 of file wx_filename.cpp.

75 {
76  resolve();
77 
78  if( m_fn.FileExists() )
79  return m_fn.GetModificationTime().GetValue().GetValue();
80 
81  return 0;
82 }
wxFileName m_fn
Definition: wx_filename.h:58
void resolve()
Definition: wx_filename.cpp:66

References m_fn, and resolve().

Referenced by FP_CACHE::Save().

◆ resolve()

void WX_FILENAME::resolve ( )
private

Definition at line 66 of file wx_filename.cpp.

67 {
68  size_t dot = m_fullName.find_last_of( wxT( '.' ) );
69  m_fn.SetName( m_fullName.substr( 0, dot ) );
70  m_fn.SetExt( m_fullName.substr( dot + 1 ) );
71 }
wxFileName m_fn
Definition: wx_filename.h:58
wxString m_fullName
Definition: wx_filename.h:60

References m_fn, and m_fullName.

Referenced by GetTimestamp().

◆ ResolvePossibleSymlinks()

void WX_FILENAME::ResolvePossibleSymlinks ( wxFileName &  aFilename)
static

Definition at line 85 of file wx_filename.cpp.

86 {
87 #ifndef __WINDOWS__
88  if( aFilename.Exists( wxFILE_EXISTS_SYMLINK ) )
89  {
90  char buffer[PATH_MAX];
91  char* realPath = realpath( TO_UTF8( aFilename.GetFullPath() ), buffer );
92 
93  if( realPath )
94  aFilename.Assign( wxString::FromUTF8( realPath ) );
95  }
96 #endif
97 }
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:96

References TO_UTF8.

Referenced by PCB_IO::FootprintSave(), SCH_SEXPR_PLUGIN_CACHE::GetRealFile(), SCH_LEGACY_PLUGIN_CACHE::GetRealFile(), PCB_EDIT_FRAME::SavePcbFile(), and SCH_EDIT_FRAME::saveSchematicFile().

◆ SetFullName()

void WX_FILENAME::SetFullName ( const wxString &  aFileNameAndExtension)

Definition at line 34 of file wx_filename.cpp.

35 {
36  m_fullName = aFileNameAndExtension;
37 }
wxString m_fullName
Definition: wx_filename.h:60

References m_fullName.

Referenced by FP_CACHE::Load(), and GPCB_FPL_CACHE::Load().

Member Data Documentation

◆ m_fn

wxFileName WX_FILENAME::m_fn
private

Definition at line 58 of file wx_filename.h.

Referenced by GetTimestamp(), and resolve().

◆ m_fullName

wxString WX_FILENAME::m_fullName
private

Definition at line 60 of file wx_filename.h.

Referenced by GetFullName(), GetFullPath(), GetName(), resolve(), and SetFullName().

◆ m_path

wxString WX_FILENAME::m_path
private

Definition at line 59 of file wx_filename.h.

Referenced by GetFullPath(), and GetPath().


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