|
1 | 1 | //////////////////////////////////////////////////////////// |
2 | 2 | // |
3 | 3 | // SFML - Simple and Fast Multimedia Library |
4 | | -// Copyright (C) 2007-2018 Laurent Gomila ([email protected]) |
| 4 | +// Copyright (C) 2007-2025 Laurent Gomila ([email protected]) |
5 | 5 | // |
6 | 6 | // This software is provided 'as-is', without any express or implied warranty. |
7 | 7 | // In no event will the authors be held liable for any damages arising from the use of this software. |
|
22 | 22 | // |
23 | 23 | //////////////////////////////////////////////////////////// |
24 | 24 |
|
25 | | -#ifndef SFML_THREADLOCAL_HPP |
26 | | -#define SFML_THREADLOCAL_HPP |
| 25 | +#pragma once |
27 | 26 |
|
28 | 27 | //////////////////////////////////////////////////////////// |
29 | 28 | // Headers |
30 | 29 | //////////////////////////////////////////////////////////// |
31 | | -#include <SFML/System/Export.hpp> |
32 | | -#include <SFML/System/NonCopyable.hpp> |
33 | | -#include <cstdlib> |
| 30 | +#include <SFML/Audio/Export.hpp> |
| 31 | + |
| 32 | +#include <memory> |
34 | 33 |
|
35 | 34 |
|
36 | 35 | namespace sf |
37 | 36 | { |
38 | | -namespace priv |
39 | | -{ |
40 | | - class ThreadLocalImpl; |
41 | | -} |
42 | | - |
43 | 37 | //////////////////////////////////////////////////////////// |
44 | | -/// \brief Defines variables with thread-local storage |
| 38 | +/// \brief Base class for classes that require an audio device |
45 | 39 | /// |
46 | 40 | //////////////////////////////////////////////////////////// |
47 | | -class SFML_SYSTEM_API ThreadLocal : NonCopyable |
| 41 | +class SFML_AUDIO_API AudioResource |
48 | 42 | { |
49 | 43 | public: |
50 | | - |
51 | 44 | //////////////////////////////////////////////////////////// |
52 | | - /// \brief Default constructor |
53 | | - /// |
54 | | - /// \param value Optional value to initialize the variable |
| 45 | + /// \brief Copy constructor |
55 | 46 | /// |
56 | 47 | //////////////////////////////////////////////////////////// |
57 | | - ThreadLocal(void* value = NULL); |
| 48 | + AudioResource(const AudioResource&) = default; |
58 | 49 |
|
59 | 50 | //////////////////////////////////////////////////////////// |
60 | | - /// \brief Destructor |
| 51 | + /// \brief Copy assignment |
61 | 52 | /// |
62 | 53 | //////////////////////////////////////////////////////////// |
63 | | - ~ThreadLocal(); |
| 54 | + AudioResource& operator=(const AudioResource&) = default; |
64 | 55 |
|
65 | 56 | //////////////////////////////////////////////////////////// |
66 | | - /// \brief Set the thread-specific value of the variable |
67 | | - /// |
68 | | - /// \param value Value of the variable for the current thread |
| 57 | + /// \brief Move constructor |
69 | 58 | /// |
70 | 59 | //////////////////////////////////////////////////////////// |
71 | | - void setValue(void* value); |
| 60 | + AudioResource(AudioResource&&) noexcept = default; |
72 | 61 |
|
73 | 62 | //////////////////////////////////////////////////////////// |
74 | | - /// \brief Retrieve the thread-specific value of the variable |
| 63 | + /// \brief Move assignment |
75 | 64 | /// |
76 | | - /// \return Value of the variable for the current thread |
| 65 | + //////////////////////////////////////////////////////////// |
| 66 | + AudioResource& operator=(AudioResource&&) noexcept = default; |
| 67 | + |
| 68 | +protected: |
| 69 | + //////////////////////////////////////////////////////////// |
| 70 | + /// \brief Default constructor |
77 | 71 | /// |
78 | 72 | //////////////////////////////////////////////////////////// |
79 | | - void* getValue() const; |
| 73 | + AudioResource(); |
80 | 74 |
|
81 | 75 | private: |
82 | | - |
83 | 76 | //////////////////////////////////////////////////////////// |
84 | 77 | // Member data |
85 | 78 | //////////////////////////////////////////////////////////// |
86 | | - priv::ThreadLocalImpl* m_impl; ///< Pointer to the OS specific implementation |
| 79 | + std::shared_ptr<void> m_device; //!< Sound device |
87 | 80 | }; |
88 | 81 |
|
89 | 82 | } // namespace sf |
90 | 83 |
|
91 | 84 |
|
92 | | -#endif // SFML_THREADLOCAL_HPP |
93 | | - |
94 | | - |
95 | 85 | //////////////////////////////////////////////////////////// |
96 | | -/// \class sf::ThreadLocal |
97 | | -/// \ingroup system |
| 86 | +/// \class sf::AudioResource |
| 87 | +/// \ingroup audio |
98 | 88 | /// |
99 | | -/// This class manipulates void* parameters and thus is not |
100 | | -/// appropriate for strongly-typed variables. You should rather |
101 | | -/// use the sf::ThreadLocalPtr template class. |
| 89 | +/// This class is for internal use only, it must be the base |
| 90 | +/// of every class that requires a valid audio device in |
| 91 | +/// order to work. |
102 | 92 | /// |
103 | 93 | //////////////////////////////////////////////////////////// |
0 commit comments