Mobile API Reference  MicroStrategy 2019
StrongPtr.h
Go to the documentation of this file.
1 //==============================================================================================
2 // FILENAME : StrongPtr.h
3 // AUTHOR : Juan Pablo Muraira
4 // CREATION : 9/26/01
5 // Copyright (C) MicroStrategy Incorporated 2001
6 // All Rights Reserved
7 //==============================================================================================
8 #ifndef MBase_StrongPtr_h
9 #define MBase_StrongPtr_h
10 
11 #ifdef _MSC_VER
12 #pragma warning(disable:4786) // 'identifier' : identifier was truncated to 'number' characters in the debug information
13 #pragma warning(disable:4284) // return type for 'identifier::operator ->' is not a UDT or reference to a UDT. Will produce errors if applied using infix notation
14 #endif
15 
16 #include "BasicTypes.h"
17 #include "StrongBase.h"
18 #include "ReturnPtr.h"
19 
20 namespace MBase
21 {
49  template<class T, class DeleteOperator = DeleteC<T> >
50  class StrongPtr: public StrongBase<T*, DeleteOperator>
51  {
52  public:
53  // Make the constructor explicit, so that we don't incur into
54  // funny implicit conversion.
55  explicit StrongPtr(T* ipData = NULL) throw():
57  {
58  }
59 
60 #if defined(__IBMCPP__) || defined(__GNUG__) || defined(__hpux)
61  // VisualAge compiler doesn't resolve copy-constructors with non-const
62  // arguments. So we have to make the argument const and make a const
63  // cast inside.
64  template <class T2>
65  explicit StrongPtr(const ReturnPtr<T2, DeleteOperator>& irReturnPtr) throw()
66  {
67  // "steal" the ownership from the return ptr
68  (this->mData) = const_cast<ReturnPtr<T2, DeleteOperator>&>(irReturnPtr).GiveUp();
69  }
70 #else
71  template <class T2>
72  explicit StrongPtr(ReturnPtr<T2, DeleteOperator>& irReturnPtr) throw()
73  {
74  // "steal" the ownership from the return ptr
75  this->mData = irReturnPtr.GiveUp();
76  }
77 #endif // __IBMCPP__
78 
79 #if defined(__IBMCPP__) || defined(__GNUG__) || defined(__hpux)
80  // VisualAge compiler doesn't resolve copy-constructors with non-const
81  // arguments. So we have to make the argument const and make a const
82  // cast inside.
83  template <class T2>
84  void operator=(const ReturnPtr<T2, DeleteOperator>& irReturnPtr) throw()
85  {
86  // "steal" the ownership from the return ptr
87  Reset(const_cast<ReturnPtr<T2, DeleteOperator>&>(irReturnPtr).GiveUp());
88  }
89 #else
90  template <class T2>
91  void operator=(ReturnPtr<T2, DeleteOperator>& irReturnPtr) throw()
92  {
93  // "steal" the ownership from the return ptr
94  Reset(irReturnPtr.GiveUp());
95  }
96 #endif // __IBMCPP__
97 
98  T* operator->() const throw()
99  {
100  _ASSERTE(this->mData!=NULL);
101  return this->mData;
102  }
103 
104  T& operator*() const throw()
105  {
106  _ASSERTE(this->mData!=NULL);
107  return *(this->mData);
108  }
109 
115  T** operator&() throw()
116  {
117  _ASSERTE((this->mData)==NULL);
118  return &(this->mData);
119  }
120 
125  template<class U,class DeleteOperatorU>
126  void Acquire(StrongPtr<U, DeleteOperatorU>& iStrongPtr) throw()
127  {
128  Reset(iStrongPtr.GiveUp());
129  }
130 
133  void Acquire(T*& irpData) throw()
134  {
135  this->Reset(irpData);
136  irpData=NULL;
137  }
138 
140  template<class U,class DeleteOperatorU>
141  void Swap(StrongPtr<U, DeleteOperatorU>& iStrongPtr) throw()
142  {
143  swap((this->mData), iStrongPtr.mData);
144  }
145 
147  {
148  return ReturnPtr<T, DeleteOperator>(this->GiveUp());
149  }
150  };
151 
153  // StrongArrayPtr is a specialization of StrongPtr for use with C++ arrays.
154  template<class T>
156  public StrongPtr< T, DeleteArray<T> >
157  {
158  public:
159  explicit StrongArrayPtr(T* ipData = NULL) throw():
160  StrongPtr<T, DeleteArray<T> >(ipData)
161  {
162  }
163 
164  T& operator[](Int32 i) const
165  {
166  _ASSERTE((this->mData)!=NULL);
167  return (this->mData)[i];
168  }
169  };
170 
171 
173  //xhan 09/25/05
174  // StrongBufferPtr is a specialization of StrongPtr for the object allocated from a buffer.
175  template<class T>
177  public StrongPtr< T, Destroy<T> >
178  {
179  public:
180  explicit StrongBufferPtr(T* ipData = NULL) throw():
181  StrongPtr<T, Destroy<T> >(ipData)
182  {
183  }
184  };
185 
186 
187 }
188 
189 #endif // MBase_StrongPtr_h
StrongBufferPtr(T *ipData=NULL)
Definition: StrongPtr.h:180
T ** operator &()
Definition: StrongPtr.h:115
void Acquire(StrongPtr< U, DeleteOperatorU > &iStrongPtr)
Definition: StrongPtr.h:126
#define _ASSERTE(x)
Definition: Asserte.h:40
T * operator->() const
Definition: StrongPtr.h:98
T * mData
Definition: StrongBase.h:80
void Reset(T * iData=NULL)
Definition: StrongBase.h:43
#define Int32
Definition: BasicTypes.h:20
void Acquire(T *&irpData)
Definition: StrongPtr.h:133
void Swap(StrongPtr< U, DeleteOperatorU > &iStrongPtr)
Swap the contents of two strong pointers.
Definition: StrongPtr.h:141
T * GiveUp()
Definition: StrongBase.h:57
Definition: Allocator.h:47
T & operator*() const
Definition: StrongPtr.h:104
Definition: StrongPtr.h:50
ReturnPtr< T, DeleteOperator > Return()
Definition: StrongPtr.h:146
T * GiveUp()
This function should only be used by StrongPtr/ReturnPtr.
Definition: ReturnPtr.h:47
StrongPtr(T *ipData=NULL)
Definition: StrongPtr.h:55
StrongArrayPtr(T *ipData=NULL)
Definition: StrongPtr.h:159
Definition: StrongPtr.h:155
Definition: StrongBase.h:23
#define NULL
Definition: Null.h:10
StrongPtr(ReturnPtr< T2, DeleteOperator > &irReturnPtr)
Definition: StrongPtr.h:72
Definition: StrongPtr.h:176
void operator=(ReturnPtr< T2, DeleteOperator > &irReturnPtr)
Definition: StrongPtr.h:91
Definition: ReturnPtr.h:22
T & operator[](Int32 i) const
Definition: StrongPtr.h:164