DART 6.13.2
Loading...
Searching...
No Matches
SharedLibrary.hpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2011-2022, The DART development contributors
3 * All rights reserved.
4 *
5 * The list of contributors can be found at:
6 * https://github.com/dartsim/dart/blob/master/LICENSE
7 *
8 * This file is provided under the following "BSD-style" License:
9 * Redistribution and use in source and binary forms, with or
10 * without modification, are permitted provided that the following
11 * conditions are met:
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * * Redistributions in binary form must reproduce the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer in the documentation and/or other materials provided
17 * with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
19 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
20 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
26 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
31 */
32
33#ifndef DART_COMMON_SHAREDLIBRARY_HPP_
34#define DART_COMMON_SHAREDLIBRARY_HPP_
35
36#include <memory>
37#include <string>
38
42
43#if DART_OS_LINUX
44
45 #define DYNLIB_HANDLE void*
46
47#elif DART_OS_MACOS
48
49 #define DYNLIB_HANDLE void*
50
51#elif DART_OS_WINDOWS
52
54using hInstance = HINSTANCE__*;
55 #define DYNLIB_HANDLE hInstance
56
57#endif
58
59#if DART_OS_LINUX
60static constexpr const char* DART_SHARED_LIB_EXTENSION = "so";
61#elif DART_OS_MACOS
62static constexpr const char* DART_SHARED_LIB_EXTENSION = "dylib";
63#elif DART_OS_WINDOWS
64static constexpr const char* DART_SHARED_LIB_EXTENSION = "dll";
65#else
66 #error Unhandled platform
67#endif
68
69#if DART_OS_LINUX
70static constexpr const char* DART_SHARED_LIB_PREFIX = "lib";
71#elif DART_OS_MACOS
72static constexpr const char* DART_SHARED_LIB_PREFIX = "lib";
73#elif DART_OS_WINDOWS
74static constexpr const char* DART_SHARED_LIB_PREFIX = "";
75#else
76 #error Unhandled platform
77#endif
78
79namespace dart {
80namespace common {
81
82namespace detail {
83class SharedLibraryManager;
84} // namespace detail
85
88{
89protected:
94
95public:
109 DART_DEPRECATED(6.10)
110 static std::shared_ptr<SharedLibrary> create(
111 const common::filesystem::path& path);
112
124 static std::shared_ptr<SharedLibrary> create(const std::string& path);
125
139 DART_DEPRECATED(6.10)
140 explicit SharedLibrary(
141 ProtectedConstructionTag, const common::filesystem::path& path);
142
154 explicit SharedLibrary(ProtectedConstructionTag, const std::string& path);
155
157 virtual ~SharedLibrary();
158
160 const common::filesystem::path& getCanonicalPath() const;
161
163 const std::string& path() const;
164
166 bool isValid() const;
167
173 void* getSymbol(const std::string& symbolName) const;
174
175protected:
176 friend class detail::SharedLibraryManager;
177
182 common::filesystem::path mCanonicalPath;
183 // TODO(JS): Remove in DART 7.
184
188 std::string mPath;
189
191 DYNLIB_HANDLE mInstance;
192
193private:
195 std::string getLastError() const;
196};
197
198} // namespace common
199} // namespace dart
200
201#endif // DART_COMMON_SHAREDLIBRARY_HPP_
#define DART_DEPRECATED(version)
Definition Deprecated.hpp:51
SharedLibrary is a RAII object wrapping a shared library.
Definition SharedLibrary.hpp:88
ProtectedConstructionTag
Definition SharedLibrary.hpp:91
@ ProtectedConstruction
Definition SharedLibrary.hpp:92
bool isValid() const
Returns true if the shared library loading was successful.
Definition SharedLibrary.cpp:119
common::filesystem::path mCanonicalPath
Canonical path to the shared library where a canonical path is an absolute path that has no elements ...
Definition SharedLibrary.hpp:182
const common::filesystem::path & getCanonicalPath() const
Returns the path to the shared library file.
Definition SharedLibrary.cpp:107
const std::string & path() const
Returns the path to the shared library file.
Definition SharedLibrary.cpp:113
std::string mPath
Canonical path to the shared library where a canonical path is an absolute path that has no elements ...
Definition SharedLibrary.hpp:188
static std::shared_ptr< SharedLibrary > create(const common::filesystem::path &path)
Creates a SharedLibrary from a path to the shared library.
Definition SharedLibrary.cpp:59
void * getSymbol(const std::string &symbolName) const
Returns a symbol from the shared library if it exists.
Definition SharedLibrary.cpp:125
friend class detail::SharedLibraryManager
Definition SharedLibrary.hpp:176
std::string getLastError() const
Returns the last loading error.
Definition SharedLibrary.cpp:143
DYNLIB_HANDLE mInstance
Handle to the loaded library.
Definition SharedLibrary.hpp:191
Definition BulletCollisionDetector.cpp:60