.\" ident @(#)gslice.3 .\" Standard Template Library .\" $$RW_INSERT_HEADER "slyrs.man" .TH gslice 3C++ "02 Apr 1998" "Rogue Wave Software" "-" .ce2 Standard C++ Library Copyright 1998, Rogue Wave Software, Inc. .SH NAME \f2gslice\fP \ - A numeric array class used to represent a generalized slice from an array. .SH SYNOPSIS .br #include .br class gslice ; .SH DESCRIPTION gslice_represents a generalized slice from an array. A generalized slice contains a starting index, a set of lengths and a set of strides. The number of lengths and strides must be equal. Together the lengths and strides allow a slice from a multiple dimension array (with the dimension equal to the number of strides) to be represented on a one dimensional valarray. The gslice maps a set of \f2n\fP indices \f2(ij)\fP, where \f2n\fP is equal to the number of strides, to a single index \f2k\fP. When applied to a valarray using the gslice subscript operator (see valarray) a gslice produces a gslice_array. The gslice_array class creates a view into the original valarray that is tailored to match parameters of the gslice. The elements in a gslice_array are references to the elements in the original array. .SH INTERFACE .br class gslice { .br public: .RE .RS 2 // constructors .RE .RS 1 gslice(); .br gslice(size_t, const valarray&, .RE .RS 8 const valarray&); .RE .RS 1 gslice (const gslice&); .RE .RS 0 .RE .RS 2 // Accessors .RE .RS 1 size_t start() const; .br valarray size() const; .br valarray stride() const; .RE .RS 0 }; .SH CONSTRUCTORS .br gslice(); .RE .RS 3 Default constructor creates a gslice specifying no elements. .RE .br gslice(size_t start, const valarray& length, .RE .RS 6 const valarray& stride); .RE .RS 3 Creates a slice with starting index, length and stride as indicated by the arguments. .RE .RE .RS 0 gslice(const gslice&) .RE .RS 3 Creates a slice with starting index, length and stride as indicated by the slice argument. .RE .SH ACCESSORS .br size_t start(); .RE .RS 3 Returns the starting index of the gslice. .RE .br valarraysize_t> size(); .RE .RS 3 Returns a valarray containing the lengths of the gslice. .RE .br Valarray stride(); .RE .RS 3 Returns a valarray containing the strides of the gslice. .RE .SH EXAMPLE .br // .br // gslice.cpp .br // .br #include "valarray.h" // Contains a valarray stream inserter .br using namespace std; .br .br int main(void) .br { .RE .RS 1 int ibuf[27] = .RE .RS 3 {0,1,2,3,4,5,6,7,8,1,2,3,4,5,6,7,8,9,2,3,4,5,6,7,8,9,10}; .RE .RS 1 size_t len_buf[3] = {3,3,3}; .br size_t stride_buf[3] = {9,3,1}; .RE .RS 0 .RE .RS 2 // create a valarray of ints .RE .RS 1 valarray vi(ibuf,27); .RE .RS 0 .RE .RS 2 // create length and stride valarrays .RE .RS 1 valarray len(len_buf,3); .br valarray stride(stride_buf,3); .RE .RS 0 .RE .RS 2 // print out the valarray .RE .RS 1 cout << vi << endl; .RE .RS 0 .RE .RS 2 // Print out all three dimensions (the entire valarray) .RE .RS 1 cout << valarray(vi[gslice(0,len,stride)]) << endl; .RE .RS 0 .RE .RS 2 // Print a two dimensional slice out of the middle .RE .RS 1 valarray len2(2); .br len2[0] = 3; .br len2[1] = 3; .br valarray stride2(2); .br stride2[0] = 3; .br stride2[1] = 1; .br cout << valarray(vi[gslice(9,len2,stride2)]) << endl; .RE .RS 0 .RE .RS 2 // Print another two dimensional slice out of the middle .br // but orthogonal to one we just did .RE .RS 1 stride2[0] = 9; .br stride2[1] = 1; .br cout << valarray(vi[gslice(3,len2,stride2)]) << endl; .RE .RS 0 .RE .RS 2 // Print out the last plane in the middle, .br // (orthogonal to both of the previous ones) .RE .RS 1 stride2[0] = 3; .br stride2[1] = 9; .br cout << valarray(vi[gslice(1,len2,stride2)]) << endl; .RE .RS 0 .RE .RS 2 // Now how about a diagonal slice? .br // upper left front to lower right back .RE .RS 1 stride2[0] = 3; .br stride2[1] = 10; .br cout << valarray(vi[gslice(0,len2,stride2)]) << endl; .RE .RS 2 .RE .RS 1 return 0; .RE .RS 0 } .br .RE .RS 0 Program Output .br .br [0,1,2,3,4,5,6,7,8,1,2,3,4,5,6,7,8,9,2,3,4,5,6,7,8,9,10] .br [0,1,2,3,4,5,6,7,8,1,2,3,4,5,6,7,8,9,2,3,4,5,6,7,8,9,10] .br [1,2,3,4,5,6,7,8,9] .br [3,4,5,4,5,6,5,6,7] .br [1,2,3,4,5,6,7,8,9] .br [0,2,4,3,5,7,6,8,10] .SH WARNINGS If your compiler does not support namespaces, then you do not need the using declaration for \f2std\fP. .SH SEE ALSO valarray, slice_array, slice, gslice_array, mask_array, indirect_array