mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-12-28 03:37:59 +00:00
ENH: support cref() and shallow copies (refPtr and tmp)
- enables building HashTables with shadowed variables - support good() and valid() as synonyms in memory classes
This commit is contained in:
@ -166,8 +166,8 @@ public:
|
||||
|
||||
// Query
|
||||
|
||||
//- True if pointer/reference is non-null
|
||||
bool valid() const noexcept { return bool(ptr_); }
|
||||
//- True if pointer/reference is non-null.
|
||||
bool good() const noexcept { return bool(ptr_); }
|
||||
|
||||
//- If the stored/referenced content is const
|
||||
bool is_const() const noexcept { return type_ == CREF; }
|
||||
@ -175,9 +175,6 @@ public:
|
||||
//- True if this is a managed pointer (not a reference)
|
||||
bool is_pointer() const noexcept { return type_ == PTR; }
|
||||
|
||||
//- Identical to is_pointer()
|
||||
bool isTmp() const noexcept { return type_ == PTR; }
|
||||
|
||||
//- True if this is a non-null managed pointer with a unique ref-count
|
||||
inline bool movable() const noexcept;
|
||||
|
||||
@ -215,12 +212,17 @@ public:
|
||||
//- delete object and set pointer to nullptr
|
||||
inline void clear() const noexcept;
|
||||
|
||||
|
||||
//- Clear existing and transfer ownership.
|
||||
inline void reset(tmp<T>&& other) noexcept;
|
||||
|
||||
//- Delete managed temporary object and set to new given pointer
|
||||
inline void reset(T* p = nullptr) noexcept;
|
||||
|
||||
|
||||
//- Clear existing and set (const) reference from other
|
||||
inline void cref(const tmp<T>& other) noexcept;
|
||||
|
||||
//- Clear existing and set (const) reference
|
||||
inline void cref(const T& obj) noexcept;
|
||||
|
||||
@ -228,6 +230,7 @@ public:
|
||||
// The pointer can be null, which is handled like a clear().
|
||||
inline void cref(const T* p) noexcept;
|
||||
|
||||
|
||||
//- Clear existing and set to (non-const) reference
|
||||
inline void ref(T& obj) noexcept;
|
||||
|
||||
@ -235,12 +238,17 @@ public:
|
||||
// The pointer can be null, which is handled like a clear().
|
||||
inline void ref(T* p) noexcept;
|
||||
|
||||
|
||||
//- Swaps the managed object with other.
|
||||
inline void swap(tmp<T>& other) noexcept;
|
||||
|
||||
|
||||
// Member Operators
|
||||
|
||||
// Note: no 'operator*()' types since there are large chunks
|
||||
// of code that use tmp\<Field\> and Field interchangeable
|
||||
// Eg, \code (a * b) - and the '*' would be misinterpreted
|
||||
|
||||
//- Dereferences (const) pointer to the managed object.
|
||||
// Fatal for a null managed pointer.
|
||||
inline const T* operator->() const;
|
||||
@ -252,11 +260,17 @@ public:
|
||||
//- Return const reference to the object - same as cref() method.
|
||||
const T& operator()() const { return cref(); }
|
||||
|
||||
|
||||
// Casting
|
||||
|
||||
//- True if pointer/reference is non-null. Same as good()
|
||||
explicit operator bool() const noexcept { return bool(ptr_); }
|
||||
|
||||
//- Cast to underlying data type, using the cref() method.
|
||||
operator const T&() const { return cref(); }
|
||||
|
||||
//- True if pointer/reference is non-null. Same as valid()
|
||||
explicit operator bool() const noexcept { return bool(ptr_); }
|
||||
|
||||
// Assignment
|
||||
|
||||
//- Transfer ownership of the managed pointer.
|
||||
// Fatal for a null managed pointer or if the object is const.
|
||||
@ -275,6 +289,12 @@ public:
|
||||
|
||||
// Housekeeping
|
||||
|
||||
//- Identical to good(), or bool operator
|
||||
bool valid() const noexcept { return bool(ptr_); }
|
||||
|
||||
//- Identical to is_pointer()
|
||||
bool isTmp() const noexcept { return type_ == PTR; }
|
||||
|
||||
//- Deprecated(2020-07) True if a null managed pointer
|
||||
//
|
||||
// \deprecated(2020-07) - use bool operator
|
||||
@ -283,6 +303,8 @@ public:
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
// Global Functions
|
||||
|
||||
//- Specialized Swap algorithm for tmp.
|
||||
|
||||
Reference in New Issue
Block a user