3D PLM Enterprise Architecture

Middleware Abstraction

Using Lists of Integers

Creating and managing one or several lists of simple types
Use Case

Abstract

This article shows how to create and manage a list of simple types, illustrated by a list of integers.


What You Will Learn With This Use Case

This use case is intended to show you how to create and manage a list of simple types.

[Top]

The CAASysCollections Case

CAASysCollections is a set of use cases of the CAASystem.edu framework that illustrates the collection management capabilities.

[Top]

What Does CAASysCollections Do

This use case shows summarizes the collection management capabilities:

This article describes the list of simple type capabilities, taking a list of integers as example.

[Top]

How to Launch CAASysCollections

To launch CAASysCollections, you will need to set up the build time environment, then compile CAASysCollections along with its prerequisites, set up the run time environment, and then execute the use case [1].

[Top]

Where to Find the CAASysCollections Code

The CAASysCollections use case is made of a file located in the CAASysCollections.m module of the CAASystem.edu framework:

Windows InstallRootDirectory\CAASystem.edu\CAASysCollections.m\
Unix InstallRootDirectory/CAASystem.edu/CAASysCollections.m/

where InstallRootDirectory is the directory where the CAA CD-ROM is installed.

[Top]

Step-by-Step

The following capabilities offered by lists of integers are described in the following steps:

#

Step

1 Create and fill in a list of integers
2 Replace items
3 Locate items
4 Quick sort the list
5 Remove duplicates
6 Exchange items
7 Copy items from/to an array
8 Remove/insert items
9 Intersect two lists

[Top]

Creating and Filling in a List of Integers

A list of integers is created as an instance of the CATListOfInt class.

#include  "CATListOfInt.h"
...
void CAAListsSample()
{
  CATListOfInt listOfInt;

  int	i1 = 5;
  listOfInt.Append ( 0 );
  listOfInt.Append ( i1 );
  listOfInt.Append ( 6 );
  listOfInt.Append ( 77 );
  listOfInt.Append ( 888 );
  listOfInt.Append ( 9999 );
  listOfInt.Append ( 0 );
  listOfInt.Append ( 0 );
  listOfInt.Append ( 0 );
  ...

The Append method appends each value to the list. The list contains nine integers 0, 5, 6, 77, 888, 9999, 0, 0, 0 stored in this order.

[Top]

Replacing Item Values

  ...
  listOfInt[5] = 92380; // Instead of 888
  listOfInt[7] = listOfInt[2] ;
  ...

Items can be accessed thanks to their rank in the list, as with tables. Note that this rank begins with 1. The list always contains nine integers: 0, 5, 6, 77, 92380, 9999, 5, 0, 0.

[Top]

Locating Items

  ...
  cout << "Locate (9999)  == "	<< listOfInt.Locate (9999) << endl;
  cout << "Locate (0)     == "  << listOfInt.Locate (0)    << endl;
  cout << "Locate (0, 3)  == "  << listOfInt.Locate (0, 3) << endl;
  ...

The Locate method returns the rank of a given value in the list. The second parameter indicates the rank from which the search begins, defaulted to the first item. The returned value is the rank found, or 0 if no item is found with this value. This code provides the following output:
Locate (9999)  == 6
Locate (0)     == 1
Locate (0, 3)  == 8

[Top]

Quick Sorting the List

  ...
  listOfInt.QuickSort();
  ...

The QuickSort method sorts the list by increasing order. The list is now 0, 0, 0, 5, 5, 6, 77, 9999, 92380.

[Top]

Removing Duplicates

  ...
  listOfInt.RemoveDuplicates();
  ...

The RemoveDuplicates method removes items whose value is found with a lower rank item. When an item is removed, all subsequent item ranks are decreased by 1. The list now contains six items, since two duplicates of 0, and a duplicate of 5 are removed: 0, 5, 6, 77, 9999, 92380.

[Top]

Exchanging Items

  ...
  listOfInt.Swap(1, 2);
  ...

The Swap method exchanges item values using their ranks. The code above exchanges the values of the first two items. The list is now: 5, 0, 6, 77, 9999, 92380.

[Top]

Copying Items from/to an Array

A list of integers can be copied in a C array of integers.
  ...
  int *rgArray = new int[listOfInt.Size()];
  listOfInt.FillArray(rgArray , listOfInt.Size());
  CATListOfInt *plistOfInt = new CATListOfInt(rgArray, listOfInt.Size());
  delete [] rgArray;
  ...

The array size is set using the Size method that returns the number of items in the list. Then, then FillArray method fills the array with the list. The second parameter is the number of items to put in the array. It is here the full list. A new list of integers can be created an filled in from an array. The second constructor parameter is the number of array items to copy in the list.

[Top]

Removing/Inserting Items

A list of integers is created using the
  ...
                                     // 5, 0, 6, 77, 9999, 92380
  plistOfInt->RemovePosition(1);     // 0, 6, 77, 9999, 92380
  plistOfInt->RemovePosition(3);     // 0, 6, 9999, 92380
  plistOfInt->InsertAt(2, 1313);     // 0, 1313, 6, 9999, 92380
  plistOfInt->InsertAt(5, 12345);    // 0, 1313, 6, 9999, 12345, 92380
  ...

The RemovePosition method removes the item whose rank is passed as parameter. When an item is removed, all subsequent item ranks are decreased by 1. The InsertAt method insert at the rank passed as the first parameter the value passed as the second parameter. When an item is inserted, all subsequent item ranks are increased by 1. The list was:
5, 0, 6, 77, 9999, 92380.
and is now:
0, 1313, 6, 9999, 12345, 92380.

[Top]

Intersecting Two Lists

  ...
  CATListOfInt listOfIntInter;
  CATListOfInt::Intersection(*plistOfInt, listOfInt, listOfIntInter);
  ...

The Intersection method copies the items whose value is found in the two lists plistOfInt and listOfInt in the newly created list listOfIntInter. The list contents are:
plistOfInt 5, 0, 6, 77, 9999, 92380
listOfInt 0, 1313, 6, 9999, 12345, 92380
listOfIntInter 0, 6, 9999, 92380

[Top]


In Short

This use case shows how to create and use a list of integers. The same capabilities are available with lists of floats or lists of doubles.

[Top]


References

[1] Building and Launching a CAA V5 Use Case
[Top]

History

Version: 1 [Mar 2000] Document created
[Top]

Copyright © 2000, Dassault Systèmes. All rights reserved.