DATRW++ library: seismic data I/O with multiple formats
writeany.h
Go to the documentation of this file.
1 /*! \file writeany.h
2  * \brief common interface for all data types (prototypes)
3  *
4  * ----------------------------------------------------------------------------
5  *
6  * \author Thomas Forbriger
7  * \date 17/02/2010
8  *
9  * common interface for all data types (prototypes)
10  *
11  * Copyright (c) 2010 by Thomas Forbriger (BFO Schiltach)
12  *
13  * ----
14  * This program is free software; you can redistribute it and/or modify
15  * it under the terms of the GNU General Public License as published by
16  * the Free Software Foundation; either version 2 of the License, or
17  * (at your option) any later version.
18  *
19  * This program is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22  * GNU General Public License for more details.
23  *
24  * You should have received a copy of the GNU General Public License
25  * along with this program; if not, write to the Free Software
26  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27  * ----
28  *
29  * REVISIONS and CHANGES
30  * - 17/02/2010 V1.0 Thomas Forbriger
31  * - 26/11/2010 V1.1 moved not input specifc part to formats.h
32  * - 07/06/2011 V1.2 promise constness of series samples
33  * - 29/07/2011 V1.3 added constructor which accepts format modifiers
34  * support property query
35  * - 07/09/2011 V1.4 more string type format ID support: openmode
36  * - 13/04/2018 V1.5 provide access to debug flag if output stream
37  *
38  * ============================================================================
39  */
40 
41 // include guard
42 #ifndef DATRW_WRITEANY_H_VERSION
43 
44 #define DATRW_WRITEANY_H_VERSION \
45  "DATRW_WRITEANY_H V1.5"
46 
47 #include<string>
48 #include<datrwxx/datwrite.h>
49 #include<datrwxx/properties.h>
50 
51 namespace datrw {
52 
53  /*! \brief General module to access all output stream types
54  *
55  * \defgroup group_writeany API: Write any format
56  */
57 
58  /*! \brief Delegate member function to underlying output stream
59  *
60  * \ingroup group_writeany
61  */
62 #define ANYDELEGATE( function ) function() const { return(Mos->function()); }
63 
64  /*! \brief Class to write any type of data file
65  *
66  * \ingroup group_writeany
67  *
68  * Notice: This does not work by inheritance. To select a specific
69  * type of output stream, we have to keep a reference and to delegate
70  * any function calls. But this is only necessary for functions that have to
71  * be called as a member function directly. Functions for which an output
72  * operator is defined, can by called by the stream output syntax.
73  * A delegating output operator will be defined below.
74  */
75  class oanystream {
76  public:
77  /*! \brief deprecated constructor, not taking format modifier
78  * \deprecated
79  * The use of this constructor is deprecated, because it does not allow
80  * format modifiers to be passed by the user.
81  */
82  oanystream(std::ostream&, const Eformat& format,
83  const bool& debug=false);
84  //! \brief This constructor accepts format modifiers
85  oanystream(std::ostream&, const std::string& format,
86  const bool& debug=false);
87  ~oanystream();
88  datrw::odatstream& odatstream() { return(*Mos); }
89  void ANYDELEGATE( flushfileheader )
90  bool ANYDELEGATE( handlesfilefree )
91  bool ANYDELEGATE( handlestracefree )
92  bool ANYDELEGATE( handlessrce )
93  bool ANYDELEGATE( handlesinfo )
94  Properties ANYDELEGATE( properties )
95  Edatatype ANYDELEGATE( seriestype )
96  static std::ios_base::openmode openmode(const Eformat& format);
97  static std::ios_base::openmode openmode(const std::string& format);
98  //! indicate debug mode
99  bool debug() { return this->odatstream().debug(); }
100  //! set debug mode
101  void debug(const bool& debug) { this->odatstream().debug(debug); }
102  private:
103  //! \brief actually open stream (to be called by constructor)
104  void open(std::ostream& os, std::string format,
105  const bool& debug=false);
106  //! \brief no copy
107  oanystream(const oanystream&);
108  //! \brief no copy
112  }; // class ianystream
113 
114 #undef ANYDELEGATE
115 
116  /*! \brief general output operator
117  *
118  * \ingroup group_writeany
119  *
120  * This function template delegates the actual output to the
121  * output operators for datrw::odatstream by accessing the underlying
122  * datrw::odatstream through the type conversion operator
123  * datrw::oanystream::odatstream()
124  */
125  template<class C>
126  oanystream& operator<<(oanystream& os, const C& c)
127  { os.odatstream() << c; return(os); }
128 
129 } // namespace datrw
130 
131 #endif // DATRW_WRITEANY_H_VERSION (includeguard)
132 
133 /* ----- END OF writeany.h ----- */
datrw::Eformat Mformat
Definition: writeany.h:111
properties base class.
Definition: properties.h:58
oanystream & operator=(const oanystream &)
no copy
Edatatype
Definition: formats.h:84
datrw::odatstream & odatstream()
Definition: writeany.h:88
datrw::odatstream * Mos
Definition: writeany.h:110
oanystream(std::ostream &, const Eformat &format, const bool &debug=false)
deprecated constructor, not taking format modifier
Definition: writeany.cc:61
bool debug()
indicate debug mode
Definition: datwrite.h:145
Root namespace of library.
Definition: aalibdatrwxx.cc:16
bool debug()
indicate debug mode
Definition: writeany.h:99
odatstream & operator<<(odatstream &os, const sff::WID2 &wid2)
Definition: datwrite.h:217
describe data properties (prototypes)
void open(std::ostream &os, std::string format, const bool &debug=false)
actually open stream (to be called by constructor)
Definition: writeany.cc:81
Class to write any type of data file.
Definition: writeany.h:75
#define ANYDELEGATE(function)
Delegate member function to underlying output stream.
Definition: writeany.h:62
Eformat
Definition: formats.h:54
generic interface definition (prototypes)
void debug(const bool &debug)
set debug mode
Definition: writeany.h:101