Skip to content

Commit

Permalink
Format all c++ files with clang-format.
Browse files Browse the repository at this point in the history
  • Loading branch information
null77 committed Jan 13, 2025
1 parent ee42968 commit bd41a92
Show file tree
Hide file tree
Showing 5 changed files with 1,555 additions and 1,444 deletions.
4 changes: 2 additions & 2 deletions src/native/SharedLibrary.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ std::string GetPath(HMODULE module)

std::string GetModulePath(void *moduleOrSymbol)
{
HMODULE module = nullptr;
HMODULE module = nullptr;
if (GetModuleHandleExW(
GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
reinterpret_cast<LPCWSTR>(moduleOrSymbol), &module))
Expand Down Expand Up @@ -64,6 +64,6 @@ std::string StripFilenameFromPath(const std::string &path)
std::string GetModuleDirectory()
{
static int placeholderSymbol = 0;
std::string moduleName = GetModulePath(&placeholderSymbol);
std::string moduleName = GetModulePath(&placeholderSymbol);
return StripFilenameFromPath(moduleName);
}
24 changes: 15 additions & 9 deletions src/native/SharedLibrary.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,28 @@
#include <dlfcn.h>
#endif

inline std::string GetSharedLibraryExtension() {
inline std::string GetSharedLibraryExtension()
{
#ifdef _WIN32
return ".dll"; // Windows
return ".dll"; // Windows
#elif __APPLE__
return ".dylib"; // OSX
#elif __linux__
return ".so"; // Linux
return ".so"; // Linux
#else
#error Unsupported platform
#endif
}

std::string GetModuleDirectory();

class SharedLibrary {
class SharedLibrary
{
public:
SharedLibrary() {}

bool open(const std::string& libraryPath) {
bool open(const std::string &libraryPath)
{
const std::string libraryPathWithExt = GetModuleDirectory() + "/" + libraryPath + GetSharedLibraryExtension();
#ifdef _WIN32
handle = LoadLibraryA(libraryPathWithExt.c_str());
Expand All @@ -38,8 +41,10 @@ class SharedLibrary {
return handle != nullptr;
}

~SharedLibrary() {
if (handle) {
~SharedLibrary()
{
if (handle)
{
#ifdef _WIN32
FreeLibrary(static_cast<HMODULE>(handle));
#else
Expand All @@ -49,7 +54,8 @@ class SharedLibrary {
}

template <typename Func>
Func getFunction(const std::string& functionName) {
Func getFunction(const std::string &functionName)
{
#ifdef _WIN32
auto func = reinterpret_cast<Func>(GetProcAddress(static_cast<HMODULE>(handle), functionName.c_str()));
#else
Expand All @@ -59,5 +65,5 @@ class SharedLibrary {
}

private:
void* handle = nullptr;
void *handle = nullptr;
};
Loading

0 comments on commit bd41a92

Please sign in to comment.