stridedstepper.h 3.03 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*! \file stridedstepper,h.h
 * \brief Stepper class for strided shapes (prototypes)
 * 
 * ----------------------------------------------------------------------------
 * 
 * $Id: stridedstepper.h,v 1.1 2002-12-06 19:08:20 forbrig Exp $
 * \author Thomas Forbriger
 * \date 24/11/2002
 * 
 * Stepper class for strided shapes (prototypes)
 * 
 * Copyright (c) 2002 by Thomas Forbriger (IMG Frankfurt) 
 * 
 * REVISIONS and CHANGES 
 *  - 24/11/2002   V1.0   Thomas Forbriger
 * 
 * ============================================================================
 */

// include guard
#ifndef TF_STRIDEDSTEPPER_H_VERSION

#define TF_STRIDEDSTEPPER_H_VERSION \
  "TF_STRIDEDSTEPPER,H_H   V1.0   "
#define TF_STRIDEDSTEPPER_H_CVSID \
  "$Id: stridedstepper.h,v 1.1 2002-12-06 19:08:20 forbrig Exp $"

#include<contxx/util/types.h>
#include<contxx/util/rawarfun.h>
#include<contxx/util/simplearray.h>

namespace contxx {

#ifdef CONTXX_PREBUILT
namespace prebuilt {
#endif

#ifdef CONTXX_PREBUILT
  using namespace contxx::prebuilt::util;
#else
  using namespace contxx::util;
#endif

namespace stepper {

/*! \brief A stepper for all strided shapes.
 *
 */
template<class Shape, Tdim N>
class StridedStepper 
{
  public:
    //! type of stride array
    typedef typename Shape::Tstrides Tstrides;
    //! type of limit arrays
    typedef typename Shape::Tlimits Tindex;
    //! Type of Shape corresponding class
    typedef Shape Tshape;
    //
    //! only non-copy constructor
    StridedStepper(const Tindex& first, const Tstrides& size, 
                   const Tstrides& stride, const Tsubscript& offset);
    //! return current index value for Representation access
    inline
    const Tsubscript& current() const { return(Mcurrent); }
    //! return current index vector for array access
    inline
    const Tindex& index() const { return(Mindex); }
    //! increment offset - return reference to itself
    inline
    StridedStepper& incr();
    //! decrement offset - return reference to itself
    inline
    StridedStepper& decr();
    //! returns true if there are more elements in incr-direction
    inline
    bool more() const;
    //! returns true if there are more elements in decr-direction
    inline
    bool less() const;
    //! set current element index to the first - return reference to itself
    StridedStepper& tofirst();
    //! set current element index to the last - return reference to itself
    StridedStepper& tolast();
  private:
    //! set of smallest index values
    const Tindex& Mfirst;
    //! set of largest index values
    Tindex Mlast;
    //! set of strides
    Tstrides Mstride;
    //! position offset defined by strided shape
    const Tsubscript& Moffset;
    //! current position
    Tsubscript Mcurrent;
    //! current position
    Tindex Mindex;

}; // StridedStepper

} // namespace stepper

#ifdef CONTXX_PREBUILT
} // namespace prebuilt
#endif

} // namespace contxx

#ifndef CONTXX_NO_DEFINITIONS
#include <contxx/shape/stridedstepper_def.h>
#endif


#endif // TF_STRIDEDSTEPPER_H_VERSION (includeguard)

/* ----- END OF stridedstepper,h.h ----- */