| # Gaudi Framework, version v25r0 |

Home |  | Generated: Mon Feb 17 2014

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
SmartIF.h
Go to the documentation of this file.
1 // $Id: SmartIF.h,v 1.10 2008/10/27 19:22:20 marcocle Exp $
2 #ifndef GAUDI_SMARTIF_H
3 #define GAUDI_SMARTIF_H 1
4
5 // Framework include files
6 #include "GaudiKernel/IInterface.h"
7
19 template <class TYPE> class SmartIF {
20 private:
22 TYPE* m_interface;
23 public:
24 // ---------- Construction and destruction ----------
26 inline SmartIF(): m_interface(0) {}
28 inline SmartIF(TYPE* ptr): m_interface(ptr) {
29 if (m_interface) m_interface->addRef();
30 }
32 template <class OTHER>
33 inline SmartIF(OTHER* ptr): m_interface(0) {
34 if (ptr) reset(ptr);
35 }
37 inline SmartIF(const SmartIF& rhs): m_interface(rhs.get()) {
38 if (m_interface) m_interface->addRef();
39 }
42 template <class T>
43 inline explicit SmartIF(const SmartIF<T>& rhs): m_interface(0) {
44 reset(rhs.get());
45 }
47 inline ~SmartIF() { reset(); }
48
49 // ---------- Boolean and comparison methods ----------
51 inline bool isValid() const { return m_interface != 0; }
52
53 // ---------- Pointer access methods ----------
56 inline operator TYPE* () const { return m_interface; }
58 inline TYPE* operator->() const { return m_interface; }
60 inline TYPE& operator *() const { return *m_interface; }
62 inline TYPE* get() const { return m_interface; }
63 #if !defined(GAUDI_V22_API) && !defined(NEW_SMARTIF)
64
65 inline TYPE*& pRef() {
66 return m_interface;
67 }
68 #endif
69
70 // ---------- Cast methods ----------
74 inline void reset(TYPE* ptr = 0) {
75 if (ptr == m_interface) return;
76 if (m_interface) m_interface->release();
77 if (ptr) {
78 m_interface = ptr;
79 m_interface->addRef();
80 } else {
81 m_interface = 0;
82 }
83 }
86 template <class OTHER>
87 inline void reset(OTHER* ptr) {
88 if (static_cast<IInterface*>(ptr) == static_cast<IInterface*>(m_interface)) return;
89 if (m_interface) m_interface->release();
90 if (ptr) {
91 ptr->queryInterface(TYPE::interfaceID(), pp_cast<void>(&m_interface)).ignore();
92 } else {
93 m_interface = 0;
94 }
95 }
96
97 // ---------- Special hacks ----------
104 inline SmartIF& operator = (IInterface* ptr) {
105 reset(ptr);
106 return *this;
107 }
109 inline SmartIF& operator = (const SmartIF& rhs) {
110 reset(rhs.get());
111 return *this;
112 }
115 template <class T>
116 inline SmartIF& operator = (const SmartIF<T>& rhs) {
117 reset(rhs.get());
118 return *this;
119 }
120 };
121
122 #if defined(_MSC_VER) && (_MSC_VER < 1500)
123
124
125
126
127
128
129
130 template <class TYPE>
131 inline bool operator == (long lhs, const SmartIF<TYPE> &rhs) {
132 return rhs == reinterpret_cast<TYPE*>(lhs);
133 }
141 template <class TYPE>
142 inline bool operator != (long lhs, const SmartIF<TYPE> &rhs) {
143 return rhs != reinterpret_cast<TYPE*>(lhs);
144 }
145 #endif
146 #endif // GAUDI_SMARTIF_H