Note! See Numeric arrays if you want arrays (and multidimentional arrays) for numeric computing.
Scopira includes several basic, generic arrays. These classes have several distinct characterists when compared to std::vector.
scopira::tool::basic_array is a simple template class that implements a straight dynamic array. It can be of any type. This template should be used instead of dynamic C arrays.
mytype *foo = 0; foo = new mytype; delete foo; foo = new mytype; delete foo;
Could be replaced with:
scopira::tool::basic_array<mytype> foo(500); foo.resize(200);
Note that basic_array's constructor, destructor and resize methods all take care of any proper memory clean up needs.
Other features of scopira::tool::basic_array include:
scopira::tool::fixed_array is a template class that implements constant size C arrays. For example, code like this:
Could be replaced by:
Fixed arrays provide the following benefits:
scopira::tool::basic_matrix is a template class that that implements a two dimensional matrix or grid of objects. The matrix has a width and height. The matrix is thought to have graphics-like coordinates. That is, the first coordinate (x) go from 0 to width, left to right. The second coordinate (y) goes from 0 to height, top down.
Internally, this class utilizes scopira::tool::basic_array. The following additional methods are provided:
scopira::tool::hybrid_array is a scopira::tool::basic_array that has some preallocaed storage via an internal scopira::tool::fixed_array. This is particularly handy when most of the uses of the array will only require a few elements, but still need the flexibily of heap allocated storage for the few cases that go over this threshold.