DART  6.7.3
SharedLibrary.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011-2019, 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 #include <boost/filesystem.hpp>
39 #include "dart/common/Platform.hpp"
40 
41 #if DART_OS_LINUX
42 
43 #define DYNLIB_HANDLE void*
44 
45 #elif DART_OS_MACOS
46 
47 #define DYNLIB_HANDLE void*
48 
49 #elif DART_OS_WINDOWS
50 
51 #ifdef NOMINMAX
52 #include <windows.h>
53 #else
54 #define NOMINMAX
55 #include <windows.h>
56 #undef NOMINMAX
57 #endif
58 using hInstance = HINSTANCE__*;
59 #define DYNLIB_HANDLE hInstance
60 
61 #endif
62 
63 namespace dart {
64 namespace common {
65 
66 namespace detail {
67 class SharedLibraryManager;
68 } // namespace detail
69 
72 {
73 protected:
75  {
77  };
78 
79 public:
91  static std::shared_ptr<SharedLibrary> create(
92  const boost::filesystem::path& path);
93 
105  explicit SharedLibrary(
106  ProtectedConstructionTag, const boost::filesystem::path& path);
107 
109  virtual ~SharedLibrary();
110 
112  const boost::filesystem::path& getCanonicalPath() const;
113 
115  bool isValid() const;
116 
122  void* getSymbol(const std::string& symbolName) const;
123 
124 protected:
126 
130  boost::filesystem::path mCanonicalPath;
131 
133  DYNLIB_HANDLE mInstance;
134 
135 private:
137  std::string getLastError() const;
138 };
139 
140 } // namespace common
141 } // namespace dart
142 
143 #endif // DART_COMMON_SHAREDLIBRARY_HPP_
SharedLibrary is a RAII object wrapping a shared library.
Definition: SharedLibrary.hpp:72
boost::filesystem::path mCanonicalPath
Canonical path to the shared library where a canonical path is an absolute path that has no elements ...
Definition: SharedLibrary.hpp:130
ProtectedConstructionTag
Definition: SharedLibrary.hpp:75
@ ProtectedConstruction
Definition: SharedLibrary.hpp:76
bool isValid() const
Returns true if the shared library loading was successful.
Definition: SharedLibrary.cpp:100
const boost::filesystem::path & getCanonicalPath() const
Returns the path to the shared library file.
Definition: SharedLibrary.cpp:94
SharedLibrary(ProtectedConstructionTag, const boost::filesystem::path &path)
Constructs from a path to the shared library.
Definition: SharedLibrary.cpp:66
static std::shared_ptr< SharedLibrary > create(const boost::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:106
std::string getLastError() const
Returns the last loading error.
Definition: SharedLibrary.cpp:124
virtual ~SharedLibrary()
Destructor.
Definition: SharedLibrary.cpp:81
DYNLIB_HANDLE mInstance
Handle to the loaded library.
Definition: SharedLibrary.hpp:133
Definition: SharedLibraryManager.hpp:63
Definition: BulletCollisionDetector.cpp:63