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 "
182 return (type_ == PTR && ptr_);
194 << this->typeName() <<
" deallocated"
211 << this->typeName() <<
" deallocated"
215 else if (type_ == CREF)
218 <<
"Attempted non-const reference to const object from a "
230 return const_cast<T&
>(cref());
240 << this->typeName() <<
" deallocated"
253 return ptr_->clone().ptr();
260 if (type_ == PTR && ptr_)
289 other.ptr_ =
nullptr;
298 ptr_ =
const_cast<T*
>(&obj);
337 << this->typeName() <<
" deallocated"
354 << this->typeName() <<
" deallocated"
358 else if (type_ == CREF)
361 <<
"Attempt to cast const object to non-const for a "
380 if (other.type_ == PTR)
384 other.ptr_ =
nullptr;
389 <<
"Attempted assignment of a deallocated "
397 <<
"Attempted assignment of an object reference of type "
416 other.ptr_ =
nullptr;
427 <<
"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.
void clear() const noexcept
word name(const complex &c)
Return string representation of complex.
bool movable() const noexcept
True if this is a non-null managed pointer.
errorManip< error > abort(error &err)
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.
void reset(T *p=nullptr) noexcept
Delete managed temporary object and set to new given pointer.
~refPtr()
Destructor: deletes managed pointer.
constexpr refPtr() noexcept
Default construct, no managed pointer.
static refPtr< T > NewFrom(Args &&... args)
Construct refPtr from derived type with forwarding arguments.
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)