Warning: this documentation for the development version is under construction.
00001 // Copyright (C) 2010-2012, INRIA 00002 // Author(s): Marc Fragu, Vivien Mallet 00003 // 00004 // This file is part of the linear-algebra library Seldon, 00005 // http://seldon.sourceforge.net/. 00006 // 00007 // Seldon is free software; you can redistribute it and/or modify it under the 00008 // terms of the GNU Lesser General Public License as published by the Free 00009 // Software Foundation; either version 2.1 of the License, or (at your option) 00010 // any later version. 00011 // 00012 // Seldon is distributed in the hope that it will be useful, but WITHOUT ANY 00013 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00014 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for 00015 // more details. 00016 // 00017 // You should have received a copy of the GNU Lesser General Public License 00018 // along with Seldon. If not, see http://www.gnu.org/licenses/. 00019 00020 00021 #ifndef SELDON_FILE_VECTOR_VECTOR_3_CXX 00022 00023 00024 #include "Vector3.hxx" 00025 00026 00027 namespace Seldon 00028 { 00029 00030 00032 // VECTOR3 // 00034 00035 00036 /*************** 00037 * CONSTRUCTOR * 00038 ***************/ 00039 00040 00042 00045 template <class T, class Allocator0, class Allocator1, class Allocator2> 00046 Vector3<T, Allocator0, Allocator1, Allocator2>::Vector3() 00047 { 00048 } 00049 00050 00052 00056 template <class T, class Allocator0, class Allocator1, class Allocator2> 00057 Vector3<T, Allocator0, Allocator1, Allocator2>::Vector3(int length) 00058 { 00059 data_.Reallocate(length); 00060 } 00061 00062 00064 00070 template <class T, class Allocator0, class Allocator1, class Allocator2> 00071 Vector3<T, Allocator0, Allocator1, Allocator2> 00072 ::Vector3(Vector<int>& length) 00073 { 00074 data_.Clear(); 00075 int n, m = length.GetSize(); 00076 data_.Reallocate(m); 00077 for (int i = 0; i < m; i++) 00078 { 00079 n = length(i); 00080 data_(i).Reallocate(n); 00081 } 00082 } 00083 00084 00086 00092 template <class T, class Allocator0, class Allocator1, class Allocator2> 00093 template <class Allocator> 00094 Vector3<T, Allocator0, Allocator1, Allocator2> 00095 ::Vector3(Vector<Vector<int>, Vect_Full, Allocator>& length) 00096 { 00097 data_.Clear(); 00098 int n, m = length.GetSize(); 00099 data_.Reallocate(m); 00100 for (int i = 0; i < m; i++) 00101 { 00102 n = length(i).GetSize(); 00103 data_(i).Reallocate(n); 00104 for (int j = 0; j < n; j++) 00105 data_(i)(j).Reallocate(length(i)(j)); 00106 } 00107 } 00108 00109 00110 /************** 00111 * DESTRUCTOR * 00112 **************/ 00113 00114 00116 00119 template <class T, class Allocator0, class Allocator1, class Allocator2> 00120 Vector3<T, Allocator0, Allocator1, Allocator2>::~Vector3() 00121 { 00122 } 00123 00124 00125 /********************** 00126 * VECTORS MANAGEMENT * 00127 **********************/ 00128 00129 00131 00134 template <class T, class Allocator0, class Allocator1, class Allocator2> 00135 int Vector3<T, Allocator0, Allocator1, Allocator2>::GetLength() const 00136 { 00137 return data_.GetLength(); 00138 } 00139 00140 00142 00145 template <class T, class Allocator0, class Allocator1, class Allocator2> 00146 int Vector3<T, Allocator0, Allocator1, Allocator2>::GetSize() const 00147 { 00148 return data_.GetSize(); 00149 } 00150 00151 00153 00157 template <class T, class Allocator0, class Allocator1, class Allocator2> 00158 int Vector3<T, Allocator0, Allocator1, Allocator2>::GetLength(int i) const 00159 { 00160 return data_(i).GetLength(); 00161 } 00162 00163 00165 00169 template <class T, class Allocator0, class Allocator1, class Allocator2> 00170 int Vector3<T, Allocator0, Allocator1, Allocator2>::GetSize(int i) const 00171 { 00172 return data_(i).GetSize(); 00173 } 00174 00175 00177 00182 template <class T, class Allocator0, class Allocator1, class Allocator2> 00183 int Vector3<T, Allocator0, Allocator1, Allocator2> 00184 ::GetLength(int i, int j) const 00185 { 00186 return data_(i)(j).GetLength(); 00187 } 00188 00189 00191 00196 template <class T, class Allocator0, class Allocator1, class Allocator2> 00197 int Vector3<T, Allocator0, Allocator1, Allocator2> 00198 ::GetSize(int i, int j) const 00199 { 00200 return data_(i)(j).GetSize(); 00201 } 00202 00203 00205 00208 template <class T, class Allocator0, class Allocator1, class Allocator2> 00209 int Vector3<T, Allocator0, Allocator1, Allocator2>::GetNelement() const 00210 { 00211 int total = 0; 00212 for (int i = 0; i < GetLength(); i++) 00213 for (int j = 0; j < GetLength(i); j++ ) 00214 total += GetLength(i, j); 00215 return total; 00216 } 00217 00218 00220 00227 template <class T, class Allocator0, class Allocator1, class Allocator2> 00228 int Vector3<T, Allocator0, Allocator1, Allocator2> 00229 ::GetNelement(int beg, int end) const 00230 { 00231 if (beg > end) 00232 throw WrongArgument("Vector3::GetNelement(int beg, int end)", 00233 "The lower bound of the range of inner vectors " 00234 "of vectors, [" + to_str(beg) + ", " + to_str(end) 00235 + "[, is strictly greater than its upper bound."); 00236 if (beg < 0 || end > GetLength()) 00237 throw WrongArgument("Vector3::GetNelement(int beg, int end)", 00238 "The inner-vector of vectors indexes should be in " 00239 "[0," + to_str(GetLength()) + "] but [" 00240 + to_str(beg) 00241 + ", " + to_str(end) + "[ was provided."); 00242 00243 int total = 0; 00244 for (int i = beg; i < end; i++) 00245 for (int j = 0; j < GetLength(i); j++ ) 00246 total += GetLength(i, j); 00247 return total; 00248 } 00249 00250 00252 00266 template <class T, class Allocator0, class Allocator1, class Allocator2> 00267 int Vector3<T, Allocator0, Allocator1, Allocator2> 00268 ::GetNelement(int beg0, int end0, int beg1, int end1) const 00269 { 00270 if (beg0 > end0) 00271 throw WrongArgument("Vector3:::GetNelement(int beg0, int end0, " 00272 "int beg1, int end1)", 00273 "The lower bound of the range of inner vectors " 00274 "of vectors, [" + to_str(beg0) + ", " + to_str(end0) 00275 + "[, is strictly greater than its upper bound."); 00276 if (beg1 > end1) 00277 throw WrongArgument("Vector3:::GetNelement(int beg0, int end0, " 00278 "int beg1, int end1)", 00279 "The lower bound of the range of " 00280 "of vectors, [" + to_str(beg1) + ", " + to_str(end1) 00281 + "[, is strictly greater than its upper bound."); 00282 if (beg0 < 0 || end0 > GetLength()) 00283 throw WrongArgument("Vector3:::GetNelement(int beg0, int end0, " 00284 "int beg1, int end1)", 00285 "The inner-vector of vectors indexes should be in " 00286 "[0," + to_str(GetLength()) + "] but [" 00287 + to_str(beg0) 00288 + ", " + to_str(end0) + "[ was provided."); 00289 00290 int total = 0; 00291 for (int i = beg0; i < end0; i++) 00292 { 00293 if (beg1 < 0 || end1 > GetLength(i)) 00294 throw WrongArgument("Vector3:::GetNelement(int beg0, int end0, " 00295 "int beg1, int end1)", 00296 "For the inner vector of vectors " 00297 + to_str(i) + ", the vectors indexes should be " 00298 "in [0," + to_str(GetLength(i)) + "] but [" 00299 + to_str(beg1) 00300 + ", " + to_str(end1) + "[ was provided."); 00301 for (int j = beg1; j < end1; j++) 00302 total += GetLength(i, j); 00303 } 00304 return total; 00305 } 00306 00307 00309 00314 template <class T, class Allocator0, class Allocator1, class Allocator2> 00315 Vector<int> Vector3<T, Allocator0, Allocator1, Allocator2> 00316 ::GetShape(int i) const 00317 { 00318 Vector<int> shape(GetLength(i)); 00319 for (int j = 0; j < GetLength(i); j++) 00320 shape(j) = GetLength(i, j); 00321 return shape; 00322 } 00323 00324 00326 00331 template <class T, class Allocator0, class Allocator1, class Allocator2> 00332 void Vector3<T, Allocator0, Allocator1, Allocator2> 00333 ::GetShape(int i, Vector<int>& shape) const 00334 { 00335 shape.Reallocate(GetLength(i)); 00336 for (int j = 0; j < GetLength(i); j++) 00337 shape(j) = GetLength(i, j); 00338 } 00339 00340 00342 00345 template <class T, class Allocator0, class Allocator1, class Allocator2> 00346 void Vector3<T, Allocator0, Allocator1, Allocator2>::Reallocate(int N) 00347 { 00348 data_.Reallocate(N); 00349 } 00350 00351 00353 00357 template <class T, class Allocator0, class Allocator1, class Allocator2> 00358 void Vector3<T, Allocator0, Allocator1, Allocator2> 00359 ::Reallocate(int i, int N) 00360 { 00361 data_(i).Reallocate(N); 00362 } 00363 00364 00366 00371 template <class T, class Allocator0, class Allocator1, class Allocator2> 00372 void Vector3<T, Allocator0, Allocator1, Allocator2> 00373 ::Reallocate(int i, int j, int N) 00374 { 00375 data_(i)(j).Reallocate(N); 00376 } 00377 00378 00380 00384 template <class T, class Allocator0, class Allocator1, class Allocator2> 00385 template <class Td, class Allocatord> 00386 void Vector3<T, Allocator0, Allocator1, Allocator2> 00387 ::Flatten(Vector<Td, VectFull, Allocatord>& data) const 00388 { 00389 data.Reallocate(GetNelement()); 00390 int i, j, k, n(0); 00391 for (i = 0; i < GetLength(); i++) 00392 for (j = 0; j < GetLength(i); j++) 00393 for (k = 0; k < GetLength(i, j); k++) 00394 data(n++) = data_(i)(j)(k); 00395 } 00396 00397 00399 00407 template <class T, class Allocator0, class Allocator1, class Allocator2> 00408 template <class Td, class Allocatord> 00409 void Vector3<T, Allocator0, Allocator1, Allocator2> 00410 ::Flatten(int beg, int end, Vector<Td, VectFull, Allocatord>& data) const 00411 { 00412 if (beg > end) 00413 throw WrongArgument("Vector3:::Flatten(int beg, int end, Vector& data)", 00414 "The lower bound of the range of inner vectors " 00415 "of vectors, [" + to_str(beg) + ", " + to_str(end) 00416 + "[, is strictly greater than its upper bound."); 00417 if (beg < 0 || end > GetLength()) 00418 throw WrongArgument("Vector3:::Flatten(int beg, int end, Vector& data)", 00419 "The inner-vector of vectors indexes should be in " 00420 "[0," + to_str(GetLength()) + "] but [" 00421 + to_str(beg) 00422 + ", " + to_str(end) + "[ was provided."); 00423 00424 data.Reallocate(GetNelement(beg, end)); 00425 int i, j, k, n(0); 00426 for (i = beg; i < end; i++) 00427 for (j = 0; j < GetLength(i); j++) 00428 for (k = 0; k < GetLength(i, j); k++) 00429 data(n++) = data_(i)(j)(k); 00430 } 00431 00432 00450 template <class T, class Allocator0, class Allocator1, class Allocator2> 00451 template <class Td, class Allocatord> 00452 void Vector3<T, Allocator0, Allocator1, Allocator2> 00453 ::Flatten(int beg0, int end0, int beg1, int end1, 00454 Vector<Td, VectFull, Allocatord>& data) const 00455 { 00456 if (beg0 > end0) 00457 throw WrongArgument("Vector3:::Flatten(int beg0, int end0, int beg1, " 00458 "int end1, Vector& data)", 00459 "The lower bound of the range of inner vectors " 00460 "of vectors, [" + to_str(beg0) + ", " + to_str(end0) 00461 + "[, is strictly greater than its upper bound."); 00462 if (beg1 > end1) 00463 throw WrongArgument("Vector3:::Flatten(int beg0, int end0, int beg1, " 00464 "int end1, Vector& data)", 00465 "The lower bound of the range of " 00466 "of vectors, [" + to_str(beg1) + ", " + to_str(end1) 00467 + "[, is strictly greater than its upper bound."); 00468 if (beg0 < 0 || end0 > GetLength()) 00469 throw WrongArgument("Vector3:::Flatten(int beg0, int end0, int beg1, " 00470 "int end1, Vector& data)", 00471 "The inner-vector of vectors indexes should be in " 00472 "[0," + to_str(GetLength()) + "] but [" 00473 + to_str(beg0) 00474 + ", " + to_str(end0) + "[ was provided."); 00475 00476 data.Reallocate(GetNelement(beg0, end0, beg1, end1)); 00477 int i, j, k, n(0); 00478 for (i = beg0; i < end0; i++) 00479 { 00480 if (beg1 < 0 || end1 > GetLength(i)) 00481 throw WrongArgument("Vector3:::Flatten(int beg0, int end0, int beg1, " 00482 "int end1, Vector& data)", 00483 "For the inner vector of vectors " 00484 + to_str(i) + ", the vectors indexes should be " 00485 "in [0," + to_str(GetLength(i)) + "] but [" 00486 + to_str(beg1) 00487 + ", " + to_str(end1) + "[ was provided."); 00488 for (j = beg1; j < end1; j++) 00489 for (k = 0; k < GetLength(i, j); k++) 00490 data(n++) = data_(i)(j)(k); 00491 } 00492 } 00493 00494 00496 00501 template <class T, class Allocator0, class Allocator1, class Allocator2> 00502 void Vector3<T, Allocator0, 00503 Allocator1, Allocator2>::PushBack(int i, int j, const T& x) 00504 { 00505 data_(i)(j).PushBack(x); 00506 } 00507 00508 00510 00514 template <class T, class Allocator0, class Allocator1, class Allocator2> 00515 void Vector3<T, Allocator0, Allocator1, Allocator2>:: 00516 PushBack(int i, const Vector<T, Vect_Full, Allocator0>& X) 00517 { 00518 data_(i).PushBack(X); 00519 } 00520 00521 00523 00526 template <class T, class Allocator0, class Allocator1, class Allocator2> 00527 void Vector3<T, Allocator0, Allocator1, Allocator2> 00528 ::PushBack(const Vector<Vector<T, Vect_Full, Allocator0>, 00529 Vect_Full, Allocator1>& X) 00530 { 00531 data_.PushBack(X); 00532 } 00533 00534 00536 00540 template <class T, class Allocator0, class Allocator1, class Allocator2> 00541 void Vector3<T, Allocator0, Allocator1, Allocator2> 00542 ::PushBack(const Vector<Vector<Vector<T, Vect_Full, Allocator0>, 00543 Vect_Full, Allocator1>, Vect_Full, Allocator2>& X) 00544 { 00545 for (int i = 0; i < X.GetLength(); i++) 00546 data_.PushBack(X(i)); 00547 } 00548 00549 00551 00555 template <class T, class Allocator0, class Allocator1, class Allocator2> 00556 void Vector3<T, Allocator0, Allocator1, Allocator2> 00557 ::PushBack(const Vector3<T, Allocator0, Allocator1, Allocator2>& X) 00558 { 00559 for (int i = 0; i < X.GetLength(); i++) 00560 data_.PushBack(X.GetVector()); 00561 } 00562 00563 00565 template <class T, class Allocator0, class Allocator1, class Allocator2> 00566 void Vector3<T, Allocator0, Allocator1, Allocator2>::Clear() 00567 { 00568 data_.Clear(); 00569 } 00570 00571 00573 00576 template <class T, class Allocator0, class Allocator1, class Allocator2> 00577 void Vector3<T, Allocator0, 00578 Allocator1, Allocator2>::Clear(int i) 00579 { 00580 data_(i).Clear(); 00581 } 00582 00583 00585 00589 template <class T, class Allocator0, class Allocator1, class Allocator2> 00590 void Vector3<T, Allocator0, Allocator1, Allocator2>::Clear(int i, int j) 00591 { 00592 data_(i)(j).Clear(); 00593 } 00594 00595 00597 00600 template <class T, class Allocator0, class Allocator1, class Allocator2> 00601 void Vector3<T, Allocator0, Allocator1, Allocator2>::Fill(const T& x) 00602 { 00603 for (int i = 0; i < data_.GetSize(); i++) 00604 for (int j = 0; j < data_(i).GetSize(); j++) 00605 data_(i)(j).Fill(x); 00606 } 00607 00608 00610 00613 template <class T, class Allocator0, class Allocator1, class Allocator2> 00614 Vector<Vector<Vector<T, Vect_Full, Allocator0>, Vect_Full, Allocator1>, 00615 Vect_Full, Allocator2>& 00616 Vector3<T, Allocator0, Allocator1, Allocator2>::GetVector() 00617 { 00618 return data_; 00619 } 00620 00621 00623 00626 template <class T, class Allocator0, class Allocator1, class Allocator2> 00627 const Vector<Vector<Vector<T, Vect_Full, Allocator0>, 00628 Vect_Full, Allocator1>, Vect_Full, Allocator2>& 00629 Vector3<T, Allocator0, Allocator1, Allocator2>::GetVector() const 00630 { 00631 return data_; 00632 } 00633 00634 00636 00640 template <class T, class Allocator0, class Allocator1, class Allocator2> 00641 Vector<Vector<T, Vect_Full, Allocator0>, VectFull, Allocator1>& 00642 Vector3<T, Allocator0, Allocator1, Allocator2>::GetVector(int i) 00643 { 00644 return data_(i); 00645 } 00646 00647 00649 00653 template <class T, class Allocator0, class Allocator1, class Allocator2> 00654 const Vector<Vector<T, Vect_Full, Allocator0>, VectFull, Allocator1>& 00655 Vector3<T, Allocator0, Allocator1, Allocator2>::GetVector(int i) const 00656 { 00657 return data_(i); 00658 } 00659 00660 00662 00667 template <class T, class Allocator0, class Allocator1, class Allocator2> 00668 Vector<T, Vect_Full, Allocator0>& 00669 Vector3<T, Allocator0, Allocator1, Allocator2>::GetVector(int i, int j) 00670 { 00671 return data_(i)(j); 00672 } 00673 00674 00676 00681 template <class T, class Allocator0, class Allocator1, class Allocator2> 00682 const Vector<T, Vect_Full, Allocator0>& 00683 Vector3<T, Allocator0, Allocator1, Allocator2>::GetVector(int i, int j) 00684 const 00685 { 00686 return data_(i)(j); 00687 } 00688 00689 00690 /********************************* 00691 * ELEMENT ACCESS AND ASSIGNMENT * 00692 *********************************/ 00693 00694 00696 00700 template <class T, class Allocator0, class Allocator1, class Allocator2> 00701 const Vector<Vector<T, Vect_Full, Allocator0>, VectFull, Allocator1>& 00702 Vector3<T, Allocator0, 00703 Allocator1, Allocator2>::operator() (int i) const 00704 { 00705 return data_(i); 00706 } 00707 00708 00710 00714 template <class T, class Allocator0, class Allocator1, class Allocator2> 00715 Vector<Vector<T, Vect_Full, Allocator0>, VectFull, Allocator1>& 00716 Vector3<T, Allocator0, Allocator1, Allocator2>::operator() (int i) 00717 { 00718 return data_(i); 00719 } 00720 00721 00723 00728 template <class T, class Allocator0, class Allocator1, class Allocator2> 00729 const Vector<T, Vect_Full, Allocator0>& 00730 Vector3<T, Allocator0, 00731 Allocator1, Allocator2>::operator() (int i, int j) const 00732 { 00733 return data_(i)(j); 00734 } 00735 00736 00738 00743 template <class T, class Allocator0, class Allocator1, class Allocator2> 00744 Vector<T, Vect_Full, Allocator0>& 00745 Vector3<T, Allocator0, Allocator1, Allocator2>::operator() (int i, int j) 00746 { 00747 return data_(i)(j); 00748 } 00749 00750 00752 00758 template <class T, class Allocator0, class Allocator1, class Allocator2> 00759 typename Vector3<T, Allocator0, Allocator1, Allocator2>::const_reference 00760 Vector3<T, Allocator0, 00761 Allocator1, Allocator2>::operator() (int i, int j, int k) const 00762 { 00763 return data_(i)(j)(k); 00764 } 00765 00766 00768 00774 template <class T, class Allocator0, class Allocator1, class Allocator2> 00775 typename Vector3<T, Allocator0, Allocator1, Allocator2>::reference 00776 Vector3<T, Allocator0, Allocator1, Allocator2>::operator() 00777 (int i, int j, int k) 00778 { 00779 return data_(i)(j)(k); 00780 } 00781 00782 00783 /********************** 00784 * CONVENIENT METHODS * 00785 *********************/ 00786 00787 00789 template <class T, class Allocator0, class Allocator1, class Allocator2> 00790 void Vector3<T, Allocator0, Allocator1, Allocator2>::Print() const 00791 { 00792 for (int i = 0; i < data_.GetSize(); i++) 00793 for(int j = 0; j < data_(i).GetSize(); j++) 00794 { 00795 cout << "Vector " << i << ", " << j << ": "; 00796 data_(i)(j).Print(); 00797 } 00798 } 00799 00800 00801 /************************** 00802 * INPUT/OUTPUT FUNCTIONS * 00803 **************************/ 00804 00805 00807 00812 template <class T, class Allocator0, class Allocator1, class Allocator2> 00813 void Vector3<T, Allocator0, Allocator1, Allocator2> 00814 ::Write(string file_name, bool with_size) const 00815 { 00816 ofstream file_stream; 00817 file_stream.open(file_name.c_str()); 00818 00819 #ifdef SELDON_CHECK_IO 00820 // Checks if the file was opened. 00821 if (!file_stream.is_open()) 00822 throw IOError("Vector3::Write(string file_name, bool with_size)", 00823 string("Unable to open file \"") + file_name + "\"."); 00824 #endif 00825 00826 this->Write(file_stream, with_size); 00827 00828 file_stream.close(); 00829 } 00830 00831 00833 00838 template <class T, class Allocator0, class Allocator1, class Allocator2> 00839 void Vector3<T, Allocator0, Allocator1, Allocator2> 00840 ::Write(ostream& stream, bool with_size) const 00841 { 00842 00843 #ifdef SELDON_CHECK_IO 00844 // Checks if the stream is ready. 00845 if (!stream.good()) 00846 throw IOError("Vector3::Write(ostream& stream, bool with_size)", 00847 "The stream is not ready."); 00848 #endif 00849 00850 if (with_size) 00851 { 00852 int m = GetLength(); 00853 stream.write(reinterpret_cast<char*>(const_cast<int*>(&m)), 00854 sizeof(int)); 00855 } 00856 00857 for (int i = 0; i < GetLength(); i++) 00858 { 00859 if (with_size) 00860 { 00861 int m = GetLength(i); 00862 stream.write(reinterpret_cast<char*>(const_cast<int*>(&m)), 00863 sizeof(int)); 00864 } 00865 for (int j = 0; j < GetLength(i); j++) 00866 data_(i)(j).Write(stream, with_size); 00867 } 00868 00869 #ifdef SELDON_CHECK_IO 00870 // Checks if data was written. 00871 if (!stream.good()) 00872 throw IOError("Vector3::Write(ostream& stream, bool with_size)", 00873 "Output operation failed."); 00874 #endif 00875 00876 } 00877 00878 00880 00887 template <class T, class Allocator0, class Allocator1, class Allocator2> 00888 void Vector3<T, Allocator0, Allocator1, Allocator2> 00889 ::Read(string file_name, bool with_size) 00890 { 00891 ifstream file_stream; 00892 file_stream.open(file_name.c_str()); 00893 00894 #ifdef SELDON_CHECK_IO 00895 // Checks if the file was opened. 00896 if (!file_stream.is_open()) 00897 throw IOError("Vector3::Read(string file_name, bool with_size)", 00898 string("Unable to open file \"") + file_name + "\"."); 00899 #endif 00900 00901 this->Read(file_stream, with_size); 00902 00903 file_stream.close(); 00904 } 00905 00906 00908 00915 template <class T, class Allocator0, class Allocator1, class Allocator2> 00916 void Vector3<T, Allocator0, Allocator1, Allocator2> 00917 ::Read(istream& stream, bool with_size) 00918 { 00919 00920 #ifdef SELDON_CHECK_IO 00921 // Checks if the stream is ready. 00922 if (!stream.good()) 00923 throw IOError("Vector3::Read(istream& stream, bool with_size)", 00924 "The stream is not ready."); 00925 #endif 00926 00927 if (with_size) 00928 { 00929 int new_size; 00930 stream.read(reinterpret_cast<char*>(&new_size), sizeof(int)); 00931 this->Reallocate(new_size); 00932 } 00933 00934 for (int i = 0; i < GetLength(); i++) 00935 { 00936 if (with_size) 00937 { 00938 int new_size; 00939 stream.read(reinterpret_cast<char*>(&new_size), sizeof(int)); 00940 this->Reallocate(i, new_size); 00941 } 00942 for (int j = 0; j < GetLength(i); j++) 00943 data_(i)(j).Read(stream, with_size); 00944 } 00945 00946 #ifdef SELDON_CHECK_IO 00947 // Checks if data was read. 00948 if (!stream.good()) 00949 throw IOError("Vector3::Read(istream& stream, bool with_size)", 00950 "Output operation failed."); 00951 #endif 00952 00953 } 00954 00955 00956 } // namespace Seldon. 00957 00958 00959 #define SELDON_FILE_VECTOR_VECTOR_3_CXX 00960 #endif