Gorgon Game Engine
Collection< T_ > Class Template Reference

Collection is a container for reference typed objects. More...

Inheritance diagram for Collection< T_ >:
[legend]

Classes

class  ConstIterator
 Const iterator allows iteration of const collections. More...
 

Public Types

typedef Iterator_< T_, CollectionIterator
 Regular iterator. More...
 

Public Member Functions

 Collection ()=default
 Default constructor. More...
 
 Collection (Collection &&col)
 Move constructor. More...
 
 Collection (const Collection &)=delete
 Disabled. More...
 
template<typename... Args_>
 Collection (T_ &t, Args_ &... args)
 Initializing constructor. More...
 
template<typename... Args_>
 Collection (T_ *t, Args_ *... args)
 Initializing constructor. More...
 
bool Add (T_ &data)
 Adds a the given item to the end of the list if it is not already in the list. More...
 
template<typename... Args_>
int Add (T_ &data, Args_ &... args)
 Adds a the given item to the end of the list. More...
 
bool Add (T_ *Data)
 Adds the given item to the end of the list if it is not already in the list. More...
 
template<typename... Args_>
int Add (T_ *Data, Args_ *... args)
 Adds the given item to the end of the list, returns the number of added elements. More...
 
template<typename... Args_>
T_ & AddNew (Args_ &&... args)
 Creates a new item and adds to the end of the collection. More...
 
void Clear ()
 Removes all items from the list, allocated memory for the list stays. More...
 
void Collapse ()
 Clears the contents of the collection and releases the memory used for the list. More...
 
void Delete (const T_ *item)
 Deletes an item from the collection using its pointer. More...
 
void Delete (ConstIterator &it)
 
void Delete (Iterator &it)
 
void Delete (long index)
 Deletes an item from the collection using its index. More...
 
void Delete (T_ &data)
 Deletes an item from the collection using its reference. More...
 
void DeleteAll ()
 Deletes and removes all elements in the collection. More...
 
void Destroy ()
 Destroys the entire collection, effectively deleting the contents and the list including all the memory used by it. More...
 
Collection Duplicate () const
 Duplicates this collection. More...
 
Iterator Find (const T_ &item)
 Searches the position of a given item, if not found end iterator returned. More...
 
ConstIterator Find (const T_ &item) const
 Searches the position of a given item, if not found end iterator returned. More...
 
Iterator Find (const T_ *item)
 Searches the position of a given item, if not found end iterator returned. More...
 
ConstIterator Find (const T_ *item) const
 Searches the position of a given item, if not found end iterator returned. More...
 
long FindLocation (const T_ &item) const
 Searches the position of a given item, if not found -1 is returned. More...
 
long FindLocation (const T_ *item) const
 Searches the position of a given item, if not found -1 is returned. More...
 
T_ & Get (long index)
 Returns the element at the given index. Checks and throws if out of range. More...
 
T_ & Get (long index) const
 Returns the element at the given index. Checks and throws if out of range. More...
 
long GetCount () const
 Returns number of elements. More...
 
long GetSize () const
 Returns number of elements. More...
 
bool Insert (T_ &data, const T_ &before)
 this method adds the given object in front of the reference. More...
 
bool Insert (T_ &data, long before)
 this method adds the given object in front of the reference. More...
 
bool Insert (T_ *data, const T_ &before)
 this method adds the given object in front of the reference. More...
 
bool Insert (T_ *data, long before)
 this method adds the given object in front of the reference. More...
 
template<typename... Args_>
T_ & InsertNew (const T_ &before, Args_... args)
 Creates a new item and inserts it before the given reference. More...
 
template<typename... Args_>
T_ & InsertNew (long before, Args_... args)
 Creates a new item and inserts it before the given reference. More...
 
void MoveBefore (const T_ &index, const T_ &before)
 this method moves the given object in the collection in front of the reference More...
 
void MoveBefore (const T_ &index, long before)
 this method moves the given object in the collection in front of the reference More...
 
void MoveBefore (long index, const T_ &before)
 this method moves the given object in the collection in front of the reference More...
 
void MoveBefore (long index, long before)
 this method moves the given object in the collection in front of the reference More...
 
Adder operator+= (T_ &data)
 Adds items to the end of the list. Use comma to add more than one item. More...
 
Adder operator+= (T_ *Data)
 Adds items to the end of the list. Use comma to add more than one item. More...
 
Collectionoperator= (Collection &&col)
 Move assignment. More...
 
Collectionoperator= (const Collection &)=delete
 Disabled. More...
 
T_ & operator[] (long index)
 Returns the item at a given index. More...
 
T_ & operator[] (long index) const
 Returns the item at a given index. More...
 
T_ & Pop ()
 Removes and returns the last item in the collection. More...
 
bool Push (T_ &data)
 Adds a the given item to the end of the list if it is not already in the list. More...
 
bool Push (T_ *Data)
 Adds the given item to the end of the list if it is not already in the list. More...
 
void Remove (const T_ &data)
 Removes an item from the collection using its reference. More...
 
void Remove (const T_ *item)
 Removes an item from the collection using its pointer. More...
 
