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 (C) 2022 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 along
19 * with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#ifndef _SCH_IO_LIB_CACHE_H_
23#define _SCH_IO_LIB_CACHE_H_
24
25#include <mutex>
26#include <optional>
27
28#include <wx/filename.h>
29
31
32
33class LIB_SYMBOL;
34class OUTPUTFORMATTER;
35
36
41{
42public:
43 SCH_IO_LIB_CACHE( const wxString& aLibraryPath );
44 virtual ~SCH_IO_LIB_CACHE();
45
47 {
48 std::lock_guard<std::mutex> mut( m_modHashMutex );
49 m_modHash++;
50 }
51
53 {
54 std::lock_guard<std::mutex> mut( m_modHashMutex );
55 return m_modHash;
56 }
57
58 // Most all functions in this class throw IO_ERROR exceptions. There are no
59 // error codes nor user interface calls from here, nor in any SCH_IO objects.
60 // Catch these exceptions higher up please.
61
63 virtual void Save( const std::optional<bool>& aOpt = std::nullopt );
64
65 virtual void Load() = 0;
66
67 virtual void AddSymbol( const LIB_SYMBOL* aSymbol );
68
69 virtual void DeleteSymbol( const wxString& aName ) = 0;
70
71 virtual LIB_SYMBOL* GetSymbol( const wxString& aName );
72
73 // If m_libFileName is a symlink follow it to the real source file
74 wxFileName GetRealFile() const;
75
76 wxDateTime GetLibModificationTime();
77
78 bool IsFile( const wxString& aFullPathAndFileName ) const;
79
80 bool IsFileChanged() const;
81
82 void SetModified( bool aModified = true ) { m_isModified = aModified; }
83
84 wxString GetLogicalName() const { return m_libFileName.GetName(); }
85
86 void SetFileName( const wxString& aFileName ) { m_libFileName = aFileName; }
87
88 wxString GetFileName() const { return m_libFileName.GetFullPath(); }
89
90 const LIB_SYMBOL_MAP& GetSymbolMap() const { return m_symbols; }
91
92protected:
94
95 int m_modHash; // Keep track of the modification status of the library.
96 std::mutex m_modHashMutex;
97
98 wxString m_fileName; // Absolute path and file name.
99 wxFileName m_libFileName; // Absolute path and file name is required here.
100 wxDateTime m_fileModTime;
101 LIB_SYMBOL_MAP m_symbols; // Map of names of #LIB_SYMBOL pointers.
104 SCH_LIB_TYPE m_libType; // Is this cache a symbol or symbol library.
105};
106
107#endif // _SCH_IO_LIB_CACHE_H_
Define a library symbol object.
Definition: lib_symbol.h:77
An interface used to output 8 bit text in a convenient way.
Definition: richio.h:322
A base cache assistant implementation for the symbol library portion of the SCH_IO API.
bool IsFile(const wxString &aFullPathAndFileName) const
virtual LIB_SYMBOL * GetSymbol(const wxString &aName)
void SetFileName(const wxString &aFileName)
wxDateTime GetLibModificationTime()
virtual void AddSymbol(const LIB_SYMBOL *aSymbol)
virtual void DeleteSymbol(const wxString &aName)=0
SCH_LIB_TYPE m_libType
LIB_SYMBOL_MAP m_symbols
wxFileName GetRealFile() const
bool IsFileChanged() const
wxDateTime m_fileModTime
wxFileName m_libFileName
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
wxString GetFileName() const
const LIB_SYMBOL_MAP & GetSymbolMap() const
virtual ~SCH_IO_LIB_CACHE()
void SetModified(bool aModified=true)
LIB_SYMBOL * removeSymbol(LIB_SYMBOL *aAlias)
wxString GetLogicalName() const
std::map< wxString, LIB_SYMBOL *, LibSymbolMapSort > LIB_SYMBOL_MAP