Top Up Prev Next Bottom Contents Index Search

1.11 FlagArray


FlagArray is a lightweight, self-expanding array of integers. It is meant to store an array of flags or counters, and its main appearance in Ptolemy is as a public member of class NamedObj, and therefore is available in most Ptolemy classes, which are derived from NamedObj. Targets and schedulers use this member to keep track of various kinds of data. Many schedulers and targets need to be able to mark blocks in various ways, for example to count invocations, or flag that the block has been visited, or to classify it as a particular type of block. This class provides a simple mechanism for doing this. A FlagArray object is indexed like an array, using square brackets. If x is a FlagArray and i is a non-negative integer, then x[i] is a reference to an integer element of the array. If i is out of bounds (beyond the currently allocated limits of the array), then the class automatically increases the size of the array. New elements are filled with zeros. Thus, a FlagArray may be viewed as an infinite dimensional array of integers initialized with zeros. If i is a negative integer, then x[i] is an error. For efficiency, the class does not test for this error at run time, so you could get a core dump if you make this error.

1.11.1 FlagArray constructors and destructor

FlagArray() 
This constructor creates a zero-length flag array.

FlagArray(int size) 
This constructor creates a flag array with the specified size already allocated and filled with zeros.

FlagArray(int size, int fill_value) 
This constructor creates a flag array with the specified size filled with the specified integer value. The destructor frees the memory allocated to store the array of integers.

1.11.2 FlagArray public methods

FlagArray & 	operator = (const FlagArray & v) 
An assignment to one FlagArray from another simply copies its size and data.

int size() const 
Return the current allocated size of the array.

int & operator [] (int n) 
If n is less than the currently allocated size of the array, then this returns a reference to the n-th element of the array. If n is greater than or equal to the currently allocated size of the array, then the size of the array is increased, the new elements are filled with zeros, and a reference to the n-th element is returned. Indexing of elements begins with zero. The returned reference, of course, can be used on the left-hand side of an assignment. This is how values are written into an array.



Top Up Prev Next Bottom Contents Index Search

Copyright © 1990-1997, University of California. All rights reserved.