ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ivect_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  */
7 
13 #include <string.h>
14 #include "fvar.hpp"
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 
34 ostream& operator<<(const ostream& ostr, const ivector& z)
35 {
36  z.write_on(ostr);
37  return (ostream&) ostr;
38 }
42 void ivector::write_on(const ostream& _s) const
43 {
44  ostream& s = (ostream&)_s;
45 #ifdef __USE_IOSTREAM__
46  std::streamsize new_w = s.width();
47  std::streamsize new_p = s.precision();
48 #if !defined(__cplusplus)
49  long new_form = s.flags();
50 #else
51  ios::fmtflags new_form = s.flags();
52 #endif
53  char new_fill = s.fill();
54 #endif
55  for (int i=indexmin(); i <= indexmax(); i++)
56  {
57 #ifdef __USE_IOSTREAM__
58  s.width(0);
59  s << " ";
60  s.width(new_w);
61  s.precision(new_p);
62  s.flags(new_form);
63  s.fill(new_fill);
64  s << (*this)[i];
65  s.width(new_w);
66  s.precision(new_p);
67  s.flags(new_form);
68  s.fill(new_fill);
69  /*
70  if (!s.good())
71  {
72  cerr << " Error in ivector write\n";
73  ad_exit(1);
74  }
75  */
76 #else
77  s << " " << (*this)[i];
78 #endif
79  }
80 }
84 istream& operator>>(const istream& istr, const ivector& _z)
85 {
87  z.read_from(istr);
88  return (istream&)istr;
89 }
93 void ivector::read_from(const istream& _s)
94 {
95  istream& s=(istream&)_s;
96  int mmin=indexmin();
97  int mmax=indexmax();
98  for (int i=mmin; i <= mmax; i++)
99  {
100  s >> (*this)[i];
101  }
102 }
#define ADUNCONST(type, obj)
Creates a shallow copy of obj that is not CONST.
Definition: fvar.hpp:140
void read_from(const istream &s)
Reads all the elements from istream _s.
Definition: ivect_io.cpp:93
Array of integers(int) with indexes from index_min to indexmax.
Definition: ivector.h:50
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
int indexmin() const
Definition: ivector.h:99
int indexmax() const
Definition: ivector.h:104
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 write_on(const ostream &s) const
Writes all the elements to the ostream _s.
Definition: ivect_io.cpp:42