shaper.h 4.97 KB
Newer Older
1
2
3
4
5
/*! \file shaper.h
 * \brief rectangular Fortran array layout (prototypes)
 * 
 * ----------------------------------------------------------------------------
 * 
6
 * $Id$
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
 * \author Thomas Forbriger
 * \since 08/12/2002
 * 
 * rectangular Fortran array layout (prototypes)
 *
 * ----
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version. 
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 * ----
 * 
 * Copyright (c) 2002 by Thomas Forbriger (IMG Frankfurt) 
 * 
 * REVISIONS and CHANGES 
 *  - 08/12/2002   V1.0   copied from libcontxx
 *  - 11/12/2002   V1.1   rework class (thof)
 *                        - remove template parameters
 *  - 12/12/2002   V1.2   (thof)
 *                        - has now full functionality
 *                        - documentation ist still missing
 *  - 15/12/2002   V1.3   (thof)
 *                        - never place in namspace prebuilt
 *  - 18/12/2002   V1.4   (thof)
 *                        - small but essential correction in operator()
 *  - 09/01/2003   V1.5   (thof)
 *                        - now throws exception in case of too many
 *                          concatenated bracket operators
 *  - 14/05/2011   V1.6   (thof)
 *                        - removed obsolete reference to libcontxx in
 *                          documentation
 * 
 * ============================================================================
 */

// include guard
#ifndef AFF_SHAPER_H_VERSION

#define AFF_SHAPER_H_VERSION \
  "AFF_SHAPER_H   V1.6"
#define AFF_SHAPER_H_CVSID \
57
  "$Id$"
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162

#include<aff/lib/strided.h>
#include<aff/lib/error.h>

namespace aff {

/*! \brief Shaper class for Fortran layout
 *
 * \todo 
 * rework documentation of class Shaper
 */
class Shaper 
{
  public:
    //! Type of Shape class
    typedef Strided Tshape;
    //! First dimension is defined by constructor
    Shaper(const Tsubscript& last): 
      Mfirst(1), Mlast(1), Mmaxlast(1), Mdim(1)
    {
      AFF_assert((last>=1), "ERROR (shaper): invalid limit");
      Mfirst[0]=1;
      Mlast[0]=last;
      Mmaxlast[0]=last;
    }
    //! First dimension is defined by constructor
    Shaper(const Tsubscript& first, const Tsubscript& last):
      Mfirst(1), Mlast(1), Mmaxlast(1), Mdim(1)
    {
      AFF_assert((last>=first), "ERROR (shaper): invalid index range");
      Mfirst[0]=first;
      Mlast[0]=last;
      Mmaxlast[0]=last;
    }
    //! First dimension is defined by constructor
    Shaper(const Tsubscript& first, const Tsubscript& last,
           const Tsubscript& maxlast):
      Mfirst(1), Mlast(1), Mmaxlast(1), Mdim(1)
    {
      AFF_assert((last>=first), "ERROR (shaper): invalid index range");
      AFF_assert((maxlast>=last), "ERROR (shaper): invalid alloc size");
      Mfirst[0]=first;
      Mlast[0]=last;
      Mmaxlast[0]=maxlast;
    }
    //! Other dimensions are defined by bracket operator
    Shaper& operator() (const Tsubscript& last)
    {
      AFF_assert((last>=1), "ERROR (shaper): invalid limit");
      check_dim();
      Mfirst[Mdim]=1;
      Mlast[Mdim]=last;
      Mmaxlast[Mdim]=last;
      Mdim++;
      return(*this);
    }
    //! Other dimensions are defined by bracket operator
    Shaper& operator() (const Tsubscript& first, const Tsubscript& last)
    {
      AFF_assert((last>=first), "ERROR (shaper): invalid index range");
      check_dim();
      Mfirst[Mdim]=first;
      Mlast[Mdim]=last;
      Mmaxlast[Mdim]=last;
      Mdim++;
      return(*this);
    }
    //! Other dimensions are defined by bracket operator
    Shaper& operator() (const Tsubscript& first, const Tsubscript& last,
                        const Tsubscript& maxlast)
    {
      AFF_assert((last>=first), "ERROR (shaper): invalid index range");
      AFF_assert((maxlast>=last), "ERROR (shaper): invalid alloc size");
      check_dim();
      Mfirst[Mdim]=first;
      Mlast[Mdim]=last;
      Mmaxlast[Mdim]=maxlast;
      Mdim++;
      return(*this);
    }
    //! Return the shape class
    operator Tshape () const
    {
      Tshape shape(Mfirst, Mmaxlast);
      shape.shrink(Mlast);
      return(shape);
    }
  private:
    //! check dimensions
    void check_dim() const
    {
      AFF_assert((Mdim<Tshape::Mmax_dimen),
                 "ERROR (Shaper): you use too many dimensions!");
    }
    //! limits
    Tshape::TIndexVec Mfirst, Mlast, Mmaxlast;
    //! next dimension to set
    Tdim Mdim;
}; // Shaper

} // namespace aff

#endif // AFF_SHAPER_H_VERSION (includeguard)

/* ----- END OF shaper.h ----- */