ADMB Documentation  11.5.3197
 All Classes Files Functions Variables Typedefs Friends Defines
ivect_io.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id$
00003  *
00004  * Author: David Fournier
00005  * Copyright (c) 2008-2012 Regents of the University of California
00006  */
00007 
00013 #include <string.h>
00014 #include "fvar.hpp"
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 
00034 ostream& operator<<(const ostream& ostr, const ivector& z)
00035 {
00036   z.write_on(ostr);
00037   return (ostream&) ostr;
00038 }
00042 void ivector::write_on(const ostream& _s) const
00043 {
00044   ostream& s = (ostream&)_s;
00045 #ifdef __USE_IOSTREAM__
00046   std::streamsize new_w = s.width();
00047   std::streamsize new_p = s.precision();
00048 #if !defined(__cplusplus)
00049   long new_form = s.flags();
00050 #else
00051   ios::fmtflags new_form = s.flags();
00052 #endif
00053   char new_fill = s.fill();
00054 #endif
00055   for (int i=indexmin(); i <= indexmax(); i++)
00056   {
00057 #ifdef __USE_IOSTREAM__
00058     s.width(0);
00059     s << " ";
00060     s.width(new_w);
00061     s.precision(new_p);
00062     s.flags(new_form);
00063     s.fill(new_fill);
00064     s << (*this)[i];
00065     s.width(new_w);
00066     s.precision(new_p);
00067     s.flags(new_form);
00068     s.fill(new_fill);
00069     /*
00070     if (!s.good())
00071     {
00072       cerr << " Error in ivector write\n";
00073       ad_exit(1);
00074     }
00075     */
00076 #else
00077     s << " " << (*this)[i];
00078 #endif
00079   }
00080 }
00084 istream& operator>>(const istream& istr, const ivector& _z)
00085 {
00086   ADUNCONST(ivector,z)
00087   z.read_from(istr);
00088   return (istream&)istr;
00089 }
00093 void ivector::read_from(const istream& _s)
00094 {
00095   istream& s=(istream&)_s;
00096   int mmin=indexmin();
00097   int mmax=indexmax();
00098   for (int i=mmin; i <= mmax; i++)
00099   {
00100     s >> (*this)[i];
00101   }
00102 }