DATRW++ library: seismic data I/O with multiple formats
datatypes.h
Go to the documentation of this file.
1 /*! \file datatypes.h
2  * \brief handle data types and data type conversion (prototypes)
3  *
4  * ----------------------------------------------------------------------------
5  *
6  * \author Thomas Forbriger
7  * \date 17/12/2010
8  *
9  * handle data types and data type conversion (prototypes)
10  *
11  * Copyright (c) 2010 by Thomas Forbriger (BFO Schiltach)
12  *
13  * This pair of source files is intended to support any information about
14  * actual data types handled internally and in files. Are data stored and
15  * passed as int or double? Is data file format able to maintain double
16  * precision or integer accuracy?
17  *
18  * Part of this (Edatatype) still is located in formats.h and should be moved
19  * to this file in the future.
20  *
21  * ----
22  * This program is free software; you can redistribute it and/or modify
23  * it under the terms of the GNU General Public License as published by
24  * the Free Software Foundation; either version 2 of the License, or
25  * (at your option) any later version.
26  *
27  * This program is distributed in the hope that it will be useful,
28  * but WITHOUT ANY WARRANTY; without even the implied warranty of
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30  * GNU General Public License for more details.
31  *
32  * You should have received a copy of the GNU General Public License
33  * along with this program; if not, write to the Free Software
34  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
35  * ----
36  *
37  * REVISIONS and CHANGES
38  * - 17/12/2010 V1.0 Thomas Forbriger
39  *
40  * ============================================================================
41  */
42 
43 // include guard
44 #ifndef DATRW_DATATYPES_H_VERSION
45 
46 #define DATRW_DATATYPES_H_VERSION \
47  "DATRW_DATATYPES_H V1.0"
48 
49 #include<iostream>
50 
51 namespace datrw {
52 
53  namespace datatypes {
54 
55  /*! global flag, indicated whether type conversion should be reported.
56  */
57  extern bool verbose_type_conversion;
58 
59  //! indicate unkown type
60  extern const char* unknown_type_id;
61 
62  /*======================================================================*/
63 
64  //! actually print report
65  void print_conversion_report(std::ostream& os,
66  const std::string& from,
67  const std::string& to);
68 
69  template<typename C>
70  inline std::string type_id() { return(unknown_type_id); }
71 
72  template<> inline std::string type_id<float>() { return("float"); }
73  template<> inline std::string type_id<double>() { return("double"); }
74  template<> inline std::string type_id<int>() { return("int"); }
75 
76  } // namespace datatypes
77 
78  /*----------------------------------------------------------------------*/
79 
80  //! switch on type conversion verbosity
81  inline void report_type_conversion()
82  {
84  } // void report_type_conversion()
85 
86  /*----------------------------------------------------------------------*/
87 
88  //! switch off type conversion verbosity
90  {
92  } // void dont_report_type_conversion()
93 
94  /*----------------------------------------------------------------------*/
95 
96  /*! call this function template to report a type conversion
97  *
98  * \param from type of source
99  * \param to type of destination
100  * \param os C++ output stream to write to
101  */
102  template<typename from, typename to>
103  inline void report_conversion(std::ostream& os)
104  {
105  std::string typeid1=::datrw::datatypes::type_id<from>();
106  std::string typeid2=::datrw::datatypes::type_id<to>();
107  ::datrw::datatypes::print_conversion_report(os, typeid1, typeid2);
108  } // void report_conversion(std::ostream& os)
109 
110  /*----------------------------------------------------------------------*/
111 
112  /*! call this function to check whether two types equal
113  *
114  * \param t1 first type
115  * \param t2 second type
116  * \return true if t1 equals t2
117  */
118  template<typename t1, typename t2>
119  inline bool types_are_equal()
120  {
121  bool retval;
122  std::string typeid1=::datrw::datatypes::type_id<t1>();
123  std::string typeid2=::datrw::datatypes::type_id<t2>();
124  retval=(typeid1==typeid2);
125  return(retval);
126  } // bool types_are_equal()
127 
128  /*======================================================================*/
129 
130 } // namespace datrw
131 
132 #endif // DATRW_DATATYPES_H_VERSION (includeguard)
133 
134 /* ----- END OF datatypes.h ----- */
void dont_report_type_conversion()
switch off type conversion verbosity
Definition: datatypes.h:89
void report_conversion(std::ostream &os)
Definition: datatypes.h:103
void report_type_conversion()
switch on type conversion verbosity
Definition: datatypes.h:81
std::string type_id< double >()
Definition: datatypes.h:73
void print_conversion_report(std::ostream &os, const std::string &from, const std::string &to)
actually print report
Definition: datatypes.cc:47
bool types_are_equal()
Definition: datatypes.h:119
Root namespace of library.
Definition: aalibdatrwxx.cc:16
std::string type_id()
Definition: datatypes.h:70
std::string type_id< float >()
Definition: datatypes.h:72
const char * unknown_type_id
indicate unkown type
Definition: datatypes.cc:45
bool verbose_type_conversion
Definition: datatypes.cc:43
std::string type_id< int >()
Definition: datatypes.h:74