ADMB Documentation  11.1.2364
 All Classes Files Functions Variables Typedefs Friends Defines
dmat_io.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id: dmat_io.cpp 2272 2014-08-29 20:13:55Z johnoel $
00003  *
00004  * Author: David Fournier
00005  * Copyright (c) 2008-2012 Regents of the University of California
00006  */
00011 // file: dmat_io.cpp
00012 
00013 // i/o operations for class dmatrix
00014 #include "fvar.hpp"
00015 
00016 #ifdef __TURBOC__
00017   #pragma hdrstop
00018   #include <iostream.h>
00019   #include <iomanip.h>
00020   #include <fstream.h>
00021 #endif
00022 
00023 #ifdef __ZTC__
00024   #include <iostream.hpp>
00025   #include <iomanip.hpp>
00026   #include <fstream.hpp>
00027 #endif
00028 
00029 #include <string.h>
00030 
00035 ostream& operator<<(const ostream& _ostr, const dmatrix& z)
00036 {
00037   ostream& ostr = (ostream&) _ostr;
00038   z.write_on(ostr);
00039   return ostr;
00040 }
00041 
00046 void dmatrix::write_on(const ostream& _s) const
00047 {
00048   using std::streamsize;
00049 
00050   ostream& s=(ostream&) _s;
00051   streamsize new_w = s.width();
00052   streamsize new_p = s.precision();
00053 #if !defined(__cplusplus)
00054   long new_form = s.flags();
00055 #else
00056   ios::fmtflags new_form = s.flags();
00057 #endif
00058   char new_fill = s.fill();
00059 
00060   for (int i=rowmin(); i <= rowmax(); i++)
00061   {
00062      s.width(new_w);
00063      s.precision(new_p);
00064      s.flags(new_form);
00065      s.fill(new_fill);
00066      s << (*this)[i];
00067      if (i<rowmax())
00068      {
00069        s << endl;
00070      }
00071   }
00072 }
00073 
00078 istream& operator>>(const istream& _istr, const dmatrix& _z)
00079 {
00080   dmatrix& z= (dmatrix&) _z;
00081   istream& istr = (istream&) _istr;
00082   z.read_from(istr);
00083 
00084   return istr;
00085 }
00086 
00091 void dmatrix::read_from(const istream& s)
00092 {
00093   for (int i=rowmin();i <= rowmax();i++)
00094   {
00095      s >> (*this)[i];
00096   }
00097 }
00098