FreeNOS
Public Member Functions | Private Attributes
Vector< T > Class Template Reference

Vectors are dynamically resizeable Arrays. More...

#include <Vector.h>

Inheritance diagram for Vector< T >:
Sequence< T > Container Comparable< Sequence< T > >

Public Member Functions

 Vector (Size size=VECTOR_DEFAULT_SIZE)
 Constructor. More...
 
 Vector (const Vector< T > &a)
 Copy constructor. More...
 
virtual ~Vector ()
 Destructor. More...
 
virtual int insert (const T &item)
 Adds the given item to the Vector, if possible. More...
 
virtual bool insert (Size position, const T &item)
 Inserts the given item at the given position. More...
 
virtual const T * get (Size position) const
 Returns the item at the given position. More...
 
virtual const T & at (Size position) const
 Return item at the given position as a reference. More...
 
virtual void clear ()
 Remove all items from the vector. More...
 
virtual bool removeAt (Size position)
 Removes the item at the given position. More...
 
virtual Size size () const
 Returns the maximum size of this Vector. More...
 
virtual Size count () const
 Returns the number of items inside the Vector. More...
 
virtual const T * vector () const
 Get Vector data pointer. More...
 
virtual bool resize (Size size)
 Resize the Vector. More...
 
- Public Member Functions inherited from Sequence< T >
virtual void fill (T value)
 Fill the Sequence with the given value. More...
 
virtual int remove (T value)
 Remove all items with the given value. More...
 
virtual bool contains (const T value) const
 Check if the given item is stored in this Sequence. More...
 
virtual int compareTo (const Sequence< T > &s) const
 Compare this Sequence to another Sequence. More...
 
virtual bool equals (const Sequence< T > &s) const
 Test if this Sequence is equal to an other Sequence. More...
 
const T & operator[] (int i) const
 Returns the item at the given position in the Sequence. More...
 
const T & operator[] (Size i) const
 Returns the item at the given position in the Sequence. More...
 
T & operator[] (int i)
 Returns the item at the given position in the Sequence. More...
 
T & operator[] (Size i)
 Returns the item at the given position in the Sequence. More...
 
- Public Member Functions inherited from Container
 Container ()
 Constructor. More...
 
virtual ~Container ()
 Destructor. More...
 
virtual bool isEmpty () const
 Check if the Container is empty. More...
 
virtual bool reserve (Size size)
 Ensure that at least the given size is available. More...
 
virtual bool shrink (Size size)
 Shrink the container size by the given amount of items. More...
 
virtual Size squeeze ()
 Try to minimize the memory required in the Container. More...
 
- Public Member Functions inherited from Comparable< Sequence< T > >
virtual ~Comparable ()
 Class destructor. More...
 

Private Attributes

T * m_array
 The actual array where the data is stored. More...
 
Size m_size
 The maximum size of the array. More...
 
Size m_count
 Number of used items in the array. More...
 

Detailed Description

template<class T>
class Vector< T >

Vectors are dynamically resizeable Arrays.

Definition at line 41 of file Vector.h.

Constructor & Destructor Documentation

◆ Vector() [1/2]

template<class T >
Vector< T >::Vector ( Size  size = VECTOR_DEFAULT_SIZE)
inline

Constructor.

Initializes the Vector with the given Size.

Parameters
sizeThe maximum size of the array

Definition at line 52 of file Vector.h.

◆ Vector() [2/2]

template<class T >
Vector< T >::Vector ( const Vector< T > &  a)
inline

Copy constructor.

Parameters
aVector reference to copy from.

Definition at line 66 of file Vector.h.

◆ ~Vector()

template<class T >
virtual Vector< T >::~Vector ( )
inlinevirtual

Destructor.

Definition at line 81 of file Vector.h.

Member Function Documentation

◆ at()

template<class T >
virtual const T& Vector< T >::at ( Size  position) const
inlinevirtual

Return item at the given position as a reference.

Parameters
positionPosition of the item to get.

Implements Sequence< T >.

Definition at line 153 of file Vector.h.

Referenced by ArgumentParser::registerPositional().

◆ clear()

template<class T >
virtual void Vector< T >::clear ( )
inlinevirtual

Remove all items from the vector.

Reimplemented from Sequence< T >.

Definition at line 161 of file Vector.h.

◆ count()

template<class T >
virtual Size Vector< T >::count ( ) const
inlinevirtual

◆ get()

template<class T >
virtual const T* Vector< T >::get ( Size  position) const
inlinevirtual

Returns the item at the given position.

Parameters
positionThe position of the item to get.
Returns
Pointer to the item at the given position.

Implements Sequence< T >.

Definition at line 139 of file Vector.h.

Referenced by API::invoke().

◆ insert() [1/2]

template<class T >
virtual int Vector< T >::insert ( const T &  item)
inlinevirtual

Adds the given item to the Vector, if possible.

Parameters
itemThe item to add to the Vector.
Returns
Position of the item in the Vector or -1 on failure.

Reimplemented from Sequence< T >.

Definition at line 93 of file Vector.h.

Referenced by ArgumentContainer::addPositional(), API::API(), Kernel::hookIntVector(), LinnFileSystem::LinnFileSystem(), BootImageCreate::readBootSymbols(), ProcessManager::registerInterruptNotify(), and ArgumentParser::registerPositional().

◆ insert() [2/2]

template<class T >
virtual bool Vector< T >::insert ( Size  position,
const T &  item 
)
inlinevirtual

Inserts the given item at the given position.

If an item exists at the given position, it will be replaced by the given item.

Parameters
positionThe position to insert the item.
itemThe item to insert
Returns
bool Whether inserting the item at the given position succeeded.

Reimplemented from Sequence< T >.

Definition at line 113 of file Vector.h.

◆ removeAt()

template<class T >
virtual bool Vector< T >::removeAt ( Size  position)
inlinevirtual

Removes the item at the given position.

Parameters
positionThe position of the item to remove.
Returns
bool Whether removing the item succeeded.

Reimplemented from Sequence< T >.

Definition at line 173 of file Vector.h.

◆ resize()

template<class T >
virtual bool Vector< T >::resize ( Size  size)
inlinevirtual

Resize the Vector.

Parameters
sizeNew size of the Vector

Reimplemented from Container.

Definition at line 224 of file Vector.h.

Referenced by Vector< Argument * >::insert().

◆ size()

template<class T >
virtual Size Vector< T >::size ( ) const
inlinevirtual

Returns the maximum size of this Vector.

Returns
size The maximum size of this Vector.

Implements Container.

Definition at line 194 of file Vector.h.

Referenced by Vector< Argument * >::resize(), ProcessManager::unregisterInterruptNotify(), and Vector< Argument * >::Vector().

◆ vector()

template<class T >
virtual const T* Vector< T >::vector ( ) const
inlinevirtual

Get Vector data pointer.

Returns
Pointer to Vector data.

Definition at line 214 of file Vector.h.

Field Documentation

◆ m_array

template<class T >
T* Vector< T >::m_array
private

◆ m_count

template<class T >
Size Vector< T >::m_count
private

◆ m_size

template<class T >
Size Vector< T >::m_size
private

The maximum size of the array.

Definition at line 250 of file Vector.h.

Referenced by Vector< Argument * >::insert(), Vector< Argument * >::resize(), Vector< Argument * >::size(), and Vector< Argument * >::Vector().


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