21 #ifndef SELDON_FILE_VECTOR_VECTOR_3_CXX
24 #include "Vector3.hxx"
45 template <
class T,
class Allocator0,
class Allocator1,
class Allocator2>
56 template <
class T,
class Allocator0,
class Allocator1,
class Allocator2>
59 data_.Reallocate(length);
70 template <
class T,
class Allocator0,
class Allocator1,
class Allocator2>
75 int n, m = length.GetSize();
77 for (
int i = 0; i < m; i++)
80 data_(i).Reallocate(n);
92 template <
class T,
class Allocator0,
class Allocator1,
class Allocator2>
93 template <
class Allocator>
98 int n, m = length.GetSize();
100 for (
int i = 0; i < m; i++)
102 n = length(i).GetSize();
103 data_(i).Reallocate(n);
104 for (
int j = 0; j < n; j++)
105 data_(i)(j).Reallocate(length(i)(j));
119 template <
class T,
class Allocator0,
class Allocator1,
class Allocator2>
134 template <
class T,
class Allocator0,
class Allocator1,
class Allocator2>
137 return data_.GetLength();
145 template <
class T,
class Allocator0,
class Allocator1,
class Allocator2>
148 return data_.GetSize();
157 template <
class T,
class Allocator0,
class Allocator1,
class Allocator2>
160 return data_(i).GetLength();
169 template <
class T,
class Allocator0,
class Allocator1,
class Allocator2>
172 return data_(i).GetSize();
182 template <
class T,
class Allocator0,
class Allocator1,
class Allocator2>
186 return data_(i)(j).GetLength();
196 template <
class T,
class Allocator0,
class Allocator1,
class Allocator2>
200 return data_(i)(j).GetSize();
209 template <
class T,
class Allocator0,
class Allocator1,
class Allocator2>
212 size_t total =
sizeof(*this) +
sizeof(pointer)*GetLength();
213 for (
int i = 0; i < GetLength(); i++)
215 total +=
sizeof(int)+
sizeof(pointer)+
sizeof(pointer)*GetLength(i);
216 for (
int j = 0; j < GetLength(i); j++)
217 total += data_(i)(j).GetMemorySize();
228 template <
class T,
class Allocator0,
class Allocator1,
class Allocator2>
232 for (
int i = 0; i < GetLength(); i++)
233 for (
int j = 0; j < GetLength(i); j++ )
234 total += GetLength(i, j);
247 template <
class T,
class Allocator0,
class Allocator1,
class Allocator2>
252 throw WrongArgument(
"Vector3::GetNelement(int beg, int end)",
253 "The lower bound of the range of inner vectors "
255 +
"[, is strictly greater than its upper bound.");
256 if (beg < 0 || end > GetLength())
257 throw WrongArgument(
"Vector3::GetNelement(int beg, int end)",
258 "The inner-vector of vectors indexes should be in "
259 "[0," +
to_str(GetLength()) +
"] but ["
261 +
", " +
to_str(end) +
"[ was provided.");
264 for (
int i = beg; i < end; i++)
265 for (
int j = 0; j < GetLength(i); j++ )
266 total += GetLength(i, j);
286 template <
class T,
class Allocator0,
class Allocator1,
class Allocator2>
291 throw WrongArgument(
"Vector3:::GetNelement(int beg0, int end0, "
292 "int beg1, int end1)",
293 "The lower bound of the range of inner vectors "
295 +
"[, is strictly greater than its upper bound.");
297 throw WrongArgument(
"Vector3:::GetNelement(int beg0, int end0, "
298 "int beg1, int end1)",
299 "The lower bound of the range of "
301 +
"[, is strictly greater than its upper bound.");
302 if (beg0 < 0 || end0 > GetLength())
303 throw WrongArgument(
"Vector3:::GetNelement(int beg0, int end0, "
304 "int beg1, int end1)",
305 "The inner-vector of vectors indexes should be in "
306 "[0," +
to_str(GetLength()) +
"] but ["
308 +
", " +
to_str(end0) +
"[ was provided.");
311 for (
int i = beg0; i < end0; i++)
313 if (beg1 < 0 || end1 > GetLength(i))
314 throw WrongArgument(
"Vector3:::GetNelement(int beg0, int end0, "
315 "int beg1, int end1)",
316 "For the inner vector of vectors "
317 +
to_str(i) +
", the vectors indexes should be "
318 "in [0," +
to_str(GetLength(i)) +
"] but ["
320 +
", " +
to_str(end1) +
"[ was provided.");
321 for (
int j = beg1; j < end1; j++)
322 total += GetLength(i, j);
334 template <
class T,
class Allocator0,
class Allocator1,
class Allocator2>
339 for (
int j = 0; j < GetLength(i); j++)
340 shape(j) = GetLength(i, j);
351 template <
class T,
class Allocator0,
class Allocator1,
class Allocator2>
355 shape.Reallocate(GetLength(i));
356 for (
int j = 0; j < GetLength(i); j++)
357 shape(j) = GetLength(i, j);
365 template <
class T,
class Allocator0,
class Allocator1,
class Allocator2>
377 template <
class T,
class Allocator0,
class Allocator1,
class Allocator2>
381 data_(i).Reallocate(N);
391 template <
class T,
class Allocator0,
class Allocator1,
class Allocator2>
395 data_(i)(j).Reallocate(N);
404 template <
class T,
class Allocator0,
class Allocator1,
class Allocator2>
405 template <
class Td,
class Allocatord>
409 data.Reallocate(GetNelement());
411 for (i = 0; i < GetLength(); i++)
412 for (j = 0; j < GetLength(i); j++)
413 for (k = 0; k < GetLength(i, j); k++)
414 data(n++) = data_(i)(j)(k);
427 template <
class T,
class Allocator0,
class Allocator1,
class Allocator2>
428 template <
class Td,
class Allocatord>
433 throw WrongArgument(
"Vector3:::Flatten(int beg, int end, Vector& data)",
434 "The lower bound of the range of inner vectors "
436 +
"[, is strictly greater than its upper bound.");
437 if (beg < 0 || end > GetLength())
438 throw WrongArgument(
"Vector3:::Flatten(int beg, int end, Vector& data)",
439 "The inner-vector of vectors indexes should be in "
440 "[0," +
to_str(GetLength()) +
"] but ["
442 +
", " +
to_str(end) +
"[ was provided.");
444 data.Reallocate(GetNelement(beg, end));
446 for (i = beg; i < end; i++)
447 for (j = 0; j < GetLength(i); j++)
448 for (k = 0; k < GetLength(i, j); k++)
449 data(n++) = data_(i)(j)(k);
470 template <
class T,
class Allocator0,
class Allocator1,
class Allocator2>
471 template <
class Td,
class Allocatord>
477 throw WrongArgument(
"Vector3:::Flatten(int beg0, int end0, int beg1, "
478 "int end1, Vector& data)",
479 "The lower bound of the range of inner vectors "
481 +
"[, is strictly greater than its upper bound.");
483 throw WrongArgument(
"Vector3:::Flatten(int beg0, int end0, int beg1, "
484 "int end1, Vector& data)",
485 "The lower bound of the range of "
487 +
"[, is strictly greater than its upper bound.");
488 if (beg0 < 0 || end0 > GetLength())
489 throw WrongArgument(
"Vector3:::Flatten(int beg0, int end0, int beg1, "
490 "int end1, Vector& data)",
491 "The inner-vector of vectors indexes should be in "
492 "[0," +
to_str(GetLength()) +
"] but ["
494 +
", " +
to_str(end0) +
"[ was provided.");
496 data.Reallocate(GetNelement(beg0, end0, beg1, end1));
498 for (i = beg0; i < end0; i++)
500 if (beg1 < 0 || end1 > GetLength(i))
501 throw WrongArgument(
"Vector3:::Flatten(int beg0, int end0, int beg1, "
502 "int end1, Vector& data)",
503 "For the inner vector of vectors "
504 +
to_str(i) +
", the vectors indexes should be "
505 "in [0," +
to_str(GetLength(i)) +
"] but ["
507 +
", " +
to_str(end1) +
"[ was provided.");
508 for (j = beg1; j < end1; j++)
509 for (k = 0; k < GetLength(i, j); k++)
510 data(n++) = data_(i)(j)(k);
521 template <
class T,
class Allocator0,
class Allocator1,
class Allocator2>
523 Allocator1, Allocator2>::PushBack(
int i,
int j,
const T& x)
525 data_(i)(j).PushBack(x);
534 template <
class T,
class Allocator0,
class Allocator1,
class Allocator2>
538 data_(i).PushBack(X);
546 template <
class T,
class Allocator0,
class Allocator1,
class Allocator2>
549 Vect_Full, Allocator1>& X)
560 template <
class T,
class Allocator0,
class Allocator1,
class Allocator2>
563 Vect_Full, Allocator1>, Vect_Full, Allocator2>& X)
565 for (
int i = 0; i < X.GetM(); i++)
566 data_.PushBack(X(i));
575 template <
class T,
class Allocator0,
class Allocator1,
class Allocator2>
585 template <
class T,
class Allocator0,
class Allocator1,
class Allocator2>
596 template <
class T,
class Allocator0,
class Allocator1,
class Allocator2>
598 Allocator1, Allocator2>::Clear(
int i)
609 template <
class T,
class Allocator0,
class Allocator1,
class Allocator2>
620 template <
class T,
class Allocator0,
class Allocator1,
class Allocator2>
623 for (
int i = 0; i < data_.GetM(); i++)
624 for (
int j = 0; j < data_(i).GetM(); j++)
633 template <
class T,
class Allocator0,
class Allocator1,
class Allocator2>
635 Vect_Full, Allocator2>&
646 template <
class T,
class Allocator0,
class Allocator1,
class Allocator2>
648 Vect_Full, Allocator1>, Vect_Full, Allocator2>&
660 template <
class T,
class Allocator0,
class Allocator1,
class Allocator2>
661 Vector<Vector<T, Vect_Full, Allocator0>, VectFull, Allocator1>&
673 template <
class T,
class Allocator0,
class Allocator1,
class Allocator2>
687 template <
class T,
class Allocator0,
class Allocator1,
class Allocator2>
701 template <
class T,
class Allocator0,
class Allocator1,
class Allocator2>
720 template <
class T,
class Allocator0,
class Allocator1,
class Allocator2>
723 Allocator1, Allocator2>::operator() (
int i)
const
734 template <
class T,
class Allocator0,
class Allocator1,
class Allocator2>
748 template <
class T,
class Allocator0,
class Allocator1,
class Allocator2>
751 Allocator1, Allocator2>::operator() (
int i,
int j)
const
763 template <
class T,
class Allocator0,
class Allocator1,
class Allocator2>
778 template <
class T,
class Allocator0,
class Allocator1,
class Allocator2>
781 Allocator1, Allocator2>::operator() (
int i,
int j,
int k)
const
783 return data_(i)(j)(k);
794 template <
class T,
class Allocator0,
class Allocator1,
class Allocator2>
795 typename Vector3<T, Allocator0, Allocator1, Allocator2>::reference
797 (
int i,
int j,
int k)
799 return data_(i)(j)(k);
809 template <
class T,
class Allocator0,
class Allocator1,
class Allocator2>
812 for (
int i = 0; i < data_.GetM(); i++)
813 for(
int j = 0; j < data_(i).GetM(); j++)
815 cout <<
"Vector " << i <<
", " << j <<
": ";
832 template <
class T,
class Allocator0,
class Allocator1,
class Allocator2>
834 ::Write(
string file_name,
bool with_size)
const
836 ofstream file_stream;
837 file_stream.open(file_name.c_str());
839 #ifdef SELDON_CHECK_IO
841 if (!file_stream.is_open())
842 throw IOError(
"Vector3::Write(string file_name, bool with_size)",
843 string(
"Unable to open file \"") + file_name +
"\".");
846 this->Write(file_stream, with_size);
858 template <
class T,
class Allocator0,
class Allocator1,
class Allocator2>
860 ::Write(ostream& stream,
bool with_size)
const
863 #ifdef SELDON_CHECK_IO
866 throw IOError(
"Vector3::Write(ostream& stream, bool with_size)",
867 "The stream is not ready.");
873 stream.write(
reinterpret_cast<char*
>(
const_cast<int*
>(&m)),
877 for (
int i = 0; i < GetLength(); i++)
881 int m = GetLength(i);
882 stream.write(
reinterpret_cast<char*
>(
const_cast<int*
>(&m)),
885 for (
int j = 0; j < GetLength(i); j++)
886 data_(i)(j).Write(stream, with_size);
889 #ifdef SELDON_CHECK_IO
892 throw IOError(
"Vector3::Write(ostream& stream, bool with_size)",
893 "Output operation failed.");
907 template <
class T,
class Allocator0,
class Allocator1,
class Allocator2>
911 ifstream file_stream;
912 file_stream.open(file_name.c_str());
914 #ifdef SELDON_CHECK_IO
916 if (!file_stream.is_open())
917 throw IOError(
"Vector3::Read(string file_name, bool with_size)",
918 string(
"Unable to open file \"") + file_name +
"\".");
921 this->Read(file_stream, with_size);
935 template <
class T,
class Allocator0,
class Allocator1,
class Allocator2>
940 #ifdef SELDON_CHECK_IO
943 throw IOError(
"Vector3::Read(istream& stream, bool with_size)",
944 "The stream is not ready.");
950 stream.read(
reinterpret_cast<char*
>(&new_size),
sizeof(
int));
951 this->Reallocate(new_size);
954 for (
int i = 0; i < GetLength(); i++)
959 stream.read(
reinterpret_cast<char*
>(&new_size),
sizeof(int));
960 this->Reallocate(i, new_size);
962 for (
int j = 0; j < GetLength(i); j++)
963 data_(i)(j).Read(stream, with_size);
966 #ifdef SELDON_CHECK_IO
969 throw IOError(
"Vector3::Read(istream& stream, bool with_size)",
970 "Output operation failed.");
979 #define SELDON_FILE_VECTOR_VECTOR_3_CXX