Wrath of Zeus
Made by Torchlight Games for CSE 125 SP24
Loading...
Searching...
No Matches
Public Member Functions
SmartVector< T > Class Template Reference

SmartVector is a wrapper for the std::vector class that adds objects either to the end of the wrapped vector if it is full or places them in gaps. More...

#include <smartvector.hpp>

Public Member Functions

 SmartVector (size_t max_size)
 Creates a SmartVector instance with a maximum wrapped vector size of the given value. More...
 
 SmartVector ()
 
size_t push (T object)
 Pushes the given object to the end of the wrapped vector if it is currently full, or to an existing empty index. More...
 
bool set (T object, size_t index)
 Overwrites the object at the specified index with the given object. More...
 
size_t pushEmpty ()
 Adds an empty object to the end of the wrapped vector (by adding the new index to the freelist. More...
 
bool remove (size_t index)
 Attempts to remove the given object at the given index of the wrapped vector. More...
 
const T get (size_t index) const
 Returns the object stored at the given index if it exists, and returns nullptr otherwise. More...
 
T get (size_t index)
 
size_t size () const
 Returns the number of elements allocated in the wrapped vector (including gaps) More...
 
size_t numElements () const
 Returns the number of elements in the wrapped vector (not including gaps) More...
 
 DEF_SERIALIZE (Archive &ar, const unsigned int version)
 

Detailed Description

template<typename T>
class SmartVector< T >

SmartVector is a wrapper for the std::vector class that adds objects either to the end of the wrapped vector if it is full or places them in gaps.

Template Parameters
TType that the wrapped vector will store.

NOTE: T must be a pointer type currently!

Constructor & Destructor Documentation

◆ SmartVector() [1/2]

template<typename T >
SmartVector< T >::SmartVector ( size_t  max_size)
inlineexplicit

Creates a SmartVector instance with a maximum wrapped vector size of the given value.

◆ SmartVector() [2/2]

template<typename T >
SmartVector< T >::SmartVector ( )
inline

Member Function Documentation

◆ DEF_SERIALIZE()

template<typename T >
SmartVector< T >::DEF_SERIALIZE ( Archive &  ar,
const unsigned int  version 
)
inline

◆ get() [1/2]

template<typename T >
T SmartVector< T >::get ( size_t  index)
inline

◆ get() [2/2]

template<typename T >
const T SmartVector< T >::get ( size_t  index) const
inline

Returns the object stored at the given index if it exists, and returns nullptr otherwise.

Returns
Pointer to the object stored at the given index if it exists and nullptr otherwise.

◆ numElements()

template<typename T >
size_t SmartVector< T >::numElements ( ) const
inline

Returns the number of elements in the wrapped vector (not including gaps)

Returns
Number of elements in the wrapped vector not including gaps.

◆ push()

template<typename T >
size_t SmartVector< T >::push ( T  object)
inline

Pushes the given object to the end of the wrapped vector if it is currently full, or to an existing empty index.

Returns
Index at which the given object is inserted in the wrapped vector.

◆ pushEmpty()

template<typename T >
size_t SmartVector< T >::pushEmpty ( )
inline

Adds an empty object to the end of the wrapped vector (by adding the new index to the freelist.

Returns
Index at which the empty object is added (last index in the wrapped vector)

◆ remove()

template<typename T >
bool SmartVector< T >::remove ( size_t  index)
inline

Attempts to remove the given object at the given index of the wrapped vector.

Returns
true if successfully removed the object and false otherwise.

◆ set()

template<typename T >
bool SmartVector< T >::set ( T  object,
size_t  index 
)
inline

Overwrites the object at the specified index with the given object.

Parameters
objectobject to place at the given index.
indexIndex at which the new object will be placed.
Returns
true if successfully placed the object at the given index, and false if the index is out of bounds.

◆ size()

template<typename T >
size_t SmartVector< T >::size ( ) const
inline

Returns the number of elements allocated in the wrapped vector (including gaps)

Returns
Number of elements in the wrapped vector including gaps.

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