KiCad PCB EDA Suite
Loading...
Searching...
No Matches
sch_io_lib_cache.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 The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * @author Wayne Stambaugh <[email protected]>
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, see <https://www.gnu.org/licenses/>.
20 */
21
22#ifndef _SCH_IO_LIB_CACHE_H_
23#define _SCH_IO_LIB_CACHE_H_
24
25#include <map>
26#include <memory>
27#include <mutex>
28#include <optional>
29
30#include <wx/filename.h>
31
33
34
35class LIB_SYMBOL;
36class OUTPUTFORMATTER;
37
38
43{
44public:
45 SCH_IO_LIB_CACHE( const wxString& aLibraryPath );
46 virtual ~SCH_IO_LIB_CACHE();
47
49 {
50 std::lock_guard<std::mutex> mut( m_modHashMutex );
51 m_modHash++;
52 }
53
55 {
56 std::lock_guard<std::mutex> mut( m_modHashMutex );
57 return m_modHash;
58 }
59
60 // Most all functions in this class throw IO_ERROR exceptions. There are no
61 // error codes nor user interface calls from here, nor in any SCH_IO objects.
62 // Catch these exceptions higher up please.
63
65 virtual void Save( const std::optional<bool>& aOpt = std::nullopt );
66
67 virtual void Load() = 0;
68
69 virtual void AddSymbol( std::unique_ptr<LIB_SYMBOL> aSymbol );
70
71 virtual void DeleteSymbol( const wxString& aName ) = 0;
72
73 virtual LIB_SYMBOL* GetSymbol( const wxString& aName );
74
75 // If m_libFileName is a symlink follow it to the real source file
76 wxFileName GetRealFile() const;
77
78 long long GetLibModificationTime();
79
80 bool IsFile( const wxString& aFullPathAndFileName ) const;
81
82 bool IsFileChanged() const;
83
84 void SetModified( bool aModified = true ) { m_isModified = aModified; }
85
92 bool HasParseError() const { return m_hasParseError; }
93
99 void SetParseError( bool aHasError = true ) { m_hasParseError = aHasError; }
100
101 wxString GetLogicalName() const { return m_libFileName.GetName(); }
102
103 void SetFileName( const wxString& aFileName );
104
105 wxString GetFileName() const { return m_libFileName.GetFullPath(); }
106
107 const LIB_SYMBOL_MAP& GetSymbolMap() const { return m_symbols; }
108
110 const std::map<wxString, wxString>& GetSymbolSourceFiles() const { return m_symbolSourceFiles; }
111
112protected:
114
115 int m_modHash; // Keep track of the modification status of the library.
116 std::mutex m_modHashMutex;
117
118 wxString m_fileName; // Absolute path and file name.
119 wxFileName m_libFileName; // Absolute path and file name is required here.
120 long long m_fileModTime;
121 LIB_SYMBOL_MAP m_symbols; // Map of names of #LIB_SYMBOL pointers.
122
127 std::map<wxString, wxString> m_symbolSourceFiles;
128
131 bool m_hasParseError; // True if library had parse error during load.
132 SCH_LIB_TYPE m_libType; // Is this cache a symbol or symbol library.
133};
134
135#endif // _SCH_IO_LIB_CACHE_H_
Define a library symbol object.
Definition lib_symbol.h:119
An interface used to output 8 bit text in a convenient way.
Definition richio.h:294
bool IsFile(const wxString &aFullPathAndFileName) const
virtual LIB_SYMBOL * GetSymbol(const wxString &aName)
void SetFileName(const wxString &aFileName)
void SetParseError(bool aHasError=true)
Set the parse error state.
virtual void DeleteSymbol(const wxString &aName)=0
SCH_LIB_TYPE m_libType
bool HasParseError() const
LIB_SYMBOL_MAP m_symbols
const std::map< wxString, wxString > & GetSymbolSourceFiles() const
For folder-based libraries, the source file each symbol was loaded from (by name).
wxFileName GetRealFile() const
bool IsFileChanged() const
long long GetLibModificationTime()
std::mutex m_modHashMutex
virtual void Save(const std::optional< bool > &aOpt=std::nullopt)
Save the entire library to file m_libFileName;.
virtual void Load()=0
std::map< wxString, wxString > m_symbolSourceFiles
For folder-based libraries, track which source file each symbol was loaded from.
SCH_IO_LIB_CACHE(const wxString &aLibraryPath)
wxString GetFileName() const
const LIB_SYMBOL_MAP & GetSymbolMap() const
void SetModified(bool aModified=true)
LIB_SYMBOL * removeSymbol(LIB_SYMBOL *aAlias)
virtual void AddSymbol(std::unique_ptr< LIB_SYMBOL > aSymbol)
wxString GetLogicalName() const
std::map< wxString, LIB_SYMBOL *, LibSymbolMapSort > LIB_SYMBOL_MAP