Overview
Examples
Screenshots
Comparisons
Applications
Download
Manual
Status & Roadmap
FAQ
Authors & License
Forums
Wiki
Funding Ultimate++
Search on this site











SourceForge.net Logo



One

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.

One is moveable type with pick and optional deep copy transfer semantics. Calling methods of picked One is logic error with exception of

void operator=(pick_ One& v)

void operator<<=(const One& v) (defined using DeepCopyOption template base class)

void Clear()

bool IsPicked() const

Members

 

One()

Constructor. Constructs empty One.

 

One(T *newt)

Constructs One with content. Content is specified by pointer to object created using operator new. One takes over ownership of this this object.

newt

Object to be added.

 

One(pick_ One<T>& p)

Pick constructor. Transfers source One in low constant time, but destroys it by picking.

p

Source One.

 

One(const One<T>& p, int)

Optional deep copy constructor.

Requires T to have deep copy constructor or optional deep copy constructor.

p

Source One.

 

~One()

Destructor.

 

void Attach(T *data)

Assigns element to One. (Note: if there is content in One while calling this function, it is destroyed).

data

Pointer to the new element created using operator new.

 

T *Detach() pick_

Removes content giving up ownership. Client is responsible for deletion of content.

Return value

Pointer to the content allocated on the heap.

 

T *operator-() pick_

Same as Detach() (operator version).

Return value

Pointer to the content allocated on the heap.

 

void Clear()

Removes and destroys content.

 

void operator=(T *data)

Same as Attach(data) (operator version).

data

Pointer to the new element created using operator new.

 

void operator=(pick_ One<T>& d)

Pick operator. Transfers source One in low constant time, but destroys it by picking.

d

Source One.

 

const T *operator->() const

Constant content access operator. Illegal if there is no content.

Return value

Returns constant pointer to content.

 

T *operator->()

Content access operator. Illegal if there is no content.

Return value

Returns pointer to content.

 

const T *operator~() const

Constant content pointer access.

Return value

Returns constant pointer to content or NULL when there is no content.

 

T *operator~()

Content pointer access.

Return value

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.

Return value

Constant reference to content.

 

T& operator*()

Content reference access. Illegal if there is no content.

Return value

Reference to content.

 

template <class TT> TTCreate()

Creates content in One. (Note: if there is content in One while calling this function, it is destroyed).

TT

Type of content. Must be equal to T or derived from it.

Return value

Reference to actual content (of type TT).

 

bool IsPicked() const

Return value

true if One is picked.

 

bool IsEmpty() const

Return value

true if there is no content.

 

operator bool() const

Return value

true if there is content.