TGUI  v0.6.10
SharedWidgetPtr.hpp
1 //
3 // TGUI - Texus's Graphical User Interface
4 // Copyright (C) 2012-2015 Bruno Van de Velde (vdv_b@tgui.eu)
5 //
6 // This software is provided 'as-is', without any express or implied warranty.
7 // In no event will the authors be held liable for any damages arising from the use of this software.
8 //
9 // Permission is granted to anyone to use this software for any purpose,
10 // including commercial applications, and to alter it and redistribute it freely,
11 // subject to the following restrictions:
12 //
13 // 1. The origin of this software must not be misrepresented;
14 // you must not claim that you wrote the original software.
15 // If you use this software in a product, an acknowledgment
16 // in the product documentation would be appreciated but is not required.
17 //
18 // 2. Altered source versions must be plainly marked as such,
19 // and must not be misrepresented as being the original software.
20 //
21 // 3. This notice may not be removed or altered from any source distribution.
22 //
24 
25 
26 #ifndef TGUI_SHARED_WIDGET_PTR_HPP
27 #define TGUI_SHARED_WIDGET_PTR_HPP
28 
29 
30 #include <SFML/System/String.hpp>
31 
32 #include <cstddef>
33 
35 
36 namespace tgui
37 {
38  class Container;
39  class Gui;
40 
42 
43  template <class T>
45  {
46  public:
47 
49 
51 
53 
54  SharedWidgetPtr(std::nullptr_t);
55 
57 
58  SharedWidgetPtr(Gui& gui, const sf::String& widgetName = "");
59 
61 
62  SharedWidgetPtr(Container& container, const sf::String& widgetName = "");
63 
65 
67 
69 
70  template <class U>
72 
74 
75  ~SharedWidgetPtr();
76 
78 
79  SharedWidgetPtr<T>& operator=(const SharedWidgetPtr<T>& copy);
80 
82 
83  template <class U>
84  SharedWidgetPtr<T>& operator=(const SharedWidgetPtr<U>& copy);
85 
87 
88  void init();
89 
91 
92  void reset();
93 
95 
96  bool operator!() const;
97 
99 
100  template <typename U>
101  bool operator ==(const SharedWidgetPtr<U>& right) const;
102 
104 
105  bool operator ==(const SharedWidgetPtr<T>& right) const;
106 
108 
109  template <typename U>
110  friend bool operator ==(const SharedWidgetPtr<T>& left, const U* right)
111  {
112  return left.m_WidgetPtr == right;
113  }
114 
116 
117  friend bool operator ==(const SharedWidgetPtr<T>& left, const T* right)
118  {
119  return left.m_WidgetPtr == right;
120  }
121 
123 
124  template <typename U>
125  friend bool operator ==(const U* left, const SharedWidgetPtr<T>& right)
126  {
127  return left == right.m_WidgetPtr;
128  }
129 
131 
132  friend bool operator ==(const T* left, const SharedWidgetPtr<T>& right)
133  {
134  return left == right.m_WidgetPtr;
135  }
136 
138 
139  template <typename U>
140  bool operator !=(const SharedWidgetPtr<U>& right) const;
141 
143 
144  bool operator !=(const SharedWidgetPtr<T>& right) const;
145 
147 
148  template <typename U>
149  friend bool operator !=(const SharedWidgetPtr<T>& left, const U* right)
150  {
151  return left.m_WidgetPtr != right;
152  }
153 
155 
156  friend bool operator !=(const SharedWidgetPtr<T>& left, const T* right)
157  {
158  return left.m_WidgetPtr != right;
159  }
160 
162 
163  template <typename U>
164  friend bool operator !=(const U* left, const SharedWidgetPtr<T>& right)
165  {
166  return left != right.m_WidgetPtr;
167  }
168 
170 
171  friend bool operator !=(const T* left, const SharedWidgetPtr<T>& right)
172  {
173  return left != right.m_WidgetPtr;
174  }
175 
177 
178  T& operator*() const;
179 
181 
182  T* operator->() const;
183 
185 
186  T* get() const;
187 
189 
190  unsigned int* getRefCount() const;
191 
193 
194  SharedWidgetPtr clone() const;
195 
197  private:
198 
199  T* m_WidgetPtr;
200  unsigned int* m_RefCount;
201 
203  };
204 
206 }
207 
209 
210 #endif // TGUI_SHARED_WIDGET_PTR_HPP
Namespace that contains all TGUI functions and classes.
Definition: AnimatedPicture.hpp:33
Definition: Gui.hpp:40
Parent class for widgets that store multiple widgets.
Definition: Container.hpp:43
Definition: SharedWidgetPtr.hpp:44