ADMB Documentation  11.1.2274
 All Classes Files Functions Variables Typedefs Friends Defines
fvarb_io.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id: fvarb_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 
00013 // i/o operations for class fvar_arry
00014 
00015 #include "fvar.hpp"
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 
00032 
00033 #ifdef __USE_IOSTREAM__
00034 
00039 uistream& operator>>(const uistream& istr, const dvar_vector& _z)
00040 {
00041   ADUNCONST(dvar_vector,z)
00042   if (allocated(z))
00043     z.read_from(istr);
00044   return (uistream&) istr;
00045 }
00046 
00051 void dvar_vector::read_from(const uistream& _s)
00052 {
00053   if (allocated(*this))
00054   {
00055     uistream& s = (uistream&) _s;
00056     int n = indexmax() - indexmin() + 1;
00057     double_and_int * p = va + indexmin();
00058 
00059     for (int i=1; i <= n; i++)
00060     {
00061        s >> (p++)->x;
00062     }
00063   }
00064 }
00065 
00070 uostream& operator<<(const uostream& ostr, const dvar_vector& z)
00071 {
00072   if (allocated(z))
00073     z.write_on(ostr);
00074   return (uostream&) ostr;
00075 }
00076 
00081 void dvar_vector::write_on(const uostream& _s) const
00082 {
00083   if (allocated(*this))
00084   {
00085     uostream& s = (uostream&) _s;
00086     int n = indexmax() - indexmin() + 1;
00087     double_and_int * p = va + indexmin();
00088 
00089     for (int i=1; i <= n; i++)
00090     {
00091        s << (p++)->x;
00092     }
00093   }
00094 }
00095 #endif