eOn client
Long-timescale dynamics: aKMC, NEB, parallel replica
☾
Toggle main menu visibility
Loading...
Searching...
No Matches
PluginLoader.h
Go to the documentation of this file.
1
/*
2
** This file is part of eOn.
3
**
4
** SPDX-License-Identifier: BSD-3-Clause
5
**
6
** Copyright (c) 2010--present, eOn Development Team
7
** All rights reserved.
8
**
9
** Repo:
10
** https://github.com/TheochemUI/eOn
11
*/
12
#pragma once
13
30
31
#include "
eon/DynLib.h
"
32
33
#include <mutex>
34
#include <stdexcept>
35
#include <string>
36
#include <unordered_map>
37
#include <vector>
38
39
namespace
eonc
{
40
41
class
PluginLoader
{
42
public
:
44
static
PluginLoader
&
instance
();
45
49
void
add_config_paths
(
const
std::string &colon_paths);
50
55
template
<
typename
Fn>
56
Fn
load_sym
(
const
char
*lib_base,
const
char
*sym_name) {
57
dynlib::Handle
h =
open_lib
(lib_base);
58
if
(!h)
59
return
nullptr
;
60
return
dynlib::loadSym<Fn>
(h, sym_name);
61
}
62
64
[[noreturn]]
void
throw_not_found
(
const
char
*lib_base,
65
const
char
*description)
const
;
66
70
[[nodiscard]]
bool
lib_present
(
const
char
*lib_base)
const
;
71
73
[[nodiscard]]
const
std::vector<std::string> &
search_paths
() const noexcept {
74
return
m_search_paths
;
75
}
76
77
PluginLoader
(
const
PluginLoader
&) =
delete
;
78
PluginLoader
&
operator=
(
const
PluginLoader
&) =
delete
;
79
80
private
:
81
PluginLoader
();
82
~PluginLoader
();
83
84
dynlib::Handle
open_lib
(
const
char
*lib_base);
85
std::vector<std::string>
lib_names
(
const
char
*lib_base)
const
;
86
void
append_paths
(
const
std::string &path_str,
char
sep);
87
88
std::vector<std::string>
m_search_paths
;
89
mutable
std::mutex
m_mutex
;
90
std::unordered_map<std::string, dynlib::Handle>
m_handles
;
92
std::string
m_last_load_error
;
93
bool
m_last_load_saw_file
=
false
;
94
};
95
96
}
// namespace eonc
DynLib.h
eonc::PluginLoader::add_config_paths
void add_config_paths(const std::string &colon_paths)
Inject search paths from the eOn config file.
Definition
PluginLoader.cpp:66
eonc::PluginLoader::m_search_paths
std::vector< std::string > m_search_paths
Definition
PluginLoader.h:88
eonc::PluginLoader::m_last_load_saw_file
bool m_last_load_saw_file
Definition
PluginLoader.h:93
eonc::PluginLoader::lib_present
bool lib_present(const char *lib_base) const
Filesystem probe: a matching library file is on the configured search path.
Definition
PluginLoader.cpp:164
eonc::PluginLoader::PluginLoader
PluginLoader()
Definition
PluginLoader.cpp:25
eonc::PluginLoader::~PluginLoader
~PluginLoader()
Definition
PluginLoader.cpp:38
eonc::PluginLoader::load_sym
Fn load_sym(const char *lib_base, const char *sym_name)
Load a symbol from a named potential library.
Definition
PluginLoader.h:56
eonc::PluginLoader::instance
static PluginLoader & instance()
Thread-safe singleton accessor (Meyer's pattern).
Definition
PluginLoader.cpp:20
eonc::PluginLoader::append_paths
void append_paths(const std::string &path_str, char sep)
Definition
PluginLoader.cpp:44
eonc::PluginLoader::m_last_load_error
std::string m_last_load_error
Last dynlib::error() from a failed open (for throw_not_found).
Definition
PluginLoader.h:92
eonc::PluginLoader::PluginLoader
PluginLoader(const PluginLoader &)=delete
eonc::PluginLoader::lib_names
std::vector< std::string > lib_names(const char *lib_base) const
Definition
PluginLoader.cpp:100
eonc::PluginLoader::m_mutex
std::mutex m_mutex
Definition
PluginLoader.h:89
eonc::PluginLoader::open_lib
dynlib::Handle open_lib(const char *lib_base)
Definition
PluginLoader.cpp:113
eonc::PluginLoader::m_handles
std::unordered_map< std::string, dynlib::Handle > m_handles
Definition
PluginLoader.h:90
eonc::PluginLoader::throw_not_found
void throw_not_found(const char *lib_base, const char *description) const
Throw a descriptive error for a missing potential library.
Definition
PluginLoader.cpp:177
eonc::PluginLoader::search_paths
const std::vector< std::string > & search_paths() const noexcept
Get the current search paths (for diagnostics).
Definition
PluginLoader.h:73
eonc::PluginLoader::operator=
PluginLoader & operator=(const PluginLoader &)=delete
eonc::dynlib::Handle
void * Handle
Definition
DynLib.h:60
eonc::dynlib::loadSym
Fn loadSym(Handle h, const char *name) noexcept
Load a symbol and cast to a function pointer type.
Definition
DynLib.h:99
eonc
RAII resource manager for the ARTn C library with global synchronization.
Definition
ARTnSaddleSearch.cpp:19
include
eon
potentials
PluginLoader.h
Generated by
1.17.0
Generated by
Doxygen 1.17.0
Analytics by
Antics
provided by
TurtleTech ehf