commore  1.0.6-SNAPSHOT
All Classes Namespaces Functions Variables Typedefs Enumerations Pages
/examples/coding/Array.cpp

Template class for Array. The implementation is fully inlined thanks to the class BaseArray.

Parameters
Titem class
Aallocator class
Remarks
Array are builtin type in Commore. Only Array for Int, Float, Double are defined.
#include "commore/Commore.h"
#include "commore/Error.h"
#include "commore/Array.h"
#include <stdio.h>
CMR_MODULE_DECLARE("EXAMPLE_ARRAY");
CMR_FILE_DECLARE();
using namespace std;
using namespace commore;
//
// Trace Array content
//
void trace_array(const ArrayInt& l, const char* label)
{
CMR_INFO("Array: %0") << label;
for (ArrayInt::const_iterator i = l.begin(); i.more(); i++)
{
CMR_INFO(" %0") << *i;
}
}
// This is an example of how to use the ArrayInt class.
// this simple program show basic usage of ArrayInt and ArrayInt::iterator
// other builtin Commore Arraies have the same behaviour
int main(int argc, const char* argv[])
{
int r= 0;
ArrayInt numbers;
CMR_INFO("Start example Array");
numbers.add(66);
numbers.add(77);
numbers.add(88);
numbers.add(55);
trace_array(numbers, "original");
//
// Time 2 by iterator
//
for (ArrayInt::iterator i = numbers.begin(); i.more(); i++)
{
*i *= 2;
}
trace_array(numbers, "new *2");
//
// Time 3 by index
//
for (int j = 0; j < numbers.size(); j++)
{
numbers[j] *= 3;
}
trace_array(numbers, "new *3");
numbers.resize(10);
trace_array(numbers, "new size 10");
return r;
}