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 "
208 return (type_ == PTR && ptr_ && ptr_->unique());
215 if (type_ == PTR && !ptr_)
218 << this->typeName() <<
" deallocated"
232 <<
"Attempted non-const reference to const object: "
236 else if (type_ == PTR && !ptr_)
239 << this->typeName() <<
" deallocated"
250 return const_cast<T&
>(cref());
260 << this->typeName() <<
" deallocated"
269 <<
"Attempt to acquire pointer to object referred to"
270 <<
" by multiple temporaries of type "
282 return ptr_->clone().ptr();
289 if (type_ == PTR && ptr_)
325 other.ptr_ =
nullptr;
340 type_ = (ptr_ ? CREF : PTR);
348 ptr_ =
const_cast<T*
>(&obj);
357 ptr_ =
const_cast<T*
>(
p);
358 type_ = (ptr_ ? CREF : PTR);
376 type_ = (ptr_ ? REF : PTR);
400 if (type_ == PTR && !ptr_)
403 << this->typeName() <<
" deallocated"
417 <<
"Attempt to cast const object to non-const: "
421 else if (type_ == PTR && !ptr_)
424 << this->typeName() <<
" deallocated"
442 if (other.type_ == PTR)
446 other.ptr_ =
nullptr;
451 <<
"Attempted assignment of a deallocated "
459 <<
"Attempted assignment of an object reference of type "
478 other.ptr_ =
nullptr;
489 <<
"Attempted copy of a deallocated "
493 else if (!
p->unique())
496 <<
"Attempted assignment of a "
498 <<
" 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.
T * ptr() const
Return managed pointer for reuse, or clone() the object reference.
errorManip< error > abort(error &err)
meshPtr reset(new Foam::fvMesh(Foam::IOobject(regionName, runTime.timeName(), runTime, Foam::IOobject::MUST_READ), false))
void reset(tmp< T > &&other) noexcept
Clear existing and transfer ownership.
#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.
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
constexpr tmp() noexcept
Construct with no managed 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.