Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

more/num/matrixio.h

Go to the documentation of this file.
00001 //  Copyright (C) 1998--2002  Petter Urkedal
00002 //
00003 //  This file is free software; you can redistribute it and/or modify
00004 //  it under the terms of the GNU General Public License as published by
00005 //  the Free Software Foundation; either version 2 of the License, or
00006 //  (at your option) any later version.
00007 //
00008 //  This file is distributed in the hope that it will be useful,
00009 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011 //  GNU General Public License for more details.
00012 //
00013 //  You should have received a copy of the GNU General Public License
00014 //  along with this program; if not, write to the Free Software
00015 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00016 //
00017 //  As a special exception, you may use this file as part of a free
00018 //  software library without restriction.  Specifically, if other files
00019 //  instantiate templates or use macros or inline functions from this
00020 //  file, or you compile this file and link it with other files to
00021 //  produce an executable, this file does not by itself cause the
00022 //  resulting executable to be covered by the GNU General Public
00023 //  License.  This exception does not however invalidate any other
00024 //  reasons why the executable file might be covered by the GNU General
00025 //  Public License.
00026 
00027 //  $Id: matrixio.h,v 1.2 2002/09/01 12:02:10 petter_urkedal Exp $
00028 
00029 
00030 #ifndef MORE_NUM_MATRIXIO_H
00031 #define MORE_NUM_MATRIXIO_H
00032 
00033 ///\if unmaintained
00034 #include <more/num/matrix.h>
00035 #include <iostream>
00036 #include <iomanip>
00037 
00038 namespace more {
00039 namespace num {
00040 
00041   template <class T, class Sg>
00042     std::ostream& operator<<(std::ostream& out, const matrix<T, Sg>& x) {
00043         std::ostream::fmtflags flags = out.flags();
00044         std::streamsize prec = out.precision();
00045         std::streamsize width = out.width();
00046         out.width(0);
00047         out << x.size(0) << ' ' << x.size(1) << '\n';
00048         for(int i = 0; i < x.size(0); i++) {
00049             for(int j = 0; j < x.size(1); j++) {
00050                 out.flags(flags);
00051                 out.precision(prec);
00052                 out.width(width);
00053                 out << x(i, j) << ' ';
00054                 if(out.fail()) return out;
00055             }
00056             out << '\n';
00057         }
00058         return out;
00059     }
00060 
00061   template <class T, class Sg>
00062     std::istream& operator>>(std::istream& in, matrix<T, Sg> x) {
00063         int n, m;
00064         in >> n >> m;
00065         matrix<T, Sg> y(n, m);
00066         for(int i = 0; i < x.size(0); i++)
00067             for(int j = 0; j < x.size(1); j++) {
00068                 in >> x(i, j);
00069                 if(in.fail()) return in;
00070             }
00071         x = y;
00072         return in;
00073     }
00074 
00075 }}
00076 ///\endif
00077 
00078 #endif

Generated on Sat Sep 7 19:11:19 2002 for more with Doxygen 1.2.13.1. Doxygen 1.2.13.1 is written and copyright 1997-2002 by Dimitri van Heesch.