Skip to content

Commit b8f5494

Browse files
author
jparisu
committed
Refs #15831: apply suggestions over fragile_ptr
Signed-off-by: jparisu <[email protected]>
1 parent e072c7b commit b8f5494

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed

src/cpp/types/fragile_ptr.hpp

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ namespace details {
3232
* @brief This class represents a Smart Pointer that works as a \c weak_ptr but has the API of a \c shared_ptr .
3333
*
3434
* A \c fragile_ptr is a Smart Pointer that holds a weak reference to an object of kind \c T .
35-
* A weak reference implies that there is no assurance that this object will exit (will not be destroyed somewhere
36-
* else) all along the life of this object.
35+
* A weak reference implies that there is no assurance that this object will exist (will not be destroyed somewhere
36+
* else) along the lifetime of this object.
3737
* This class replicates the API of a shared_ptr and those times that the internal reference is used
3838
* (operator-> and operator*) it throws an exception if the internal reference has expired.
3939
*
@@ -61,13 +61,13 @@ class fragile_ptr
6161
fragile_ptr() noexcept = default;
6262

6363
//! Default constructors and operator= from other \c fragile_ptr ( \c weak_ptr are copiable and moveable).
64-
fragile_ptr(const fragile_ptr<T>& copy_other) = default;
65-
fragile_ptr(fragile_ptr<T>&& move_other) = default;
66-
fragile_ptr& operator=(const fragile_ptr<T>& copy_other) = default;
67-
fragile_ptr& operator=(fragile_ptr<T>&& move_other) = default;
64+
fragile_ptr(const fragile_ptr<T>& copy_other) noexcept = default;
65+
fragile_ptr(fragile_ptr<T>&& move_other) noexcept = default;
66+
fragile_ptr& operator=(const fragile_ptr<T>& copy_other) noexcept = default;
67+
fragile_ptr& operator=(fragile_ptr<T>&& move_other) noexcept = default;
6868

6969
//! Default destructor
70-
virtual ~fragile_ptr() = default;
70+
~fragile_ptr() = default;
7171

7272
/////////////////////
7373
// CONSTRUCTORS FROM SHARED PTR
@@ -79,28 +79,28 @@ class fragile_ptr
7979
*
8080
* @param shared_reference \c shared_ptr to the reference to point from this.
8181
*/
82-
fragile_ptr(const std::shared_ptr<T>& shared_reference)
82+
fragile_ptr(const std::shared_ptr<T>& shared_reference) noexcept
8383
: reference_(shared_reference)
8484
{
8585
// Do nothing
8686
}
8787

8888
//! Same as calling basic constructor.
89-
fragile_ptr(std::nullptr_t)
89+
fragile_ptr(std::nullptr_t) noexcept
9090
{
9191
// Do nothing
9292
}
9393

9494
/**
95-
* @brief Construct a new fragile ptr object from a shared one
95+
* @brief Assign the fragile ptr object from a shared one
9696
*
9797
* It initializes the internal \c weak_ptr with the reference of the shared one.
9898
*
9999
* @param shared_reference \c shared_ptr to the reference to point from this.
100100
*/
101-
fragile_ptr& operator=(const std::shared_ptr<T>& copy_other)
101+
fragile_ptr& operator=(const std::shared_ptr<T>& shared_reference) noexcept
102102
{
103-
this->reference_ = copy_other;
103+
this->reference_ = shared_reference;
104104
return *this;
105105
}
106106

@@ -110,7 +110,9 @@ class fragile_ptr
110110
/**
111111
* @brief Compare this ptr reference with a shared one.
112112
*
113-
* @todo use if_enabled or somehow limit this cast to only those U that are coherent
113+
* @param other \c shared_ptr to compare with.
114+
*
115+
* @todo use if_enabled or somehow limit this cast to only those U that are coherent.
114116
*/
115117
template <typename U>
116118
bool operator==(const std::shared_ptr<U>& other) const noexcept
@@ -125,7 +127,7 @@ class fragile_ptr
125127
/**
126128
* @brief Cast this object to a \c shared_ptr object of type \c U .
127129
*
128-
* @todo use if_enabled or somehow limit this cast to only those U that are coherent
130+
* @todo use if_enabled or somehow limit this cast to only those U that are coherent.
129131
*/
130132
template <typename U>
131133
operator std::shared_ptr<U> () const
@@ -143,12 +145,12 @@ class fragile_ptr
143145
}
144146

145147
//! Cast this object to a \c shared_ptr of the same type.
146-
operator std::shared_ptr<T>() const
148+
operator std::shared_ptr<T>() const noexcept
147149
{
148150
return this->lock();
149151
}
150152

151-
//! Wether the internal ptr is valid (it it has been initialized and it has expired).
153+
//! Whether the internal ptr is valid (it has been initialized and has not expired).
152154
operator bool() const noexcept
153155
{
154156
return !reference_.expired();
@@ -186,7 +188,7 @@ class fragile_ptr
186188
*
187189
* @return T* internal reference (could be null)
188190
*/
189-
T* get() const
191+
T* get() const noexcept
190192
{
191193
return lock().get();
192194
}
@@ -225,7 +227,8 @@ class fragile_ptr
225227
* @brief This method calls \c weak_ptr::lock . In case the reference is not valid anymore
226228
* it throws an exception to warn about its usage.
227229
*
228-
* It uses for those cases where using the internal reference must be protected by an exception call in error case.
230+
* It is used for those cases where using the internal reference must be protected by an exception call
231+
* in case of error.
229232
*
230233
* @return return of shared_ptr result from lock
231234
* @throw \c Inconsistency if the internal reference is not valid.

0 commit comments

Comments
 (0)