File: DynLibManager.hpp

package info (click to toggle)
yade 2025.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 33,308 kB
  • sloc: cpp: 93,298; python: 50,409; sh: 577; makefile: 162
file content (46 lines) | stat: -rw-r--r-- 1,347 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*************************************************************************
*  Copyright (C) 2004 by Olivier Galizzi                                 *
*  olivier.galizzi@imag.fr                                               *
*  Copyright (C) 2004 by Bronek Kozicki                                  *
*                                                                        *
*  This program is free software; it is licensed under the terms of the  *
*  GNU General Public License v2 or later. See file LICENSE for details. *
*************************************************************************/

#pragma once

#include <dlfcn.h>

#include <lib/base/Logging.hpp>
#include <lib/base/Math.hpp>
#include <map>

namespace yade { // Cannot have #include directive inside.

class DynLibManager {
private:
	std::map<const std::string, void*> handles;
	bool                               autoUnload;

public:
	DynLibManager();
	~DynLibManager();
	void addBaseDirectory(const std::string& dir);

	bool load(const std::string& libName);

	bool unload(const std::string& libName);
	bool isLoaded(const std::string& libName);
	bool unloadAll();
	void setAutoUnload(bool enabled);

	std::string lastError();
	DECLARE_LOGGER;

private:
	bool        closeLib(const std::string libName);
	bool        error();
	std::string lastError_;
};

} // namespace yade