3D PLM Enterprise Architecture |
Middleware Abstraction |
Lists of PointersManaging pointers to instances of the same class |
Quick Reference |
AbstractYou often need to manage several objects at the same time rather than a single one, either to handle them as a whole or to pass them as an argument of a method. The list of pointers enables you to gather pointers to instances of the same class in a list and provides many methods to handle them.
|
The following applies to list of pointers:
CATLISTP(T)
refers to a class-collection of
pointers to instances of type T (T is mostly a class)NULL
pointers can be inserted in the collection, and
duplicate pointers are allowed. The collection class can be managed as a
dynamic array through resizing, or as a stack or queueDo not use CATLISTP(T)
with T as a non-class (int
or double for example), it is doesn't make sense.
[Top]
To create a class for a list a pointers to MyClass, with the two methods Append
and RemoveValue
, create the following header file.
class MyClass; // Declare the class #include "CATLISTP_Clean.h" // Clean previous method requests #define CATLISTP_Append // Request the methods to create #define CATLISTP_RemoveValue #include "CATLISTP_Declare.h" // Include macros CATLISTP_DECLARE(MyClass); // Declare the collection class typedef CATLISTP(MyClass) MyClassCollection; // Define a handy name |
The source file is as follows.
#include "MyClass.h" #include "MyClassCollection.h" #include "CATLISTP_Define.h" CATLISTP_DEFINE(MyClass); |
[Top]
All the methods that you can set yo a list of pointers class are declared in CATLISTP_AllFunc.h.
#define CATLISTP_CtorFromArrayPtrs #define CATLISTP_Append #define CATLISTP_AppendList #define CATLISTP_InsertAt #define CATLISTP_ReSize #define CATLISTP_Locate #define CATLISTP_RemoveValue #define CATLISTP_RemoveList #define CATLISTP_RemovePosition #define CATLISTP_RemoveAll #define CATLISTP_RemoveNulls #define CATLISTP_RemoveDuplicates #define CATLISTP_Compare #define CATLISTP_Swap #define CATLISTP_QuickSort #define CATLISTP_FillArrayPtrs #define CATLISTP_NbOccur #define CATLISTP_Intersection |
Including first CATLISTP_Clean.h ensures that no previously declared method remains.
[Top]
You can construct a list of pointers using the following constructors.
CATLISTP(T)::CATLISTP(T) ( int iInitAlloc = 0); |
iInitAlloc
By default, when no argument is specified, no pre-allocation is done.
CATLISTP(T)::CATLISTP(T) ( const CATLISTP(T)& iCopy ); |
iCopy
.iCopy
CATLISTP(T)::CATLISTP(T) ( T** iArray, int iSize ); |
iSize
items from the iArray
array.iArray
iSize
Define the CATLISTP_CtorFromArrayPtrs
preprocessor flag if
you need this function.
CATLISTP(T)::CATLISTP(T) ( T* iArray, int iSize ); |
iSize
items from the iArray
array.iArray
iSize
Define the CATLISTP_CtorFromArrayVals
preprocessor flag if
you need this function.
Note that the destructor doesn't delete the pointed objects. Refer to the ApplyDelete method
[Top]
You can copy a list a pointers in an existing one as follows.
CATLISTP(T)& CATLISTP(T)::operator= ( const CATLISTP(T)& iCopy ); |
iCopy
[Top]
You can add items to a list of pointers as follows.
void CATLISTP(T)::Append ( T* iAdd ); |
iAdd
to the end of the list.iAdd
Define the CATLISTP_Append
preprocessor flag if you need
this function.
void CATLISTP(T)::Append ( const CATLISTP(T)& iConcat ); |
iConcat
list to to the end of the
self list.iConcat
Define the CATLISTP_AppendList
preprocessor flag if you need
this function.
void CATLISTP(T)::InsertAt ( int iPos, T* iAdd ); |
iPos
iAdd
Define the CATLISTP_InsertAt
preprocessor flag if you need
this function.
void CATLISTP(T)::InsertBefore ( int iPos, T* iAdd ); |
iPos
iAdd
Define the CATLISTP_InsertBefore
preprocessor flag if you
need this function.
[Top]
You can remove items to a list of pointers as follows.
int CATLISTP(T)::RemoveValue ( T* iRemove ); |
iRemove
.iRemove
Define the CATLISTP_RemoveValue
preprocessor flag if you
need this function.
int CATLISTP(T)::Remove ( const CATLISTP(T)& iSubstract ); |
iSubstract
list from the listiSubstract
Define the CATLISTP_RemoveList
preprocessor flag if you need
this function.
void CATLISTP(T)::RemovePosition ( int iPos ); |
iPos
.iPos
Define the CATLISTP_RemovePosition
preprocessor flag if you
need this function.
void CATLISTP(T)::RemoveAll ( CATCollec::MemoryHandling iMH = CATCollec::ReleaseAllocation ); |
iMH
iMH
to specify if memory allocation is to be
freed (the default) or kept.CATCollec::ReleaseAllocation
to
free, and CATCollec::KeepAllocation
to keep the memory
allocation.Define the CATLISTP_RemoveAll
preprocessor flag if you need
this function.
int CATLISTP(T)::RemoveNulls(); |
Define the CATLISTP_RemoveNulls
preprocessor flag if you
need this function.
int CATLISTP(T)::RemoveDuplicates (); |
Define the CATLISTP_RemoveDuplicatesCount
preprocessor flag
if you need this function.
void CATLISTP(T)::RemoveDuplicates ( CATLISTP(T)& ioExtract ); |
ioExtract
list.ioExtract
Define the CATLISTP_RemoveDuplicatesExtract
preprocessor
flag if you need this function.
[Top]
You can retrieve and set the size of a list of pointers as follows.
int CATLISTP(T)::Size() const; |
This method is provided by default and doesn't require a specific #define
statement.
void CATLISTP(T)::Size ( int iSize ); |
iSize
, NULL pointers are
appended to match the requested size. Otherwise, the items whose index
is greater from iSize
are removed.iSize
Add #define CATLISTP_ReSize
if you need this method.
[Top]
You can retrieve items from and locate items in a list of pointers as follows.
T* CATLISTP(T)::operator[] ( int iPos) const; |
iPos
th item of the list.iPos
Size
methodThis method is provided by default and doesn't require a specific #define
statement.
T*& CATLISTP(T)::operator[] ( int iPos); |
iPos
th item of the list.iPos
Size
methodThis method is provided by default and doesn't require a specific #define
statement.
int CATLISTP(T)::Locate ( T* iLocate, int iFrom = 1 ) const; |
iLocate
. By
default, this function scans the list of pointers from the first item
down to the end of the list.iLocate
iFrom
Size
method. The
default value is 1.Add #define CATLISTP_Locate
if you need this method.
[Top]
You can replace, swap, and sort items in a list of pointers as follows.
void CATLISTP(T)::Replace ( int iPos, T* iReplace); |
iPos
with the iReplace
value.iPos
Size
methodiReplace
Add #define CATLISTP_Replace
if you need this method.
void CATLISTP(T)::Swap ( int iPos1, int iPos2 ); |
iPos1
and iPos2
.iPos1
Size
methodiPos2
Size
methodAdd #define CATLISTP_Swap
if you need this method.
void CATLISTP(T)::QuickSort ( int (*iPFCompare) (const T*, const T*) ); |
iPFCompare
. This QuickSort
function is similar to the qsort
utility of the iPFCompare
:Add #define CATLISTP_QuickSort
if you need this method.
[Top]
You can apply the following operations to items of a list of pointers as follows.
typedef int (T::*PtrMbrFunct) (); int CATLISTP(T)::ApplyMemberFunct ( PtrMemberFunct iPF, int iFrom = 1, int iTo = 0, T** iPLast = NULL, int* iPRC = NULL ) const; |
iPF
on items of the
list (NULLs ignored).iFrom
item up to the iTo
item.
(if iTo
equals 0, it means up to the end of the list)iPF
returns an int
. If it is
equal to 0, calls continue on next items, else the index of the item on
which the process stops is returned.iPLast
is a pointer to a T pointer. If
provided, it will contain the the value of the last item (a pointer)
processed by the function.iPRC
is a pointer to an int
.
If provided, it will contain the value returned by the last call made by
the function.iPF
to all
items of the list (if each call returns 0).iPF
iFrom
iTo
iPLast
iPRC
Add #define CATLISTP_ApplyMemberFunct
if you need this
method.
typedef int (T::*PtrMbrFunctConst) () const; int CATLISTP(T)::ApplyMemberFunctConst ( PtrMemberFunctConst iPF, int iFrom = 1, int iTo = 0, T** iPLast = NULL, int* iPRC = NULL ) const; |
iPF
on items of the
list (NULLs ignored).iFrom
item up to the iTo
item.
(if iTo
equals 0, it means up to the end of the list)iPF
returns an int
. If it is
equal to 0, calls continue on next items, else the index of the item on
which the process stops is returned.iPLast
is a pointer to a T pointer. If
provided, it will contain the the value of the last item (a pointer)
processed by the function.iPRC
is a pointer to an int
.
If provided, it will contain the value returned by the last call made by
the function.iPF
to all
items of the list (if each call returns 0).iPF
iFrom
iTo
iPLast
iPRC
Add #define CATLISTP_ApplyMemberFunctConst
if you need this
method.
typedef int (*PtrGlbFunct) ( T* ); int CATLISTP(T)::ApplyGlobalFunct ( PtrGlbFunct iPF, int iFrom = 1, int iTo = 0, T** iPLast = NULL, int* iPRC = NULL ) const; |
iPF
on items of
the list (NULLs ignored).iFrom
item up to the iTo
item.
(if iTo
equals 0, it means up to the end of the list)iPF
returns an int
. If it is
equal to 0, calls continue on next items, else the index of the item on
which the process stops is returned.iPLast
is a pointer to a T pointer. If
provided, it will contain the value of the last item (a pointer)
processed by the function.iPRC
is a pointer to an int
.
If provided, it will contain the value returned by the last call made by
the function.iPF
to all
items of the list (if each call returns 0).iPF
iFrom
iTo
iPLast
iPRC
Add #define CATLISTP_ApplyGlobalFunct
if you need this
method.
void CATLISTP(T)::ApplyDelete ( CATCollec::Direction iDir = CATCollec::FromFirstToLast) const; enum CATCollec::Direction { CATCollec::FromFirstToLast, CATCollec::FromLastToFirst }; |
iDir
Add #define CATLISTP_ApplyDelete
if you need this method.
[Top]
You can compare items of two lists of pointers as follows.
int CATLISTP(T)::operator== (const CATLISTP(T)& iLP) const; |
iLP
to the current list. Returns 1 when lists
are equal.iLP
This method is provided by default and doesn't require a specific #define
statement.
int CATLISTP(T)::operator!= (const CATLISTP(T)& iLP) const; |
iLP
to the current list. Returns 1 when lists
are different.iLP
This method is provided by default and doesn't require a specific #define
statement.
int CATLISTP(T)::operator<= (const CATLISTP(T)& iLP) const; |
iLP
to to the current list. Returns 1 when to
the current list is less or equal to iLP
.iLP
Add #define CATLISTP_leOP
if you need this method.
int CATLISTP(T)::operator>= (const CATLISTP(T)& iLP) const; |
iLP
to to the current list. Returns 1 when to
the current list is greater or equal to iLP
.iLP
Add #define CATLISTP_geOP
if you need this method.
int CATLISTP(T)::operator≤ (const CATLISTP(T)& iLP) const; |
iLP
to the current list. Returns 1 when the
current list is less than iLP
.iLP
Add #define CATLISTP_ltOP
if you need this method.
int CATLISTP(T)::operator> (const CATLISTP(T)& iLP) const; |
iLP
to the current list. Returns 1 when
the current list is greater than iLP
.iLP
Add #define CATLISTP_gtOP
if you need this method.
int CATLISTP(T)::Compare ( const CATLISTP(T)& iLP1, const CATLISTP(T)& iLP2, int (*iPFCompare) (const T*, const T*) ); |
iLP1
is greater, -1 if iLP2
is
greater, or 0 if they are equal. The first discriminator is the size,
then each element is compared using the function pointed by iPFCompare
.iLP1
iLP2
Add #define CATLISTP_Compare
if you need this method.
[Top]
You can do the following:
void CATLISTP(T)::FillArray ( T** ioArray, int iMaxSize ) const; |
ioArray
array of
pointers. (It should have the same size than the list.)ioArray
iMaxSize
Add #define CATLISTP_FillArrayPtrs
if you need this method.
static void CATLISTP(T)::Intersection ( const CATLISTP(T)& iLP1, const CATLISTP(T)& iLP2, CATLISTP(T)& ioResult ); |
ioResult
list the intersection of iLP1
and iLP2
list. If iLP1
contains duplicates,
the ioResult
may also contain duplicates.iLP1
iLP2
ioResult
Add #define CATLISTP_Intersection
if you need this method.
int CATLISTP(T)::NbOccur ( T* iTest ); |
iTest
.iTest
Add #define CATLISTP_NbOccur
if you need this method.
OPERATOR<<
output pointed instances on a
ostream
ostream& ::operator<< ( ostream& ioOS, const CATLISTP(T)& iLP ) const; |
::operator<<
defined for type T on each
instance pointed by the listioOS
iLP
Add #define CATLISTP_ostreamOP
if you need this method.
void CATLISTP(T)::PrintAddr ( ostream& ioOS ) const; |
ioOS
Add #define CATLISTP_PrintAddr
if you need this method.
Version: 1 [Mar 2000] | Document created |
[Top] |
Copyright © 2000, Dassault Systèmes. All rights reserved.