The aggregates Bag, Set and List

The aggregate types bag, set and list are implemented as subtypes of dbLinkedAggregate. Since these aggregates are expandable, they have a common implementation. Arrays, that have fixed sized, have another implementation.
The type of the aggregate element is added by the C++ template mechanism. List is declared as follows:
template <class ListMember>
class List : public dbLinkedAggregate
For example the EXPRESS type LIST OF INTEGER will then be declared as
List<int>
Aggregates are allocated in memory by a new operator that requires reference to a memory allocator object. Bag, set and list aggregates have constructors with 3 parameters:

  1. Reference to memory allocator object.
  2. Constant specifying the primitive type of the aggregate element. The primitive type must be specified by one of the following values:
    1. sdaiINTEGER
    2. sdaiREAL
    3. sdaiBOOLEAN
    4. sdaiLOGICAL
    5. sdaiSTRING
    6. sdaiENUMERATION
    7. sdaiINSTANCE
    8. sdaiAGGR
  3. An integer specifying the size, in number of aggregate elements, of each of the buffers linked together to store the aggregate in memory. Note that this does not limit the total size of the aggregate.


A List<int> is then allocated in memory as shown below
// The first 3 ints are stored in the first buffer and
//the next 3 ints in the next buffer etc.
List<int> intList = new(ma)List<int>(ma, sdaiINTEGER, 3);
Methods for Bag, Set and List:
The current version of the C++ EXPRESS API has the following methods for Bag, Set and List:

  • void add(element, CMemoryAllocator) – adds the specified element to the aggregate. Reference to memory allocator object is needed because adding an element may imply allocating a new buffer for the element.
  • int size() – return number of elements in the aggregate.
  • void reset() – number of elements is set to zero without releasing the buffers
  • ListMember first() – return the first element of a list
  • ListMember getElement(EDMULONG elementNo) – return list element by index
  • double getRealElement(EDMULONG elementNo) – return real value by index


SET example:
// Create another product
product* p2 = newObject(product);
p2->put_id("Aircraft 2");
p2->put_name("Aircraft propeller map");
p2->put_description("Aircraft 2");
printf("\nProduct Aircraft 2 created.");
// Allocate SET OF products
Set<action_items*>* prodSet = new(&ma) Set<action_items*>(&ma, sdaiINSTANCE, 2);
// Add the two products already created
prodSet->add(p1,&ma);
prodSet->add(p2,&ma);
// Assign set to attribute items of applied_action_assignment
applied_action_assignment *aaa = newObject(applied_action_assignment);
aaa->put_items(prodSet);
LIST example :
List<STRING> theWeekDays(&ma, sdaiSTRING, 7);
theWeekDays.add("Sunday", &ma);
theWeekDays.add("Monday", &ma);
theWeekDays.add("Tuesday", &ma);
theWeekDays.add("Wednesday", &ma);