FlagArrayis 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
FlagArrayobject is indexed like an array, using square brackets. If
iis a non-negative integer, then
x[i]is a reference to an integer element of the array. If
iis 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
FlagArraymay be viewed as an infinite dimensional array of integers initialized with zeros. If
iis 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.
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.
FlagArray & operator = (const FlagArray & v)An assignment to one
FlagArrayfrom another simply copies its size and data.
int size() constReturn the current allocated size of the array.
int & operator  (int n)If
nis less than the currently allocated size of the array, then this returns a reference to the n-th element of the array. If
nis 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.