Commit 9d5cb575 authored by Mark Olesen's avatar Mark Olesen
Browse files

ENH: additional methods for tmpNrc (as per tmp)

- move constructable
- factory methods: New, NewFrom
- reset methods
parent 369604e9
......@@ -85,6 +85,26 @@ public:
typedef Foam::refCount::zero refCount;
// Factory Methods
//- Construct tmpNrc of T with forwarding arguments
// \param args list of arguments with which an instance of T
// will be constructed.
//
// \note Similar to std::make_shared, but the overload for
// array types is not disabled.
template<class... Args>
inline static tmpNrc<T> New(Args&&... args);
//- Construct tmpNrc from derived type with forwarding arguments
// \param args list of arguments with which an instance of U
// will be constructed.
//
// \note Similar to New but for derived types
template<class U, class... Args>
inline static tmpNrc<T> NewFrom(Args&&... args);
// Constructors
//- Construct with no managed pointer.
......@@ -99,6 +119,9 @@ public:
//- Construct for a const reference to an object.
inline tmpNrc(const T& obj) noexcept;
//- Move construct
inline tmpNrc(tmpNrc<T>&& t);
//- Copy construct
inline tmpNrc(const tmpNrc<T>& t);
......@@ -160,6 +183,13 @@ public:
//- delete object and set pointer to nullptr
inline void clear() const;
//- Release ownership of managed temporary object.
// After this call no object is managed.
inline void reset();
//- Delete managed temporary object and set to new given pointer
inline void reset(T* p);
//- Swaps the managed object with other tmpNrc.
inline void swap(tmpNrc<T>& other) noexcept;
......
......@@ -26,6 +26,24 @@ License
#include "error.H"
#include <typeinfo>
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
template<class T>
template<class... Args>
inline Foam::tmpNrc<T> Foam::tmpNrc<T>::New(Args&&... args)
{
return tmpNrc<T>(new T(std::forward<Args>(args)...));
}
template<class T>
template<class U, class... Args>
inline Foam::tmpNrc<T> Foam::tmpNrc<T>::NewFrom(Args&&... args)
{
return tmpNrc<T>(new U(std::forward<Args>(args)...));
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class T>
......@@ -60,6 +78,17 @@ inline Foam::tmpNrc<T>::tmpNrc(const T& obj) noexcept
{}
template<class T>
inline Foam::tmpNrc<T>::tmpNrc(tmpNrc<T>&& t)
:
ptr_(t.ptr_),
type_(t.type_)
{
t.ptr_ = nullptr;
t.type_ = PTR;
}
template<class T>
inline Foam::tmpNrc<T>::tmpNrc(const tmpNrc<T>& t)
:
......@@ -243,6 +272,24 @@ inline void Foam::tmpNrc<T>::clear() const
}
template<class T>
inline void Foam::tmpNrc<T>::reset()
{
clear();
ptr_ = nullptr;
type_ = PTR;
}
template<class T>
inline void Foam::tmpNrc<T>::reset(T* p)
{
clear();
ptr_ = p;
type_ = PTR;
}
template<class T>
inline void Foam::tmpNrc<T>::swap(tmpNrc<T>& other) noexcept
{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment