SharedPointer.h
Go to the documentation of this file.
1 /*=============================================================================
2  Copyright (C) 2012 Allied Vision Technologies. All Rights Reserved.
3 
4  Redistribution of this file, in original or modified form, without
5  prior written consent of Allied Vision Technologies is prohibited.
6 
7 -------------------------------------------------------------------------------
8 
9  File: SharedPointer.h
10 
11  Description: Definition of an example shared pointer class that can be
12  used with the Vimba CPP API.
13  (This include file contains example code only.)
14 
15 -------------------------------------------------------------------------------
16 
17  THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
18  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
19  NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20  DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
21  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
24  AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
25  TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 
28 =============================================================================*/
29 
30 #ifndef AVT_VMBAPI_SHAREDPOINTER_H
31 #define AVT_VMBAPI_SHAREDPOINTER_H
32 
33 #include <VimbaCPP/Include/Mutex.h>
34 
35 namespace AVT {
36 namespace VmbAPI {
37 
38  //Coding style of this file is different to mimic the shared_ptr classes of std and boost.
39 
41  {
42  };
43 
45  {
46  public:
47  virtual ~ref_count_base() {;}
48 
49  virtual void inc() = 0;
50  virtual void dec() = 0;
51  virtual long use_count() const = 0;
52  };
53 
54  template <class T>
55  class ref_count : public virtual AVT::VmbAPI::ref_count_base
56  {
57  private:
59  long m_nCount;
61 
62  ref_count(const ref_count &rRefCount);
63  ref_count& operator = (const ref_count &rRefCount);
64 
65  public:
66  explicit ref_count(T *pObject);
67  virtual ~ref_count();
68 
69  virtual void inc();
70  virtual void dec();
71  virtual long use_count() const;
72  };
73 
74  template <class T>
75  class shared_ptr
76  {
77  private:
79 
80  template<class T2>
81  friend class shared_ptr;
82 
85 
86  template <class T2>
87  static void swap(T2 &rValue1, T2 &rValue2);
88 
89  public:
90  shared_ptr();
91  template <class T2>
92  explicit shared_ptr(T2 *pObject);
93  shared_ptr(const shared_ptr &rSharedPointer);
94  template <class T2>
95  shared_ptr(const shared_ptr<T2> &rSharedPointer);
96  template <class T2>
97  shared_ptr(const shared_ptr<T2> &rSharedPointer, dynamic_cast_tag);
98 
99  virtual ~shared_ptr();
100 
101  shared_ptr& operator = (const shared_ptr &rSharedPointer);
102  template <class T2>
103  shared_ptr& operator = (const shared_ptr<T2> &rSharedPointer);
104 
105  void reset();
106  template <class T2>
107  void reset(T2 *pObject);
108 
109  T* get() const;
110  T& operator * () const;
111  T* operator -> () const;
112  long use_count() const;
113  bool unique() const;
114 
116 
117  operator unspecified_bool_type () const
118  {
119  if(m_pObject == 0)
120  {
121  return 0;
122  }
123 
124  return &this_type::m_pObject;
125  }
126 
127  void swap(shared_ptr &rSharedPointer);
128  };
129 
130  template<class T, class T2>
131  shared_ptr<T> dynamic_pointer_cast(const shared_ptr<T2> &rSharedPointer);
132 
133  template<class T1, class T2>
134  bool operator==(const shared_ptr<T1>& sp1, const shared_ptr<T2>& sp2);
135  template<class T1, class T2>
136  bool operator!=(const shared_ptr<T1>& sp1, const shared_ptr<T2>& sp2);
137 
138 }} //namespace AVT::VmbAPI
139 
141 
142 #endif //AVT_VMBAPI_SHAREDPOINTER_H
AVT::VmbAPI::ref_count_base
Definition: SharedPointer.h:44
AVT::VmbAPI::shared_ptr::operator=
shared_ptr & operator=(const shared_ptr &rSharedPointer)
Definition: SharedPointer_impl.h:207
AVT::VmbAPI::ref_count
Definition: SharedPointer.h:55
AVT::VmbAPI::ref_count_base::~ref_count_base
virtual ~ref_count_base()
Definition: SharedPointer.h:47
AVT::VmbAPI::shared_ptr::m_pObject
T * m_pObject
Definition: SharedPointer.h:84
AVT::VmbAPI::ref_count::m_pObject
T * m_pObject
Definition: SharedPointer.h:58
AVT::VmbAPI::shared_ptr::~shared_ptr
virtual ~shared_ptr()
Definition: SharedPointer_impl.h:187
AVT::VmbAPI::shared_ptr::this_type
shared_ptr< T > this_type
Definition: SharedPointer.h:78
AVT::VmbAPI::Mutex
Definition: Mutex.h:42
AVT
Definition: AncillaryData.h:35
AVT::VmbAPI::ref_count::inc
virtual void inc()
Definition: SharedPointer_impl.h:69
AVT::VmbAPI::shared_ptr::operator->
T * operator->() const
Definition: SharedPointer_impl.h:240
AVT::VmbAPI::shared_ptr::reset
void reset()
Definition: SharedPointer_impl.h:215
AVT::VmbAPI::shared_ptr::get
T * get() const
Definition: SharedPointer_impl.h:228
AVT::VmbAPI::ref_count::operator=
ref_count & operator=(const ref_count &rRefCount)
Definition: SharedPointer_impl.h:44
AVT::VmbAPI::dynamic_cast_tag
Definition: SharedPointer.h:40
AVT::VmbAPI::ref_count::ref_count
ref_count(const ref_count &rRefCount)
Definition: SharedPointer_impl.h:39
AVT::VmbAPI::operator!=
bool operator!=(const shared_ptr< T1 > &sp1, const shared_ptr< T2 > &sp2)
Definition: SharedPointer_impl.h:282
AVT::VmbAPI::shared_ptr::swap
static void swap(T2 &rValue1, T2 &rValue2)
Definition: SharedPointer_impl.h:107
AVT::VmbAPI::ref_count_base::dec
virtual void dec()=0
AVT::VmbAPI::ref_count::use_count
virtual long use_count() const
Definition: SharedPointer_impl.h:100
AVT::VmbAPI::ref_count::dec
virtual void dec()
Definition: SharedPointer_impl.h:79
AVT::VmbAPI::ref_count_base::inc
virtual void inc()=0
AVT::VmbAPI::ref_count::m_Mutex
Mutex m_Mutex
Definition: SharedPointer.h:60
AVT::VmbAPI::ref_count::~ref_count
virtual ~ref_count()
Definition: SharedPointer_impl.h:58
AVT::VmbAPI::shared_ptr::shared_ptr
friend class shared_ptr
Definition: SharedPointer.h:81
AVT::VmbAPI::shared_ptr::use_count
long use_count() const
Definition: SharedPointer_impl.h:246
Mutex.h
AVT::VmbAPI::shared_ptr::operator*
T & operator*() const
Definition: SharedPointer_impl.h:234
AVT::VmbAPI::shared_ptr::unspecified_bool_type
T *this_type::* unspecified_bool_type
Definition: SharedPointer.h:115
AVT::VmbAPI::shared_ptr
Definition: SharedPointer.h:75
AVT::VmbAPI::shared_ptr::m_pRefCount
AVT::VmbAPI::ref_count_base * m_pRefCount
Definition: SharedPointer.h:83
AVT::VmbAPI::shared_ptr::unique
bool unique() const
Definition: SharedPointer_impl.h:257
AVT::VmbAPI::operator==
bool operator==(const shared_ptr< T1 > &sp1, const shared_ptr< T2 > &sp2)
Definition: SharedPointer_impl.h:276
SharedPointer_impl.h
AVT::VmbAPI::dynamic_pointer_cast
shared_ptr< T > dynamic_pointer_cast(const shared_ptr< T2 > &rSharedPointer)
Definition: SharedPointer_impl.h:270
AVT::VmbAPI::ref_count::m_nCount
long m_nCount
Definition: SharedPointer.h:59
AVT::VmbAPI::ref_count_base::use_count
virtual long use_count() const =0


avt_vimba_camera
Author(s): Allied Vision Technologies, Miquel Massot
autogenerated on Sat Jun 3 2023 02:14:12