21#ifndef LIBRARY_MANAGER_H
22#define LIBRARY_MANAGER_H
26#include <tl/expected.hpp>
43template<
typename ResultType>
63 std::optional<LIBRARY_ERROR>
error;
120 bool HasLibrary(
const wxString& aNickname,
bool aCheckEnabled =
false )
const;
129 bool aIncludeInvalid =
false )
const;
132 std::optional<LIBRARY_TABLE_ROW*>
GetRow(
const wxString& aNickname,
136 std::optional<LIBRARY_TABLE_ROW*>
FindRowByURI(
const wxString& aUri,
156 virtual bool IsWritable(
const wxString& aNickname )
const {
return false; }
164 virtual std::map<wxString, LIB_DATA>&
globalLibs()
const = 0;
169 std::optional<const LIB_DATA*>
fetchIfLoaded(
const wxString& aNickname )
const;
171 std::optional<LIB_DATA*>
fetchIfLoaded(
const wxString& aNickname );
223 void LoadGlobalTables( std::initializer_list<LIBRARY_TABLE_TYPE> aTablesToLoad = {} );
229 std::unique_ptr<LIBRARY_MANAGER_ADAPTER>&& aAdapter );
253 bool aIncludeInvalid =
false )
const;
263 const wxString &aNickname,
268 const wxString &aUri,
272 void LoadProjectTables(
const wxString& aProjectPath );
285 std::optional<wxString> GetFullURI(
LIBRARY_TABLE_TYPE aType,
const wxString& aNickname,
286 bool aSubstituted =
false )
const;
288 static wxString GetFullURI(
const LIBRARY_TABLE_ROW* aRow,
bool aSubstituted =
false );
290 static wxString ExpandURI(
const wxString& aShortURI,
const PROJECT& aProject );
292 static bool UrisAreEquivalent(
const wxString& aURI1,
const wxString& aURI2 );
296 std::vector<LIBRARY_TABLE_TYPE> aTablesToLoad = {} );
298 void loadNestedTables( LIBRARY_TABLE& aTable );
304 std::map<LIBRARY_TABLE_TYPE, std::unique_ptr<LIBRARY_TABLE>>
m_tables;
312 std::map<LIBRARY_TABLE_TYPE, std::unique_ptr<LIBRARY_MANAGER_ADAPTER>>
m_adapters;
std::optional< float > AsyncLoadProgress() const
Returns async load progress between 0.0 and 1.0, or nullopt if load is not in progress.
virtual bool IsWritable(const wxString &aNickname) const
Return true if the given nickname exists and is not a read-only library.
std::optional< LIBRARY_TABLE * > ProjectTable() const
Retrieves the project library table for this adapter type, or nullopt if one doesn't exist.
LIBRARY_TABLE * GlobalTable() const
Retrieves the global library table for this adapter type.
LIBRARY_MANAGER_ADAPTER(LIBRARY_MANAGER &aManager)
Constructs a type-specific adapter into the library manager.
bool IsLibraryLoaded(const wxString &aNickname)
std::vector< LIBRARY_TABLE_ROW * > Rows(LIBRARY_TABLE_SCOPE aScope=LIBRARY_TABLE_SCOPE::BOTH, bool aIncludeInvalid=false) const
Like LIBRARY_MANAGER::Rows but filtered to the LIBRARY_TABLE_TYPE of this adapter.
std::optional< LIBRARY_TABLE_ROW * > FindRowByURI(const wxString &aUri, LIBRARY_TABLE_SCOPE aScope=LIBRARY_TABLE_SCOPE::BOTH) const
Like LIBRARY_MANAGER::FindRowByURI but filtered to the LIBRARY_TABLE_TYPE of this adapter.
virtual std::map< wxString, LIB_DATA > & globalLibs()=0
virtual std::mutex & globalLibsMutex()=0
virtual LIBRARY_TABLE_TYPE Type() const =0
The type of library table this adapter works with.
bool DeleteLibrary(const wxString &aNickname)
Deletes the given library from disk if it exists; returns true if deleted.
LIBRARY_RESULT< LIB_DATA * > loadIfNeeded(const wxString &aNickname)
Fetches a loaded library, triggering a load of that library if it isn't loaded yet.
std::optional< wxString > FindLibraryByURI(const wxString &aURI) const
LIBRARY_MANAGER & Manager() const
virtual void AsyncLoad()=0
Loads all available libraries for this adapter type in the background.
void abortLoad()
Aborts any async load in progress; blocks until fully done aborting.
std::optional< wxString > GetLibraryDescription(const wxString &aNickname) const
virtual LIBRARY_RESULT< IO_BASE * > createPlugin(const LIBRARY_TABLE_ROW *row)=0
Creates a concrete plugin for the given row.
void GlobalTablesChanged(std::initializer_list< LIBRARY_TABLE_TYPE > aChangedTables={})
Notify the adapter that the global library tables have changed.
bool HasLibrary(const wxString &aNickname, bool aCheckEnabled=false) const
Test for the existence of aNickname in the library tables.
std::optional< LIBRARY_TABLE_ROW * > GetRow(const wxString &aNickname, LIBRARY_TABLE_SCOPE aScope=LIBRARY_TABLE_SCOPE::BOTH) const
Like LIBRARY_MANAGER::GetRow but filtered to the LIBRARY_TABLE_TYPE of this adapter.
virtual void ShowConfigurationDialog(const wxString &aNickname, wxWindow *aParent) const
std::map< wxString, LIB_DATA > m_libraries
std::vector< wxString > GetLibraryNames() const
Returns a list of library nicknames that are available (skips any that failed to load)
std::vector< std::future< void > > m_futures
virtual bool SupportsConfigurationDialog(const wxString &aNickname) const
static wxString getUri(const LIBRARY_TABLE_ROW *aRow)
std::mutex m_libraries_mutex
virtual std::map< wxString, LIB_DATA > & globalLibs() const =0
std::atomic< size_t > m_loadCount
LIBRARY_MANAGER & m_manager
std::optional< const LIB_DATA * > fetchIfLoaded(const wxString &aNickname) const
std::map< wxString, std::unique_ptr< LIBRARY_TABLE > > m_childTables
Map of full URI to table object for tables that are referenced by global or project tables.
static wxString DefaultGlobalTablePath(LIBRARY_TABLE_TYPE aType)
static std::vector< LIBRARY_TABLE_TYPE > InvalidGlobalTables()
static bool GlobalTablesValid()
std::map< LIBRARY_TABLE_TYPE, std::unique_ptr< LIBRARY_TABLE > > m_projectTables
LIBRARY_MANAGER(const LIBRARY_MANAGER &)=delete
static bool CreateGlobalTable(LIBRARY_TABLE_TYPE aType, bool aPopulateDefaultLibraries)
void LoadGlobalTables(std::initializer_list< LIBRARY_TABLE_TYPE > aTablesToLoad={})
(Re)loads the global library tables in the given list, or all tables if no list is given
std::map< LIBRARY_TABLE_TYPE, std::unique_ptr< LIBRARY_TABLE > > m_tables
LIBRARY_MANAGER & operator=(const LIBRARY_MANAGER &)=delete
static bool IsTableValid(const wxString &aPath)
std::map< LIBRARY_TABLE_TYPE, std::unique_ptr< LIBRARY_MANAGER_ADAPTER > > m_adapters
Container for project specific data.
void ProjectChanged() override
tl::expected< ResultType, LIBRARY_ERROR > LIBRARY_RESULT
LOAD_STATUS
Status of a library load managed by a library adapter.
LIBRARY_ERROR(const wxString &aMessage)
Storage for an actual loaded library (including library content owned by the plugin)
std::vector< wxString > available_fields_cache
std::unique_ptr< IO_BASE > plugin
const LIBRARY_TABLE_ROW * row
The overall status of a loaded or loading library.
std::optional< LIBRARY_ERROR > error