22 #ifndef SELDON_FILE_ARRAY4D_CXX
24 #include "Array4D.hxx"
38 template <
class T,
class Allocator>
60 template <
class T,
class Allocator>
68 length34_ = long(length3_) * long(length4_);
69 length234_ = long(length2_) * long(length3_) * long(length4_);
70 int nb_elt = long(i) * long(j) * long(k) * long(l);
72 #ifdef SELDON_CHECK_MEMORY
77 data_ = Allocator::allocate(nb_elt,
this);
79 #ifdef SELDON_CHECK_MEMORY
91 if (data_ == NULL && i != 0 && j != 0 && k != 0 && l != 0)
92 throw NoMemory(
"Array4D::Array4D(int, int, int, int)",
93 string(
"Unable to allocate memory for an array of size ")
94 +
to_str(
static_cast<long int>(i)
95 *
static_cast<long int>(j)
96 *
static_cast<long int>(k)
97 *
static_cast<long int>(l)
98 *
static_cast<long int>(
sizeof(T)))
100 +
" x " +
to_str(k) +
" x " +
to_str(l) +
" elements).");
107 template <
class T,
class Allocator>
138 template <
class T,
class Allocator>
141 if (i != length1_ || j != length2_ || k != length3_ || l != length4_)
148 length34_ = long(k) * long(l);
149 length234_ = long(j) * long(k) * long(l);
150 int nb_elt = long(i) * long(j) * long(k) * long(l);
152 #ifdef SELDON_CHECK_MEMORY
158 reinterpret_cast<pointer
>(Allocator::reallocate(data_,
161 #ifdef SELDON_CHECK_MEMORY
173 if (data_ == NULL && i != 0 && j != 0 && k != 0 && l != 0)
174 throw NoMemory(
"Array4D::Reallocate(int, int, int, int)",
175 string(
"Unable to reallocate memory")
176 +
" for an array of size "
177 +
to_str(
static_cast<long int>(i)
178 *
static_cast<long int>(j)
179 *
static_cast<long int>(k)
180 *
static_cast<long int>(l)
181 *
static_cast<long int>(
sizeof(T)))
195 template <
class T,
class Allocator>
205 #ifdef SELDON_CHECK_MEMORY
212 Allocator::deallocate(data_, length1_ * length234_);
216 #ifdef SELDON_CHECK_MEMORY
241 template <
class T,
class Allocator>
244 return sizeof(*this) + size_t(
sizeof(T))*GetDataSize();
253 template <
class T,
class Allocator>
256 Allocator::memoryset(data_,
char(0),
257 GetDataSize()*
sizeof(value_type));
266 template <
class T,
class Allocator>
269 long taille = this->GetDataSize();
270 for (
long i = 0; i < taille; i++)
280 template <
class T,
class Allocator>
284 T x_;
long taille = this->GetDataSize();
286 for (
long i = 0; i < taille; i++)
295 template <
class T,
class Allocator>
298 #ifndef SELDON_WITHOUT_REINIT_RANDOM
301 long taille = this->GetDataSize();
302 for (
long i = 0; i < taille; i++)
311 template <
class T,
class Allocator>
316 for (i = 0; i < GetLength1(); i++)
318 for (j = 0; j < GetLength2(); j++)
320 for (k = 0; k < GetLength3(); k++)
322 for (l = 0; l < GetLength4(); l++)
323 cout << (*
this)(i, j, k, l) <<
'\t';
347 ::Write(
string FileName,
bool with_size)
const
350 FileStream.open(FileName.c_str(), ofstream::binary);
352 #ifdef SELDON_CHECK_IO
354 if (!FileStream.is_open())
355 throw IOError(
"Array4D::Write(string FileName)",
356 string(
"Unable to open file \"") + FileName +
"\".");
359 Write(FileStream, with_size);
374 ::Write(ofstream& FileStream,
bool with_size)
const
377 #ifdef SELDON_CHECK_IO
379 if (!FileStream.good())
380 throw IOError(
"Array4D::Write(ofstream& FileStream)",
381 "Stream is not ready.");
386 FileStream.write(
reinterpret_cast<char*
>(
const_cast<int*
>(&length1_)),
388 FileStream.write(
reinterpret_cast<char*
>(
const_cast<int*
>(&length2_)),
390 FileStream.write(
reinterpret_cast<char*
>(
const_cast<int*
>(&length3_)),
392 FileStream.write(
reinterpret_cast<char*
>(
const_cast<int*
>(&length4_)),
396 FileStream.write(
reinterpret_cast<char*
>(data_),
397 length234_ * length1_ *
sizeof(value_type));
399 #ifdef SELDON_CHECK_IO
401 if (!FileStream.good())
402 throw IOError(
"Array4D::Write(ofstream& FileStream)",
403 string(
"Output operation failed.")
404 +
string(
" The output file may have been removed")
405 +
" or there is no space left on device.");
419 template <
class T,
class Allocator>
423 FileStream.open(FileName.c_str(), ifstream::binary);
425 #ifdef SELDON_CHECK_IO
427 if (!FileStream.is_open())
428 throw IOError(
"Array4D::Read(string FileName)",
429 string(
"Unable to open file \"") + FileName +
"\".");
432 Read(FileStream, with_size);
446 template <
class T,
class Allocator>
448 ::Read(ifstream& FileStream,
bool with_size)
451 #ifdef SELDON_CHECK_IO
453 if (!FileStream.good())
454 throw IOError(
"Matrix_Pointers::Read(ifstream& FileStream)",
455 "Stream is not ready.");
460 int new_l1, new_l2, new_l3, new_l4;
461 FileStream.read(
reinterpret_cast<char*
>(&new_l1),
sizeof(
int));
462 FileStream.read(
reinterpret_cast<char*
>(&new_l2),
sizeof(
int));
463 FileStream.read(
reinterpret_cast<char*
>(&new_l3),
sizeof(
int));
464 FileStream.read(
reinterpret_cast<char*
>(&new_l4),
sizeof(
int));
465 Reallocate(new_l1, new_l2, new_l3, new_l4);
468 FileStream.read(
reinterpret_cast<char*
>(data_),
469 length234_ * length1_ *
sizeof(value_type));
471 #ifdef SELDON_CHECK_IO
473 if (!FileStream.good())
474 throw IOError(
"Array4D::Read(ifstream& FileStream)",
475 string(
"Output operation failed.")
476 +
string(
" The intput file may have been removed")
477 +
" or may not contain enough data.");
489 template <
class T,
class Allocator>
502 out << A(i, j, k, l) <<
'\t';
515 #define SELDON_FILE_ARRAY4D_CXX