3D PLM Enterprise Architecture

Middleware Abstraction

Using Sets

Creating and managing sets of CATString instances
Use Case

Abstract

This article shows how to create and manage a set of CATString instances.


What You Will Learn With This Use Case

This use case is intended to show you how to create and manage a set of CATString instances.

[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 set of CATString instance capabilities. Note that the set of CATUnicodeString offers the same capabilities.

[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 several classes 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 set
2 Count the items
3 Insert items
4 Access items
5 Copy items from/to an array
6 Apply basic operators

[Top]

Creating and Filling a Set

A set of CATString instances is itself an instance of the CATSetOfCATString class.

void CAASetsSample()
{
  CATSetOfCATString set1;

  set1.Add( CATString("A") );
  set1.Add( CATString("B") );
  set1.Add( CATString("D") );
  ...

The Add method adds CATString instances to the set.

[Top]

Counting the Items

  ...
  cout << "set1.Size() = " << set1.Size() << endl;
  ...

The Size method returns the number of items in the set. This code provides the following output:
set1.Size() = 3

[Top]

Inserting Items

  ...                           // A, B, D
  set1.Add( CATString("A"));    // A, B, D
  set1.Add( CATString("C"));    // A, B, C, D
  ...

The Add method adds items to the set. Note that no duplicate items can exist in a set. As a consequence, the first call to Add has no effect, since an item containing "A" already exists in the set. The second call to Add adds "C" to the set. This character string is not appended to the set, but inserted using the alphabetical order.

[Top]

Accessing Items

  ...
  cout << "set1[2] = " << set1[2].CastToCharPtr() << endl;
  ...

A given item in the set can be used by means of its rank in the set as if it where in an array. Note that the rank begins with 1. This code provides the following output:
set1[2] = B

[Top]

Copying Items from/to an Array

  ...
  CATString *iArray = new CATString[4];
  iArray[0] = "B";
  iArray[1] = "C";
  iArray[2] = "D";
  iArray[3] = "E";
  CATSetOfCATString set2(iArray, 4);

  CATString *ioArray = new CATString[set1.Size()];
  set1.Array(ioArray);
  ...

An array of CATString can be used as input for a set of CATString instances. The second parameter is the number of items to copy from the array. Conversely, a set of CATString instances can be used a input to create an array. The Size method is used to set the array size. The Array method fills the array from the set.

[Top]

Applying Basic Operators

  ...
  CATSetOfCATString set3(set1);
  set3.Add(set2);

  CATSetOfCATString set4;
  CATSetOfCATString::Intersection(set1, set2, set4);

  CATSetOfCATString set5(set1);
  set5.Remove(set2);
  ...

The Add method can also take a set as parameter to merge two sets. The following table shows the input sets and the result. Note that the set does include duplicates, and that the items are arranged using the alphabetical order.

set2 B, C, D, E
set3 A, B, C, D
resulting set3 A, B, C, D, E

The Intersection static method performs the intersection of set1 with set2, and puts the result in set 4. The following table shows the input sets and the result.

set1 A, B, C, D
set2 B, C, D, E
set4 B, C, D

The Remove method takes a set as parameter to subtract it from the set to which the method applies. The following table shows the input sets and the result.

set5 A, B, C, D
set2 B, C, D, E
resulting set5 A

[Top]


In Short

This use case shows how to create and use a set of CATString instances. The same capabilities apply to a set of CATUnicodeString instances.

[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.