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 
115  typedef T* this_type::*unspecified_bool_type;
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 * m_pRefCount
Definition: SharedPointer.h:83
bool operator!=(const shared_ptr< T1 > &sp1, const shared_ptr< T2 > &sp2)
T *this_type::* unspecified_bool_type
shared_ptr< T > this_type
Definition: SharedPointer.h:78
bool operator==(const shared_ptr< T1 > &sp1, const shared_ptr< T2 > &sp2)
shared_ptr< T > dynamic_pointer_cast(const shared_ptr< T2 > &rSharedPointer)


avt_vimba_camera
Author(s): Miquel Massot , Allied Vision Technologies
autogenerated on Wed Jun 5 2019 22:22:40