Loading...
Searching...
No Matches
IRAResource.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
13#pragma once
14
26
27#include "eon/DynLib.h"
28#include <mutex>
29#include <stdexcept>
30#include <string>
31
32namespace eonc {
33
34// ---------------------------------------------------------------------------
35// IIRAResource: injectable ABI. Production uses IRAResource::instance().
36// ---------------------------------------------------------------------------
38public:
39 // IRA C API function pointer types (from iralib_interf.h)
40 using libira_match_fn = void (*)(int nat1, const int *typ1,
41 const double *coords1, const int *cand1,
42 int nat2, const int *typ2,
43 const double *coords2, const int *cand2,
44 double distThreshold, double **rotMat,
45 double **trans, int **perm,
46 double *hausdorffDist, int *ierr);
47 using libira_cshda_pbc_fn = void (*)(int nat1, const int *typ1,
48 const double *coords1, int nat2,
49 const int *typ2, const double *coords2,
50 const double *lat, double distThreshold,
51 int **found, double **dists);
53 void (*)(int nat, const int *typ, const double *coords, double threshold,
54 int prescreenIh, int *n_mat, double **mat, int **perm, char **op,
55 int **n, int **p, double **ax, double **angle, double **dH,
56 char **pg, int *n_prin_ax, double **prin_ax, int *cerr);
57 using libira_get_nmax_fn = int (*)();
58
60 std::mutex library_mutex;
61
62 virtual ~IIRAResource() = default;
63 virtual void require_loaded() = 0;
64 [[nodiscard]] virtual bool is_loaded() const noexcept = 0;
65 [[nodiscard]] virtual libira_match_fn get_match_fn() const = 0;
66 [[nodiscard]] virtual libira_cshda_pbc_fn get_cshda_pbc_fn() const = 0;
67 [[nodiscard]] virtual libira_compute_all_fn get_compute_all_fn() const = 0;
68 [[nodiscard]] virtual libira_get_nmax_fn get_get_nmax_fn() const = 0;
69
70 IIRAResource(const IIRAResource &) = delete;
71 IIRAResource &operator=(const IIRAResource &) = delete;
72
73protected:
74 IIRAResource() = default;
75};
76
77// ---------------------------------------------------------------------------
78// IRAResource: process-default loader (Meyer's singleton).
79// ---------------------------------------------------------------------------
80class IRAResource : public IIRAResource {
81public:
84
85 [[nodiscard]] bool is_loaded() const noexcept override { return m_loaded; }
86
88 void require_loaded() override;
89
90 [[nodiscard]] libira_match_fn get_match_fn() const override {
91 return libira_match_;
92 }
93 [[nodiscard]] libira_cshda_pbc_fn get_cshda_pbc_fn() const override {
94 return libira_cshda_pbc_;
95 }
96 [[nodiscard]] libira_compute_all_fn get_compute_all_fn() const override {
98 }
99 [[nodiscard]] libira_get_nmax_fn get_get_nmax_fn() const override {
100 return libira_get_nmax_;
101 }
102
103 ~IRAResource() override;
104 IRAResource(const IRAResource &) = delete;
106
107private:
109 friend class Runtime;
110
111 bool m_loaded{false};
113
114 // Loaded function pointers (null if library not found)
119
121 template <typename Fn> Fn load_sym(const char *name) const {
122 return reinterpret_cast<Fn>(dynlib::sym(m_handle, name));
123 }
124};
125
128
129} // namespace eonc
virtual void require_loaded()=0
virtual libira_compute_all_fn get_compute_all_fn() const =0
virtual ~IIRAResource()=default
virtual libira_match_fn get_match_fn() const =0
void(*)(int nat1, const int *typ1, const double *coords1, const int *cand1, int nat2, const int *typ2, const double *coords2, const int *cand2, double distThreshold, double **rotMat, double **trans, int **perm, double *hausdorffDist, int *ierr) libira_match_fn
Definition IRAResource.h:40
std::mutex library_mutex
Serializes access to the Fortran backend's shared global state.
Definition IRAResource.h:60
IIRAResource(const IIRAResource &)=delete
void(*)(int nat, const int *typ, const double *coords, double threshold, int prescreenIh, int *n_mat, double **mat, int **perm, char **op, int **n, int **p, double **ax, double **angle, double **dH, char **pg, int *n_prin_ax, double **prin_ax, int *cerr) libira_compute_all_fn
Definition IRAResource.h:52
virtual bool is_loaded() const noexcept=0
void(*)(int nat1, const int *typ1, const double *coords1, int nat2, const int *typ2, const double *coords2, const double *lat, double distThreshold, int **found, double **dists) libira_cshda_pbc_fn
Definition IRAResource.h:47
virtual libira_get_nmax_fn get_get_nmax_fn() const =0
virtual libira_cshda_pbc_fn get_cshda_pbc_fn() const =0
int(*)() libira_get_nmax_fn
Definition IRAResource.h:57
libira_compute_all_fn get_compute_all_fn() const override
Definition IRAResource.h:96
libira_match_fn get_match_fn() const override
Definition IRAResource.h:90
~IRAResource() override
libira_get_nmax_fn get_get_nmax_fn() const override
Definition IRAResource.h:99
Fn load_sym(const char *name) const
Try to load a symbol; returns nullptr on failure.
void require_loaded() override
Throws std::runtime_error if libira is not available.
IRAResource(const IRAResource &)=delete
libira_get_nmax_fn libira_get_nmax_
libira_match_fn libira_match_
libira_cshda_pbc_fn get_cshda_pbc_fn() const override
Definition IRAResource.h:93
libira_compute_all_fn libira_compute_all_
static IRAResource & instance()
Thread-safe singleton accessor (Meyer's pattern).
dynlib::Handle m_handle
bool is_loaded() const noexcept override
Definition IRAResource.h:85
libira_cshda_pbc_fn libira_cshda_pbc_
friend class Runtime
IRAResource & operator=(const IRAResource &)=delete
void * sym(Handle h, const char *name) noexcept
Definition DynLib.h:75
void * Handle
Definition DynLib.h:60
RAII resource manager for the ARTn C library with global synchronization.
IRAResource & get_ira_resource()
Global access to thread-safe IRA resource.