stridedstepper.h 3.16 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.4 2002-12-18 17:41:33 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
24
25
26
27
28
 * 
 * ============================================================================
 */

// include guard
29
#ifndef AFF_STRIDEDSTEPPER_H_VERSION
30

31
#define AFF_STRIDEDSTEPPER_H_VERSION \
thomas.forbriger's avatar
thomas.forbriger committed
32
  "AFF_STRIDEDSTEPPER,H_H   V1.2"
33
#define AFF_STRIDEDSTEPPER_H_CVSID \
thomas.forbriger's avatar
thomas.forbriger committed
34
  "$Id: stridedstepper.h,v 1.4 2002-12-18 17:41:33 forbrig Exp $"
35

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

38
39
namespace aff {
namespace util {
40
41
42

/*! \brief A stepper for all strided shapes.
 *
thomas.forbriger's avatar
thomas.forbriger committed
43
44
45
 * \note
 * The Stepper holds a reference to the shape. It is designed to be a
 * temporary object.
46
47
48
49
 */
class StridedStepper 
{
  public:
thomas.forbriger's avatar
thomas.forbriger committed
50
51
    //! Type of Shape corresponding class
    typedef aff::Strided Tshape;
52
    //! type of stride array
thomas.forbriger's avatar
thomas.forbriger committed
53
    typedef Tshape::TIndexVec TIndexVec;
54
    //! type of limit arrays
thomas.forbriger's avatar
thomas.forbriger committed
55
    typedef Tshape::TSizeVec TSizeVec;
56
57
    //
    //! only non-copy constructor
thomas.forbriger's avatar
thomas.forbriger committed
58
    StridedStepper(const Strided& strided);
59
60
61
    //! 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
62
63
64
    const TIndexVec& index() const { return(Mindex); }
    //! return current index vector for array access
    const Tsubscript& index(const Tdim& i) const { return(Mindex[i]); }
65
66
67
68
69
    //! 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
70
71
    bool more() const
    { return(Mcurrent<Mshape.last_offset()); }
72
    //! returns true if there are more elements in decr-direction
thomas.forbriger's avatar
thomas.forbriger committed
73
74
    bool less() const
    { return(Mcurrent>Mshape.first_offset()); }
75
    //! set current element index to the first - return reference to itself
thomas.forbriger's avatar
thomas.forbriger committed
76
77
78
79
80
81
    StridedStepper& tofirst()
    {
      Mindex=Mshape.first();
      Mcurrent=Mshape.first_offset();
      return(*this);
    }
82
    //! set current element index to the last - return reference to itself
thomas.forbriger's avatar
thomas.forbriger committed
83
84
85
86
87
88
    StridedStepper& tolast()
    {
      Mindex=Mshape.last();
      Mcurrent=Mshape.last_offset();
      return(*this);
    }
89
  private:
thomas.forbriger's avatar
thomas.forbriger committed
90
91
92
    //! hold reference to shape
    const Tshape& Mshape;
    //! hold current position offset to memory
93
    Tsubscript Mcurrent;
thomas.forbriger's avatar
thomas.forbriger committed
94
95
96
97
    //! hold current index vector
    TIndexVec Mindex;
    //! hold carry values
    TSizeVec Mcarry;
98
99
100

}; // StridedStepper

101
} // namespace util
102

103
} // namespace aff
104

105
#endif // AFF_STRIDEDSTEPPER_H_VERSION (includeguard)
106

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