21 #ifndef SELDON_FILE_ARRAY3D_CXX
23 #include "Array3D.hxx"
37 template <
class T,
class Allocator>
56 template <
class T,
class Allocator>
63 length23_ = long(length2_) * long(length3_);
64 int nb_elt = long(i)*long(j)*long(k);
66 #ifdef SELDON_CHECK_MEMORY
71 data_ = Allocator::allocate(nb_elt,
this);
73 #ifdef SELDON_CHECK_MEMORY
83 if (data_ == NULL && i != 0 && j != 0 && k != 0)
84 throw NoMemory(
"Array3D::Array3D(int, int, int)",
85 string(
"Unable to allocate memory for an array of size ")
86 +
to_str(
static_cast<long int>(i)
87 *
static_cast<long int>(j)
88 *
static_cast<long int>(k)
89 *
static_cast<long int>(
sizeof(T)))
91 +
" x " +
to_str(k) +
" elements).");
98 template <
class T,
class Allocator>
126 template <
class T,
class Allocator>
129 if (i != length1_ || j != length2_ || k != length3_)
135 length23_ = long(j) * long(k);
136 int nb_elt = long(i)*long(j)*long(k);
138 #ifdef SELDON_CHECK_MEMORY
144 reinterpret_cast<pointer
>(Allocator::reallocate(data_,
147 #ifdef SELDON_CHECK_MEMORY
157 if (data_ == NULL && i != 0 && j != 0 && k != 0)
158 throw NoMemory(
"Array3D::Reallocate(int, int, int)",
159 string(
"Unable to reallocate memory")
160 +
" for an array of size "
161 +
to_str(
static_cast<long int>(i)
162 *
static_cast<long int>(j)
163 *
static_cast<long int>(k)
164 *
static_cast<long int>(
sizeof(T)))
166 +
" x " +
to_str(k) +
" elements).");
191 template <
class T,
class Allocator>
201 length23_ = long(j) * long(k);
211 template <
class T,
class Allocator>
227 template <
class T,
class Allocator>
235 #ifdef SELDON_CHECK_MEMORY
242 Allocator::deallocate(data_, length1_ * length23_);
246 #ifdef SELDON_CHECK_MEMORY
270 template <
class T,
class Allocator>
273 return sizeof(*this) + size_t(
sizeof(T))*GetDataSize();
282 template <
class T,
class Allocator>
285 Allocator::memoryset(data_,
char(0),
286 GetDataSize()*
sizeof(value_type));
295 template <
class T,
class Allocator>
298 long taille = this->GetDataSize();
299 for (
long i = 0; i < taille; i++)
309 template <
class T,
class Allocator>
313 long taille = this->GetDataSize();
316 for (
long i = 0; i < taille; i++)
325 template <
class T,
class Allocator>
328 #ifndef SELDON_WITHOUT_REINIT_RANDOM
331 long taille = this->GetDataSize();
332 for (
long i = 0; i < taille; i++)
341 template <
class T,
class Allocator>
346 for (i = 0; i < GetLength1(); i++)
348 for (j = 0; j < GetLength2(); j++)
350 for (k = 0; k < GetLength3(); k++)
351 cout << (*
this)(i, j, k) <<
'\t';
373 ::Write(
string FileName,
bool with_size)
const
376 FileStream.open(FileName.c_str(), ofstream::binary);
378 #ifdef SELDON_CHECK_IO
380 if (!FileStream.is_open())
381 throw IOError(
"Array3D::Write(string FileName)",
382 string(
"Unable to open file \"") + FileName +
"\".");
385 Write(FileStream, with_size);
400 ::Write(ofstream& FileStream,
bool with_size)
const
403 #ifdef SELDON_CHECK_IO
405 if (!FileStream.good())
406 throw IOError(
"Array3D::Write(ofstream& FileStream)",
407 "Stream is not ready.");
412 FileStream.write(
reinterpret_cast<char*
>(
const_cast<int*
>(&length1_)),
414 FileStream.write(
reinterpret_cast<char*
>(
const_cast<int*
>(&length2_)),
416 FileStream.write(
reinterpret_cast<char*
>(
const_cast<int*
>(&length3_)),
420 FileStream.write(
reinterpret_cast<char*
>(data_),
421 length23_ * length1_ *
sizeof(value_type));
423 #ifdef SELDON_CHECK_IO
425 if (!FileStream.good())
426 throw IOError(
"Array3D::Write(ofstream& FileStream)",
427 string(
"Output operation failed.")
428 +
string(
" The output file may have been removed")
429 +
" or there is no space left on device.");
443 template <
class T,
class Allocator>
447 FileStream.open(FileName.c_str(), ifstream::binary);
449 #ifdef SELDON_CHECK_IO
451 if (!FileStream.is_open())
452 throw IOError(
"Array3D::Read(string FileName)",
453 string(
"Unable to open file \"") + FileName +
"\".");
456 Read(FileStream, with_size);
470 template <
class T,
class Allocator>
472 ::Read(ifstream& FileStream,
bool with_size)
475 #ifdef SELDON_CHECK_IO
477 if (!FileStream.good())
478 throw IOError(
"Matrix_Pointers::Read(ifstream& FileStream)",
479 "Stream is not ready.");
484 int new_l1, new_l2, new_l3;
485 FileStream.read(
reinterpret_cast<char*
>(&new_l1),
sizeof(
int));
486 FileStream.read(
reinterpret_cast<char*
>(&new_l2),
sizeof(
int));
487 FileStream.read(
reinterpret_cast<char*
>(&new_l3),
sizeof(
int));
488 Reallocate(new_l1, new_l2, new_l3);
491 FileStream.read(
reinterpret_cast<char*
>(data_),
492 length23_ * length1_ *
sizeof(value_type));
494 #ifdef SELDON_CHECK_IO
496 if (!FileStream.good())
497 throw IOError(
"Array3D::Read(ifstream& FileStream)",
498 string(
"Output operation failed.")
499 +
string(
" The intput file may have been removed")
500 +
" or may not contain enough data.");
512 template <
class T,
class Allocator>
523 out << A(i, j, k) <<
'\t';
538 template <
class T0,
class T,
class Allocator>
543 for (
long i = 0; i < taille; i++)
549 #define SELDON_FILE_ARRAY3D_CXX