3D PLM Enterprise Architecture

Middleware Abstraction

Using Lists of Pointers

Creating and managing lists of pointers
Use Case

Abstract

This article shows how to create and manage a list of pointers, illustrated by a list of pointers to the CAASysPoint class.


What You Will Learn With This Use Case

This use case is intended to show you how to create and manage a list of pointers [1].

[Top]

The CAASysCollections Use 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 pointer capabilities, taking a list of pointers to instances of the CAASysPoint class 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 [2].

[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 list of pointers
2 Fill in a list of pointers
3 Locate a pointer
4 Remove pointers

The CATSysPoint class used represents 2D points.

[Top]

Creating a List of Pointers

A list of pointers to instances of the CATSysPoint class is created as a class using macros. The class header file named  CAASysListOfSysPointPtr.h is as follows:

#ifndef CAASysListOfSysPointPtr_h
#define CAASysListOfSysPointPtr_h

#include "CAASysPoint.h"

#include "CATLISTP_Clean.h"
#include "CATLISTP_AllFunct.h"

#include  "CATLISTP_Declare.h"
CATLISTP_DECLARE(CAASysPoint)

#endif

The CATLISTP_Clean.h file undefines all possible previously defined methods, while the CATLISTP_AllFunct.h defines for the list class to create all the available methods for list of pointer classes. The CATLISTP_DECLARE macro creates the class header file.

The source file named CAASysListOfSysPointPtr.cpp is as follows:

#include "CAASysListOfSysPointPtr.h"

#include  "CATLISTP_Define.h"
CATLISTP_DEFINE(CAASysPoint)

The CATLISTP_DEFINE macro creates the class source file. The list of pointer to the CAASysPoint class is now created. Its name is CATLISTP(CAASysPoint).

[Top]

Filling in a List of Pointers

  CATLISTP(CAASysPoint) lpCAASysPoint;

  CAASysPoint p0(0, 1);
  CAASysPoint p1(1, 2);
  CAASysPoint p2(2, 3);
  CAASysPoint p3(3, 4);
  CAASysPoint p4(4, 5);

  lpCAASysPoint.Append(&p0);
  lpCAASysPoint.Append(&p1);
  lpCAASysPoint.Append(&p2);
  lpCAASysPoint.Append(&p3);
  lpCAASysPoint.Append(&p4);
  ...

The CATLISTP(CAASysPoint) class is first instantiated, and then instances of the CAASysPoint are created. Then the Append method appends pointers to the created points to the list.

[Top]

Locating Items

  ...
  int indexP2 = lpCAASysPoint.Locate(&p2);
  cout << "L1.Locate(&p2) == " << indexP2 << endl;

  float xP2 = lpCAASysPoint[indexP2]->getX();
  float yP2 = lpCAASysPoint[indexP2]->getY();
  ...

The Locate method returns the rank of a given pointer in the list. Note that this rank begins with 1. The located pointer can be used by means of its rank in the list as if it where in an array, for example to get the point x and y coordinates. This code provides the following output:
L1.Locate(&p2) == 3

[Top]

Removing Items

  ...
  lpCAASysPoint.RemoveValue(&p1);
  lpCAASysPoint.RemoveValue(&p3);
  ...

The RemoveValue method removes the pointer passed as parameter from the list. The list now includes three pointers to points p0, p2, and p4.

[Top]


In Short

This use case shows how to create a class for a list a pointers to a given class, and how to use it.

[Top]


References

[1] Lists of Pointers
[2] 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.