DATRW++ library: seismic data I/O with multiple formats
readany.h
Go to the documentation of this file.
1 /*! \file readany.h
2  * \brief provides all specific data reading classes (prototypes)
3  *
4  * ----------------------------------------------------------------------------
5  *
6  * \author Thomas Forbriger
7  * \date 31/03/2004
8  *
9  * provides all specific data reading classes (prototypes)
10  *
11  * ----
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 2 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25  * ----
26  *
27  * Copyright (c) 2004 by Thomas Forbriger (BFO Schiltach)
28  *
29  * REVISIONS and CHANGES
30  * - 31/03/2004 V1.0 Thomas Forbriger
31  * - 29/06/2007 V1.1 added SAC binary format
32  * - 19/09/2007 V1.2 added raw GSE format
33  * - 12/11/2009 V1.3 added TSOFT data
34  * - 06/10/2010 V1.4 added ASCII format of T. Forbrigers any2ascii
35  * - 23/11/2010 V1.5 use static members
36  * - 25/11/2010 V1.6 added Seismic Unix format
37  * - 26/11/2010 V1.7 moved not input specifc part to formats.h
38  * - 29/07/2011 V1.8 added constructor accepting format modifiers
39  * support property query
40  * - 07/09/2011 V1.9 more string type format ID support: openmode
41  * - 29/11/2011 V1.10 present complete idatstream interface
42  * - 13/04/2018 V1.11 provide access to debug flag if output stream
43  *
44  * ============================================================================
45  */
46 
47 // include guard
48 #ifndef DATRW_READANY_H_VERSION
49 
50 #define DATRW_READANY_H_VERSION \
51  "DATRW_READANY_H V1.11"
52 
53 #include<string>
54 #include<datrwxx/datread.h>
55 #include<datrwxx/formats.h>
56 #include<datrwxx/properties.h>
57 
58 namespace datrw {
59 
60  /*! \brief General module to access all input stream types
61  *
62  * \defgroup group_readany API: Read any format
63  */
64 
65  /*! \brief Delegate member function to underlying input stream
66  *
67  * \ingroup group_readany
68  */
69 #define ANYDELEGATE( function ) function() const { return(Mis->function()); }
70 
71  /*! \brief Class to read any type of data file
72  *
73  * \ingroup group_readany
74  *
75  * Notice: This does not work by inheritance. To select a specific
76  * type of input stream, we have to keep a reference and to delegate
77  * any function calls. But this is only necessary for functions that have to
78  * be called as a member function directly. Functions for which an input
79  * operator is defined, can by called by the stream input syntax.
80  * A delegating input operator will be defined below.
81  */
82  class ianystream {
83  public:
84  /*! \brief deprecated constructor, not taking format modifier
85  * \deprecated
86  * The use of this constructor is deprecated, because it does not allow
87  * format modifiers to be passed by the user.
88  */
89  ianystream(std::istream&, const Eformat& format,
90  const bool& debug=false);
91  //! \brief This constructor accepts format modifiers
92  ianystream(std::istream&, const std::string& format,
93  const bool& debug=false);
94  ~ianystream();
95  datrw::idatstream& idatstream() { return(*Mis); }
96  bool ANYDELEGATE( last )
97  bool ANYDELEGATE( good )
98  bool ANYDELEGATE( hasfree )
99  bool ANYDELEGATE( hassrce )
100  bool ANYDELEGATE( hasinfo )
101  bool ANYDELEGATE( providesd )
102  bool ANYDELEGATE( providesf )
103  bool ANYDELEGATE( providesi )
104  void ANYDELEGATE( skipseries )
105  Tdseries ANYDELEGATE( dseries )
106  Tfseries ANYDELEGATE( fseries )
107  Tiseries ANYDELEGATE( iseries )
108  ::sff::INFO ANYDELEGATE( info )
109  ::sff::WID2 ANYDELEGATE( wid2 )
110  ::sff::FREE ANYDELEGATE( free )
111  ::sff::SRCE ANYDELEGATE( srce )
112  Properties ANYDELEGATE( properties )
113  static std::ios_base::openmode openmode(const Eformat& format);
114  static std::ios_base::openmode openmode(const std::string& format);
115  //! indicate debug mode
116  bool debug() { return this->idatstream().debug(); }
117  //! set debug mode
118  void debug(const bool& debug) { this->idatstream().debug(debug); }
119  private:
120  //! \brief actually open stream (to be called by constructor)
121  void open(std::istream& os, std::string format,
122  const bool& debug=false);
123  //! \brief no copy
124  ianystream(const ianystream&);
125  //! \brief no copy
129  }; // class ianystream
130 
131 #undef ANYDELEGATE
132 
133  /*! \brief general input operator
134  *
135  * \ingroup group_readany
136  *
137  * This function template delegates the actual output to the
138  * output operators for datrw::idatstream by accessing the underlying
139  * datrw::idatstream through the type conversion operator
140  * datrw::ianystream::idatstream()
141  */
142  template<class C>
144  { is.idatstream() >> c; return(is); }
145 
146 } // namespace datrw
147 
148 #endif // DATRW_READANY_H_VERSION (includeguard)
149 
150 /* ----- END OF readany.h ----- */
ianystream & operator=(const ianystream &)
no copy
properties base class.
Definition: properties.h:58
aff::Series< float > Tfseries
Definition: types.h:46
datrw::idatstream * Mis
Definition: readany.h:127
STL namespace.
aff::Series< double > Tdseries
Definition: types.h:45
ianystream(std::istream &, const Eformat &format, const bool &debug=false)
deprecated constructor, not taking format modifier
Definition: readany.cc:143
bool debug()
indicate debug mode
Definition: readany.h:116
Class to read any type of data file.
Definition: readany.h:82
bool debug()
indicate debug mode
Definition: datread.h:116
Root namespace of library.
Definition: aalibdatrwxx.cc:16
void debug(const bool &debug)
set debug mode
Definition: readany.h:118
datrw::idatstream & idatstream()
Definition: readany.h:95
describe data properties (prototypes)
aff::Series< int > Tiseries
Definition: types.h:47
datrw::Eformat Mformat
Definition: readany.h:128
common description of formats (prototypes)
Eformat
Definition: formats.h:54
#define ANYDELEGATE(function)
Delegate member function to underlying input stream.
Definition: readany.h:69
idatstream & operator>>(idatstream &is, sff::WID2 &wid2)
Definition: datread.cc:161
void open(std::istream &os, std::string format, const bool &debug=false)
actually open stream (to be called by constructor)
Definition: readany.cc:162