ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
fvara_io.cpp
Go to the documentation of this file.
1 /*
2  * $Id$
3  *
4  * Author: David Fournier
5  * Copyright (c) 2008-2012 Regents of the University of California
6  */
11 // file: fvara_io.cpp
12 // i/o operations for class fvar_arry
13 
14 #include "fvar.hpp"
15 
16 
17 #ifdef __TURBOC__
18  #pragma hdrstop
19  #include <iostream.h>
20  #include <iomanip.h>
21  #include <fstream.h>
22  #define __USE_IOSTREAM__
23 #endif
24 
25 #ifdef __ZTC__
26  #include <iostream.hpp>
27  #include <iomanip.hpp>
28  #include <fstream.hpp>
29  #define __USE_IOSTREAM__
30 #endif
31 
36 ostream& operator<<(const ostream& ostr, const dvar_vector& z)
37 {
38  if (allocated(z))
39  z.write_on(ostr);
40 
41  return (ostream&) ostr;
42 }
43 
48 void dvar_vector::write_on(const ostream& _s) const
49 {
50  ostream& s =(ostream&) _s;
51 #ifdef __USE_IOSTREAM__
52  std::streamsize new_w = s.width();
53  std::streamsize new_p = s.precision();
54 #if !defined(__cplusplus)
55  long new_form = s.flags();
56 #else
57  ios::fmtflags new_form = s.flags();
58 #endif
59  char new_fill = s.fill();
60 #endif
61 
62  for (int i=indexmin(); i <= indexmax(); i++)
63  {
64  #ifdef __USE_IOSTREAM__
65  s.width(0);
66  s << " ";
67  s.width(new_w);
68  s.precision(new_p);
69  s.flags(new_form);
70  s.fill(new_fill);
71  s << (*this)[i];
72  #else
73  s << " " << (*this)[i];
74  #endif
75  }
76 }
77 
82 istream& operator>>(const istream& istr, const dvar_vector& _z)
83 {
85  if (allocated(z))
86  z.read_from(istr);
87  return (istream&)istr;
88 }
89 
94 void dvar_vector::read_from(const istream& s)
95 {
96  if (allocated(*this))
97  for (int i=indexmin(); i <= indexmax(); i++)
98  {
99  s >> elem(i);
100  }
101 }
int allocated(const ivector &v)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
Definition: fvar_a59.cpp:13
#define ADUNCONST(type, obj)
Creates a shallow copy of obj that is not CONST.
Definition: fvar.hpp:140
prevariable elem(int i)
Definition: fvar.hpp:2221
ADMB variable vector.
Definition: fvar.hpp:2172
void write_on(const ostream &) const
Description not yet available.
Definition: fvara_io.cpp:48
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
int indexmin() const
Definition: fvar.hpp:2287
istream & operator>>(const istream &input, const d3_array &arr3)
Read values from input stream into arr3.
Definition: d3_io.cpp:60
ostream & operator<<(const ostream &_s, preshowpoint p)
Description not yet available.
Definition: admanip.cpp:48
void read_from(const istream &)
Description not yet available.
Definition: fvara_io.cpp:94
int indexmax() const
Definition: fvar.hpp:2292