Mobile API Reference  MicroStrategy 2019
StrongBase.h
Go to the documentation of this file.
1 //==============================================================================================
2 // FILENAME : StrongBase.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_StrongBase_h
9 #define MBase_StrongBase_h
10 
11 #include "Null.h"
12 #include "DeleteOperator.h"
13 #include "Asserte.h"
15 
16 namespace MBase
17 {
22  template<class T,class DeleteOperator>
23  class StrongBase
24  {
25  public:
28  ~StrongBase();
29 
34  T Get() const throw()
35  {
36  return mData;
37  }
38 
43  void Reset(T iData = NULL) throw()
44  {
45  if(mData!=iData)
46  {
47  //To avoid problems with circular references make a temporary
48  //copy first and set the member to the new one before deleting it
49  T lData = mData;
50  mData = iData;
51  DeleteOperator()(lData);
52  }
53  }
54 
57  T GiveUp() throw()
58  {
59  T lTemp=mData;
60  mData=NULL;
61  return lTemp;
62  }
63 
65  bool IsNull() const throw()
66  {
67  return mData==NULL;
68  }
69 
70  protected:
71  // Make the constructor explicit, so that we don't incur into
72  // funny implicit conversion.
73  // The constructor is non-throw because allowing an exception
74  // to escape would mean a resource leak of some soft.
75  explicit StrongBase(T iData = NULL) throw():
76  mData(iData)
77  {
78  }
79 
80  T mData;
81  private:
82 
84  // No Copy constructor or assignment operator allowed on StrongBase.
85  // Since StrongBase has destructive copy, there will never be two
86  // copies of the same resource. We chose to disallow the copy altogether,
87  // to avoid further bugs.
88  // If the user wants to transfer ownership between resources, he must
89  // do so explicitly (by calling Acquire or a combination of Reset and GiveUp).
90  // Declare and not define copy constructor and assignment operator
91  // This prevents the compiler from generating them automatically.
92  // It gives a compiler error if someone tries to use them.
93  StrongBase(const StrongBase&);
94  StrongBase& operator=(const StrongBase&);
96  };
97 
98  template<class T,class DeleteOperator>
100  {
101  DeleteOperator()(mData);
102  mData = T();
103  }
104 
105 }
106 
107 #endif // MBase_StrongBase_h
T mData
Definition: StrongBase.h:80
void Reset(T iData=NULL)
Definition: StrongBase.h:43
T Get() const
Definition: StrongBase.h:34
bool IsNull() const
Check for NULL.
Definition: StrongBase.h:65
T GiveUp()
Definition: StrongBase.h:57
Definition: Allocator.h:47
~StrongBase()
Definition: StrongBase.h:99
Definition: StrongBase.h:23
#define NULL
Definition: Null.h:10
StrongBase(T iData=NULL)
Definition: StrongBase.h:75