Glotzilla Container

#include GLOTZILLA_DATATYPES


The Glotzilla container class consists of a simple array, which is complemeted by a variety of functions for array manipulation to make life easier. The class automatically keeps track of the length of the array, allocates memory, etc. In general, the glotzilla container is not an appropriate substitute for the more optimized STL vector class, but it is more flexible and contains more functions.

Declaration

A Glotzilla container container is a C++ template; thus declaration requires that you provide the type of data the container will hold.

glotzilla::container <int> my_container;     //a container to hold many integers

Glotzilla containers can also hold custom objects

#include <string>     //declare the STL string class
...
glotzilla::container <std::string> myContainer;     //a container to hold many strings

Putting Elements into Container

glotzilla::container myContainer;

for(i=0; i<1000000; i++)
{
	myContainer.push(i);     //puts the value of i at the top of the container
}

Accessing Elements

As with a C array, you can access elements of a container using the [] operator.

glotzilla::container myContainer;

for(i=0; i<1000000; i++)
{
	myContainer.push(i);     //puts the value of i at the top of the front of the container
        cout << myContainer[i]<<endl;     //prints the value of i to the screen
}

Getting the Number of Elements in a Container

Similarly to the STL vector class, you can easily obtain the size of the container with the .size() or .length() function.

glotzilla::container myContainer;

for(i=0; i<1000000; i++)
{
	myContainer.push(i);     //puts the value of i at the top of the front of the container
        cout << myContainer[i]<<endl;     //prints the value of i to the screen
}

cout << myContainer.length() <<endl;     //prints 1000000 to the screen
cout << myContainer.size() <<endl;     //prints 1000000 to the screen

Deleting a Container

The memory allocated for a container is automatically freed when the container goes out of scope. To reset the container so that its length is zero, you can use the .clear() or .reset() functions.

glotzilla::container myContainer;

for(i=0; i<1000000; i++)
{
	myContainer.push(i);     //puts the value of i at the top of the front of the container
        cout << myContainer[i]<<endl;     //prints the value of i to the screen
}


cout << myContainer.length() <<endl;     //prints 1000000 to the screen
myContainer.clear();     
cout << myContainer.length() <<endl;     //prints 0 to the screen