Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-06-02 08:58:14

0001 ////////////////////////////////////////////////////////////
0002 //
0003 // SFML - Simple and Fast Multimedia Library
0004 // Copyright (C) 2007-2023 Laurent Gomila (laurent@sfml-dev.org)
0005 //
0006 // This software is provided 'as-is', without any express or implied warranty.
0007 // In no event will the authors be held liable for any damages arising from the use of this software.
0008 //
0009 // Permission is granted to anyone to use this software for any purpose,
0010 // including commercial applications, and to alter it and redistribute it freely,
0011 // subject to the following restrictions:
0012 //
0013 // 1. The origin of this software must not be misrepresented;
0014 //    you must not claim that you wrote the original software.
0015 //    If you use this software in a product, an acknowledgment
0016 //    in the product documentation would be appreciated but is not required.
0017 //
0018 // 2. Altered source versions must be plainly marked as such,
0019 //    and must not be misrepresented as being the original software.
0020 //
0021 // 3. This notice may not be removed or altered from any source distribution.
0022 //
0023 ////////////////////////////////////////////////////////////
0024 
0025 #ifndef SFML_THREADLOCALPTR_HPP
0026 #define SFML_THREADLOCALPTR_HPP
0027 
0028 ////////////////////////////////////////////////////////////
0029 // Headers
0030 ////////////////////////////////////////////////////////////
0031 #include <SFML/System/ThreadLocal.hpp>
0032 
0033 
0034 namespace sf
0035 {
0036 ////////////////////////////////////////////////////////////
0037 /// \brief Pointer to a thread-local variable
0038 ///
0039 ////////////////////////////////////////////////////////////
0040 template <typename T>
0041 class ThreadLocalPtr : private ThreadLocal
0042 {
0043 public:
0044 
0045     ////////////////////////////////////////////////////////////
0046     /// \brief Default constructor
0047     ///
0048     /// \param value Optional value to initialize the variable
0049     ///
0050     ////////////////////////////////////////////////////////////
0051     ThreadLocalPtr(T* value = NULL);
0052 
0053     ////////////////////////////////////////////////////////////
0054     /// \brief Overload of unary operator *
0055     ///
0056     /// Like raw pointers, applying the * operator returns a
0057     /// reference to the pointed-to object.
0058     ///
0059     /// \return Reference to the thread-local variable
0060     ///
0061     ////////////////////////////////////////////////////////////
0062     T& operator *() const;
0063 
0064     ////////////////////////////////////////////////////////////
0065     /// \brief Overload of operator ->
0066     ///
0067     /// Similarly to raw pointers, applying the -> operator
0068     /// returns the pointed-to object.
0069     ///
0070     /// \return Pointer to the thread-local variable
0071     ///
0072     ////////////////////////////////////////////////////////////
0073     T* operator ->() const;
0074 
0075     ////////////////////////////////////////////////////////////
0076     /// \brief Conversion operator to implicitly convert the
0077     ///        pointer to its raw pointer type (T*)
0078     ///
0079     /// \return Pointer to the actual object
0080     ///
0081     ////////////////////////////////////////////////////////////
0082     operator T*() const;
0083 
0084     ////////////////////////////////////////////////////////////
0085     /// \brief Assignment operator for a raw pointer parameter
0086     ///
0087     /// \param value Pointer to assign
0088     ///
0089     /// \return Reference to self
0090     ///
0091     ////////////////////////////////////////////////////////////
0092     ThreadLocalPtr<T>& operator =(T* value);
0093 
0094     ////////////////////////////////////////////////////////////
0095     /// \brief Assignment operator for a ThreadLocalPtr parameter
0096     ///
0097     /// \param right ThreadLocalPtr to assign
0098     ///
0099     /// \return Reference to self
0100     ///
0101     ////////////////////////////////////////////////////////////
0102     ThreadLocalPtr<T>& operator =(const ThreadLocalPtr<T>& right);
0103 };
0104 
0105 } // namespace sf
0106 
0107 #include <SFML/System/ThreadLocalPtr.inl>
0108 
0109 
0110 #endif // SFML_THREADLOCALPTR_HPP
0111 
0112 
0113 ////////////////////////////////////////////////////////////
0114 /// \class sf::ThreadLocalPtr
0115 /// \ingroup system
0116 ///
0117 /// sf::ThreadLocalPtr is a type-safe wrapper for storing
0118 /// pointers to thread-local variables. A thread-local
0119 /// variable holds a different value for each different
0120 /// thread, unlike normal variables that are shared.
0121 ///
0122 /// Its usage is completely transparent, so that it is similar
0123 /// to manipulating the raw pointer directly (like any smart pointer).
0124 ///
0125 /// Usage example:
0126 /// \code
0127 /// MyClass object1;
0128 /// MyClass object2;
0129 /// sf::ThreadLocalPtr<MyClass> objectPtr;
0130 ///
0131 /// void thread1()
0132 /// {
0133 ///     objectPtr = &object1; // doesn't impact thread2
0134 ///     ...
0135 /// }
0136 ///
0137 /// void thread2()
0138 /// {
0139 ///     objectPtr = &object2; // doesn't impact thread1
0140 ///     ...
0141 /// }
0142 ///
0143 /// int main()
0144 /// {
0145 ///     // Create and launch the two threads
0146 ///     sf::Thread t1(&thread1);
0147 ///     sf::Thread t2(&thread2);
0148 ///     t1.launch();
0149 ///     t2.launch();
0150 ///
0151 ///     return 0;
0152 /// }
0153 /// \endcode
0154 ///
0155 /// ThreadLocalPtr is designed for internal use; however you
0156 /// can use it if you feel like it fits well your implementation.
0157 ///
0158 ////////////////////////////////////////////////////////////