ADMB Documentation  11.1.1927
 All Classes Files Functions Variables Typedefs Friends Defines
lvect_io.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id: lvect_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: dvect_io.cpp
00012 #include "fvar.hpp"
00013 
00014 // i/o ooperations for class lvector
00015 
00016 #ifdef __TURBOC__
00017   #pragma hdrstop
00018   #include <iostream.h>
00019   #include <iomanip.h>
00020   #include <fstream.h>
00021   #define __USE_IOSTREAM__
00022 #endif
00023 
00024 #ifdef __ZTC__
00025   #include <iostream.hpp>
00026   #include <iomanip.hpp>
00027   #include <fstream.hpp>
00028   #define __USE_IOSTREAM__
00029 #endif
00030 
00031 #include <string.h>
00032 
00037 ostream& operator<<(const ostream& _ostr, const lvector& z)
00038 {
00039   ostream & ostr = (ostream&) _ostr;
00040   z.write_on(ostr);
00041   return ostr;
00042 }
00043 
00048 void lvector::write_on(const ostream& _s) const
00049 {
00050   ostream & s = (ostream&) _s;
00051 #ifdef __USE_IOSTREAM__
00052   int new_w = s.width();
00053   int 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 
00060   char new_fill = s.fill();
00061 #endif
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      /*
00073      if (!s.good())
00074      {
00075        cerr << " Error in lvector write\n";
00076        ad_exit(1);
00077      }
00078      */
00079   #else
00080      s << " " << (*this)[i];
00081      /*
00082      if (!s.good())
00083      {
00084        cerr << " Error in lvector write\n";
00085        ad_exit(1);
00086      }
00087      */
00088   #endif
00089   }
00090 }
00091 
00096 istream& operator>>(const istream& _istr, const lvector& _z)
00097 {
00098   ADUNCONST(lvector,z)
00099   istream & istr = (istream&) _istr;
00100   z.read_from(istr);
00101 
00102   return istr;
00103 }
00104 
00109 void lvector::read_from(const istream& _s)
00110 {
00111   istream& s=(istream&) _s;
00112   int n = indexmax() - indexmin() + 1;
00113   AD_LONG_INT * p = v + indexmin();
00114 
00115   for (int i=1; i <= n; i++)
00116   {
00117      s >> *(p++);
00118   }
00119 }
00120