Top Up Prev Next Bottom Contents Index Search

7.5 Example Message types

The kernel provides two simple sample message types for transferring arrays of data. They are almost identical except that one holds an array of integers and the other holds an array of single precision floating point data. The array contents live on the heap. Each is derived from class Message. Each provides a public data member that points to the data. As a rule, we recommend against public data members for classes, but an exception was made in this case, perhaps unwisely. This section will describe the interface of the FloatVecData class. The interface for IntVecData is almost identical. Three constructors are provided:

FloatVecData(int len); 
This form creates an uninitialized array of length len in the FloatVecData object. Since the pointer to the data is public the array may easily be filled in.

FloatVecData(int len,const float *srcData); 
This form creates an array of length len and initializes it with len elements from srcData.

FloatVecData(int len,const double *srcData); 
This form is the same, except that the source data is double precision (it is converted to single precision). This is the only function for which an analogous function does not exist in IntVecData (an IntVecData can only be initialized from an integer array). An appropriate copy constructor, assignment operator, and destructor are defined.

int length() const; 
Return the length of the array.

float *data; 
Public data member; points to the array. It is permissible to read or assign the len elements starting at data; the effect of altering the data pointer itself is undefined.

const char* dataType() const; 
Returns the string "FloatVecData".

int isA(const char* type) const; 
TRUE for type equal to "FloatVecData", otherwise false.

StringList print() const; 
Returns a comma-separated list of elements enclosed in curly braces.

Message* clone() const; 
Creates an identical copy with new.

Top Up Prev Next Bottom Contents Index Search
Copyright © 1990-1997, University of California. All rights reserved.