KiCad PCB EDA Suite
Loading...
Searching...
No Matches
io_base.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) 2023 KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20
21#ifndef IO_BASE_H_
22#define IO_BASE_H_
23
24#include <vector>
25#include <string>
26#include <wx/string.h>
27
28class REPORTER;
30class STRING_UTF8_MAP;
31
33{
34public:
39 {
40 wxString m_Description;
41 std::vector<std::string> m_FileExtensions;
42 std::vector<std::string> m_ExtensionsInDir;
43 bool m_IsFile;
44 bool m_CanRead;
46
47 IO_FILE_DESC( const wxString& aDescription, const std::vector<std::string>& aFileExtensions,
48 const std::vector<std::string>& aExtsInFolder = {}, bool aIsFile = true,
49 bool aCanRead = true, bool aCanWrite = true ) :
50 m_Description( aDescription ),
51 m_FileExtensions( aFileExtensions ), m_ExtensionsInDir( aExtsInFolder ),
52 m_IsFile( aIsFile ), m_CanRead( aCanRead ), m_CanWrite( aCanWrite )
53 {
54 }
55
56 IO_FILE_DESC() : IO_FILE_DESC( wxEmptyString, {} ) {}
57
61 wxString FileFilter() const;
62
63 operator bool() const { return !m_Description.empty(); }
64 };
65
66 virtual ~IO_BASE() = default;
67
71 const wxString& GetName() const { return m_name; }
72
76 virtual void SetReporter( REPORTER* aReporter ) { m_reporter = aReporter; }
77
81 virtual void SetProgressReporter( PROGRESS_REPORTER* aReporter ) { m_progressReporter = aReporter; }
82
83
85 // Library-related functions
87
93 virtual const IO_FILE_DESC GetLibraryDesc() const = 0;
94
102 virtual const IO_FILE_DESC GetLibraryFileDesc() const { return GetLibraryDesc(); }
103
111 virtual bool CanReadLibrary( const wxString& aFileName ) const;
112
129 virtual void CreateLibrary( const wxString& aLibraryPath,
130 const STRING_UTF8_MAP* aProperties = nullptr );
131
149 virtual bool DeleteLibrary( const wxString& aLibraryPath,
150 const STRING_UTF8_MAP* aProperties = nullptr );
151
162 virtual bool IsLibraryWritable( const wxString& aLibraryPath );
163
188 virtual void GetLibraryOptions( STRING_UTF8_MAP* aListToAppendTo ) const;
189
190protected:
191 // Delete the zero-argument base constructor to force proper construction
192 IO_BASE() = delete;
193
198 IO_BASE( const wxString& aName ) :
199 m_name( aName ),
200 m_reporter( nullptr ),
201 m_progressReporter( nullptr )
202 {
203 }
204
205
207 wxString m_name;
208
211
214};
215
216#endif // IO_BASE_H_
IO_BASE()=delete
const wxString & GetName() const
Return a brief hard coded name for this IO interface.
Definition: io_base.h:71
REPORTER * m_reporter
Reporter to log errors/warnings to, may be nullptr.
Definition: io_base.h:210
wxString m_name
Name of the IO loader.
Definition: io_base.h:207
virtual bool DeleteLibrary(const wxString &aLibraryPath, const STRING_UTF8_MAP *aProperties=nullptr)
Delete an existing library and returns true, or if library does not exist returns false,...
Definition: io_base.cpp:50
virtual void GetLibraryOptions(STRING_UTF8_MAP *aListToAppendTo) const
Append supported IO options to aListToAppenTo along with internationalized descriptions.
Definition: io_base.cpp:61
virtual const IO_FILE_DESC GetLibraryFileDesc() const
Get the descriptor for the individual library elements that this IO plugin operates on.
Definition: io_base.h:102
IO_BASE(const wxString &aName)
Definition: io_base.h:198
virtual ~IO_BASE()=default
virtual const IO_FILE_DESC GetLibraryDesc() const =0
Get the descriptor for the library container that this IO plugin operates on.
virtual void SetReporter(REPORTER *aReporter)
Set an optional reporter for warnings/errors.
Definition: io_base.h:76
virtual void SetProgressReporter(PROGRESS_REPORTER *aReporter)
Set an optional progress reporter.
Definition: io_base.h:81
virtual void CreateLibrary(const wxString &aLibraryPath, const STRING_UTF8_MAP *aProperties=nullptr)
Create a new empty library at aLibraryPath empty.
Definition: io_base.cpp:44
PROGRESS_REPORTER * m_progressReporter
Progress reporter to track the progress of the operation, may be nullptr.
Definition: io_base.h:213
virtual bool CanReadLibrary(const wxString &aFileName) const
Checks if this IO object can read the specified library file/directory.
Definition: io_base.cpp:67
virtual bool IsLibraryWritable(const wxString &aLibraryPath)
Return true if the library at aLibraryPath is writable.
Definition: io_base.cpp:56
A progress reporter interface for use in multi-threaded environments.
A pure virtual class used to derive REPORTER objects from.
Definition: reporter.h:71
A name/value tuple with unique names and optional values.
Container that describes file type info.
Definition: io_base.h:39
std::vector< std::string > m_ExtensionsInDir
In case of folders: extensions of files inside.
Definition: io_base.h:42
IO_FILE_DESC(const wxString &aDescription, const std::vector< std::string > &aFileExtensions, const std::vector< std::string > &aExtsInFolder={}, bool aIsFile=true, bool aCanRead=true, bool aCanWrite=true)
Definition: io_base.h:47
bool m_IsFile
Whether the library is a folder or a file.
Definition: io_base.h:43
wxString m_Description
Description shown in the file picker dialog.
Definition: io_base.h:40
bool m_CanWrite
Whether the IO can write this file type.
Definition: io_base.h:45
std::vector< std::string > m_FileExtensions
Filter used for file pickers if m_IsFile is true.
Definition: io_base.h:41
bool m_CanRead
Whether the IO can read this file type.
Definition: io_base.h:44
wxString FileFilter() const
Definition: io_base.cpp:38