template <class T>
class One : private MoveableAndDeepCopyOption< One<T> >
T |
Type or base class of element stored in One. |
One is a container capable of containing none or single element of type specified as template argument or derived from it.
The container is similar to std::unique_ptr., but unlike it, it is treated more like container than smart pointer. For example, it propagates constantness of One to contained element.
One is moveable type with pick and optional clone transfer semantics.
One()
Default constructor. Constructs empty One.
One(T *newt)
Constructs One with content newt. Content is specified by pointer to object created using operator new. One takes over ownership of this this object.
template <class TT> One(One<TT>&& p)
Pick constructor. TT must be the same as T or derived from T.
One(const One<T>& p, int)
Optional deep copy constructor.
Requires T to have deep copy constructor or optional deep copy constructor.
~One()
Default destructor.
void Clear()
Removes the element stored in One.
bool IsPicked() const
Returns true if One has been picked.
void Attach(T *data)
Assigns element to One. (Note: if there is content in One while calling this function, it is destroyed). data must be pointer to the new content created using operator new.
T *Detach()
Removes content giving up ownership. Client is responsible for deletion of content. If One is empty, return value is NULL, otherwise the return value is pointer to the content allocated on the heap.
void operator=(T *data)
Same as Attach(data) (operator version).
template <class TT> void operator=(One<TT>&& d)
Pick assignment. TT must be the same as T or derived from T.
const T *operator->() const
Constant content access operator. Illegal if there is no content. Returns constant pointer to content.
T *operator->()
Content access operator. Illegal if there is no content. Returns pointer to content.
const T *operator~() const
const T *Get() const
Constant content pointer access. Returns constant pointer to content or NULL when there is no content.
T *operator~()
T *Get()
Content pointer access. Returns pointer to content or NULL when there is no content.
const T& operator*() const
Content constant reference access. Illegal if there is no content. Returns constant reference to content.
T& operator*()
Content reference access. Illegal if there is no content. Returns reference to content.
template <class TT, class... Args> TT& Create(Args&&... args)
Creates TT content in One. If there is content in One while calling this function, it is destroyed. Additional arguments can be specified for TT constructor.
T& Create()
Creates T content in One (default constructed).
template <class TT> bool Is() const
Returns true if One contains object of type TT or derived from TT. T must be polymorphic.
bool IsEmpty() const
Returns true if there is no content.
operator bool() const
Returns true if there is content.
template <class T, class... Args> One<T> MakeOne(Args... args)
This simple utility function creates One<T> instance.
|