The Collection

Definition

A Collection is a bundle of heterogeneous data (a la struct C). Each data in a collection is indexed by a name. Available types of data are:

collection.gif

The class Collection.

Types

There exists only 1 type of Collection:

Construction

To declare a collection, just use:
Collection c1;
or
Collection *c2= new Collection;

To copy a specified collection in an other collection, use:

Collection *c1, *c2;
...
*c1=*c2;
or
Collection *c2;
...
Collection *c3=c2->Clone();

Destruction

To delete the data of a collection without deleting the collection itself, just use:
c1.Delete();

Consultation

The easiest way to set a data in a collection is to use the following macros:

The easiest way to get a data from a collection is to use the following macros:

Examples:

  1. Set and get a primitive value named "foo" in the collection:
    Collection col;
    Float f=1.2;
    col.SETVALUE("foo",Float,f);
    f=col.GETVALUE("foo",Float);
    

  2. Set and get an array of primitive values named "bar" in the collection:
    Collection col;
    Ushort *t1 = new Ushort[15]; *t2;
    col.SETARRAY("bar",Ushort,t1,15);
    int x=col.GETARRAYSIZE("bar",Ushort);
    t2=col.GETARRAY("bar",Ushort);
    

  3. Set and get a Pandore object (Imc3duc) named "foo" in the collection:
    Collection col;
    Imc3duc *im1=new Imc3duc(25,45,260), *im2;
    col.SETPOBJECT("foo",Imc3duc,im1)
    im2=col.GETPOBJECT("foo",Imc3duc)
    

  4. Set and get an array of Pandore objects (Point2d) named "bar" in the collection:
    Collection col;
    Point2d **p1, **p2;
    p1=new Point2d*[12];
    for (int i=0; i<12; i++) p1[i]=new Point2d(i,i);
    col.SETPARRAY("bar",Point2d,p1,12);
    p2=(Point2d**)col.GETPARRAY("bar",Point2d);
    

Warning:
SETARRAY, SETPOBJECT and SETPARRAY do not make a copy of the data, it is just a reference to the object. Consequently, the following example generates an error because p1 is a local array that is deleted at the end of the function Bar.
Errc Bar( Collection  &cold ) {
   Point2d p1[12];
   cold.SETPARRAY("foo",Point2d,p1,12);
}
Remarks:
In case of SETXXXX, if the name already exists then the related data is replaced without destruction.
Note:
In the special case of a variable number of data with a same name, the convention is to use several arrays prefixed with the name: name.0, name.1, name.2... For example, the red, green and blue for 10 pixels can be represented by three arrays: t.1, t.2, t.3 with 10 items each. The member function NbOf() returns the number of components and GETNARRAYS() returns the list of arrays. For example:
Collection col;
Long minsize, size;
std::string type;

col.NbOf("foo",type,size,minsize);

if (type == "Array:Char") {
   Char **foo=cold.GETNARRAYS("foo",Char,size,minsize)
   for (int i=0; i<size; i++) {
      Char* foo_i=foo[i]; 
      for (c=0; c<minsize; c++) {
       < ... using foo_i[c] ... >       
      }
   }
}

File Transfer

To save a collection, just use:
Collection col;
col.SaveFile("foobar.pan");

To load a collection, just use:

Collection col;
col2.LoadFile("foobar.pan");

The Pantheon project
Image Team GREYC Laboratory
UMR CNRS 6072 - ENSICAEN - University of Caen, France
This page was last modified on 19 June 2015