class::var::Array

class var::Array
  : public api::WorkObject

The Array class is a template used to contain a standard C array.

It provides methods to access the array safely.

#include <sapi/var.hpp>
u32 c_array[64]; //C style array
Array<u32, 64> array; //var::Array

printf("C array is %ld bytes\n", sizeof(c_array));
printf("Array is %ld bytes\n", array.size());

printf("C array has %ld items\n", sizeof(c_array)/sizeof(u32));
printf("Array has %ld items\n", array.count());

printf("C array back is %ld\n", c_array[sizeof(c_array)/sizeof(u32)-1]);
printf("Array back is %ld\n", array.back());

The Array class has a fixed number of items. It can be created dynamically with new and delete or allocated on the stack or heap.

If you are looking for dynamic sizing, see var::Vector is an array that is dynamically sized where items can be appended.

var::Queue allows for pushing items on the front of a list and popping them from the back.

Summary

[Array](#classvar_1_1_array_1a8fe235a0401b163f7dd1aac4b1388ee3)()

const T & at(

u32 idx
) const

T & at(

u32 idx
)

T & back()

const T & back() const

T * begin()

const T * begin() const

u32 count() const

T * data()

const T * data() const

T * end()

const T * end() const

void fill(

const T & value
)

T & front()

const T & front() const

u32 size() const

typedef std::iterator< std::random_access_iterator_tag, const T, ptrdiff_t, const T *, const T & > const_iterator

typedef std::iterator< std::random_access_iterator_tag, T, ptrdiff_t, T *, T & > iterator

Members

Array()

const T & at(

u32 idx
) const

Returns a read-only item of the index value specified.

Parameters

  • idx The object index

If idx exceeds the size of the array, ApiObject::exit_fatal() is called.


T & at(

u32 idx
)

Returns an item of the index value specified.

Parameters

  • idx The object index

If the idx exceeds the size of the array, SObject::exit_fatal() is called.


T & back()

Returns a reference last object in the array.


const T & back() const

Returns a reference to the last object in the array (read-only).


T * begin()

const T * begin() const

u32 count() const

Returns the number of objects in the array.

#include <sapi/var.hpp>
Array<u32, 64> array;
for(u32 i=0; i < array.count(); i++){
  array.at(i) = i;
}

T * data()

Returns a pointer to the data.


const T * data() const

Returns a read-only pointer to the data.


T * end()

const T * end() const

void fill(

const T & value
)

Fills the array with the specified value.


T & front()

Returns a reference to the first object in the array.


const T & front() const

Returns a reference to first object in the array (read-only).


u32 size() const

Returns the size of the array in bytes.

Use count() to get the number of objects in the array.

#include <sapi/var.hpp>
Array<u32, 64> array;
printf("This array uses %ld bytes in memory\n", array.size());

typedef std::iterator< std::random_access_iterator_tag, const T, ptrdiff_t, const T *, const T & > const_iterator

typedef std::iterator< std::random_access_iterator_tag, T, ptrdiff_t, T *, T & > iterator

X

Thanks for Coming!

Subscribe to news and updates