J
jacob navia
Hi
The new release contains a significant innovation: generic containers.
Generic containers are like virtual classes in the sense that you have
no creation function, i.e. you can never create a generic container,
only a specific kind of container (list, array, hash table, etc)
The iGenericContainer interface allows to treat all containers for
specific general functions the same. For instance
iGenericContainer.GetSize(someContainer);
will always return a size_t with the number of elements in the
container, no matter which container it is that is passed as argument.
The general container interface has no functions to add an element
however, since the syntax for sequential or associative elements
differ.
A further classification then, allows for those 2 branches:
Sequential containers (lists, arrays, string-arrays, bitststrings, etc)
and associative containers (hash-tables, trees) share with the generic
containers all the generic interface, adding some functions of their own.
This allows for writing of powerful completely general functions like
this "append" function (that is part of the generic sequential
containers interface):
static int Append(SequentialContainer *g1,SequentialContainer *g2)
{
int r;
void *element;
Iterator *it1 = newIterator((GenericContainer *)g2);
for (element = it1->GetFirst(it1);
element != NULL;
element = it1->GetNext(it1)) {
r = iGenericContainer.Add(g1,element);
if (r <=0) {
return r;
}
}
return 1;
}
This function will append to the first container the second one, no
matter what the exact types of g1 or g2 are.
Note that the iterators are part of the generic interface, not the
sequential one.
All of this is completely extensible and will work with ANY future
container that agrees to respect the defined protocol.
jacob
The new release contains a significant innovation: generic containers.
Generic containers are like virtual classes in the sense that you have
no creation function, i.e. you can never create a generic container,
only a specific kind of container (list, array, hash table, etc)
The iGenericContainer interface allows to treat all containers for
specific general functions the same. For instance
iGenericContainer.GetSize(someContainer);
will always return a size_t with the number of elements in the
container, no matter which container it is that is passed as argument.
The general container interface has no functions to add an element
however, since the syntax for sequential or associative elements
differ.
A further classification then, allows for those 2 branches:
Sequential containers (lists, arrays, string-arrays, bitststrings, etc)
and associative containers (hash-tables, trees) share with the generic
containers all the generic interface, adding some functions of their own.
This allows for writing of powerful completely general functions like
this "append" function (that is part of the generic sequential
containers interface):
static int Append(SequentialContainer *g1,SequentialContainer *g2)
{
int r;
void *element;
Iterator *it1 = newIterator((GenericContainer *)g2);
for (element = it1->GetFirst(it1);
element != NULL;
element = it1->GetNext(it1)) {
r = iGenericContainer.Add(g1,element);
if (r <=0) {
return r;
}
}
return 1;
}
This function will append to the first container the second one, no
matter what the exact types of g1 or g2 are.
Note that the iterators are part of the generic interface, not the
sequential one.
All of this is completely extensible and will work with ANY future
container that agrees to respect the defined protocol.
jacob