SFF++ library: reading and writing SFF from C++
sffostream.h
Go to the documentation of this file.
1 
44 // include guard
45 #ifndef TF_SFFOSTREAM_H_VERSION
46 
47 #define TF_SFFOSTREAM_H_VERSION \
48  "TF_SFFOSTREAM_H V1.4"
49 
50 #include<sffxx.h>
51 #include<iostream>
52 #include<new>
53 
54 namespace sff {
55 
56 namespace helper {
57 
59  public:
60  ostream_manager(std::ostream& os, const bool& debug=false);
61  void setfileheader(const FileHeader&);
62  void settraceheader(const TraceHeader&);
63  void setinfo(const INFO&);
64  void setwid2(const WID2&);
65  void setsrce(const SRCE&);
66  void setfree(const FREE&);
67  void setnormmode(const Enormmode&);
68  void nextislast();
69  void clearlast();
70  TraceHeader traceheader() const;
71  const FileHeader& fileheader() const;
72  const Enormmode& normmode() const;
73  protected:
75  void flushheader();
76  std::ostream& Mos;
77  private:
80  bool Mlast;
85  protected:
86  bool Mdebug;
87  }; // class ostream_manager
88 
89 } // namespace helper
90 
110  template<class C>
112  public:
113  typedef C Tseries;
114  typedef typename C::Tcoc Tcseries;
116  SFFostream(std::ostream& os, const bool& debug=false):
117  Tbase(os, debug), Mhasseries(false) { }
119  {
120  if (!Mhasseries) throw
121  Terror("ERROR (~SFFostream): no waveform!");
122  this->nextislast();
123  write();
124  }
126  void setseries(const Tcseries& series);
127  private:
128  void write();
131  }; // class SFFostream
132 
133  /*----------------------------------------------------------------------*/
134 
135  template<class C>
136  inline
137  void
139  {
140  using std::cout;
141  using std::endl;
142  // flush file header (in case we have to write the first trace)
143  this->flushheader();
144  if (Mhasseries)
145  {
146  Mos << OutputWaveform<Tseries>(Mseries,
147  this->traceheader(),
148  this->normmode());
149  Mhasseries=false;
150  if (Mdebug)
151  {
152  cout << "DEBUG (SFFostream::write): trace written:" << endl;
153  cout << " " << this->traceheader().wid2().line().substr(0,70)
154  << endl;
155  cout << " index range: " << Mseries.f() << " - "
156  << Mseries.l() << "; ";
157  cout << "some values: " << Mseries(Mseries.f())
158  << ", " << Mseries(Mseries.f()+1)
159  << ", " << Mseries(Mseries.f()+2)
160  << ", " << Mseries(Mseries.f()+3)
161  << endl;
162  }
163  }
164  if (Mdebug) { cout << "DEBUG (SFFostream::write): finished" << endl; }
165  } // SFFostream<C>::write()
166 
167  /*----------------------------------------------------------------------*/
168 
169  template<class C>
170  inline
171  void
173  {
174  using std::cout;
175  using std::endl;
176  this->write();
177  // using a deep copy here is the save way!
178  Mseries=series.copyout();
179  Mhasseries=true;
180  if (Mdebug)
181  {
182  cout << "DEBUG (SFFostream::setseries) finished:" << endl;
183  cout << " index range: " << Mseries.f() << " - "
184  << Mseries.l() << endl;
185  cout << " some values: " << Mseries(Mseries.f())
186  << ", " << Mseries(Mseries.f()+1)
187  << ", " << Mseries(Mseries.f()+2)
188  << ", " << Mseries(Mseries.f()+3)
189  << endl;
190  }
191  } // SFFostream<C>::setseries(const Tcseries& series)
192 
193  /*----------------------------------------------------------------------*/
194 
196  template<class C>
197  SFFostream<C>& operator<<(SFFostream<C>& os, const typename C::Tcoc& c)
198  { os.setseries(c); return(os); }
199 
200  template<class C>
201  SFFostream<C>& operator<<(SFFostream<C>& os, const WID2& wid2)
202  { os.setwid2(wid2); return(os); }
203 
204  template<class C>
205  SFFostream<C>& operator<<(SFFostream<C>& os, const INFO& info)
206  { os.setinfo(info); return(os); }
207 
208  template<class C>
209  SFFostream<C>& operator<<(SFFostream<C>& os, const FREE& free)
210  { os.setfree(free); return(os); }
211 
212  template<class C>
213  SFFostream<C>& operator<<(SFFostream<C>& os, const SRCE& srce)
214  { os.setsrce(srce); return(os); }
215 
216  template<class C>
217  SFFostream<C>& operator<<(SFFostream<C>& os, const FileHeader& fh)
218  { os.setfileheader(fh); return(os); }
219 
220  template<class C>
221  SFFostream<C>& operator<<(SFFostream<C>& os, const TraceHeader& th)
222  { os.settraceheader(th); return(os); }
223 
224 } // namespace sff
225 
226 #endif // TF_SFFOSTREAM_H_VERSION (includeguard)
227 
228 /* ----- END OF sffostream.h ----- */
void setfileheader(const FileHeader &)
Definition: sffostream.cc:53
SFF trace header elements.
Definition: sffxx.h:282
all SFF modules
Definition: offset.cc:42
void setfree(const FREE &)
Definition: sffostream.cc:89
Tcseries Mseries
Definition: sffostream.h:129
void setwid2(const WID2 &)
Definition: sffostream.cc:76
void setnormmode(const Enormmode &)
Definition: sffostream.cc:106
void settraceheader(const TraceHeader &)
Definition: sffostream.cc:61
Enormmode
Definition: sffxx.h:114
void setseries(const Tcseries &series)
finish previous trace and start with a new one
Definition: sffostream.h:172
helper::ostream_manager Tbase
Definition: sffostream.h:115
C::Tcoc Tcseries
Definition: sffostream.h:114
void setinfo(const INFO &)
Definition: sffostream.cc:69
TraceHeader traceheader() const
Definition: sffostream.cc:127
Waveform Header.
Definition: sffxx.h:209
void flushheader()
flush file header to output (if not done yet)
Definition: sffostream.cc:146
const Enormmode & normmode() const
Definition: sffostream.cc:141
SFFostream(std::ostream &os, const bool &debug=false)
Definition: sffostream.h:116
void setsrce(const SRCE &)
Definition: sffostream.cc:83
const FileHeader & fileheader() const
Definition: sffostream.cc:136
ostream_manager(std::ostream &os, const bool &debug=false)
Definition: sffostream.cc:47
SFF library (prototypes)
SFF file header elements.
Definition: sffxx.h:232