OpendTect-6_4  6.4
ascbinstream.h
Go to the documentation of this file.
1 #ifndef ascbinstream_h
2 #define ascbinstream_h
3 
4 /*+
5 ________________________________________________________________________
6 
7  (C) dGB Beheer B.V.; (LICENSE) http://opendtect.org/OpendTect_license.txt
8  Author: Bert
9  Date: Oct 2013
10  RCS: $Id$
11 ________________________________________________________________________
12 
13 -*/
14 
15 #include "basicmod.h"
16 #include "commondefs.h"
17 #include "plftypes.h"
18 #include "od_iosfwd.h"
19 
20 
31 {
32 public:
33 
34  ascbinostream(od_ostream&,bool binary);
35  ascbinostream(od_ostream*,bool binary);
36  virtual ~ascbinostream();
37  bool isOK() const;
38  bool isBad() const;
39 
40 # define mDeclascbinostreamAddFns(typ) \
41  ascbinostream& add(typ,char post=od_tab); \
42  ascbinostream& add(typ,const char* post)
43 
45  mDeclascbinostreamAddFns(unsigned char);
54 
55  template <class T>
56  ascbinostream& addEOL( T t ) { return add( t, od_newline ); }
57 
58  template <class T,class IT>
59  inline ascbinostream& addArr(const T*,IT sz,const char* between="\t",
60  const char* post="\n");
62 
63  ascbinostream& addBin(const void*,od_stream_Count nrbytes);
64  template <class T>
65  inline ascbinostream& addBin( const T& t )
66  { return addBin( &t, sizeof(T) ); }
67 
68  od_ostream& stream() { return strm_; }
69 
70 protected:
71 
73  const bool binary_;
74  const bool strmmine_;
75 
76 };
77 
78 
82 {
83 public:
84 
85  ascbinistream(od_istream&,bool binary);
86  ascbinistream(od_istream*,bool binary);
87  virtual ~ascbinistream();
88  bool isOK() const;
89  bool isBad() const;
90 
91  ascbinistream& get(char&);
92  ascbinistream& get(unsigned char&);
93  ascbinistream& get(od_int16&);
94  ascbinistream& get(od_uint16&);
95  ascbinistream& get(od_int32&);
96  ascbinistream& get(od_uint32&);
97  ascbinistream& get(od_int64&);
98  ascbinistream& get(od_uint64&);
99  ascbinistream& get(float&);
100  ascbinistream& get(double&);
101 
102  template <class T,class IT>
103  inline ascbinistream& getArr(T* arr,IT sz);
105 
106  ascbinistream& getBin(void*,od_stream_Count nrbytes);
107  template <class T>
108  inline ascbinistream& getBin( T& t )
109  { return getBin( &t, sizeof(T) ); }
110 
111  od_istream& stream() { return strm_; }
112 
113 protected:
114 
116  const bool binary_;
117  const bool strmmine_;
118 
119 };
120 
121 
122 template <class T,class IT>
123 inline ascbinostream& ascbinostream::addArr( const T* arr, IT sz,
124  const char* between,
125  const char* post )
126 {
127  if ( binary_ )
128  return addBin( &sz, sizeof(IT) ).addBin( arr, sz * sizeof(T) );
129 
130  strm_ << sz;
131  for ( int idx=0; idx<sz; idx++ )
132  strm_ << arr[idx] << (idx == sz-1 ? post : between);
133 
134  return *this;
135 }
136 
137 
138 template <class T,class IT>
139 inline ascbinistream& ascbinistream::getArr( T* arr, IT sz )
140 {
141  if ( binary_ )
142  return getBin( arr, sz*sizeof(T) );
143 
144  for ( int idx=0; idx<sz; idx++ )
145  strm_ >> arr[idx];
146  return *this;
147 }
148 
149 
150 #endif
od_ostream & stream()
Definition: ascbinstream.h:68
#define mExpClass(module)
Definition: commondefs.h:160
ascbinostream & addEOL(T t)
Definition: ascbinstream.h:56
OD class for stream write common access to the user log file, or std::cout in batch progs...
Definition: od_ostream.h:26
#define od_int64
Definition: plftypes.h:36
const bool binary_
Definition: ascbinstream.h:73
od_istream & strm_
Definition: ascbinstream.h:115
od_ostream & strm_
Definition: ascbinstream.h:72
const bool binary_
Definition: ascbinstream.h:116
const bool strmmine_
Definition: ascbinstream.h:74
ascbinostream & addArr(const T *, IT sz, const char *between="\t", const char *post="\n")
Will write both sz and the array.
Definition: ascbinstream.h:123
od_uint64 od_stream_Count
Definition: od_iosfwd.h:18
OD class for stream read.
Definition: od_istream.h:24
#define od_uint32
Definition: plftypes.h:32
reads from a stream that was created in ascbinostream style.
Definition: ascbinstream.h:81
#define mDeclascbinostreamAddFns(typ)
Definition: ascbinstream.h:40
ascbinistream & getBin(T &t)
Definition: ascbinstream.h:108
const bool strmmine_
Definition: ascbinstream.h:117
#define od_int16
Definition: plftypes.h:27
ascbinostream & addBin(const void *, od_stream_Count nrbytes)
#define od_uint64
Definition: plftypes.h:37
#define od_int32
Definition: plftypes.h:31
ascbinostream & addBin(const T &t)
Definition: ascbinstream.h:65
od_istream & stream()
Definition: ascbinstream.h:111
#define od_uint16
Definition: plftypes.h:28
ascbinistream & getArr(T *arr, IT sz)
Will NOT read the sz! Read sz and allocate first.
Definition: ascbinstream.h:139
writes to a stream that can be Ascii or Binary.
Definition: ascbinstream.h:30
#define od_newline
Definition: od_iosfwd.h:25

Generated at for the OpendTect seismic interpretation project. Copyright (C): dGB Beheer B. V. 2019