Rudiments
Public Member Functions | List of all members
dynamicarray< valuetype > Class Template Reference

#include <dynamicarray.h>

Inherits arraycollection< valuetype >.

Public Member Functions

 dynamicarray ()
 
 dynamicarray (uint64_t initiallength, uint64_t incrementlength)
 
 dynamicarray (dynamicarray< valuetype > &v)
 
 dynamicarray (arraycollection< valuetype > &v)
 
dynamicarray< valuetype > & operator= (dynamicarray< valuetype > &v)
 
dynamicarray< valuetype > & operator= (arraycollection< valuetype > &v)
 
 ~dynamicarray ()
 
void zero (uint64_t count)
 
void zero (uint64_t start, uint64_t count)
 
void set (byte_t value, uint64_t count)
 
void set (byte_t value, uint64_t start, uint64_t count)
 
valuetypeoperator[] (uint64_t index)
 
uint64_t getInitialCount ()
 
uint64_t getIncrementCount ()
 
uint64_t getCount ()
 
bool clear ()
 
bool clear (uint64_t initiallength, uint64_t incrementlength)
 
- Public Member Functions inherited from arraycollection< valuetype >
virtual const chargetType ()
 
virtual ssize_t write ()
 
virtual ssize_t write (output *out)
 
virtual ssize_t writeJson ()
 
virtual ssize_t writeJson (bool indent)
 
virtual ssize_t writeJson (output *out)
 
virtual ssize_t writeJson (output *out, bool indent)
 
- Public Member Functions inherited from collection
 collection ()
 
 collection (collection &c)
 
collectionoperator= (collection &c)
 
virtual ~collection ()
 
comparatorgetComparator ()
 
void setComparator (comparator *newcomp)
 
virtual bool isReadOnly ()
 
virtual bool isBlockBased ()
 
virtual uint64_t getBlockSize ()
 
virtual bool isSequentialAccess ()
 
virtual void setManageValues (bool manage)
 
virtual bool getManageValues ()
 
virtual void setManageArrayValues (bool manage)
 
virtual bool getManageArrayValues ()
 
virtual void setManageKeys (bool manage)
 
virtual bool getManageKeys ()
 
virtual void setManageArrayKeys (bool manage)
 
virtual bool getManageArrayKeys ()
 
- Public Member Functions inherited from object
virtual ~object ()
 

Detailed Description

template<class valuetype>
class dynamicarray< valuetype >

The dynamicarray class allows you to store an arbitrary number of values and access them with array-like syntax.

Internally, the class stores these values in a series of extents. The size of the initial and incremental extents are defined in the constructor.

"valuetype" can be any scalar type, including a pointer, but cannot be an array.

Ie. these are legal: dynamicarray<int> d; dynamicarray<myclass> d; dynamicarray<myclass *> d;

These are not legal and whether they work or even compile would be platform-dependent: dynamicarray<int[100]> d; dynamicarray<myclass[100]> d; dynamicarray<myclass *[100]> d;

However, it is possible to create an array of arrays by nesting dynamicarrays and/or staticarrays, like:

dynamicarray<dynamicarray<int> > d;
dynamicarray<dynamicarray<myclass> > d;
dynamicarray<dynamicarray<myclass *> > d;
dynamicarray<staticarray<int> > d;
dynamicarray<staticarray<myclass> > d;
dynamicarray<staticarray<myclass *> > d;

NOTE: If "valuetype" is a pointer and either of collection::setManageValues(true) or collection::setManageArrayValue(true) are called, then all elements of the dynamicarray prior to the highest set element must also be set to something.

For example, if element 9 is set to some value then elements 0-8 must also be set to some value. They may be set to 0 or NULL, but they must be set.

Otherwise attempts to delete the uninitialized elements during calls to clear() or the destructor will likely cause the program to crash.

Constructor & Destructor Documentation

◆ dynamicarray() [1/4]

Creates an empty instance of the dynamicarray class.

◆ dynamicarray() [2/4]

template<class valuetype >
dynamicarray< valuetype >::dynamicarray ( uint64_t initiallength,
uint64_t incrementlength )
inline

Creates an empty instance of the dynamicarray class. The initial extent will be created with "initiallength" members and each successive extent will be created with "incrementlength" members.

◆ dynamicarray() [3/4]

Creates an instance of the dynamicarray class that is a copy of "v".

◆ dynamicarray() [4/4]

Creates an instance of the dynamicarray class that is a copy of "v".

◆ ~dynamicarray()

template<class valuetype >
dynamicarray< valuetype >::~dynamicarray ( )
inline

Deletes this instance of the dynamicarray class and all of its values.

Member Function Documentation

◆ clear() [1/2]

template<class valuetype >
bool dynamicarray< valuetype >::clear ( )
inlinevirtual

Clears the array.

Always returns true.

Implements collection.

◆ clear() [2/2]

template<class valuetype >
bool dynamicarray< valuetype >::clear ( uint64_t initiallength,
uint64_t incrementlength )
inline

Clears the array and resets the lengths of the initial and incremental extents.

◆ getCount()

template<class valuetype >
uint64_t dynamicarray< valuetype >::getCount ( )
inlinevirtual

Returns the number of elements in the array.

Implements collection.

◆ operator=() [1/2]

Makes this instance of the dynamicarray class identical to "v".

◆ operator=() [2/2]

Makes this instance of the dynamicarray class identical to "v".

◆ operator[]()

template<class valuetype >
valuetype & dynamicarray< valuetype >::operator[] ( uint64_t index)
inlinevirtual

Provides read/write access to the "index"th element of the dynamicarray.

Implements arraycollection< valuetype >.

◆ set() [1/2]

template<class valuetype >
void dynamicarray< valuetype >::set ( byte_t value,
uint64_t count )
inline

Sets all bytes of the first "count" elements of the dynamicarray to "value".

◆ set() [2/2]

template<class valuetype >
void dynamicarray< valuetype >::set ( byte_t value,
uint64_t start,
uint64_t count )
inline

Sets all bytes of "count" elements of the dynamicarray, starting at "start", to "value".

◆ zero() [1/2]

template<class valuetype >
void dynamicarray< valuetype >::zero ( uint64_t count)
inline

Sets all bytes of the first "count" elements of the dynamicarray to 0.

◆ zero() [2/2]

template<class valuetype >
void dynamicarray< valuetype >::zero ( uint64_t start,
uint64_t count )
inline

Sets all bytes of "count" elements of the dynamicarray, starting at "start", to 0.