rwlogo
SourcePro C++ 12.0

SourcePro® C++ API Reference Guide



   SourcePro C++
Documentation Home

RWSlice Class Reference
[Math Collections]

Represents an index that can be used for subscripting vectors, matrices, and arrays. More...

#include <rw/rwslice.h>

Inheritance diagram for RWSlice:
RWRange RWToEnd

List of all members.

Public Member Functions

 RWSlice (int begin, int length)
 RWSlice (int begin, int length, int stride)
 RWSlice (const char *s)

Related Functions

(Note that these are not member functions.)



const RWSliceRWAll

Detailed Description

An RWSlice object is an index which can be used for subscripting vectors, matrices, and arrays. By subscripting with RWSlice objects, you create views of selected elements. These new views are vectors, matrices, or arrays in their own right, rather than simply helper classes. This means that a view created with subscripting can be used as an rvalue, an lvalue, or kept as an object for use later.

The classes RWRange and RWToEnd are derived from RWSlice. RWRange and RWToEnd objects can be used wherever an RWSlice object can be used.

Although they are not declared, the C++ language automatically defines a copy constructor and an assignment operator. These can be useful when passing RWSlice objects as function arguments or using RWSlice objects as class instance variables.

Synopsis

 #include <rw/math/mathvec.h>
 RWMathVec<double> x(20,2);
 RWMathVec<double> y = x("4:9"); // set y to view 
                                 // elements 4 through 9

Examples

 #include <iostream.h>
 #include <rw/math/genmat.h>
 
 int main()
 {
    RWGenMat<int> A(6,6);
    RWSlice I("0::2");  // indices 0,2,4
    RWSlice J(1,3,2);   // indices 1,3,5
    A(I,I) = 1;
    A(I,J) = 2;
    A(J,I) = 3;
    A(J,J) = 4;
    cout << A << endl;
 }

Program output:

 6x6
 [
      1     2     1     2     1     2
      3     4     3     4     3     4
      1     2     1     2     1     2
      3     4     3     4     3     4
      1     2     1     2     1     2
      3     4     3     4     3     4
 ]
See also:
RWRange, RWToEnd, RWMathVec::operator()(), RWGenMat::operator()(), RWMathArray::operator()()

Constructor & Destructor Documentation

RWSlice::RWSlice ( int  begin,
int  length 
) [inline]

Constructs an object that indexes length elements starting at element begin.

RWSlice::RWSlice ( int  begin,
int  length,
int  stride 
) [inline]

Constructs an object that indexes length elements starting at element begin. The parameter stride is the increment between successive selected elements. If the stride is negative, the new view reverses the indices.

RWSlice::RWSlice ( const char *  s  ) 

Constructs an index from the null terminated character string s. The syntax of the character string is x:y:z, where x, y, and z are integers. The resulting index selects elements from x through y, inclusive, with an increment of z between successive selected elements. Any or all of x, y, and z may be left out, in which case they default to 0, the last element, and 1, respectively. If z is omitted, the second colon may also be omitted. The character string * is a synonym for :, which selects all elements.


Friends And Related Function Documentation

const RWSlice& RWAll [related]

This special index selects all the elements.

 All Classes Functions Variables Typedefs Enumerations Enumerator Friends

© Copyright Rogue Wave Software, Inc. All Rights Reserved.
Rogue Wave and SourcePro are registered trademarks of Rogue Wave Software, Inc. in the United States and other countries. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.