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" 98 if (ptr_ && immovable) type_ = CACHE_PTR;
105 ptr_(const_cast<T*>(&obj)),
142 ptr_->refCount::operator++();
143 this->checkUseCount();
148 <<
"Attempted copy/move of a deallocated " 173 ptr_->refCount::operator++();
174 this->checkUseCount();
180 <<
"Attempted copy/move of a deallocated " 209 return (type_ == CREF);
217 return (type_ < REF_Types);
225 return (type_ > REF_Types);
232 return (ptr_ && type_ == PTR && ptr_->refCount::unique());
239 if (!ptr_ && is_pointer())
242 << this->typeName() <<
" deallocated" 256 <<
"Attempted non-const reference to const object: " 260 else if (!ptr_ && is_pointer())
263 << this->typeName() <<
" deallocated" 277 << this->typeName() <<
" deallocated" 283 if (!ptr_->refCount::unique())
286 <<
"Attempt to acquire pointer to object referred to" 287 <<
" by multiple temporaries of type " 300 return ptr_->clone().ptr();
307 if (ptr_ && is_pointer())
309 if (ptr_->refCount::unique())
315 ptr_->refCount::operator--();
335 if (ptr_ && immovable) type_ = CACHE_PTR;
352 other.ptr_ =
nullptr;
368 type_ = (ptr_ ? CREF : PTR);
376 ptr_ =
const_cast<T*
>(&obj);
385 ptr_ =
const_cast<T*
>(
p);
386 type_ = (ptr_ ? CREF : PTR);
404 type_ = (ptr_ ? REF : PTR);
428 if (!ptr_ && is_pointer())
431 << this->typeName() <<
" deallocated" 445 <<
"Attempt to cast const object to non-const: " 449 else if (!ptr_ && is_pointer())
452 << this->typeName() <<
" deallocated" 471 if (other.is_pointer())
476 other.ptr_ =
nullptr;
482 <<
"Attempted assignment of a deallocated " 490 <<
"Attempted assignment of an object reference of type " 510 other.ptr_ =
nullptr;
521 <<
"Attempted copy of a deallocated " 525 else if (!
p->refCount::unique())
528 <<
"Attempted assignment of a " 530 <<
" 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.
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for 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.
bool is_const() const noexcept
If the stored/referenced content is const.
void reset(tmp< T > &&other) noexcept
Clear existing and transfer ownership.