OpendTect-6_4  6.4
conn.h
Go to the documentation of this file.
1 #ifndef conn_h
2 #define conn_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: 21-10-1995
10  Contents: Connections with data providers (Streams, databases)
11  RCS: $Id$
12 ________________________________________________________________________
13 
14 -*/
15 
16 
17 #include "generalmod.h"
18 #include "multiid.h"
19 class IOObj;
20 class StreamConn;
21 
30 mExpClass(General) Conn
31 {
32 public:
33 
34  virtual ~Conn() {}
35  virtual void close() {}
36 
37  virtual bool isBad() const = 0;
38  virtual const char* creationMessage() const { return 0; }
39 
40  virtual const char* connType() const = 0;
41  virtual bool forRead() const = 0;
42  virtual bool forWrite() const { return !forRead(); }
43 
44  virtual StreamConn* getStream() { return 0; }
45  inline bool isStream() const
46  { return const_cast<Conn*>(this)->getStream(); }
47 
48  inline Conn* conn() { return gtConn(); }
49  inline const Conn* conn() const { return gtConn(); }
51 
52  const MultiID& linkedTo() const { return ioobjid_; }
53  void setLinkedTo( const MultiID& id ) { ioobjid_ = id; }
54 
55  // to fill 'forread' variables
56  static const bool Read; // true
57  static const bool Write; // false
58 
59 protected:
60 
61  Conn() {}
62 
64 
65  virtual Conn* gtConn() const { return const_cast<Conn*>(this); }
66 
67 };
68 
69 
74 mExpClass(General) XConn : public Conn
75 {
76 
77  friend class IOX;
78 
79 public:
80 
81  XConn() : conn_(0), mine_(true) {}
82  ~XConn() { if ( mine_ ) delete conn_; }
83 
84  virtual bool isBad() const
85  { return conn_ ? conn_->isBad() : true; }
86  virtual const char* creationMessage() const
87  { return conn_ ? conn_->creationMessage() : 0; }
88  virtual bool forRead() const
89  { return conn_ && conn_->forRead(); }
90  virtual bool forWrite() const
91  { return conn_ && conn_->forWrite(); }
92  virtual void close()
93  { if ( conn_ ) conn_->close(); }
94  virtual StreamConn* getStream()
95  { return conn_ ? conn_->getStream() : 0; }
96 
97  void setConn( Conn* c, bool becomesmine=true )
98  { if ( mine_ ) delete conn_;
99  conn_ = c; mine_ = becomesmine; }
100 
101  const char* connType() const { return sType(); }
102  static const char* sType();
103 
104 protected:
105 
106  Conn* conn_;
107  bool mine_;
108 
109  Conn* gtConn() const { return const_cast<Conn*>(conn_); }
110 
111 };
112 
113 
114 #endif
Conn()
Definition: conn.h:61
#define mExpClass(module)
Definition: commondefs.h:160
bool mine_
Definition: conn.h:107
Definition: ioobj.h:58
virtual bool isBad() const
Conn * conn_
Definition: conn.h:106
virtual bool isBad() const
Definition: conn.h:84
const Conn * conn() const
Returns the actual connection doing the work.
Definition: conn.h:49
virtual bool forWrite() const
Definition: conn.h:42
virtual bool forRead() const
virtual const char * creationMessage() const
Definition: conn.h:38
virtual bool forWrite() const
Definition: conn.h:90
virtual ~Conn()
Definition: conn.h:34
void setLinkedTo(const MultiID &id)
Definition: conn.h:53
virtual void close()
Definition: conn.h:35
const char * connType() const
Definition: conn.h:101
Conn * gtConn() const
Definition: conn.h:109
virtual StreamConn * getStream()
Definition: conn.h:44
virtual bool forRead() const
Definition: conn.h:88
const char * connType() const
Definition: streamconn.h:55
XConn()
Definition: conn.h:81
static const bool Read
Definition: conn.h:56
Connection implemented in terms of another Conn object.
Definition: conn.h:74
Conn * conn()
Definition: conn.h:48
void setConn(Conn *c, bool becomesmine=true)
Definition: conn.h:97
virtual void close()
Definition: conn.h:92
const MultiID & linkedTo() const
Definition: conn.h:52
Data connection.
Definition: conn.h:30
virtual StreamConn * getStream()
Definition: conn.h:94
virtual const char * creationMessage() const
Definition: conn.h:86
MultiID ioobjid_
Definition: conn.h:63
Definition: iox.h:22
bool isStream() const
Definition: conn.h:45
static const bool Write
Definition: conn.h:57
virtual Conn * gtConn() const
Definition: conn.h:65
Connection with an underlying iostream.
Definition: streamconn.h:26
virtual StreamConn * getStream()
Definition: streamconn.h:41
~XConn()
Definition: conn.h:82
Compound key consisting of ints.
Definition: multiid.h:25

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