]> git.sesse.net Git - casparcg/blob - dependencies64/sfml/include/SFML/System/ThreadLocalPtr.hpp
Updated some libraries to newer versions and/or versions compiled for vc12 (freeimage...
[casparcg] / dependencies64 / sfml / include / SFML / System / ThreadLocalPtr.hpp
1 ////////////////////////////////////////////////////////////
2 //
3 // SFML - Simple and Fast Multimedia Library
4 // Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
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 //
23 ////////////////////////////////////////////////////////////
24
25 #ifndef SFML_THREADLOCALPTR_HPP
26 #define SFML_THREADLOCALPTR_HPP
27
28 ////////////////////////////////////////////////////////////
29 // Headers
30 ////////////////////////////////////////////////////////////
31 #include <SFML/System/ThreadLocal.hpp>
32
33
34 namespace sf
35 {
36 ////////////////////////////////////////////////////////////
37 /// \brief Pointer to a thread-local variable
38 ///
39 ////////////////////////////////////////////////////////////
40 template <typename T>
41 class ThreadLocalPtr : private ThreadLocal
42 {
43 public:
44
45     ////////////////////////////////////////////////////////////
46     /// \brief Default constructor
47     ///
48     /// \param value Optional value to initialize the variable
49     ///
50     ////////////////////////////////////////////////////////////
51     ThreadLocalPtr(T* value = NULL);
52
53     ////////////////////////////////////////////////////////////
54     /// \brief Overload of unary operator *
55     ///
56     /// Like raw pointers, applying the * operator returns a
57     /// reference to the pointed-to object.
58     ///
59     /// \return Reference to the thread-local variable
60     ///
61     ////////////////////////////////////////////////////////////
62     T& operator *() const;
63
64     ////////////////////////////////////////////////////////////
65     /// \brief Overload of operator ->
66     ///
67     /// Similarly to raw pointers, applying the -> operator
68     /// returns the pointed-to object.
69     ///
70     /// \return Pointer to the thread-local variable
71     ///
72     ////////////////////////////////////////////////////////////
73     T* operator ->() const;
74
75     ////////////////////////////////////////////////////////////
76     /// \brief Conversion operator to implicitly convert the
77     ///        pointer to its raw pointer type (T*)
78     ///
79     /// \return Pointer to the actual object
80     ///
81     ////////////////////////////////////////////////////////////
82     operator T*() const;
83
84     ////////////////////////////////////////////////////////////
85     /// \brief Assignment operator for a raw pointer parameter
86     ///
87     /// \param value Pointer to assign
88     ///
89     /// \return Reference to self
90     ///
91     ////////////////////////////////////////////////////////////
92     ThreadLocalPtr<T>& operator =(T* value);
93
94     ////////////////////////////////////////////////////////////
95     /// \brief Assignment operator for a ThreadLocalPtr parameter
96     ///
97     /// \param right ThreadLocalPtr to assign
98     ///
99     /// \return Reference to self
100     ///
101     ////////////////////////////////////////////////////////////
102     ThreadLocalPtr<T>& operator =(const ThreadLocalPtr<T>& right);
103 };
104
105 } // namespace sf
106
107 #include <SFML/System/ThreadLocalPtr.inl>
108
109
110 #endif // SFML_THREADLOCALPTR_HPP
111
112
113 ////////////////////////////////////////////////////////////
114 /// \class sf::ThreadLocalPtr
115 /// \ingroup system
116 ///
117 /// sf::ThreadLocalPtr is a type-safe wrapper for storing
118 /// pointers to thread-local variables. A thread-local
119 /// variable holds a different value for each different
120 /// thread, unlike normal variables that are shared.
121 ///
122 /// Its usage is completely transparent, so that it is similar
123 /// to manipulating the raw pointer directly (like any smart pointer).
124 ///
125 /// Usage example:
126 /// \code
127 /// MyClass object1;
128 /// MyClass object2;
129 /// sf::ThreadLocalPtr<MyClass> objectPtr;
130 ///
131 /// void thread1()
132 /// {
133 ///     objectPtr = &object1; // doesn't impact thread2
134 ///     ...
135 /// }
136 ///
137 /// void thread2()
138 /// {
139 ///     objectPtr = &object2; // doesn't impact thread1
140 ///     ...
141 /// }
142 ///
143 /// int main()
144 /// {
145 ///     // Create and launch the two threads
146 ///     sf::Thread t1(&thread1);
147 ///     sf::Thread t2(&thread2);
148 ///     t1.launch();
149 ///     t2.launch();
150 ///
151 ///     return 0;
152 /// }
153 /// \endcode
154 ///
155 /// ThreadLocalPtr is designed for internal use; however you
156 /// can use it if you feel like it fits well your implementation.
157 ///
158 ////////////////////////////////////////////////////////////