stridedstepper.h 3.63 KB
Newer Older
1
/*! \file stridedstepper.h
2
3
4
5
 * \brief Stepper class for strided shapes (prototypes)
 * 
 * ----------------------------------------------------------------------------
 * 
thomas.forbriger's avatar
thomas.forbriger committed
6
 * $Id: stridedstepper.h,v 1.5 2002-12-19 18:30:06 forbrig Exp $
7
 * \author Thomas Forbriger
8
 * \since 08/12/2002
9
10
 * 
 * Stepper class for strided shapes (prototypes)
11
12
13
14
 *
 * \note
 * You will not include this header directly. It is included through array.h
 * or binarray.h
15
16
17
18
 * 
 * Copyright (c) 2002 by Thomas Forbriger (IMG Frankfurt) 
 * 
 * REVISIONS and CHANGES 
19
 *  - 08/12/2002   V1.0   copied from libcontxx
20
21
 *  - 15/12/2002   V1.1   (thof)
 *                        - never place in namespace prebuilt
thomas.forbriger's avatar
thomas.forbriger committed
22
23
 *  - 18/12/2002   V1.2   (thof)
 *                        - reorganized the whole thing
thomas.forbriger's avatar
thomas.forbriger committed
24
25
26
27
 *  - 19/12/2002   V1.3   (thof)
 *                        - introduced Mvalid;
 *                          cycling full array needs and invalidate AFTER
 *                          passing the first or last element
28
29
30
31
32
 * 
 * ============================================================================
 */

// include guard
33
#ifndef AFF_STRIDEDSTEPPER_H_VERSION
34

35
#define AFF_STRIDEDSTEPPER_H_VERSION \
thomas.forbriger's avatar
thomas.forbriger committed
36
  "AFF_STRIDEDSTEPPER,H_H   V1.3"
37
#define AFF_STRIDEDSTEPPER_H_CVSID \
thomas.forbriger's avatar
thomas.forbriger committed
38
  "$Id: stridedstepper.h,v 1.5 2002-12-19 18:30:06 forbrig Exp $"
39

thomas.forbriger's avatar
thomas.forbriger committed
40
#include<aff/lib/strided.h>
41

42
43
namespace aff {
namespace util {
44
45
46

/*! \brief A stepper for all strided shapes.
 *
thomas.forbriger's avatar
thomas.forbriger committed
47
48
49
 * \note
 * The Stepper holds a reference to the shape. It is designed to be a
 * temporary object.
50
51
52
53
 */
class StridedStepper 
{
  public:
thomas.forbriger's avatar
thomas.forbriger committed
54
55
    //! Type of Shape corresponding class
    typedef aff::Strided Tshape;
56
    //! type of stride array
thomas.forbriger's avatar
thomas.forbriger committed
57
    typedef Tshape::TIndexVec TIndexVec;
58
    //! type of limit arrays
thomas.forbriger's avatar
thomas.forbriger committed
59
    typedef Tshape::TSizeVec TSizeVec;
60
61
    //
    //! only non-copy constructor
thomas.forbriger's avatar
thomas.forbriger committed
62
    StridedStepper(const Strided& strided);
63
64
65
    //! return current index value for Representation access
    const Tsubscript& current() const { return(Mcurrent); }
    //! return current index vector for array access
thomas.forbriger's avatar
thomas.forbriger committed
66
67
68
    const TIndexVec& index() const { return(Mindex); }
    //! return current index vector for array access
    const Tsubscript& index(const Tdim& i) const { return(Mindex[i]); }
69
70
71
72
73
    //! increment offset - return reference to itself
    StridedStepper& incr();
    //! decrement offset - return reference to itself
    StridedStepper& decr();
    //! returns true if there are more elements in incr-direction
thomas.forbriger's avatar
thomas.forbriger committed
74
    bool more() const
thomas.forbriger's avatar
thomas.forbriger committed
75
    { return(Mcurrent<Mlast_offset); }
76
    //! returns true if there are more elements in decr-direction
thomas.forbriger's avatar
thomas.forbriger committed
77
    bool less() const
thomas.forbriger's avatar
thomas.forbriger committed
78
79
80
81
    { return(Mcurrent>Mfirst_offset); }
    //! valid if not passed and or beginning
    const bool& valid() const
    { return(Mvalid); }
82
    //! set current element index to the first - return reference to itself
thomas.forbriger's avatar
thomas.forbriger committed
83
84
85
86
    StridedStepper& tofirst()
    {
      Mindex=Mshape.first();
      Mcurrent=Mshape.first_offset();
thomas.forbriger's avatar
thomas.forbriger committed
87
      Mvalid=true;
thomas.forbriger's avatar
thomas.forbriger committed
88
89
      return(*this);
    }
90
    //! set current element index to the last - return reference to itself
thomas.forbriger's avatar
thomas.forbriger committed
91
92
93
94
    StridedStepper& tolast()
    {
      Mindex=Mshape.last();
      Mcurrent=Mshape.last_offset();
thomas.forbriger's avatar
thomas.forbriger committed
95
      Mvalid=true;
thomas.forbriger's avatar
thomas.forbriger committed
96
97
      return(*this);
    }
98
  private:
thomas.forbriger's avatar
thomas.forbriger committed
99
100
101
    //! hold reference to shape
    const Tshape& Mshape;
    //! hold current position offset to memory
102
    Tsubscript Mcurrent;
thomas.forbriger's avatar
thomas.forbriger committed
103
104
105
106
    //! hold current index vector
    TIndexVec Mindex;
    //! hold carry values
    TSizeVec Mcarry;
thomas.forbriger's avatar
thomas.forbriger committed
107
108
109
110
    //! cycle check
    bool Mvalid;
    //! store current bounds to reduce execution time 
    Tsubscript Mfirst_offset, Mlast_offset;
111
112
113

}; // StridedStepper

114
} // namespace util
115

116
} // namespace aff
117

118
#endif // AFF_STRIDEDSTEPPER_H_VERSION (includeguard)
119

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