diff --git a/Library/include/playrho/d2/Joint.hpp b/Library/include/playrho/d2/Joint.hpp index 9edc4480e2..21aca9bcb3 100644 --- a/Library/include/playrho/d2/Joint.hpp +++ b/Library/include/playrho/d2/Joint.hpp @@ -160,7 +160,7 @@ class Joint /// @brief Copy constructor. /// @details This constructor copies all the details of \a other. - Joint(const Joint& other) : m_self{other.m_self ? other.m_self->Clone_() : nullptr} + Joint(const Joint& other) : m_impl{other.m_impl ? other.m_impl->Clone_() : nullptr} { // Intentionally empty. } @@ -168,7 +168,7 @@ class Joint /// @brief Move constructor. /// @details This constructor moves all the details of \a other into *this and /// leaves \a other in the default constructed state. - Joint(Joint&& other) noexcept : m_self{std::move(other.m_self)} + Joint(Joint&& other) noexcept : m_impl{std::move(other.m_impl)} { // Intentionally empty. } @@ -212,7 +212,7 @@ class Joint /// @see https://foonathan.net/2015/10/overload-resolution-1/ template , typename = std::enable_if_t>> - explicit Joint(T&& arg) : m_self{std::make_unique>(std::forward(arg))} + explicit Joint(T&& arg) : m_impl{std::make_unique>(std::forward(arg))} { // Intentionally empty. } @@ -221,7 +221,7 @@ class Joint /// @details This operator copies all the details of \a other into *this. Joint& operator=(const Joint& other) { - m_self = other.m_self ? other.m_self->Clone_() : nullptr; + m_impl = other.m_impl ? other.m_impl->Clone_() : nullptr; return *this; } @@ -230,7 +230,7 @@ class Joint /// leaves \a other in the default constructed state. Joint& operator=(Joint&& other) noexcept { - m_self = std::move(other.m_self); + m_impl = std::move(other.m_impl); return *this; } @@ -249,18 +249,18 @@ class Joint /// @brief Swap function. void swap(Joint& other) noexcept { - std::swap(m_self, other.m_self); + std::swap(m_impl, other.m_impl); } /// @brief Checks whether this instance contains a value. bool has_value() const noexcept { - return static_cast(m_self); + return static_cast(m_impl); } friend TypeID GetType(const Joint& object) noexcept { - return object.m_self ? object.m_self->GetType_() : GetTypeID(); + return object.m_impl ? object.m_impl->GetType_() : GetTypeID(); } template @@ -271,8 +271,8 @@ class Joint friend bool operator==(const Joint& lhs, const Joint& rhs) noexcept { - return (lhs.m_self == rhs.m_self) || - ((lhs.m_self && rhs.m_self) && (lhs.m_self->IsEqual_(*rhs.m_self))); + return (lhs.m_impl == rhs.m_impl) || + ((lhs.m_impl && rhs.m_impl) && (lhs.m_impl->IsEqual_(*rhs.m_impl))); } friend bool operator!=(const Joint& lhs, const Joint& rhs) noexcept @@ -282,46 +282,46 @@ class Joint friend BodyID GetBodyA(const Joint& object) noexcept { - return object.m_self ? object.m_self->GetBodyA_() : InvalidBodyID; + return object.m_impl ? object.m_impl->GetBodyA_() : InvalidBodyID; } friend BodyID GetBodyB(const Joint& object) noexcept { - return object.m_self ? object.m_self->GetBodyB_() : InvalidBodyID; + return object.m_impl ? object.m_impl->GetBodyB_() : InvalidBodyID; } friend bool GetCollideConnected(const Joint& object) noexcept { - return object.m_self ? object.m_self->GetCollideConnected_() : false; + return object.m_impl ? object.m_impl->GetCollideConnected_() : false; } friend bool ShiftOrigin(Joint& object, const Length2& value) noexcept { - return object.m_self ? object.m_self->ShiftOrigin_(value) : false; + return object.m_impl ? object.m_impl->ShiftOrigin_(value) : false; } friend void InitVelocity(Joint& object, const Span& bodies, const playrho::StepConf& step, const ConstraintSolverConf& conf) { - if (object.m_self) { - object.m_self->InitVelocity_(bodies, step, conf); + if (object.m_impl) { + object.m_impl->InitVelocity_(bodies, step, conf); } } friend bool SolveVelocity(Joint& object, const Span& bodies, const playrho::StepConf& step) { - return object.m_self ? object.m_self->SolveVelocity_(bodies, step) : false; + return object.m_impl ? object.m_impl->SolveVelocity_(bodies, step) : false; } friend bool SolvePosition(const Joint& object, const Span& bodies, const ConstraintSolverConf& conf) { - return object.m_self ? object.m_self->SolvePosition_(bodies, conf) : false; + return object.m_impl ? object.m_impl->SolvePosition_(bodies, conf) : false; } private: - std::unique_ptr m_self; ///< Self pointer. + std::unique_ptr m_impl; ///< Pointer to implementation. }; // Traits... @@ -433,8 +433,8 @@ inline std::add_pointer_t> TypeCast(const Joint* value) noex { static_assert(!std::is_reference_v, "T may not be a reference."); using ReturnType = std::add_pointer_t; - if (value && value->m_self && (GetType(*value) == GetTypeID())) { - return static_cast(value->m_self->GetData_()); + if (value && value->m_impl && (GetType(*value) == GetTypeID())) { + return static_cast(value->m_impl->GetData_()); } return nullptr; } @@ -444,8 +444,8 @@ inline std::add_pointer_t TypeCast(Joint* value) noexcept { static_assert(!std::is_reference_v, "T may not be a reference."); using ReturnType = std::add_pointer_t; - if (value && value->m_self && (GetType(*value) == GetTypeID())) { - return static_cast(value->m_self->GetData_()); + if (value && value->m_impl && (GetType(*value) == GetTypeID())) { + return static_cast(value->m_impl->GetData_()); } return nullptr; } diff --git a/Library/include/playrho/d2/Shape.hpp b/Library/include/playrho/d2/Shape.hpp index 59626d3c4c..de6625219e 100644 --- a/Library/include/playrho/d2/Shape.hpp +++ b/Library/include/playrho/d2/Shape.hpp @@ -221,7 +221,7 @@ class Shape Shape() noexcept = default; /// @brief Copy constructor. - Shape(const Shape& other) : m_self{other.m_self ? other.m_self->Clone_() : nullptr} + Shape(const Shape& other) : m_impl{other.m_impl ? other.m_impl->Clone_() : nullptr} { // Intentionally empty. } @@ -240,7 +240,7 @@ class Shape /// @throws std::bad_alloc if there's a failure allocating storage. template , typename = std::enable_if_t>> - explicit Shape(T&& arg) : m_self{std::make_unique>(std::forward(arg))} + explicit Shape(T&& arg) : m_impl{std::make_unique>(std::forward(arg))} { // Intentionally empty. } @@ -248,7 +248,7 @@ class Shape /// @brief Copy assignment. Shape& operator=(const Shape& other) { - m_self = other.m_self ? other.m_self->Clone_() : nullptr; + m_impl = other.m_impl ? other.m_impl->Clone_() : nullptr; return *this; } @@ -273,155 +273,155 @@ class Shape /// @brief Swap support. void swap(Shape& other) noexcept { - std::swap(m_self, other.m_self); + std::swap(m_impl, other.m_impl); } /// @brief Checks whether this instance contains a value. bool has_value() const noexcept { - return static_cast(m_self); + return static_cast(m_impl); } friend ChildCounter GetChildCount(const Shape& shape) noexcept { - return shape.m_self ? shape.m_self->GetChildCount_() : static_cast(0); + return shape.m_impl ? shape.m_impl->GetChildCount_() : static_cast(0); } friend DistanceProxy GetChild(const Shape& shape, ChildCounter index) { - if (!shape.m_self) { + if (!shape.m_impl) { throw InvalidArgument("index out of range"); } - return shape.m_self->GetChild_(index); + return shape.m_impl->GetChild_(index); } friend MassData GetMassData(const Shape& shape) { - return shape.m_self ? shape.m_self->GetMassData_() : MassData{}; + return shape.m_impl ? shape.m_impl->GetMassData_() : MassData{}; } friend NonNegative GetVertexRadius(const Shape& shape, ChildCounter idx) { - if (!shape.m_self) { + if (!shape.m_impl) { throw InvalidArgument("index out of range"); } - return shape.m_self->GetVertexRadius_(idx); + return shape.m_impl->GetVertexRadius_(idx); } friend void SetVertexRadius(Shape& shape, ChildCounter idx, NonNegative value) { - if (shape.m_self) { - auto copy = shape.m_self->Clone_(); + if (shape.m_impl) { + auto copy = shape.m_impl->Clone_(); copy->SetVertexRadius_(idx, value); - shape.m_self = std::move(copy); + shape.m_impl = std::move(copy); } } friend NonNegativeFF GetFriction(const Shape& shape) noexcept { - return shape.m_self ? shape.m_self->GetFriction_() : NonNegativeFF(); + return shape.m_impl ? shape.m_impl->GetFriction_() : NonNegativeFF(); } friend void SetFriction(Shape& shape, NonNegative value) { - if (shape.m_self) { - auto copy = shape.m_self->Clone_(); + if (shape.m_impl) { + auto copy = shape.m_impl->Clone_(); copy->SetFriction_(value); - shape.m_self = std::move(copy); + shape.m_impl = std::move(copy); } } friend Real GetRestitution(const Shape& shape) noexcept { - return shape.m_self ? shape.m_self->GetRestitution_() : Real(0); + return shape.m_impl ? shape.m_impl->GetRestitution_() : Real(0); } friend void SetRestitution(Shape& shape, Real value) { - if (shape.m_self) { - auto copy = shape.m_self->Clone_(); + if (shape.m_impl) { + auto copy = shape.m_impl->Clone_(); copy->SetRestitution_(value); - shape.m_self = std::move(copy); + shape.m_impl = std::move(copy); } } friend NonNegative GetDensity(const Shape& shape) noexcept { - return shape.m_self ? shape.m_self->GetDensity_() : DefaultDensity; + return shape.m_impl ? shape.m_impl->GetDensity_() : DefaultDensity; } friend void SetDensity(Shape& shape, NonNegative value) { - if (shape.m_self) { - auto copy = shape.m_self->Clone_(); + if (shape.m_impl) { + auto copy = shape.m_impl->Clone_(); copy->SetDensity_(value); - shape.m_self = std::move(copy); + shape.m_impl = std::move(copy); } } friend Filter GetFilter(const Shape& shape) noexcept { - return shape.m_self ? shape.m_self->GetFilter_() : Filter{}; + return shape.m_impl ? shape.m_impl->GetFilter_() : Filter{}; } friend void SetFilter(Shape& shape, Filter value) { - if (shape.m_self) { - auto copy = shape.m_self->Clone_(); + if (shape.m_impl) { + auto copy = shape.m_impl->Clone_(); copy->SetFilter_(value); - shape.m_self = std::move(copy); + shape.m_impl = std::move(copy); } } friend bool IsSensor(const Shape& shape) noexcept { - return shape.m_self ? shape.m_self->IsSensor_() : false; + return shape.m_impl ? shape.m_impl->IsSensor_() : false; } friend void SetSensor(Shape& shape, bool value) { - if (shape.m_self) { - auto copy = shape.m_self->Clone_(); + if (shape.m_impl) { + auto copy = shape.m_impl->Clone_(); copy->SetSensor_(value); - shape.m_self = std::move(copy); + shape.m_impl = std::move(copy); } } friend void Translate(Shape& shape, const Length2& value) { - if (shape.m_self) { - auto copy = shape.m_self->Clone_(); + if (shape.m_impl) { + auto copy = shape.m_impl->Clone_(); copy->Translate_(value); - shape.m_self = std::move(copy); + shape.m_impl = std::move(copy); } } friend void Scale(Shape& shape, const Vec2& value) { - if (shape.m_self) { - auto copy = shape.m_self->Clone_(); + if (shape.m_impl) { + auto copy = shape.m_impl->Clone_(); copy->Scale_(value); - shape.m_self = std::move(copy); + shape.m_impl = std::move(copy); } } friend void Rotate(Shape& shape, const UnitVec& value) { - if (shape.m_self) { - auto copy = shape.m_self->Clone_(); + if (shape.m_impl) { + auto copy = shape.m_impl->Clone_(); copy->Rotate_(value); - shape.m_self = std::move(copy); + shape.m_impl = std::move(copy); } } friend const void* GetData(const Shape& shape) noexcept { - return shape.m_self ? shape.m_self->GetData_() : nullptr; + return shape.m_impl ? shape.m_impl->GetData_() : nullptr; } friend TypeID GetType(const Shape& shape) noexcept { - return shape.m_self ? shape.m_self->GetType_() : GetTypeID(); + return shape.m_impl ? shape.m_impl->GetType_() : GetTypeID(); } template @@ -429,8 +429,8 @@ class Shape friend bool operator==(const Shape& lhs, const Shape& rhs) noexcept { - return (lhs.m_self == rhs.m_self) || - ((lhs.m_self && rhs.m_self) && (lhs.m_self->IsEqual_(*rhs.m_self))); + return (lhs.m_impl == rhs.m_impl) || + ((lhs.m_impl && rhs.m_impl) && (lhs.m_impl->IsEqual_(*rhs.m_impl))); } friend bool operator!=(const Shape& lhs, const Shape& rhs) noexcept @@ -439,7 +439,7 @@ class Shape } private: - std::unique_ptr m_self; ///< Self pointer. + std::unique_ptr m_impl; ///< Pointer to implementation. }; // Related non-member functions... @@ -449,8 +449,8 @@ std::add_pointer_t> TypeCast(const Shape* value) noexcept { static_assert(!std::is_reference::value, "T may not be a reference."); using ReturnType = std::add_pointer_t>; - if (value && value->m_self && (GetType(*value) == GetTypeID())) { - return static_cast(value->m_self->GetData_()); + if (value && value->m_impl && (GetType(*value) == GetTypeID())) { + return static_cast(value->m_impl->GetData_()); } return nullptr; }