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 "
53 template<
class... Args>
61 template<
class U,
class... Args>
71 return "tmp<" +
word(
typeid(
T).
name()) +
'>';
99 if (
p && !
p->unique())
102 <<
"Attempted construction of a "
104 <<
" from non-unique pointer"
113 ptr_(
const_cast<T*
>(&obj)),
155 <<
"Attempted copy of a deallocated "
186 <<
"Attempted copy of a deallocated "
206 return (type_ == PTR && ptr_ && ptr_->unique());
218 << this->typeName() <<
" deallocated"
235 << this->typeName() <<
" deallocated"
239 else if (type_ == CREF)
242 <<
"Attempted non-const reference to const object from a "
254 return const_cast<T&
>(cref());
264 << this->typeName() <<
" deallocated"
273 <<
"Attempt to acquire pointer to object referred to"
274 <<
" by multiple temporaries of type "
286 return ptr_->clone().ptr();
293 if (type_ == PTR && ptr_)
329 other.ptr_ =
nullptr;
338 ptr_ =
const_cast<T*
>(&obj);
377 << this->typeName() <<
" deallocated"
394 << this->typeName() <<
" deallocated"
398 else if (type_ == CREF)
401 <<
"Attempt to cast const object to non-const for a "
420 if (other.type_ == PTR)
424 other.ptr_ =
nullptr;
429 <<
"Attempted assignment of a deallocated "
437 <<
"Attempted assignment of an object reference of type "
456 other.ptr_ =
nullptr;
467 <<
"Attempted copy of a deallocated "
471 else if (!
p->unique())
474 <<
"Attempted assignment of a "
476 <<
" to non-unique pointer"
void operator=(const tmp< T > &other)
Transfer ownership of the managed pointer.
A class for handling words, derived from Foam::string.
void clear() const noexcept
A class for managing temporary objects.
static tmp< T > NewFrom(Args &&... args)
Construct tmp from derived type with forwarding arguments.
static word typeName()
The type-name, constructed from type-name of T.
const T * operator->() const
Dereferences (const) pointer to the managed object.
word name(const complex &c)
Return string representation of complex.
T * ptr() const
Return managed pointer for reuse, or clone() the object reference.
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
Default construct, no managed pointer.
void reset(T *p=nullptr) noexcept
Delete managed temporary object and set to new given pointer.
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.