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
35public:
36 // IRA C API function pointer types (from iralib_interf.h)
37 using libira_match_fn = void (*)(int nat1, const int *typ1,
38 const double *coords1, const int *cand1,
39 int nat2, const int *typ2,
40 const double *coords2, const int *cand2,
41 double distThreshold, double **rotMat,
42 double **trans, int **perm,
43 double *hausdorffDist, int *ierr);
44 using libira_cshda_pbc_fn = void (*)(int nat1, const int *typ1,
45 const double *coords1, int nat2,
46 const int *typ2, const double *coords2,
47 const double *lat, double distThreshold,
48 int **found, double **dists);
50 void (*)(int nat, const int *typ, const double *coords, double threshold,
51 int prescreenIh, int *n_mat, double **mat, int **perm, char **op,
52 int **n, int **p, double **ax, double **angle, double **dH,
53 char **pg, int *n_prin_ax, double **prin_ax, int *cerr);
54 using libira_get_nmax_fn = int (*)();
55
58
60 std::mutex library_mutex;
61
63 [[nodiscard]] bool is_loaded() const noexcept { return m_loaded; }
64
66 void require_loaded() const;
67
68 // Function pointer accessors
75
77 IRAResource(const IRAResource &) = delete;
78 IRAResource &operator=(const IRAResource &) = delete;
79
80private:
83
84 bool m_loaded{false};
86
87 // Loaded function pointers (null if library not found)
92
94 template <typename Fn> Fn load_sym(const char *name) const {
95 return reinterpret_cast<Fn>(dynlib::sym(m_handle, name));
96 }
97};
98
101
102} // namespace eonc
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:37
void require_loaded() const
Throws std::runtime_error if libira is not available.
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:49
std::mutex library_mutex
Global mutex to ensure only one thread accesses IRA library at a time.
Definition IRAResource.h:60
libira_compute_all_fn get_compute_all_fn() const
Definition IRAResource.h:71
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:44
Fn load_sym(const char *name) const
Try to load a symbol; returns nullptr on failure.
Definition IRAResource.h:94
IRAResource(const IRAResource &)=delete
Non-copyable, non-movable.
libira_get_nmax_fn libira_get_nmax_
Definition IRAResource.h:91
libira_match_fn libira_match_
Definition IRAResource.h:88
libira_get_nmax_fn get_get_nmax_fn() const
Definition IRAResource.h:74
libira_compute_all_fn libira_compute_all_
Definition IRAResource.h:90
bool is_loaded() const noexcept
True if libira was successfully loaded.
Definition IRAResource.h:63
static IRAResource & instance()
Singleton accessor (Meyer's pattern).
dynlib::Handle m_handle
Definition IRAResource.h:85
libira_cshda_pbc_fn get_cshda_pbc_fn() const
Definition IRAResource.h:70
libira_cshda_pbc_fn libira_cshda_pbc_
Definition IRAResource.h:89
int(*)() libira_get_nmax_fn
Definition IRAResource.h:54
libira_match_fn get_match_fn() const
Definition IRAResource.h:69
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.