46 if (ptr_ && ptr_->refCount::use_count() > 1)
49 <<
"Attempt to create more than " 50 << (ptr_->refCount::use_count() + 1)
51 <<
" tmp's referring to the same object of type tmp<" 52 <<
typeid(
T).name() <<
'>' 82 if (ptr_ && !ptr_->refCount::unique())
85 <<
"Attempted construction of a " 87 <<
" from non-unique pointer" 96 ptr_(const_cast<T*>(&obj)),
133 ptr_->refCount::operator++();
134 this->checkUseCount();
139 <<
"Attempted copy/move of a deallocated " 164 ptr_->refCount::operator++();
165 this->checkUseCount();
171 <<
"Attempted copy/move of a deallocated " 200 return (type_ == CREF);
208 return (type_ < REF_Types);
216 return (type_ > REF_Types);
223 return (ptr_ && type_ == PTR && ptr_->refCount::unique());
230 if (!ptr_ && is_pointer())
233 << this->typeName() <<
" deallocated" 247 <<
"Attempted non-const reference to const object: " 251 else if (!ptr_ && is_pointer())
254 << this->typeName() <<
" deallocated" 268 << this->typeName() <<
" deallocated" 274 if (!ptr_->refCount::unique())
277 <<
"Attempt to acquire pointer to object referred to" 278 <<
" by multiple temporaries of type " 291 return ptr_->clone().ptr();
298 if (ptr_ && is_pointer())
300 if (ptr_->refCount::unique())
306 ptr_->refCount::operator--();
319 if (ptr_ && type_ == PTR)
327 if (type_ == CACHE_PTR)
357 other.ptr_ =
nullptr;
363 template<
class... Args>
367 ptr_ =
new T(std::forward<Args>(
args)...);
384 type_ = (ptr_ ? CREF : PTR);
392 ptr_ =
const_cast<T*
>(&obj);
401 ptr_ =
const_cast<T*
>(
p);
402 type_ = (ptr_ ? CREF : PTR);
420 type_ = (ptr_ ? REF : PTR);
444 if (!ptr_ && is_pointer())
447 << this->typeName() <<
" deallocated" 461 <<
"Attempt to cast const object to non-const: " 465 else if (!ptr_ && is_pointer())
468 << this->typeName() <<
" deallocated" 487 if (other.is_pointer())
492 other.ptr_ =
nullptr;
498 <<
"Attempted assignment of a deallocated " 506 <<
"Attempted assignment of an object reference of type " 526 other.ptr_ =
nullptr;
537 <<
"Attempted copy of a deallocated " 541 else if (!
p->refCount::unique())
544 <<
"Attempted assignment of a " 546 <<
" to non-unique pointer" static word typeName()
The type-name, constructed from type-name of T.
constexpr tmp() noexcept
Construct with no managed pointer.
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.
bool movable() const noexcept
True if this is a non-null managed pointer with a unique ref-count.
T & ref() const
Return non-const reference to the contents of a non-null managed pointer.
~tmp() noexcept
Destructor: deletes managed pointer when the ref-count is 0.
const T & cref() const
Return const reference to the object or to the contents of a (non-null) managed pointer.
void protect(bool on) noexcept
Use specified protection against moving for the managed pointer. No-op for references.
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
A class for handling words, derived from Foam::string.
errorManip< error > abort(error &err)
const T * operator->() const
Dereferences (const) pointer to the managed object.
void swap(tmp< T > &other) noexcept
Swaps the managed object with other.
bool is_reference() const noexcept
True if this is a reference (not a pointer)
void operator=(const tmp< T > &other)
Transfer ownership of the managed pointer.
bool is_pointer() const noexcept
True if this is a managed pointer (not a reference)
void clear() const noexcept
If object pointer points to valid object: delete object and set pointer to nullptr.
T * ptr() const
Return managed pointer for reuse, or clone() the object reference.
A class for managing temporary objects.
T & emplace(Args &&... args)
Reset with emplace construction. Return reference to the new content.
Foam::argList args(argc, argv)
bool is_const() const noexcept
If the stored/referenced content is const.
void reset(tmp< T > &&other) noexcept
Clear existing and transfer ownership.