44inline void Foam::tmp<T>::checkUseCount()
const
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++();
139 <<
"Attempted copy/move of a deallocated "
164 ptr_->refCount::operator++();
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: "
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();
300 if (ptr_->refCount::unique())
306 ptr_->refCount::operator--();
319 if (ptr_ && type_ == PTR)
327 if (type_ == CACHE_PTR)
357 other.ptr_ =
nullptr;
363template<
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: "
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"
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
A class for managing temporary objects.
T & emplace(Args &&... args)
Reset with emplace construction. Return reference to the new content.
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).
bool is_pointer() const noexcept
True if this is a managed pointer (not a reference).
static word typeName()
The type-name, constructed from type-name of T.
void protect(bool on) noexcept
Use specified protection against moving for the managed pointer. No-op for references.
const T & cref() const
Return const reference to the object or 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 movable() const noexcept
True if this is a non-null managed pointer with a unique ref-count.
void operator=(const tmp< T > &other)
Transfer ownership of the managed pointer.
void reset(tmp< T > &&other) noexcept
Clear existing and transfer ownership.
const T * operator->() const
Dereferences (const) pointer to the managed object.
bool is_const() const noexcept
If the stored/referenced content is const.
T * ptr() const
Return managed pointer for reuse, or clone() the object reference.
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.
constexpr tmp() noexcept
Construct with no managed pointer.
A class for handling words, derived from Foam::string.
limits reset(1/(limits.max()+VSMALL), 1/(limits.min()+VSMALL))
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
const word GlobalIOList< Tuple2< scalar, vector > >::typeName("scalarVectorTable")
errorManip< error > abort(error &err)
void rhs(fvMatrix< typename Expr::value_type > &m, const Expr &expression)
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
Foam::argList args(argc, argv)