ADMB Documentation  11.1x.2711
 All Classes Files Functions Variables Typedefs Friends Defines
fvara_io.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id: fvara_io.cpp 1919 2014-04-22 22:02:01Z johnoel $
00003  *
00004  * Author: David Fournier
00005  * Copyright (c) 2008-2012 Regents of the University of California
00006  */
00011 // file: fvara_io.cpp
00012 // i/o operations for class fvar_arry
00013 
00014 #include "fvar.hpp"
00015 
00016 
00017 #ifdef __TURBOC__
00018   #pragma hdrstop
00019   #include <iostream.h>
00020   #include <iomanip.h>
00021   #include <fstream.h>
00022   #define __USE_IOSTREAM__
00023 #endif
00024 
00025 #ifdef __ZTC__
00026   #include <iostream.hpp>
00027   #include <iomanip.hpp>
00028   #include <fstream.hpp>
00029   #define __USE_IOSTREAM__
00030 #endif
00031 
00036 ostream& operator<<(const ostream& ostr, const dvar_vector& z)
00037 {
00038   if (allocated(z))
00039     z.write_on(ostr);
00040 
00041   return (ostream&) ostr;
00042 }
00043 
00048 void dvar_vector::write_on(const ostream& _s) const
00049 {
00050   ostream& s =(ostream&) _s;
00051 #ifdef __USE_IOSTREAM__
00052   std::streamsize new_w = s.width();
00053   std::streamsize new_p = s.precision();
00054 #if !defined(__cplusplus)
00055   long new_form = s.flags();
00056 #else
00057   ios::fmtflags new_form = s.flags();
00058 #endif
00059   char new_fill = s.fill();
00060 #endif
00061 
00062   for (int i=indexmin(); i <= indexmax(); i++)
00063   {
00064   #ifdef __USE_IOSTREAM__
00065      s.width(0);
00066      s << " ";
00067      s.width(new_w);
00068      s.precision(new_p);
00069      s.flags(new_form);
00070      s.fill(new_fill);
00071      s << (*this)[i];
00072   #else
00073      s << " " << (*this)[i];
00074   #endif
00075   }
00076 }
00077 
00082 istream& operator>>(const istream& istr, const dvar_vector& _z)
00083 {
00084   ADUNCONST(dvar_vector,z)
00085   if (allocated(z))
00086     z.read_from(istr);
00087   return (istream&)istr;
00088 }
00089 
00094 void dvar_vector::read_from(const istream& s)
00095 {
00096   if (allocated(*this))
00097     for (int i=indexmin(); i <= indexmax(); i++)
00098     {
00099        s >> elem(i);
00100     }
00101 }