Teamcenter C++ API Reference  2312
ScopedSmPtr.hxx
Go to the documentation of this file.
1 // Copyright 2022 Siemens Digital Industries Software
2 // ==================================================
3 // Copyright 2017.
4 // Siemens Product Lifecycle Management Software Inc.
5 // All Rights Reserved.
6 // ==================================================
7 // Copyright 2022 Siemens Digital Industries Software
8 
17 #ifndef TEAMCENTER_BASE_UTILS_SCOPED_SM_PTR_HXX
18 #define TEAMCENTER_BASE_UTILS_SCOPED_SM_PTR_HXX
19 
20 #include <cstdlib>
21 /* */
22 #include <base_utils/Mem.h>
23 
24 namespace Teamcenter
25 {
30 template < class T > struct scoped_smptr_my_deallocator
31 {
32  void operator() (T* bucket) const { MEM_free(bucket); }
33 };
89 template <class T, class F=scoped_smptr_my_deallocator< T > > class scoped_smptr
90 {
91 public:
96  explicit scoped_smptr( T* b = 0 ) : bucket( b ) {}
97 
101  virtual ~scoped_smptr() { F f; f( bucket ); } /* */
102 
103 
109  scoped_smptr & operator=(T * ptr) { F f; f(bucket); bucket = ptr; return *this; }
110 
114  T** operator&() { return &bucket; }
115 
119  T& operator*() const { return *bucket; }
120 
124  T* operator->() const { return bucket; }
125 
129  const T& operator[](std::size_t inx) const { return bucket[inx]; }
130 
134  T& operator[](std::size_t inx) { return bucket[inx]; }
135 
139  const T& operator[](int inx) const { return bucket[inx]; }
140 
144  T& operator[](int inx) { return bucket[inx]; }
145 
149  const T& operator[](unsigned int inx) const { return bucket[inx]; }
150 
154  T& operator[](unsigned int inx) { return bucket[inx]; }
155 
159  const T& operator[](short inx) const { return bucket[inx]; }
160 
164  T& operator[](short inx) { return bucket[inx]; }
165 
169  const T& operator[](long inx) const { return bucket[inx]; }
170 
174  T& operator[](long inx) { return bucket[inx]; }
175 
184  const T* getString() const { static const T s_empty = T(); return bucket ? bucket : &s_empty; }
185 
189  T*& getReference() { return bucket; }
190 
194  T* get() const { return bucket; }
195 
199  T* release() { T* tmp = bucket; bucket = 0; return tmp; }
200 
202  bool operator == (const T* t) const { return bucket == t; }
203 
205  bool operator != (const T* t) const { return bucket != t; }
206 
208  bool operator! () const
209  {
210  return bucket == 0;
211  }
212 
213 protected:
217  T* bucket;
218 
219 private:
223  scoped_smptr( const scoped_smptr& );
224 
229 };
230 
231 }
232 
233 #endif