Skip to content

Commit

Permalink
Add default ctor for sdl::SharedObject
Browse files Browse the repository at this point in the history
  • Loading branch information
Ybalrid committed Jan 5, 2020
1 parent fec752c commit a8b0138
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions sources/cpp-sdl2/shared_object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,12 @@ class SharedObject
if (!handle_) throw Exception("SDL_LoadObject");
}

///Construct an empty shared object handler. You can move assign to it.
SharedObject() = default;

///Automatically unload the library for you
~SharedObject() { SDL_UnloadObject(handle_); }

///This class isn't copyable
SharedObject(SharedObject const&) = delete;

///This class isn't copyable
SharedObject& operator=(SharedObject const&) = delete;

/// Move ctor
SharedObject(SharedObject&& other) noexcept { *this = std::move(other); }

Expand All @@ -49,13 +46,27 @@ class SharedObject
{
if (handle_ != other.handle_)
{
if (handle_) SDL_UnloadObject(handle_);
// If we currently hold an object
if (handle_)
{
// Free so we do not leak
SDL_UnloadObject(handle_);
}

// Assign from other handle, and set it to null
handle_ = other.handle_;
other.handle_ = nullptr;
}

return *this;
}

///This class isn't copyable
SharedObject(SharedObject const&) = delete;

///This class isn't copyable
SharedObject& operator=(SharedObject const&) = delete;

///Retrieve the raw address of a function inside the owned object. User has to cast this to the correct function pointer type
FunctionAddress function_pointer(std::string const& functionName) const
{
Expand Down

0 comments on commit a8b0138

Please sign in to comment.