Rudiments
Public Member Functions | List of all members
staticarray< valuetype, count > Class Template Reference

Inherits arraycollection< valuetype >.

Public Member Functions

 staticarray ()
 
 staticarray (staticarray< valuetype, count > &v)
 
 staticarray (arraycollection< valuetype > &v)
 
staticarray< valuetype, count > & operator= (staticarray< valuetype, count > &v)
 
staticarray< valuetype, count > & operator= (arraycollection< valuetype > &v)
 
 ~staticarray ()
 
valuetype & operator[] (uint64_t index)
 
uint64_t getCount ()
 
bool clear ()
 
- Public Member Functions inherited from arraycollection< valuetype >
virtual const char * getType ()
 
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, uint64_t count>
class staticarray< valuetype, count >

The staticarray class allows you to store a pre-defined number of values and access them with array-like syntax.

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

Ie. these are legal: staticarray<int,10> d; staticarray<myclass,10> d; staticarray<myclass *,10> d;

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

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

staticarray<staticarray<in >,10> d;
staticarray<staticarray<myclass>,10> d;
staticarray<staticarray<myclass *>,10> d;
staticarray<dynamicarray<int>,10> d;
staticarray<dynamicarray<myclass>,10> d;
staticarray<dynamicarray<myclass *>,10> d;

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

For example, if the staticarray has count 10 then elements 0-9 must 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

◆ staticarray() [1/3]

template<class valuetype , uint64_t count>
staticarray< valuetype, count >::staticarray
inline

Creates an empty instance of the staticarray class with "count" elements. "count" is given in the template definition.

◆ staticarray() [2/3]

template<class valuetype , uint64_t count>
staticarray< valuetype, count >::staticarray ( staticarray< valuetype, count > &  v)
inline

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

◆ staticarray() [3/3]

template<class valuetype , uint64_t count>
staticarray< valuetype, count >::staticarray ( arraycollection< valuetype > &  v)
inline

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

◆ ~staticarray()

template<class valuetype , uint64_t count>
staticarray< valuetype, count >::~staticarray
inline

Deletes this instance of the staticarray class.

Member Function Documentation

◆ clear()

template<class valuetype , uint64_t count>
bool staticarray< valuetype, count >::clear
inlinevirtual

Clears the array. Always returns true.

Implements collection.

◆ getCount()

template<class valuetype , uint64_t count>
uint64_t staticarray< valuetype, count >::getCount
inlinevirtual

Returns the number of elements in the array.

Implements collection.

◆ operator=() [1/2]

template<class valuetype , uint64_t count>
staticarray< valuetype, count > & staticarray< valuetype, count >::operator= ( arraycollection< valuetype > &  v)
inline

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

◆ operator=() [2/2]

template<class valuetype , uint64_t count>
staticarray< valuetype, count > & staticarray< valuetype, count >::operator= ( staticarray< valuetype, count > &  v)
inline

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

◆ operator[]()

template<class valuetype , uint64_t count>
valuetype & staticarray< valuetype, count >::operator[] ( uint64_t  index)
inlinevirtual

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

Implements arraycollection< valuetype >.