Scopira  20080306
scopira::basekit::nslice< T, DIM > Class Template Reference

#include <narray.h>

Public Types

typedef T data_type
 
typedef nindex< DIM > index_type
 
typedef niterator< T, DIM > iterator
 
typedef niterator< T, DIM > const_iterator
 
typedef T value_type
 
typedef T * pointer
 
typedef T & reference
 
typedef const T & const_reference
 
typedef size_t size_type
 
typedef ptrdiff_t difference_type
 

Public Member Functions

 nslice (void)
 default ctor, makes a null slice
 
 nslice (const this_type &rhs)
 (light) copy ctor
 
 nslice (narray< T, DIM > &rhs)
 does an all_slice on the source narray
 
 nslice (narray< T, DIM > *rhs)
 does an all_slice on the source narray
 
 nslice (T *_var, size_t _prime, index_type _size, index_type _stride)
 init, ctor
 
bool load (scopira::tool::itflow_i &in)
 
void save (scopira::tool::otflow_i &out) const
 
T * c_array (void) const
 
niterator< T, DIM > begin (void) const
 
niterator< T, DIM > end (void) const
 
bool is_null (void) const
 is the slice "null", ie not pointing to ANYTHING
 
void set_null (void)
 sets thte slice to null
 
bool empty (void) const
 empty?
 
size_t size (void) const
 gets the size (1D)
 
size_t width (void) const
 width
 
size_t height (void) const
 height
 
size_t depth (void) const
 depth
 
const index_typedimen (void) const
 gets the width
 
void resize (size_t len)
 
void resize (size_t neww, size_t newh)
 
void resize (size_t neww, size_t newh, size_t newd)
 
void resize (const index_type &news)
 
template<int SIM>
nslice< T, SIM > slicer (index_type base, nindex< SIM > dimen, nindex< SIM > direction) const
 
template<int SIM>
nslice< T, SIM > slicer (index_type base, nindex< SIM > dimen) const
 default directions
 
nslice< T, 1 > slicer (index_type base, size_t len, size_t direction=0) const
 1D specialized slicer, just to be nice
 
nslice< T, 1 > diagonal_slice (void)
 
nslice< T, DIM > all_slice (void) const
 all slice
 
size_t size_rows (void) const
 number of rows
 
nslice< T, DIM-1 > row_slice (size_t r) const
 get a particular row
 
nslice< T, 1 > xslice (size_t basex, size_t len) const
 vector to vector
 
nslice< T, 1 > xslice (size_t basex, size_t basey, size_t len) const
 vector slice
 
nslice< T, 1 > yslice (size_t basex, size_t basey, size_t len) const
 vector slice
 
nslice< T, 2 > xyslice (size_t basex, size_t basey, size_t width, size_t height) const
 matrix slice
 
nslice< T, 1 > xslice (index_type base, size_t len) const
 vector slice
 
nslice< T, 1 > yslice (index_type base, size_t len) const
 vector slice
 
nslice< T, 1 > zslice (index_type base, size_t len) const
 vector slice
 
nslice< T, 1 > tslice (index_type base, size_t len) const
 vector slice
 
nslice< T, 2 > xyslice (index_type base, size_t width, size_t height) const
 matrix slice
 
void clear (void)
 set all to 0
 
void set_all (T v) const
 set all elements
 
void copy (const narray< T, DIM > &at)
 copy
 
void copy (const nslice< T, DIM > &at)
 deep copy
 
void copy (const const_nslice< T, DIM > &at)
 deep copy
 
T & operator() (index_type idx) const
 access, by index
 
T & operator[] (size_t idx) const
 Nice, referece-based element access.
 
void set (size_t idx, T v) const
 Sets the value of an element.
 
get (size_t idx) const
 Gets the value of an element.
 
T & operator() (size_t x, size_t y) const
 
void set (size_t x, size_t y, T v) const
 
get (size_t x, size_t y) const
 
T & operator() (size_t x, size_t y, size_t z) const
 
void set (size_t x, size_t y, size_t z, T v) const
 
get (size_t x, size_t y, size_t z) const
 
bool is_flat_stride (void) const
 
