ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
lvect_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: dvect_io.cpp
12 #include "fvar.hpp"
13 
14 // i/o ooperations for class lvector
15 
16 #ifdef __TURBOC__
17  #pragma hdrstop
18  #include <iostream.h>
19  #include <iomanip.h>
20  #include <fstream.h>
21  #define __USE_IOSTREAM__
22 #endif
23 
24 #ifdef __ZTC__
25  #include <iostream.hpp>
26  #include <iomanip.hpp>
27  #include <fstream.hpp>
28  #define __USE_IOSTREAM__
29 #endif
30 
31 #include <string.h>
32 
37 ostream& operator<<(const ostream& _ostr, const lvector& z)
38 {
39  ostream & ostr = (ostream&) _ostr;
40  z.write_on(ostr);
41  return ostr;
42 }
43 
48 void lvector::write_on(const ostream& _s) const
49 {
50  ostream& s = (ostream&)_s;
51 #ifdef __USE_IOSTREAM__
52  using std::streamsize;
53  streamsize new_w = s.width();
54  streamsize new_p = s.precision();
55 #if !defined(__cplusplus)
56  long new_form = s.flags();
57 #else
58  ios::fmtflags new_form = s.flags();
59 #endif
60  char new_fill = s.fill();
61 #endif
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  /*
73  if (!s.good())
74  {
75  cerr << " Error in lvector write\n";
76  ad_exit(1);
77  }
78  */
79  #else
80  s << " " << (*this)[i];
81  /*
82  if (!s.good())
83  {
84  cerr << " Error in lvector write\n";
85  ad_exit(1);
86  }
87  */
88  #endif
89  }
90 }
91 
96 istream& operator>>(const istream& _istr, const lvector& _z)
97 {
99  istream & istr = (istream&) _istr;
100  z.read_from(istr);
101 
102  return istr;
103 }
104 
109 void lvector::read_from(const istream& _s)
110 {
111  istream& s=(istream&) _s;
112  int n = indexmax() - indexmin() + 1;
113  AD_LONG_INT * p = v + indexmin();
114 
115  for (int i=1; i <= n; i++)
116  {
117  s >> *(p++);
118  }
119 }
120 
void write_on(const ostream &s) const
Description not yet available.
Definition: lvect_io.cpp:48
AD_LONG_INT * v
Definition: fvar.hpp:658
#define ADUNCONST(type, obj)
Creates a shallow copy of obj that is not CONST.
Definition: fvar.hpp:140
int indexmin() const
Definition: fvar.hpp:676
Description not yet available.
Definition: fvar.hpp:656
int indexmax() const
Definition: fvar.hpp:681
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
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
#define AD_LONG_INT
Definition: fvar.hpp:81
void read_from(const istream &s)
Description not yet available.
Definition: lvect_io.cpp:109