22 #ifndef SELDON_FILE_VECTOR_VECTOR2_CXX
25 #include "Vector2.hxx"
46 template <
class T,
class Allocator0,
class Allocator1>
56 template <
class T,
class Allocator0,
class Allocator1>
59 data_.Reallocate(length);
68 template <
class T,
class Allocator0,
class Allocator1>
72 long m = length.GetSize();
74 for(
long i = 0; i < m; i++)
75 data_(i).Reallocate(length(i));
85 template <
class T,
class Allocator0,
class Allocator1>
100 template <
class T,
class Allocator0,
class Allocator1>
103 for (
long i = 0; i < GetLength(); i++)
104 if (GetLength(i) > 0)
114 template <
class T,
class Allocator0,
class Allocator1>
117 return data_.GetSize();
125 template <
class T,
class Allocator0,
class Allocator1>
128 return data_.GetLength();
137 template <
class T,
class Allocator0,
class Allocator1>
140 return data_(i).GetSize();
149 template <
class T,
class Allocator0,
class Allocator1>
152 size_t total =
sizeof(*this) +
sizeof(pointer)*GetLength();
153 for (
long i = 0; i < GetLength(); i++)
154 total += data_(i).GetMemorySize();
165 template <
class T,
class Allocator0,
class Allocator1>
168 return data_(i).GetLength();
176 template <
class T,
class Allocator0,
class Allocator1>
180 for (
long i = 0; i < GetLength(); i++)
181 total += GetLength(i);
194 template <
class T,
class Allocator0,
class Allocator1>
198 throw WrongArgument(
"Vector2::GetNelement(long beg, long end)",
199 "The lower bound of the range of inner vectors, ["
201 +
"[, is strictly greater than its upper bound.");
202 if (beg < 0 || end > GetLength())
203 throw WrongArgument(
"Vector2::GetNelement(long beg, long end)",
204 "The inner-vector indexes should be in [0,"
206 +
", " +
to_str(end) +
"[ was provided.");
209 for (
long i = beg; i < end; i++)
210 total += GetLength(i);
219 template <
class T,
class Allocator0,
class Allocator1>
223 for (
long i = 0; i < GetLength(); i++)
224 shape(i) = GetLength(i);
233 template <
class T,
class Allocator0,
class Allocator1>
236 shape.Reallocate(GetLength());
237 for (
long i = 0; i < GetLength(); i++)
238 shape(i) = GetLength(i);
246 template <
class T,
class Allocator0,
class Allocator1>
258 template <
class T,
class Allocator0,
class Allocator1>
261 data_(i).Reallocate(N);
270 template <
class T,
class Allocator0,
class Allocator1>
274 long m = length.GetSize();
276 for(
long i = 0; i < m; i++)
277 data_(i).Reallocate(length(i));
287 template <
class T,
class Allocator0,
class Allocator1>
291 throw WrongArgument(
"Vector2::SelectInnerVector(long beg, long end)",
292 "The lower bound of the range of inner vectors, ["
294 +
"[, is strictly greater than its upper bound.");
295 if (beg < 0 || end > GetLength())
296 throw WrongArgument(
"Vector2::SelectInnerVector(long beg, long end)",
297 "The inner-vector indexes should be in [0,"
299 +
", " +
to_str(end) +
"[ was provided.");
302 for (
long i = 0; i < end - beg; i++)
303 data_(i) = data_(beg + i);
305 data_.Resize(end - beg);
314 template <
class T,
class Allocator0,
class Allocator1>
320 for (i = 0; i < GetLength(); i++)
321 for (j = 0; j < GetLength(i); j++)
322 data(n++) = data_(i)(j);
332 template <
class T,
class Allocator0,
class Allocator1>
333 template <
class Td,
class Allocatord>
337 data.Reallocate(GetNelement());
339 for (i = 0; i < GetLength(); i++)
340 for (j = 0; j < GetLength(i); j++)
341 data(n++) = data_(i)(j);
354 template <
class T,
class Allocator0,
class Allocator1>
355 template <
class Td,
class Allocatord>
360 throw WrongArgument(
"Vector2::Flatten(long beg, long end, Vector& data)",
361 "The lower bound of the range of inner vectors, ["
363 +
"[, is strictly greater than its upper bound.");
364 if (beg < 0 || end > GetLength())
365 throw WrongArgument(
"Vector2::Flatten(long beg, long end, Vector& data)",
366 "The inner-vector indexes should be in [0,"
368 +
", " +
to_str(end) +
"[ was provided.");
370 data.Reallocate(GetNelement(beg, end));
372 for (i = beg; i < end; i++)
373 for (j = 0; j < GetLength(i); j++)
374 data(n++) = data_(i)(j);
383 template <
class T,
class Allocator0,
class Allocator1>
386 data_(i).PushBack(x);
394 template <
class T,
class Allocator0,
class Allocator1>
407 template <
class T,
class Allocator0,
class Allocator1>
412 for (
long i = 0; i < V.GetM(); i++)
413 data_.PushBack(V(i));
422 template <
class T,
class Allocator0,
class Allocator1>
431 template <
class T,
class Allocator0,
class Allocator1>
442 template <
class T,
class Allocator0,
class Allocator1>
453 template <
class T,
class Allocator0,
class Allocator1>
456 for (
long i = 0; i < data_.GetM(); i++)
465 template <
class T,
class Allocator0,
class Allocator1>
477 template <
class T,
class Allocator0,
class Allocator1>
490 template <
class T,
class Allocator0,
class Allocator1>
491 Vector<T, VectFull, Allocator0>&
503 template <
class T,
class Allocator0,
class Allocator1>
517 template <
class T,
class Allocator0,
class Allocator1>
533 template <
class T,
class Allocator0,
class Allocator1>
553 template <
class T,
class Allocator0,
class Allocator1>
566 template <
class T,
class Allocator0,
class Allocator1>
580 template <
class T,
class Allocator0,
class Allocator1>
594 template <
class T,
class Allocator0,
class Allocator1>
595 typename Vector2<T, Allocator0, Allocator1>::reference
616 template <
class T,
class Allocator0,
class Allocator1>
620 if (V.GetLength() != GetLength())
622 for (
long i = 0; i < GetLength(); i++)
623 if (V.GetLength(i) != GetLength(i))
630 template <
class T,
class Allocator0,
class Allocator1>
633 for (
long i = 0; i < data_.GetM(); i++)
635 cout <<
"Vector " << i <<
": ";
655 template <
class T,
class Allocator0,
class Allocator1>
657 ::Write(
string file_name,
bool with_size)
const
659 ofstream file_stream;
660 file_stream.open(file_name.c_str());
662 #ifdef SELDON_CHECK_IO
664 if (!file_stream.is_open())
665 throw IOError(
"Vector2::Write(string file_name, bool with_size)",
666 string(
"Unable to open file \"") + file_name +
"\".");
669 this->Write(file_stream, with_size);
684 template <
class T,
class Allocator0,
class Allocator1>
686 ::Write(ostream& stream,
bool with_size)
const
689 #ifdef SELDON_CHECK_IO
692 throw IOError(
"Vector2::Write(ostream& stream, bool with_size)",
693 "The stream is not ready.");
699 stream.write(
reinterpret_cast<char*
>(
const_cast<int*
>(&m)),
703 for (
long i = 0; i < GetLength(); i++)
704 data_(i).Write(stream, with_size);
706 #ifdef SELDON_CHECK_IO
709 throw IOError(
"Vector2::Write(ostream& stream, bool with_size)",
710 "Output operation failed.");
727 template <
class T,
class Allocator0,
class Allocator1>
731 ifstream file_stream;
732 file_stream.open(file_name.c_str());
734 #ifdef SELDON_CHECK_IO
736 if (!file_stream.is_open())
737 throw IOError(
"Vector2::Read(string file_name, bool with_size)",
738 string(
"Unable to open file \"") + file_name +
"\".");
741 this->Read(file_stream, with_size);
758 template <
class T,
class Allocator0,
class Allocator1>
763 #ifdef SELDON_CHECK_IO
766 throw IOError(
"Vector2::Read(istream& stream, bool with_size)",
767 "The stream is not ready.");
773 stream.read(
reinterpret_cast<char*
>(&new_size),
sizeof(
int));
774 this->Reallocate(new_size);
777 for (
long i = 0; i < GetLength(); i++)
778 data_(i).Read(stream, with_size);
780 #ifdef SELDON_CHECK_IO
783 throw IOError(
"Vector2::Read(istream& stream, bool with_size)",
784 "Output operation failed.");
793 #define SELDON_FILE_VECTOR_VECTOR2_CXX