70 ptr_(const_cast<T*>(&obj)),
101 <<
"Attempted copy/move of a deallocated " 132 <<
"Attempted copy/move of a deallocated " 159 reset(
const_cast<tmp<T>&
>(rhs), reuse);
168 reset(
const_cast<tmp<T>&
>(rhs),
false);
195 return (type_ == CREF);
203 return (type_ < REF_Types);
211 return (type_ > REF_Types);
218 return (ptr_ && is_pointer());
225 if (!ptr_ && is_pointer())
228 << this->typeName() <<
" deallocated" 242 <<
"Attempted non-const reference to const object: " 246 else if (!ptr_ && is_pointer())
249 << this->typeName() <<
" deallocated" 265 dup.type_ = (is_const() ? CREF : REF);
292 << this->typeName() <<
" deallocated" 305 return ptr_->clone().ptr();
342 other.ptr_ =
nullptr;
375 template<
class... Args>
379 ptr_ =
new T(std::forward<Args>(
args)...);
396 type_ = (ptr_ ? CREF : PTR);
404 ptr_ =
const_cast<T*
>(&obj);
413 ptr_ =
const_cast<T*
>(
p);
414 type_ = (ptr_ ? CREF : PTR);
432 type_ = (ptr_ ? REF : PTR);
459 << this->typeName() <<
" deallocated" 472 <<
"Attempt to cast const object to non-const: " 479 << this->typeName() <<
" deallocated" 493 << this->typeName() <<
" deallocated" 507 <<
"Attempt to cast const object to non-const: " 514 << this->typeName() <<
" deallocated" 533 if (other.is_pointer())
538 other.ptr_ =
nullptr;
544 <<
"Attempted assignment of a deallocated " 552 <<
"Attempted assignment of an object reference of type " 575 return tmp<T>(cref());
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
const T & cref() const
Return const reference to the object or to the contents of a (non-null) managed pointer.
T * ptr() const
Return managed pointer for reuse, or clone() the object reference.
const T * operator->() const
Dereferences (const) pointer to the managed object.
A class for managing references or pointers (no reference counting)
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
void operator=(const refPtr< T > &other)
Transfer ownership of managed pointer.
T * get() noexcept
Return pointer without nullptr checking.
A class for handling words, derived from Foam::string.
T & emplace(Args &&... args)
Reset with emplace construction. Return reference to the new content.
const T & operator*() const
Return const reference to the object.
constexpr refPtr() noexcept
Construct with no managed pointer.
static word typeName()
The type-name, constructed from type-name of T.
errorManip< error > abort(error &err)
T & ref() const
Return non-const reference to the contents of a non-null managed pointer.
void clear() const noexcept
If object pointer points to valid object: delete object and set pointer to nullptr.
bool is_const() const noexcept
If the stored/referenced content is const.
T * release() noexcept
Release ownership and return the pointer. A no-op for reference objects (returns nullptr).
bool is_pointer() const noexcept
True if this is a managed pointer (not a reference)
bool movable() const noexcept
True if this is a non-null managed pointer.
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
bool is_reference() const noexcept
True if this is a reference (not a pointer)
refPtr< T > shallowClone() const noexcept
Return a shallow copy as a wrapped reference, preserving the const/non-const status.
T * ptr() const
Return managed pointer for reuse, or clone() the object reference.
A class for managing temporary objects.
void swap(refPtr< T > &other) noexcept
Swaps the managed object with other.
Foam::argList args(argc, argv)
bool is_const() const noexcept
If the stored/referenced content is const.
~refPtr() noexcept
Destructor: deletes managed pointer.
bool is_pointer() const noexcept
True if this is a managed pointer (not a reference)
void reset(T *p=nullptr) noexcept
Delete managed pointer and set to new given pointer.