Go to the documentation of this file.
39 if (ptr_->count() > 1)
42 <<
"Attempt to create more than 2 tmp's referring to"
43 " the same object of type " << typeName()
52 template<
class... Args>
60 template<
class U,
class... Args>
91 if (
p && !
p->unique())
94 <<
"Attempted construction of a " << typeName()
95 <<
" from non-unique pointer"
104 ptr_(
const_cast<T*
>(&obj)),
146 <<
"Attempted copy of a deallocated " << typeName()
175 <<
"Attempted copy of a deallocated " << typeName()
201 return (!ptr_ && isTmp());
208 return (ptr_ || type_ == CREF);
215 return (type_ == PTR && ptr_ && ptr_->unique());
222 return "tmp<" +
word(
typeid(
T).
name()) +
'>';
248 << typeName() <<
" deallocated"
265 << typeName() <<
" deallocated"
272 <<
"Attempted non-const reference to const object from a "
284 if (isTmp() && !ptr_)
287 << typeName() <<
" deallocated"
291 return const_cast<T&
>(*ptr_);
303 << typeName() <<
" deallocated"
306 else if (!ptr_->unique())
309 <<
"Attempt to acquire pointer to object referred to"
310 <<
" by multiple temporaries of type " << typeName()
320 return ptr_->clone().ptr();
372 other.ptr_ =
nullptr;
381 ptr_ =
const_cast<T*
>(&obj);
424 if (!ptr_ && isTmp())
427 << typeName() <<
" deallocated"
443 << typeName() <<
" deallocated"
450 <<
"Attempt to cast const object to non-const for a " << typeName()
461 return (ptr_ || type_ == CREF);
473 <<
"Attempted copy of a deallocated " << typeName()
476 else if (!
p->unique())
479 <<
"Attempted assignment of a " << typeName()
480 <<
" to non-unique pointer"
508 <<
"Attempted assignment to a deallocated " << typeName()
515 <<
"Attempted assignment to a const reference to an object"
516 <<
" of type " <<
typeid(
T).
name()
534 other.ptr_ =
nullptr;
T & constCast() const
Non-const dereference, even if the object is const.
A class for handling words, derived from Foam::string.
void clear() const noexcept
A class for managing temporary objects.
bool empty() const noexcept
True if this is a non-null managed pointer.
bool isTmp() const noexcept
True if this is a managed pointer (not a const reference)
const T & operator()() const
Return const reference to the object.
static tmp< T > NewFrom(Args &&... args)
Construct tmp from derived type with forwarding arguments.
void reset() noexcept
Release ownership of managed temporary object.
void operator=(T *p)
Take ownership of the pointer.
const T * operator->() const
Dereferences (const) pointer to the managed object.
T * get() noexcept
Return pointer without nullptr checking.
word name(const complex &c)
Return string representation of complex.
word typeName() const
Return type-name of the tmp, constructed from type-name of T.
errorManip< error > abort(error &err)
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
void swap(tmp< T > &other) noexcept
Swaps the managed object with other.
static tmp< T > New(Args &&... args)
Construct tmp of T with forwarding arguments.
constexpr tmp() noexcept
Construct with no managed pointer.
bool valid() const noexcept
Foam::argList args(argc, argv)
~tmp()
Destructor: deletes managed pointer when the ref-count is 0.
bool movable() const noexcept
True if this is a non-null managed pointer with a unique ref-count.