Go to the documentation of this file.
35 template<
class... Args>
43 template<
class U,
class... Args>
53 return "refPtr<" +
word(
typeid(
T).
name()) +
'>';
100 ptr_(
const_cast<T*
>(&obj)),
131 <<
"Attempted copy of a deallocated "
162 <<
"Attempted copy of a deallocated "
184 return (type_ == PTR && ptr_);
191 if (type_ == PTR && !ptr_)
194 << this->typeName() <<
" deallocated"
208 <<
"Attempted non-const reference to const object: "
212 else if (type_ == PTR && !ptr_)
215 << this->typeName() <<
" deallocated"
226 return const_cast<T&
>(cref());
238 dup.type_ = (is_const() ? CREF : REF);
265 << this->typeName() <<
" deallocated"
278 return ptr_->clone().ptr();
285 if (type_ == PTR && ptr_)
314 other.ptr_ =
nullptr;
329 type_ = (ptr_ ? CREF : PTR);
337 ptr_ =
const_cast<T*
>(&obj);
346 ptr_ =
const_cast<T*
>(
p);
347 type_ = (ptr_ ? CREF : PTR);
365 type_ = (ptr_ ? REF : PTR);
392 << this->typeName() <<
" deallocated"
405 <<
"Attempt to cast const object to non-const: "
412 << this->typeName() <<
" deallocated"
426 << this->typeName() <<
" deallocated"
440 <<
"Attempt to cast const object to non-const: "
447 << this->typeName() <<
" deallocated"
465 if (other.type_ == PTR)
469 other.ptr_ =
nullptr;
474 <<
"Attempted assignment of a deallocated "
482 <<
"Attempted assignment of an object reference of type "
501 other.ptr_ =
nullptr;
512 <<
"Attempted copy of a deallocated "
static refPtr< T > New(Args &&... args)
Construct refPtr of T with forwarding arguments.
void swap(refPtr< T > &other) noexcept
Swaps the managed object with other.
A class for handling words, derived from Foam::string.
A class for managing temporary objects.
refPtr< T > shallowClone() const noexcept
void clear() const noexcept
void reset(refPtr< T > &&other) noexcept
Clear existing and transfer ownership.
bool movable() const noexcept
True if this is a non-null managed pointer.
errorManip< error > abort(error &err)
const T & operator*() const
Return const reference to the object.
meshPtr reset(new Foam::fvMesh(Foam::IOobject(regionName, runTime.timeName(), runTime, Foam::IOobject::MUST_READ), false))
T * ptr() const
Return managed pointer for reuse, or clone() the object reference.
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
~refPtr()
Destructor: deletes managed pointer.
constexpr refPtr() noexcept
Construct with no managed pointer.
static refPtr< T > NewFrom(Args &&... args)
Construct refPtr from derived type with forwarding arguments.
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
void operator=(const refPtr< T > &other)
Transfer ownership of the managed pointer.
Foam::argList args(argc, argv)
const T * operator->() const
Dereferences (const) pointer to the managed object.
static word typeName()
The type-name, constructed from type-name of T.
A class for managing references or pointers (no reference counting)