37 return "refPtr<" +
word(
typeid(
T).
name()) +
'>';
42template<
class... Args>
50template<
class U,
class... Args>
100 ptr_(
const_cast<T*
>(&obj)),
131 <<
"Attempted copy of a deallocated "
133 <<
abort(FatalError);
162 <<
"Attempted copy of a deallocated "
164 <<
abort(FatalError);
184 return (type_ == PTR && ptr_);
191 if (type_ == PTR && !ptr_)
194 << this->typeName() <<
" deallocated"
208 <<
"Attempted non-const reference to const object: "
210 <<
abort(FatalError);
212 else if (type_ == PTR && !ptr_)
215 << this->typeName() <<
" deallocated"
216 <<
abort(FatalError);
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 autoPtr< Time > New()
Construct (dummy) Time - no functionObjects or libraries.
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
void reset()
Reset to defaults.
A class for managing references or pointers (no reference counting)
constexpr refPtr() noexcept
Construct with no managed pointer.
static word typeName()
The type-name, constructed from type-name of T.
const T & operator*() const
Return const reference to the object.
void swap(refPtr< T > &other) noexcept
Swaps the managed object with other.
void clear() const noexcept
~refPtr()
Destructor: deletes managed pointer.
bool movable() const noexcept
True if this is a non-null managed pointer.
const T * operator->() const
Dereferences (const) pointer to the managed object.
T * ptr() const
Return managed pointer for reuse, or clone() the object reference.
static refPtr< T > NewFrom(Args &&... args)
Construct refPtr from derived type with forwarding arguments.
refPtr< T > shallowClone() const noexcept
void operator=(const refPtr< T > &other)
Transfer ownership of the managed pointer.
A class for managing temporary objects.
A class for handling words, derived from Foam::string.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
errorManip< error > abort(error &err)
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Foam::argList args(argc, argv)