array_def.h 3.95 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.16 2003-01-03 20:43:52 forbrig Exp $
7
 * \author Thomas Forbriger
8
 * \since 08/12/2002
9
10
 * 
 * array class definitions (definitions)
11
12
13
14
 *
 * \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
15
 * yourself. It is included via array.h if you use the full template version
16
 * of the library.
17
18
19
20
 * 
 * Copyright (c) 2002 by Thomas Forbriger (IMG Frankfurt) 
 * 
 * REVISIONS and CHANGES 
21
 *  - 08/12/2002   V1.0   copied from libcontxx
22
23
24
25
 *  - 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
26
27
 *  - 18/12/2002   V1.2   (thof)
 *                        - added stepper code to scalar assignment operator
thomas.forbriger's avatar
thomas.forbriger committed
28
29
30
31
32
33
 *  - 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
34
35
 *  - 23/12/2002   V1.4   (thof)
 *                        - copyin() and copyout() work
thomas.forbriger's avatar
thomas.forbriger committed
36
37
38
 *  - 28/12/2002   V1.5   (thof)
 *                        - changed base class from specialization to
 *                          independent class template
39
40
41
42
43
 *  - 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
44
45
46
 *  - 03/01/2003   V1.7   (thof)
 *                        - copyout function now returns an aff::Array rather
 *                          than an aff::ConstArray
47
48
49
50
 * 
 * ============================================================================
 */

51
#ifndef AFF_ARRAY_DEC_H_VERSION 
52
53
54
55
#error "include this only through array_dec.h"
#endif

// include guard
56
#ifndef AFF_ARRAY_DEF_H_VERSION
57

58
#define AFF_ARRAY_DEF_H_VERSION \
thomas.forbriger's avatar
thomas.forbriger committed
59
  "AFF_ARRAY_DEF_H   V1.7"
60
#define AFF_ARRAY_DEF_H_CVSID \
thomas.forbriger's avatar
thomas.forbriger committed
61
  "$Id: array_def.h,v 1.16 2003-01-03 20:43:52 forbrig Exp $"
62
63

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

65
namespace aff {
66

67
#ifdef AFF_PREBUILT
68
69
70
namespace prebuilt {
#endif

71
#ifdef AFF_PREBUILT
thomas.forbriger's avatar
thomas.forbriger committed
72
#ifndef AFF_COMPILING_LIBRARY
73
74
75
76
#error "definition read in prebuilt mode and not during library compilation"
#endif
#endif

77
78
/*----------------------------------------------------------------------*/

79
  //! check shape and representation
80
  template<class T>
81
    void ConstArray<T>::check_consistency() const
82
    {
83
84
85
86
87
      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");
88
89
90
91
    }

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

92
  //! create a value (deep) copy
93
  template<class T>
thomas.forbriger's avatar
thomas.forbriger committed
94
    Array<T> ConstArray<T>::copyout() const
95
    {
96
      aff::Array<T> copy(Tshape(this->first(),this->last()));
thomas.forbriger's avatar
thomas.forbriger committed
97
      copy.copyin(*this);
98
      return(copy);
99
100
    }

101
/*======================================================================*/
102

103
  //! set whole array to scalar value
thomas.forbriger's avatar
thomas.forbriger committed
104
  template<class T>
105
    Array<T>& Array<T>::operator=(const T& value)
106
    {
107
      Tshape::Tstepper st(this->shape());
thomas.forbriger's avatar
thomas.forbriger committed
108
      for(st.tofirst(); st.valid(); st.incr())
109
      { Mrepresentation[st.current()]=value; } 
110
111
112
      return(*this);
    }

113
#ifdef AFF_PREBUILT
114
115
116
} // namespace prebuilt
#endif

117
} // namespace aff
118

119
#endif // AFF_ARRAY_DEF_H_VERSION (includeguard)
120
121

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