OpendTect-6_4  6.4
bindatadesc.h
Go to the documentation of this file.
1 #ifndef bindatadesc_h
2 #define bindatadesc_h
3 
4 /*
5 ________________________________________________________________________
6 
7  (C) dGB Beheer B.V.; (LICENSE) http://opendtect.org/OpendTect_license.txt
8  Author: A.H.Bril
9  Date: Feb 2001
10  Contents: Binary data interpretation
11  RCS: $Id$
12 ________________________________________________________________________
13 
14 */
15 
16 #include "basicmod.h"
17 #include "gendefs.h"
18 
19 #define mDeclBinDataDescConstr(T,ii,is) \
20  BinDataDesc( const T* ) { set( ii, is, sizeof(T) ); } \
21  BinDataDesc( const T& ) { set( ii, is, sizeof(T) ); }
22 
44 {
45 public:
46 
47  enum ByteCount { N1=1, N2=2, N4=4, N8=8 };
48 
49  BinDataDesc( bool ii=false, bool is=true,
50  ByteCount b=N4 )
51  : isint_(ii), issigned_(is), nrbytes_(b) {}
52  BinDataDesc( bool ii, bool is, int b )
53  : isint_(ii), issigned_(is),
54  nrbytes_(nearestByteCount(ii,b)) {}
55  BinDataDesc( unsigned char c1, unsigned char c2 )
56  { set(c1,c2); }
57  BinDataDesc( const char* s ) { set(s); }
58  virtual ~BinDataDesc() {}
59 
60  inline bool isInteger() const { return isint_; }
61  inline bool isSigned() const { return issigned_; }
62  inline ByteCount nrBytes() const { return nrbytes_; }
63  inline void set( bool ii, bool is, ByteCount b )
64  { isint_ = ii; issigned_ = is; nrbytes_ = b; }
65  inline void set( bool ii, bool is, int b )
66  { isint_ = ii; issigned_ = is;
67  nrbytes_ = nearestByteCount(ii,b); }
68  void setInteger( bool yn ) { isint_ = yn; }
69  void setSigned( bool yn ) { issigned_ = yn; }
70  void setNrBytes( ByteCount n ) { nrbytes_ = n; }
71  void setNrBytes( int n )
72  { nrbytes_ = nearestByteCount(isint_,n); }
73 
74  // dump/restore
75  virtual int maxStringifiedSize() const { return 18; }
76  virtual void toString(BufferString&) const;
77  virtual void set(const char*);
78  virtual void dump(unsigned char&,unsigned char&) const;
79  virtual void set(unsigned char,unsigned char);
80 
81  mDeclBinDataDescConstr(signed char,true,true)
82  mDeclBinDataDescConstr(short,true,true)
83  mDeclBinDataDescConstr(int,true,true)
84  mDeclBinDataDescConstr(unsigned char,true,false)
85  mDeclBinDataDescConstr(unsigned short,true,false)
86  mDeclBinDataDescConstr(unsigned int,true,false)
87  mDeclBinDataDescConstr(float,false,true)
88  mDeclBinDataDescConstr(double,false,true)
89 
90  inline bool operator ==( const BinDataDesc& dc ) const
91  { return isEqual(dc); }
92  inline bool operator !=( const BinDataDesc& dc ) const
93  { return !isEqual(dc); }
94  inline bool isEqual( const BinDataDesc& dc ) const
95  {
96  unsigned char c11=0, c12=0, c21=0, c22=0;
97  dump(c11,c12); dc.dump(c21,c22);
98  return c11 == c21 && c12 == c22;
99  }
100 
101  int sizeFor( int n ) const { return nrbytes_ * n; }
102  virtual bool convertsWellTo(const BinDataDesc&) const;
103 
104  static ByteCount nearestByteCount( bool is_int, int s )
105  {
106  if ( !is_int ) return s > 6 ? N8 : N4;
107  if ( s > 6 ) s = 8;
108  else if ( s > 2 ) s = 4;
109  else if ( s < 2 ) s = 1;
110  return (ByteCount)s;
111  }
112 
113  static int nextSize( bool is_int, int s )
114  {
115  if ( s < 0 || s > 8 ) return -1;
116  if ( s == 0 ) return is_int ? 1 : 4;
117  if ( !is_int ) return s == 4 ? 8 : -1;
118  return s == 1 ? 2 : ( s == 2 ? 4 : 8 );
119  }
120 
121 protected:
122 
123  bool isint_;
124  bool issigned_;
126 
127  void setFrom(unsigned char,bool);
128 
129 };
130 
131 #undef mDeclBinDataDescConstr
132 
133 
134 #endif
#define mExpClass(module)
Definition: commondefs.h:160
BinDataDesc(const char *s)
Definition: bindatadesc.h:57
BinDataDesc(bool ii, bool is, int b)
Definition: bindatadesc.h:52
ByteCount
Definition: bindatadesc.h:47
virtual ~BinDataDesc()
Definition: bindatadesc.h:58
bool isint_
Definition: bindatadesc.h:123
void setInteger(bool yn)
Definition: bindatadesc.h:68
static ByteCount nearestByteCount(bool is_int, int s)
Definition: bindatadesc.h:104
void setSigned(bool yn)
Definition: bindatadesc.h:69
bool isEqual(const BinDataDesc &dc) const
Definition: bindatadesc.h:94
static int nextSize(bool is_int, int s)
Definition: bindatadesc.h:113
ByteCount nrBytes() const
Definition: bindatadesc.h:62
BinDataDesc(bool ii=false, bool is=true, ByteCount b=N4)
Definition: bindatadesc.h:49
ByteCount nrbytes_
Definition: bindatadesc.h:125
void setNrBytes(int n)
Definition: bindatadesc.h:71
bool issigned_
Definition: bindatadesc.h:124
virtual void dump(unsigned char &, unsigned char &) const
bool operator!=(const ArrayNDInfo &a1, const ArrayNDInfo &a2)
Definition: arrayndinfo.h:62
virtual int maxStringifiedSize() const
Definition: bindatadesc.h:75
bool isInteger() const
Definition: bindatadesc.h:60
OD::String with its own variable length buffer. The buffer has a guaranteed minimum size...
Definition: bufstring.h:40
BinDataDesc(unsigned char c1, unsigned char c2)
Definition: bindatadesc.h:55
#define mDeclBinDataDescConstr(T, ii, is)
Definition: bindatadesc.h:19
int sizeFor(int n) const
Definition: bindatadesc.h:101
Description of binary data.
Definition: bindatadesc.h:43
bool isSigned() const
Definition: bindatadesc.h:61
Export_Basic const char * toString(ViewStyle)
void setNrBytes(ByteCount n)
Definition: bindatadesc.h:70

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