template<int SIM>
scopira::basekit::nslice< T, SIM > slicer (index_type base, nindex< SIM > dimen, nindex< SIM > direction) const
 
template<int SIM>
scopira::basekit::nslice< T, SIM > slicer (index_type base, nindex< SIM > dimen) const
 

Friends

class scopira::basekit::const_nslice< T, DIM >
 

Detailed Description

template<class T, int DIM>
class scopira::basekit::nslice< T, DIM >

The nslice class is a lightweight array-like class that lets you view a subset of an narray. You can thing of them as a pointer to the contents of a narray.

Some other notes:

  • nslice does not itself contain data, it refers to the data in the host narray
  • Do not destroy (or resize) the host narray. If you do so, you must aquire new nslice instances from the narray.
  • nslice is fully copyable and ease to pass around

See Numeric arrays for a introduction.

See also
Numeric arrays
scopira::basekit::nslice
scopira::basekit::nindex
Author
Aleksander Demko

Member Function Documentation

◆ begin()

template<class T, int DIM>
niterator<T, DIM> scopira::basekit::nslice< T, DIM >::begin ( void  ) const
inline

◆ c_array()

template<class T, int DIM>
T* scopira::basekit::nslice< T, DIM >::c_array ( void  ) const
inline

Gets the contents of the slice as a ray C array.

This is only valid if the X stride is 1.

Author
Aleksander Demko

References scopira::basekit::const_nslice< T, DIM >::is_flat_stride().

Referenced by scopira::basekit::nslice< T, DIM >::load(), and scopira::basekit::nslice< T, DIM >::save().

◆ diagonal_slice()

template<class T , int DIM>
scopira::basekit::nslice< T, 1 > scopira::basekit::nslice< T, DIM >::diagonal_slice ( void  )

This returns a slice vector that goes across the diagonal.

This only works on matrix nslices (for now).

Author
Aleksander Demko

◆ end()

template<class T, int DIM>
niterator<T, DIM> scopira::basekit::nslice< T, DIM >::end ( void  ) const
inline

◆ get() [1/2]

template<class T, int DIM>
T scopira::basekit::nslice< T, DIM >::get ( size_t  x,
size_t  y 
) const
inline

Gets an individual element out of a matrix. This is only valid on two dimentional arrays.

Parameters
xthe x value of the element to reference
ythe y value of the element to reference
Returns
the value of the specified element
Author
Aleksander Demko

References scopira::basekit::const_nslice< T, DIM >::height(), and scopira::basekit::const_nslice< T, DIM >::width().

◆ get() [2/2]

template<class T, int DIM>
T scopira::basekit::nslice< T, DIM >::get ( size_t  x,
size_t  y,
size_t  z 
) const
inline

Gets an individual element out of a cube. This is only valid on three dimentional arrays.

Parameters
xthe x value of the element to reference
ythe y value of the element to reference
zthe z value of the element to reference
Returns
the value of the specified element
Author
Aleksander Demko

References scopira::basekit::const_nslice< T, DIM >::depth(), scopira::basekit::const_nslice< T, DIM >::height(), and scopira::basekit::const_nslice< T, DIM >::width().

◆ is_flat_stride()

template<class T, int DIM>
bool scopira::basekit::nslice< T, DIM >::is_flat_stride ( void  ) const
inline

Returns true if this slice has a "flat" stride. See scopira::basekit::is_flat_stride.

Author
Aleksander Demko

References scopira::basekit::is_flat_stride().

Referenced by scopira::basekit::nslice< T, DIM >::load(), and scopira::basekit::nslice< T, DIM >::save().

◆ load()

◆ operator()() [1/2]

template<class T, int DIM>
T& scopira::basekit::nslice< T, DIM >::operator() ( size_t  x,
size_t  y 
) const
inline

2-dimensional (matrix) array access operator. This is only valid on two dimentional arrays.

Parameters
xthe x value of the element to reference
ythe y value of the element to reference
Returns
a reference to the specified value
Author
Aleksander Demko

References scopira::basekit::const_nslice< T, DIM >::height(), and scopira::basekit::const_nslice< T, DIM >::width().