void Remove (ConstIterator &it)
 
void Remove (Iterator &it)
 
void Remove (long index)
 Removes an item from the collection using its index. More...
 
void Reserve (long amount)
 Allocates memory for the given amount of items. More...
 
void Sort ()
 Sorts items in the collection. More...
 
template<class P_ >
void Sort (P_ predicate=P_())
 Sorts items in the collection. More...
 
void Swap (Collection &col)
 Swaps the given collection with this one. More...
 

Iterator related

begin iterator

Iterator begin ()
 
Iterator end ()
 end iterator More...
 
Iterator First ()
 returns the iterator to the first item More...
 
Iterator Last ()
 returns the iterator to the last item More...
 
ConstIterator begin () const
 begin iterator More...
 
ConstIterator end () const
 end iterator More...
 
ConstIterator First () const
 returns the iterator to the first item More...
 
ConstIterator Last () const
 returns the iterator to the last item More...
 

Detailed Description

template<class T_>
class Gorgon::Containers::Collection< T_ >

Collection is a container for reference typed objects.

A container never copies its elements nor destroys unless requested specifically. Internally, a collection stores its objects in a vector as pointers. This class supports move semantics. Also copying of a collection is disabled for performance reasons. Use Duplicate method to create a duplicate of a collection.

Member Typedef Documentation

◆ Iterator

typedef Iterator_<T_, Collection> Iterator

Regular iterator.

See also
Container::Iterator

Constructor & Destructor Documentation

◆ Collection() [1/5]

Collection ( )
default

Default constructor.

◆ Collection() [2/5]

Collection ( T_ &  t,
Args_ &...  args 
)

Initializing constructor.

Warning
Visual studio erroneously allows rvalues (function return values or temporaries) to be bound to normal references. This means, its possible to pass those without getting an error. This problem is fixed by setting warning 4239 to cause an error. If working with older libraries that require this behavior,
use #pragma warning(disable: 4329)
before including necessary header.

◆ Collection() [3/5]

Collection ( T_ *  t,
Args_ *...  args 
)

Initializing constructor.

Warning
Visual studio erroneously allows rvalues (function return values or temporaries) to be bound to normal references. This means, its possible to pass those without getting an error. This problem is fixed by setting warning 4239 to cause an error. If working with older libraries that require this behavior, use
#pragma warning(disable: 4329)
before, including necessary header.

◆ Collection() [4/5]

Collection ( const Collection< T_ > &  )
delete

Disabled.

◆ Collection() [5/5]

Collection ( Collection< T_ > &&  col)

Move constructor.

Member Function Documentation

◆ Add() [1/4]

bool Add ( T_ &  data)

Adds a the given item to the end of the list if it is not already in the list.

◆ Add() [2/4]

int Add ( T_ &  data,
Args_ &...  args 
)

Adds a the given item to the end of the list.

◆ Add() [3/4]

bool Add ( T_ *  Data)

Adds the given item to the end of the list if it is not already in the list.

◆ Add() [4/4]

int Add ( T_ *  Data,
Args_ *...  args 
)

Adds the given item to the end of the list, returns the number of added elements.

◆ AddNew()

T_& AddNew ( Args_ &&...  args)

Creates a new item and adds to the end of the collection.

◆ begin() [1/2]

Iterator begin ( )

◆ begin() [2/2]

ConstIterator begin ( ) const

begin iterator

◆ Clear()

void Clear ( )

Removes all items from the list, allocated memory for the list stays.

◆ Collapse()

void Collapse ( )

Clears the contents of the collection and releases the memory used for the list.

Items are not freed.

◆ Delete() [1/5]

void Delete ( const T_ *  item)

Deletes an item from the collection using its pointer.

Deleting both removes the item from the list and free the item itself. If given item does not exists, this function deletes the item and does nothing else

◆ Delete() [2/5]

void Delete ( ConstIterator it)

◆ Delete() [3/5]

void Delete ( Iterator it)

◆ Delete() [4/5]

void Delete ( long  index)

Deletes an item from the collection using its index.

Deleting both removes the item from the list and free the item itself.

◆ Delete() [5/5]

void Delete ( T_ &  data)

Deletes an item from the collection using its reference.

Deleting both removes the item from the list and free the item itself. If given item does not exists, this function deletes the item and does nothing else

◆ DeleteAll()

void DeleteAll ( )

Deletes and removes all elements in the collection.

◆ Destroy()

void Destroy ( )

Destroys the entire collection, effectively deleting the contents and the list including all the memory used by it.

◆ Duplicate()

Collection Duplicate ( ) const

Duplicates this collection.

Copy constructor is disabled for performance reasons. Therefore, this function is necessary to duplicate a collection

◆ end() [1/2]

Iterator end ( )

end iterator

◆ end() [2/2]

ConstIterator end ( ) const

end iterator

◆ Find() [1/4]

Iterator Find ( const T_ &  item)

Searches the position of a given item, if not found end iterator returned.

◆ Find() [2/4]

ConstIterator Find ( const T_ &  item) const

Searches the position of a given item, if not found end iterator returned.

◆ Find() [3/4]

Iterator Find ( const T_ *  item)

Searches the position of a given item, if not found end iterator returned.

◆ Find() [4/4]

ConstIterator Find ( const T_ *  item) const

Searches the position of a given item, if not found end iterator returned.

◆ FindLocation() [1/2]

long FindLocation ( const T_ &  item) const

Searches the position of a given item, if not found -1 is returned.

◆ FindLocation() [2/2]

long FindLocation ( const T_ *  item) const

Searches the position of a given item, if not found -1 is returned.

◆ First() [1/2]

Iterator First ( )

returns the iterator to the first item

◆ First() [2/2]

ConstIterator First ( ) const

returns the iterator to the first item

◆ Get() [1/2]

T_& Get ( long  index)

Returns the element at the given index. Checks and throws if out of range.

◆ Get() [2/2]

T_& Get ( long  index) const

Returns the element at the given index. Checks and throws if out of range.

◆ GetCount()

long GetCount ( ) const

Returns number of elements.

◆ GetSize()

long GetSize ( ) const

Returns number of elements.

◆ Insert() [1/4]

bool Insert ( T_ &  data,
const T_ &  before 
)

this method adds the given object in front of the reference.

You may use the size of the collection for this function to behave like Add.

◆ Insert() [2/4]

bool Insert ( T_ &  data,
long  before 
)

this method adds the given object in front of the reference.

You may use the size of the collection for this function to behave like Add.

◆ Insert() [3/4]

bool Insert ( T_ *  data,
const T_ &  before 
)

this method adds the given object in front of the reference.

You may use the size of the collection for this function to behave like Add.

◆ Insert() [4/4]

bool Insert ( T_ *  data,
long  before 
)

this method adds the given object in front of the reference.

You may use the size of the collection for this function to behave like Add.

◆ InsertNew() [1/2]

T_& InsertNew ( const T_ &  before,
Args_...  args 
)

Creates a new item and inserts it before the given reference.

You may use the size of the collection for this function to behave like Add.

◆ InsertNew() [2/2]

T_& InsertNew ( long  before,
Args_...  args 
)

Creates a new item and inserts it before the given reference.

You may use the size of the collection for this function to behave like Add.

◆ Last() [1/2]

Iterator Last ( )

returns the iterator to the last item

◆ Last() [2/2]

ConstIterator Last ( ) const

returns the iterator to the last item

◆ MoveBefore() [1/4]

void MoveBefore ( const T_ &  index,
const T_ &  before 
)

this method moves the given object in the collection in front of the reference

◆ MoveBefore() [2/4]

void MoveBefore ( const T_ &  index,
long  before 
)

this method moves the given object in the collection in front of the reference

◆ MoveBefore() [3/4]

void MoveBefore ( long  index,
const T_ &  before 
)

this method moves the given object in the collection in front of the reference

◆ MoveBefore() [4/4]

void MoveBefore ( long  index,
long  before 
)

this method moves the given object in the collection in front of the reference

◆ operator+=() [1/2]

Adder operator+= ( T_ &  data)

Adds items to the end of the list. Use comma to add more than one item.

◆ operator+=() [2/2]

Adder operator+= ( T_ *  Data)

Adds items to the end of the list. Use comma to add more than one item.

◆ operator=() [1/2]

Collection& operator= ( Collection< T_ > &&  col)

Move assignment.

◆ operator=() [2/2]

Collection& operator= ( const Collection< T_ > &  )
delete

Disabled.

◆ operator[]() [1/2]

T_& operator[] ( long  index)

Returns the item at a given index.

◆ operator[]() [2/2]

T_& operator[] ( long  index) const

Returns the item at a given index.

◆ Pop()

T_& Pop ( )

Removes and returns the last item in the collection.

◆ Push() [1/2]

bool Push ( T_ &  data)

Adds a the given item to the end of the list if it is not already in the list.

◆ Push() [2/2]

bool Push ( T_ *  Data)

Adds the given item to the end of the list if it is not already in the list.

◆ Remove() [1/5]

void Remove ( const T_ &  data)

Removes an item from the collection using its reference.

If the item does not exists, nothing is done.

◆ Remove() [2/5]

void Remove ( const T_ *  item)

Removes an item from the collection using its pointer.

If the item does not exists, nothing is done.

◆ Remove() [3/5]

void Remove ( ConstIterator it)

◆ Remove() [4/5]

void Remove ( Iterator it)

◆ Remove() [5/5]

void Remove ( long  index)

Removes an item from the collection using its index.

◆ Reserve()

void Reserve ( long  amount)

Allocates memory for the given amount of items.

◆ Sort() [1/2]

void Sort ( )

Sorts items in the collection.

Regular std::sort cannot work on collections as assignment will copy objects

◆ Sort() [2/2]

void Sort ( P_  predicate = P_())

Sorts items in the collection.

Regular std::sort cannot work on collections as assignment will copy objects

◆ Swap()

void Swap ( Collection< T_ > &  col)

Swaps the given collection with this one.


The documentation for this class was generated from the following file: