C++ Math Library Reference    

Operators

The mwArray class support three types of operators

Array Indexing Operators

Indexing is implemented through the complex interaction of three classes: mwArray, mwSubArray, and mwIndex. The indexing operator is (), and its usual argument is an mwIndex, which can be made from a scalar or another array. When applied to an mwArray, operator() returns an mwSubArray. The mwSubArray ``remembers'' the indexing operation and defers evaluation until the result is either assigned or referred to.

The MATLAB C++ Math Library supports one- and two-dimensional indexing.

mwSubArray operator()(const mwIndex &a) const

This routine implements one-dimensional indexing with an mwIndex object providing the subscript.

mwSubArray operator()(const mwIndex &a)

This routine modifies the contents of an array using one-dimensional indexing. Because this routine is non-const, calls to it are valid targets for the assignment operator.

mwSubArray operator()(const mwIndex &a, const mwIndex &b) const

This is the most general form of two-dimensional indexing. Because mwIndex objects can be made from integers, double-precision floating-point numbers and even mwArrays, this routine can handle two-dimensional indexing of any type.

mwSubArray operator()(const mwIndex &a, const mwIndex &b)

Like its one-dimensional counterpart, this routine allows two-dimensional indexing expressions as the target of assignment statements.

Cell Content Indexing.   These two versions of the cell() member function let you index into the contents of a cell. For example, A.cell(1,2) refers to the contents of the cell in the second column of the first row in an array A.

The cell() member functions follow the library convention for varargin functions. You can pass up to 32 arguments to the functions. To index into more than 32 dimensions, you must construct an mwVarargin object and pass it as the first argument. That object allows you to reference an additional 32 arguments, the first of which can again be an mwVarargin object.

The second non-const signature supports calls that are targets of the assignment operator and modify the contents of a cell.

Structure Field Indexing.   The two versions of the field() member function let you reference the field of a structure. For example, A.field("name") accesses the contents of the field called name within the structure A.

The second non-const signature supports calls that are targets of the assignment operator and modify the contents of a field.

Stream I/O Operators

The two operators, << and >>, are used for stream input and output. Technically, these stream operators are not member functions; they are friend functions.

friend inline ostream& operator<<(ostream &os, const mwArray&)

Calling this operator inserts an mwArray object into the given stream. If the stream is cout, the contents of the mwArray object appear on the terminal screen or elsewhere if standard output has been redirected on the command line. This function simply invokes Write() as described below.

friend inline istream& operator>>(istream &is, mwArray&)

This is the stream extraction operator, capable of extracting, or reading, an mwArray from a stream. The stream can be any C++ stream object, for example, standard input, a file, or a string. This function simply invokes Read() as described below.

The stream operators call Read() and Write(), mwArray public member functions.

void Read(istream&)

Reads an mwArray from an input stream. An array definition consists of an optional scale factor and asterisk, *, followed by a bracket [, one or more semicolon-separated rows of double-precision floating-point numbers, and a closing bracket ].

void Write(ostream&, int32 precision =5, int32 line_width =75) const

Formats mwArray objects using the given precision (number of digits) and line width, and then writes the objects into the given stream. operator<<() uses the default values shown above, which are appropriate for 80-character-wide terminals.

Note  Write() writes arrays in exactly the format that Read() reads them. An array written by Write() can be read by Read().

Assignment Operators
mwArray &operator=(const mwArray&);
   The final operator, =, is the assignment operator. C++ requires that the assignment operator be a member function. Like the copy constructor, the assignment operator does not actually make a copy of the input array, but rather references (keeps a pointer to) the input array's data; this is an optimization made purely for efficiency, and has no effect on the semantics of assignment. If you write A = B and then modify B, the values in A will remain unchanged.


 The mwArray Class User-Defined Conversion