Class documentation of Concepts

Loading...
Searching...
No Matches
stiffArray.hh
Go to the documentation of this file.
1
8#ifndef stiffArray_hh
9#define stiffArray_hh
10
11#include "toolbox/array.hh"
12#include "basics/debug.hh"
13
14#define StiffArrayConstr_D 0
15#define StiffArrayDestr_D 0
16
17namespace concepts {
18
19 // *********************************************************** StiffArray **
20
28 template<uint dim, class F>
29 class StiffArray : public virtual OutputOperator {
30 public:
32 StiffArray() : data_(new F[dim]) {}
37 StiffArray(const F& dft) : data_(new F[dim]) { *this = dft; }
42 StiffArray(const Array<F>& dft) : data_(new F[dim]) {
43 memorycpy(data_, (const F*)dft, dim);
44 conceptsAssert(dft.size() == dim, Assertion());
45 }
51 template<class H>
52 StiffArray(const StiffArray<dim,H>& a, F fnc(const H&))
53 : data_(new F[dim]) {
54 F* d = data_; const H* e = (const H*)a;
55 for(uint i = dim; i--;) *d++ = fnc(*e++);
56 }
62 template<class H>
63 StiffArray(const StiffArray<dim,H>& a, const F& fnc(const H&))
64 : data_(new F[dim]) {
65 F* d = data_; const H* e = (const H*)a;
66 for(uint i = dim; i--;) *d++ = fnc(*e++);
67 }
69 StiffArray(const StiffArray<dim,F>& a) : data_(new F[dim]) {
70 std::memcpy(data_, a.data_, dim*sizeof(F));
71 }
72 ~StiffArray() {
73 DEBUGL(StiffArrayDestr_D, "data = " << data_);
74 delete[] data_;
75 DEBUGL(StiffArrayDestr_D, "done.");
76 }
77 uint length() { return dim; }
79 void zeros() { std::memset(data_, 0, dim*sizeof(F)); }
81 operator F*() { return data_; }
83 operator const F*() const { return data_; }
85 F* data() { return data_; }
87 const F* data() const { return data_; }
88
89
90 operator Array<F>() const { return Array<F>(data_,dim); }
91
92 Array<F> array_data() const { return Array<F>(data_,dim); }
93
95 const F& operator[] (const int i) const {
96 conceptsAssert3(i < (int)dim, Assertion(),
97 "i = " << i << ", dim = " << dim);
98 return data_[i];
99 }
101 F& operator[] (const int i) {
102 conceptsAssert3(i < (int)dim, Assertion(),
103 "i = " << i << ", dim = " << dim);
104 return data_[i];
105 }
106
109 F* d = data_; for(uint i = dim; i--;) *d++ *= n;
110 return *this;
111 }
114 F* d = data_; for(uint i = dim; i--;) *d++ /= n;
115 return *this;
116 }
119 F* d = data_; for(uint i = dim; i--;) *d++ = n;
120 return *this;
121 }
124 F* d = data_; for(uint i = dim; i--;) *d++ += n;
125 return *this;
126 }
129 F* d = data_; for(uint i = dim; i--;) *d++ -= n;
130 return *this;
131 }
134 F* d = data_; const F* e = (const F*)a;
135 for(uint i = dim; i--;) *d++ *= *e++;
136 return *this;
137 }
141 F* d = data_; for(uint i = dim; i--;) *d = fnc(*d++);
142 return *this;
143 }
144 protected:
145 virtual std::ostream& info(std::ostream& os) const;
146 private:
148 F* data_;
149 };
150
151 template<uint dim, class F>
152 std::ostream& StiffArray<dim, F>::info(std::ostream& os) const {
153 os << concepts::typeOf(*this)<<"([";
154 F* d = data_;
155 for (uint i = dim; i--;)
156 os << *d++ << ((i == 0) ? "" : ", ");
157 return os << "])";
158 }
159
160 // ****************************************************** StiffArray<1,F> **
161
162 template<class F>
163 class StiffArray<1,F> : public virtual OutputOperator {
164 public:
171 StiffArray(const F& dft) : data_(dft) {}
177 conceptsAssert(dft.size() == 1, Assertion());
178 data_ = dft[0];
179 }
185 template<class H>
186 StiffArray(const StiffArray<1,H>& a, F fnc(const H&)) {
187 data_ = fnc(a);
188 }
190 StiffArray(const StiffArray<1,F>& a) : data_(a.data_) {}
191 ~StiffArray() {
192 DEBUGL(StiffArrayDestr_D, "done.");
193 }
194 uint length() { return 1; }
196 void zeros() { data_ = 0; }
198 operator F() const { return data_; }
199
201 const F& operator[] (const int i) const {
202 conceptsAssert3(i == 0, Assertion(), "i = " << i);
203 return data_;
204 }
206 F& operator[] (const int i) {
207 conceptsAssert3(i == 0, Assertion(), "i = " << i);
208 return data_;
209 }
210
213 data_ *= n; return *this;
214 }
217 data_ /= n; return *this;
218 }
221 data_ = n; return *this;
222 }
225 data_ += n; return *this;
226 }
229 data_ -= n; return *this;
230 }
234 data_ = fnc(data_); return *this;
235 }
236 protected:
237 virtual std::ostream& info(std::ostream& os) const;
238 private:
240 F data_;
241 };
242
243 template<class F>
244 std::ostream& StiffArray<1, F>::info(std::ostream& os) const {
245 return os << concepts::typeOf(*this)<<"([" << data_ << "])";
246 }
247
248 // ****************************************************** StiffArray<0,F> **
249
254 template<class F>
255 class StiffArray<0,F> : public virtual OutputOperator {
256 public:
258 (concepts::MissingFeature("makes no sense")); }
259 };
260
261
262} // namespace concepts
263
264#endif // stiffArray_hh
#define conceptsException(exc)
StiffArray< 1, F > & operator*=(const F n)
Scaling operator.
void zeros()
Fills the memory with zeros.
StiffArray(const StiffArray< 1, H > &a, F fnc(const H &))
StiffArray(const Array< F > &dft)
StiffArray< 1, F > & operator=(const F n)
Assignement operator.
StiffArray< 1, F > & operator/=(const F n)
Division operator.
StiffArray< 1, F > & operator+=(const F n)
Addition operator.
StiffArray< 1, F > & apply(F &fnc(F &))
StiffArray< 1, F > & operator-=(const F n)
Subtraction operator.
StiffArray(const StiffArray< 1, F > &a)
Copy constructor.
virtual std::ostream & info(std::ostream &os) const
Returns information in an output stream.
StiffArray(const StiffArray< dim, H > &a, const F &fnc(const H &))
Definition stiffArray.hh:63
StiffArray(const StiffArray< dim, H > &a, F fnc(const H &))
Definition stiffArray.hh:52
StiffArray< dim, F > & apply(F &fnc(F &))
const F & operator[](const int i) const
Index operator.
Definition stiffArray.hh:95
StiffArray(const StiffArray< dim, F > &a)
Copy constructor.
Definition stiffArray.hh:69
void zeros()
Fills the memory with zeros.
Definition stiffArray.hh:79
F * data()
Returns a pointer to the data in the array.
Definition stiffArray.hh:85
const F * data() const
Returns a pointer to the data in the array.
Definition stiffArray.hh:87
StiffArray< dim, F > & operator=(const F n)
Assignement operator.
StiffArray< dim, F > & operator*=(const StiffArray< dim, F > &a)
Multiplication operator.
StiffArray< dim, F > & operator-=(const F n)
Subtraction operator.
StiffArray< dim, F > & operator*=(const F n)
Scaling operator.
StiffArray< dim, F > & operator/=(const F n)
Division operator.
StiffArray(const F &dft)
Definition stiffArray.hh:37
StiffArray()
Constructor.
Definition stiffArray.hh:32
StiffArray(const Array< F > &dft)
Definition stiffArray.hh:42
StiffArray< dim, F > & operator+=(const F n)
Addition operator.
#define conceptsAssert(cond, exc)
#define DEBUGL(doit, msg)
Definition debug.hh:40
#define conceptsAssert3(cond, exc, msg)
std::string typeOf(const T &t)
Definition output.hh:43
void memorycpy(F *dest, const G *src, size_t n)
Copies n entries from src to dest (faster than std::memcpy)
Set< F > makeSet(uint n, const F &first,...)
Definition set.hh:320