array_def.h 4.67 KB
Newer Older
1
2
3
4
5
/*! \file array_def.h
 * \brief array class definitions (definitions)
 * 
 * ----------------------------------------------------------------------------
 * 
thomas.forbriger's avatar
thomas.forbriger committed
6
 * $Id: array_def.h,v 1.17 2006/03/28 16:03:01 tforb Exp $
7
 * \author Thomas Forbriger
8
 * \since 08/12/2002
9
10
 * 
 * array class definitions (definitions)
11
 *
thomas.forbriger's avatar
thomas.forbriger committed
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
 * ----
 * 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
 * ----
 *
28
29
30
 * \note
 * This header containes definitions of functions of class aff::Array. They
 * will be contained in a binary library. You must not include this header
thomas.forbriger's avatar
thomas.forbriger committed
31
 * yourself. It is included via array.h if you use the full template version
32
 * of the library.
33
34
35
36
 * 
 * Copyright (c) 2002 by Thomas Forbriger (IMG Frankfurt) 
 * 
 * REVISIONS and CHANGES 
37
 *  - 08/12/2002   V1.0   copied from libcontxx
38
39
40
41
 *  - 16/12/2002   V1.1   (thof)
 *                        - definitions are now for base class
 *                          (i.e. spcialization for const T)
 *                        - added standard constructors
thomas.forbriger's avatar
thomas.forbriger committed
42
43
 *  - 18/12/2002   V1.2   (thof)
 *                        - added stepper code to scalar assignment operator
thomas.forbriger's avatar
thomas.forbriger committed
44
45
46
47
48
49
 *  - 19/12/2002   V1.3   (thof)
 *                        - size constructors did not work
 *                        - replaced four size-argument constructors by one
 *                          constructor with default arguments
 *                        - distinguish between mutable and non-mutable
 *                          representation
thomas.forbriger's avatar
thomas.forbriger committed
50
51
 *  - 23/12/2002   V1.4   (thof)
 *                        - copyin() and copyout() work
thomas.forbriger's avatar
thomas.forbriger committed
52
53
54
 *  - 28/12/2002   V1.5   (thof)
 *                        - changed base class from specialization to
 *                          independent class template
55
56
57
58
59
 *  - 29/12/2002   V1.6   (thof)
 *                        - due to clearer concept of representation access
 *                          constructors became more simple and are defined in
 *                          declaration - only copy operations remain here
 *                        - member template cannot be explicitely instantiated
thomas.forbriger's avatar
thomas.forbriger committed
60
61
62
 *  - 03/01/2003   V1.7   (thof)
 *                        - copyout function now returns an aff::Array rather
 *                          than an aff::ConstArray
63
64
65
66
 * 
 * ============================================================================
 */

67
#ifndef AFF_ARRAY_DEC_H_VERSION 
68
69
70
71
#error "include this only through array_dec.h"
#endif

// include guard
72
#ifndef AFF_ARRAY_DEF_H_VERSION
73

74
#define AFF_ARRAY_DEF_H_VERSION \
thomas.forbriger's avatar
thomas.forbriger committed
75
  "AFF_ARRAY_DEF_H   V1.7"
76
#define AFF_ARRAY_DEF_H_CVSID \
thomas.forbriger's avatar
thomas.forbriger committed
77
  "$Id: array_def.h,v 1.17 2006/03/28 16:03:01 tforb Exp $"
78
79

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

81
namespace aff {
82

83
#ifdef AFF_PREBUILT
84
85
86
namespace prebuilt {
#endif

87
#ifdef AFF_PREBUILT
thomas.forbriger's avatar
thomas.forbriger committed
88
#ifndef AFF_COMPILING_LIBRARY
89
90
91
92
#error "definition read in prebuilt mode and not during library compilation"
#endif
#endif

93
94
/*----------------------------------------------------------------------*/

95
  //! check shape and representation
96
  template<class T>
97
    void ConstArray<T>::check_consistency() const
98
    {
99
100
101
102
103
      AFF_assert((this->Tshape::first_offset()>=0),
                 "ERROR (ConstArray): invalid shape");
      AFF_assert((this->Tshape::last_offset()<
                  Tsubscript(Mrepresentation.size())),
              "ERROR (ConstArray): shape and representation are inconsistent");
104
105
106
107
    }

/*----------------------------------------------------------------------*/

108
  //! create a value (deep) copy
109
  template<class T>
thomas.forbriger's avatar
thomas.forbriger committed
110
    Array<T> ConstArray<T>::copyout() const
111
    {
112
      aff::Array<T> copy(Tshape(this->first(),this->last()));
thomas.forbriger's avatar
thomas.forbriger committed
113
      copy.copyin(*this);
114
      return(copy);
115
116
    }

117
/*======================================================================*/
118

119
  //! set whole array to scalar value
thomas.forbriger's avatar
thomas.forbriger committed
120
  template<class T>
121
    Array<T>& Array<T>::operator=(const T& value)
122
    {
123
      Tshape::Tstepper st(this->shape());
thomas.forbriger's avatar
thomas.forbriger committed
124
      for(st.tofirst(); st.valid(); st.incr())
125
      { Mrepresentation[st.current()]=value; } 
126
127
128
      return(*this);
    }

129
#ifdef AFF_PREBUILT
130
131
132
} // namespace prebuilt
#endif

133
} // namespace aff
134

135
#endif // AFF_ARRAY_DEF_H_VERSION (includeguard)
136
137

/* ----- END OF array_def.h ----- */