Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use C++17 in context API #1837

Merged
merged 1 commit into from
Dec 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion library/public/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class F3D_EXPORT context
* For example, `getSymbol("EGL", "eglGetProcAddress")` looks for the symbol
* `eglGetProcAddress` in the library `libEGL.so` on Linux.
*/
[[nodiscard]] static function getSymbol(const std::string& lib, const std::string& func);
[[nodiscard]] static function getSymbol(std::string_view lib, std::string_view func);

/**
* An exception that can be thrown when the requested library cannot be loaded.
Expand Down
9 changes: 5 additions & 4 deletions library/src/context.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
namespace f3d
{
//----------------------------------------------------------------------------
context::function context::getSymbol(const std::string& lib, const std::string& func)
context::function context::getSymbol(std::string_view lib, std::string_view func)
{
std::string libName = vtksys::DynamicLoader::LibPrefix();
libName += lib;
Expand All @@ -26,16 +26,17 @@ context::function context::getSymbol(const std::string& lib, const std::string&

if (!handle)
{
throw context::loading_exception("Cannot find " + lib + " library");
throw context::loading_exception("Cannot find " + std::string(lib) + " library");
}

using symbol = context::fptr (*)(const char*);

symbol address = reinterpret_cast<symbol>(vtksys::DynamicLoader::GetSymbolAddress(handle, func));
symbol address =
reinterpret_cast<symbol>(vtksys::DynamicLoader::GetSymbolAddress(handle, func.data()));

if (!address)
{
throw context::symbol_exception("Cannot find " + func + " symbol");
throw context::symbol_exception("Cannot find " + std::string(func) + " symbol");
}

return address;
Expand Down
Loading