◆ operator()() [2/2]

template<class T, int DIM>
T& scopira::basekit::nslice< T, DIM >::operator() ( size_t  x,
size_t  y,
size_t  z 
) const
inline

3-dimensional (cube) array access operator. This is only valid on three dimentional arrays.

Parameters
xthe x value of the element to reference
ythe y value of the element to reference
zthe z value of the element to reference
Returns
a reference to the specified value
Author
Aleksander Demko

References scopira::basekit::const_nslice< T, DIM >::depth(), scopira::basekit::const_nslice< T, DIM >::height(), and scopira::basekit::const_nslice< T, DIM >::width().

◆ resize() [1/4]

template<class T, int DIM>
void scopira::basekit::nslice< T, DIM >::resize ( size_t  len)
inline

Resize the vector to the new length.

This destroys the previous contents.

Parameters
lenthe length of the vector (x dimension)
Author
Aleksander Demko

References scopira::basekit::nslice< T, DIM >::resize().

Referenced by scopira::basekit::nslice< T, DIM >::copy(), and scopira::basekit::nslice< T, DIM >::resize().

◆ resize() [2/4]

template<class T, int DIM>
void scopira::basekit::nslice< T, DIM >::resize ( size_t  neww,
size_t  newh 
)
inline

Resize the matrix to the new dimensions.

This destroys the previous contents.

Parameters
newwthe new width (x dimension)
newhthe new width (y dimension)
Author
Aleksander Demko

References scopira::basekit::nslice< T, DIM >::resize().

Referenced by scopira::basekit::nslice< T, DIM >::resize().

◆ resize() [3/4]

template<class T, int DIM>
void scopira::basekit::nslice< T, DIM >::resize ( size_t  neww,
size_t  newh,
size_t  newd 
)
inline

Resize the cube (3 dimensional array) to the new dimensions.

This destroys the previous contents.

Parameters
newwthe new width (x dimension)
newhthe new width (y dimension)
newdthe new depth (z dimension)
Author
Aleksander Demko

References scopira::basekit::const_nslice< T, DIM >::all_slice(), scopira::basekit::const_nslice< T, DIM >::diagonal_slice(), scopira::basekit::nslice< T, DIM >::resize(), scopira::basekit::const_nslice< T, DIM >::resize(), and scopira::basekit::const_nslice< T, DIM >::slicer().

Referenced by scopira::basekit::nslice< T, DIM >::resize().

◆ resize() [4/4]

template<class T , int DIM>
void scopira::basekit::nslice< T, DIM >::resize ( const index_type news)

Generic resize function that takes a index_type.

This destroys the previous contents.

Author
Aleksander Demko

References scopira::basekit::nslice< T, DIM >::slicer().

◆ save()

◆ set() [1/2]

template<class T, int DIM>
void scopira::basekit::nslice< T, DIM >::set ( size_t  x,
size_t  y,
v 
) const
inline

Sets an individual element out of a matrix. This is only valid on two dimentional arrays.

Parameters
xthe x value of the element to reference
ythe y value of the element to reference
vthe new value
Author
Aleksander Demko

References scopira::basekit::const_nslice< T, DIM >::height(), and scopira::basekit::const_nslice< T, DIM >::width().

◆ set() [2/2]

template<class T, int DIM>
void scopira::basekit::nslice< T, DIM >::set ( size_t  x,
size_t  y,
size_t  z,
v 
) const
inline

Sets an individual element out of a cube. This is only valid on three dimentional arrays.

Parameters
xthe x value of the element to reference
ythe y value of the element to reference
zthe z value of the element to reference
vthe new value
Author
Aleksander Demko

References scopira::basekit::const_nslice< T, DIM >::depth(), scopira::basekit::const_nslice< T, DIM >::height(), and scopira::basekit::const_nslice< T, DIM >::width().

◆ slicer()

template<class T, int DIM>
template<int SIM>
nslice<T,SIM> scopira::basekit::nslice< T, DIM >::slicer ( index_type  base,
nindex< SIM >  dimen,
nindex< SIM >  direction 
) const

The documentation for this class was generated from the following file: