diff options
author | James Cowgill <james410@cowgill.org.uk> | 2014-12-09 20:21:40 +0000 |
---|---|---|
committer | James Cowgill <james410@cowgill.org.uk> | 2014-12-09 20:21:40 +0000 |
commit | fa21c65d0c764705cfc377bf0d0de08fac26874e (patch) | |
tree | dbc9e87bbd8684d15e79fc0c8b7a8985389c3b35 /src/SFML/System | |
parent | dd835931261c340acd5f0409341d13fa2670423e (diff) |
Imported Upstream version 2.2.0+dfsg
Diffstat (limited to 'src/SFML/System')
34 files changed, 2405 insertions, 1921 deletions
diff --git a/src/SFML/System/Android/Activity.cpp b/src/SFML/System/Android/Activity.cpp new file mode 100644 index 0000000..b5ba35d --- /dev/null +++ b/src/SFML/System/Android/Activity.cpp @@ -0,0 +1,69 @@ +//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2007-2013 Laurent Gomila (laurent.gom@gmail.com) +// Copyright (C) 2013 Jonathan De Wachter (dewachter.jonathan@gmail.com) +// +// This software is provided 'as-is', without any express or implied warranty. +// In no event will the authors be held liable for any damages arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it freely, +// subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; +// you must not claim that you wrote the original software. +// If you use this software in a product, an acknowledgment +// in the product documentation would be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, +// and must not be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. +// +//////////////////////////////////////////////////////////// + + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include <SFML/System/Android/Activity.hpp> +#include <android/log.h> + +#define LOGE(...) ((void)__android_log_print(ANDROID_LOG_INFO, "sfml-error", __VA_ARGS__)) + +LogcatStream::LogcatStream() : +std::streambuf() +{ + // Nothing to do +} + +std::streambuf::int_type LogcatStream::overflow (std::streambuf::int_type c) +{ + if (c == "\n"[0]) + { + m_message.push_back(c); + LOGE(m_message.c_str()); + m_message.clear(); + } + + m_message.push_back(c); + + return traits_type::not_eof(c); +} + +namespace sf +{ +namespace priv +{ +ActivityStates* getActivity(ActivityStates* initializedStates, bool reset) +{ + static ActivityStates* states = NULL; + + if (!states || reset) + states = initializedStates; + + return states; +} +} +} diff --git a/src/SFML/System/Android/Activity.hpp b/src/SFML/System/Android/Activity.hpp new file mode 100644 index 0000000..bd6bbc9 --- /dev/null +++ b/src/SFML/System/Android/Activity.hpp @@ -0,0 +1,101 @@ +//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2013 Jonathan De Wachter (dewachter.jonathan@gmail.com) +// +// This software is provided 'as-is', without any express or implied warranty. +// In no event will the authors be held liable for any damages arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it freely, +// subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; +// you must not claim that you wrote the original software. +// If you use this software in a product, an acknowledgment +// in the product documentation would be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, +// and must not be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. +// +//////////////////////////////////////////////////////////// + +#ifndef SFML_ACTIVITY_HPP +#define SFML_ACTIVITY_HPP + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include <SFML/Window/Event.hpp> +#include <SFML/Window/EglContext.hpp> +#include <SFML/System/Mutex.hpp> +#include <android/native_activity.h> +#include <android/configuration.h> +#include <EGL/egl.h> +#include <vector> +#include <map> +#include <string> +#include <fstream> + +class SFML_SYSTEM_API LogcatStream : public std::streambuf +{ +public: + LogcatStream(); + + std::streambuf::int_type overflow (std::streambuf::int_type c); + +private: + std::string m_message; +}; + +namespace sf +{ +namespace priv +{ +struct ActivityStates +{ + ANativeActivity* activity; + ANativeWindow* window; + + ALooper* looper; + AInputQueue* inputQueue; + AConfiguration* config; + + EGLDisplay display; + EglContext* context; + + void* savedState; + size_t savedStateSize; + + Mutex mutex; + + void (*forwardEvent)(const Event& event); + int (*processEvent)(int fd, int events, void* data); + + std::map<int, Vector2i> touchEvents; + Vector2i mousePosition; + bool isButtonPressed[Mouse::ButtonCount]; + + bool mainOver; + + Vector2i screenSize; + + bool initialized; + bool terminated; + + bool fullscreen; + + bool updated; + + LogcatStream logcat; +}; + +SFML_SYSTEM_API ActivityStates* getActivity(ActivityStates* initializedStates=NULL, bool reset=false); + +} // namespace priv +} // namespace sf + + +#endif // SFML_ACTIVITY_HPP diff --git a/src/SFML/System/Android/ResourceStream.cpp b/src/SFML/System/Android/ResourceStream.cpp new file mode 100644 index 0000000..abfa29e --- /dev/null +++ b/src/SFML/System/Android/ResourceStream.cpp @@ -0,0 +1,85 @@ +//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2013 Jonathan De Wachter (dewachter.jonathan@gmail.com) +// +// This software is provided 'as-is', without any express or implied warranty. +// In no event will the authors be held liable for any damages arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it freely, +// subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; +// you must not claim that you wrote the original software. +// If you use this software in a product, an acknowledgment +// in the product documentation would be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, +// and must not be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. +// +//////////////////////////////////////////////////////////// + + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include <SFML/System/Android/ResourceStream.hpp> +#include <SFML/System/Android/Activity.hpp> +#include <SFML/System/Lock.hpp> + + +namespace sf +{ +namespace priv +{ + +//////////////////////////////////////////////////////////// +ResourceStream::ResourceStream(const std::string& filename) : +m_file (NULL) +{ + ActivityStates* states = getActivity(NULL); + Lock(states->mutex); + m_file = AAssetManager_open(states->activity->assetManager, filename.c_str(), AASSET_MODE_UNKNOWN); +} + + +//////////////////////////////////////////////////////////// +ResourceStream::~ResourceStream() +{ + AAsset_close(m_file); +} + + +//////////////////////////////////////////////////////////// +Int64 ResourceStream::read(void *data, Int64 size) +{ + return AAsset_read(m_file, data, size); +} + + +//////////////////////////////////////////////////////////// +Int64 ResourceStream::seek(Int64 position) +{ + AAsset_seek(m_file, position, SEEK_SET); +} + + +//////////////////////////////////////////////////////////// +Int64 ResourceStream::tell() +{ + return getSize() - AAsset_getRemainingLength(m_file); +} + + +//////////////////////////////////////////////////////////// +Int64 ResourceStream::getSize() +{ + return AAsset_getLength(m_file); +} + + +} // namespace priv +} // namespace sf diff --git a/src/SFML/System/Android/ResourceStream.hpp b/src/SFML/System/Android/ResourceStream.hpp new file mode 100644 index 0000000..8f5829b --- /dev/null +++ b/src/SFML/System/Android/ResourceStream.hpp @@ -0,0 +1,113 @@ +//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2013 Jonathan De Wachter (dewachter.jonathan@gmail.com) +// +// This software is provided 'as-is', without any express or implied warranty. +// In no event will the authors be held liable for any damages arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it freely, +// subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; +// you must not claim that you wrote the original software. +// If you use this software in a product, an acknowledgment +// in the product documentation would be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, +// and must not be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. +// +//////////////////////////////////////////////////////////// + +#ifndef SFML_RESOURCESTREAM_HPP +#define SFML_RESOURCESTREAM_HPP + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include <SFML/System/Export.hpp> +#include <SFML/System/InputStream.hpp> +#include <android/asset_manager.h> +#include <string> + + +namespace sf +{ +namespace priv +{ +//////////////////////////////////////////////////////////// +/// \brief Read from Android asset files +/// +//////////////////////////////////////////////////////////// +class SFML_SYSTEM_API ResourceStream : public InputStream +{ +public: + + //////////////////////////////////////////////////////////// + /// \brief Default constructor + /// + /// \param filename Filename of the asset + /// + //////////////////////////////////////////////////////////// + ResourceStream(const std::string& filename); + + //////////////////////////////////////////////////////////// + /// \brief Destructor + /// + //////////////////////////////////////////////////////////// + ~ResourceStream(); + + //////////////////////////////////////////////////////////// + /// \brief Read data from the asset + /// + /// \param data Buffer where the asset data is copied + /// \param size Number of bytes read + /// + /// \return The number of bytes actually read, or -1 on error + /// + //////////////////////////////////////////////////////////// + Int64 read(void *data, Int64 size); + + //////////////////////////////////////////////////////////// + /// \brief Change the current reading position in the asset file + /// + /// \param position The position to seek to, from the beginning + /// + /// \return The position actually sought to, or -1 on error + /// + //////////////////////////////////////////////////////////// + Int64 seek(Int64 position); + + //////////////////////////////////////////////////////////// + /// \brief Get the current reading position in the asset file + /// + /// \return The current position, or -1 on error. + /// + //////////////////////////////////////////////////////////// + Int64 tell(); + + //////////////////////////////////////////////////////////// + /// \brief Return the size of the asset file + /// + /// \return The total number of bytes available in the asset, or -1 on error + /// + //////////////////////////////////////////////////////////// + Int64 getSize(); + +private: + + //////////////////////////////////////////////////////////// + // Member data + //////////////////////////////////////////////////////////// + AAsset* m_file; ///< The asset file to read +}; + +} // namespace priv + +} // namespace sf + + +#endif // SFML_RESOURCESTREAM_HPP diff --git a/src/SFML/System/CMakeLists.txt b/src/SFML/System/CMakeLists.txt index 5ef9139..74c95de 100644 --- a/src/SFML/System/CMakeLists.txt +++ b/src/SFML/System/CMakeLists.txt @@ -1,83 +1,99 @@ -
-set(INCROOT ${PROJECT_SOURCE_DIR}/include/SFML/System)
-set(SRCROOT ${PROJECT_SOURCE_DIR}/src/SFML/System)
-
-# all source files
-set(SRC
- ${SRCROOT}/Clock.cpp
- ${INCROOT}/Clock.hpp
- ${SRCROOT}/Err.cpp
- ${INCROOT}/Err.hpp
- ${INCROOT}/Export.hpp
- ${INCROOT}/InputStream.hpp
- ${SRCROOT}/Lock.cpp
- ${INCROOT}/Lock.hpp
- ${SRCROOT}/Mutex.cpp
- ${INCROOT}/Mutex.hpp
- ${INCROOT}/NonCopyable.hpp
- ${SRCROOT}/Sleep.cpp
- ${INCROOT}/Sleep.hpp
- ${SRCROOT}/String.cpp
- ${INCROOT}/String.hpp
- ${SRCROOT}/Thread.cpp
- ${INCROOT}/Thread.hpp
- ${INCROOT}/Thread.inl
- ${SRCROOT}/ThreadLocal.cpp
- ${INCROOT}/ThreadLocal.hpp
- ${INCROOT}/ThreadLocalPtr.hpp
- ${INCROOT}/ThreadLocalPtr.inl
- ${SRCROOT}/Time.cpp
- ${INCROOT}/Time.hpp
- ${INCROOT}/Utf.hpp
- ${INCROOT}/Utf.inl
- ${INCROOT}/Vector2.hpp
- ${INCROOT}/Vector2.inl
- ${INCROOT}/Vector3.hpp
- ${INCROOT}/Vector3.inl
-)
-source_group("" FILES ${SRC})
-
-# add platform specific sources
-if(WINDOWS)
- set(PLATFORM_SRC
- ${SRCROOT}/Win32/ClockImpl.cpp
- ${SRCROOT}/Win32/ClockImpl.hpp
- ${SRCROOT}/Win32/MutexImpl.cpp
- ${SRCROOT}/Win32/MutexImpl.hpp
- ${SRCROOT}/Win32/SleepImpl.cpp
- ${SRCROOT}/Win32/SleepImpl.hpp
- ${SRCROOT}/Win32/ThreadImpl.cpp
- ${SRCROOT}/Win32/ThreadImpl.hpp
- ${SRCROOT}/Win32/ThreadLocalImpl.cpp
- ${SRCROOT}/Win32/ThreadLocalImpl.hpp
- )
- source_group("windows" FILES ${PLATFORM_SRC})
-else()
- set(PLATFORM_SRC
- ${SRCROOT}/Unix/ClockImpl.cpp
- ${SRCROOT}/Unix/ClockImpl.hpp
- ${SRCROOT}/Unix/MutexImpl.cpp
- ${SRCROOT}/Unix/MutexImpl.hpp
- ${SRCROOT}/Unix/SleepImpl.cpp
- ${SRCROOT}/Unix/SleepImpl.hpp
- ${SRCROOT}/Unix/ThreadImpl.cpp
- ${SRCROOT}/Unix/ThreadImpl.hpp
- ${SRCROOT}/Unix/ThreadLocalImpl.cpp
- ${SRCROOT}/Unix/ThreadLocalImpl.hpp
- )
- source_group("unix" FILES ${PLATFORM_SRC})
-endif()
-
-# build the list of external libraries to link
-set(SYSTEM_EXT_LIBS)
-if(UNIX)
- set(SYSTEM_EXT_LIBS ${SYSTEM_EXT_LIBS} pthread)
-endif()
-if(LINUX)
- set(SYSTEM_EXT_LIBS ${SYSTEM_EXT_LIBS} rt)
-endif()
-
-# define the sfml-system target
-sfml_add_library(sfml-system
- SOURCES ${SRC} ${PLATFORM_SRC}
- EXTERNAL_LIBS ${SYSTEM_EXT_LIBS})
+ +set(INCROOT ${PROJECT_SOURCE_DIR}/include/SFML/System) +set(SRCROOT ${PROJECT_SOURCE_DIR}/src/SFML/System) + +# all source files +set(SRC + ${SRCROOT}/Clock.cpp + ${INCROOT}/Clock.hpp + ${SRCROOT}/Err.cpp + ${INCROOT}/Err.hpp + ${INCROOT}/Export.hpp + ${INCROOT}/InputStream.hpp + ${SRCROOT}/Lock.cpp + ${INCROOT}/Lock.hpp + ${SRCROOT}/Mutex.cpp + ${INCROOT}/Mutex.hpp + ${INCROOT}/NonCopyable.hpp + ${SRCROOT}/Sleep.cpp + ${INCROOT}/Sleep.hpp + ${SRCROOT}/String.cpp + ${INCROOT}/String.hpp + ${INCROOT}/String.inl + ${SRCROOT}/Thread.cpp + ${INCROOT}/Thread.hpp + ${INCROOT}/Thread.inl + ${SRCROOT}/ThreadLocal.cpp + ${INCROOT}/ThreadLocal.hpp + ${INCROOT}/ThreadLocalPtr.hpp + ${INCROOT}/ThreadLocalPtr.inl + ${SRCROOT}/Time.cpp + ${INCROOT}/Time.hpp + ${INCROOT}/Utf.hpp + ${INCROOT}/Utf.inl + ${INCROOT}/Vector2.hpp + ${INCROOT}/Vector2.inl + ${INCROOT}/Vector3.hpp + ${INCROOT}/Vector3.inl +) +source_group("" FILES ${SRC}) + +# add platform specific sources +if(SFML_OS_WINDOWS) + set(PLATFORM_SRC + ${SRCROOT}/Win32/ClockImpl.cpp + ${SRCROOT}/Win32/ClockImpl.hpp + ${SRCROOT}/Win32/MutexImpl.cpp + ${SRCROOT}/Win32/MutexImpl.hpp + ${SRCROOT}/Win32/SleepImpl.cpp + ${SRCROOT}/Win32/SleepImpl.hpp + ${SRCROOT}/Win32/ThreadImpl.cpp + ${SRCROOT}/Win32/ThreadImpl.hpp + ${SRCROOT}/Win32/ThreadLocalImpl.cpp + ${SRCROOT}/Win32/ThreadLocalImpl.hpp + ) + source_group("windows" FILES ${PLATFORM_SRC}) +else() + set(PLATFORM_SRC + ${SRCROOT}/Unix/ClockImpl.cpp + ${SRCROOT}/Unix/ClockImpl.hpp + ${SRCROOT}/Unix/MutexImpl.cpp + ${SRCROOT}/Unix/MutexImpl.hpp + ${SRCROOT}/Unix/SleepImpl.cpp + ${SRCROOT}/Unix/SleepImpl.hpp + ${SRCROOT}/Unix/ThreadImpl.cpp + ${SRCROOT}/Unix/ThreadImpl.hpp + ${SRCROOT}/Unix/ThreadLocalImpl.cpp + ${SRCROOT}/Unix/ThreadLocalImpl.hpp + ) + + if(SFML_OS_ANDROID) + set(PLATFORM_SRC ${PLATFORM_SRC} + ${SRCROOT}/Android/Activity.hpp + ${SRCROOT}/Android/Activity.cpp + ${SRCROOT}/Android/ResourceStream.cpp + ${SRCROOT}/Android/ResourceStream.cpp + ) + endif() + + source_group("unix" FILES ${PLATFORM_SRC}) +endif() + +# build the list of external libraries to link +if(SFML_OS_LINUX OR SFML_OS_FREEBSD OR SFML_OS_MACOSX) + list(APPEND SYSTEM_EXT_LIBS pthread) +endif() +if(SFML_OS_LINUX) + list(APPEND SYSTEM_EXT_LIBS rt) +endif() +if(SFML_OS_WINDOWS) + list(APPEND SYSTEM_EXT_LIBS winmm) +endif() +if(SFML_OS_ANDROID) + list(APPEND SYSTEM_EXT_LIBS android log) +endif() + +# define the sfml-system target +sfml_add_library(sfml-system + SOURCES ${SRC} ${PLATFORM_SRC} + EXTERNAL_LIBS ${SYSTEM_EXT_LIBS}) diff --git a/src/SFML/System/Clock.cpp b/src/SFML/System/Clock.cpp index de3c642..d6ccf24 100644 --- a/src/SFML/System/Clock.cpp +++ b/src/SFML/System/Clock.cpp @@ -1,63 +1,63 @@ -////////////////////////////////////////////////////////////
-//
-// SFML - Simple and Fast Multimedia Library
-// Copyright (C) 2007-2013 Laurent Gomila (laurent.gom@gmail.com)
-//
-// This software is provided 'as-is', without any express or implied warranty.
-// In no event will the authors be held liable for any damages arising from the use of this software.
-//
-// Permission is granted to anyone to use this software for any purpose,
-// including commercial applications, and to alter it and redistribute it freely,
-// subject to the following restrictions:
-//
-// 1. The origin of this software must not be misrepresented;
-// you must not claim that you wrote the original software.
-// If you use this software in a product, an acknowledgment
-// in the product documentation would be appreciated but is not required.
-//
-// 2. Altered source versions must be plainly marked as such,
-// and must not be misrepresented as being the original software.
-//
-// 3. This notice may not be removed or altered from any source distribution.
-//
-////////////////////////////////////////////////////////////
-
-////////////////////////////////////////////////////////////
-// Headers
-////////////////////////////////////////////////////////////
-#include <SFML/System/Clock.hpp>
-
-#if defined(SFML_SYSTEM_WINDOWS)
- #include <SFML/System/Win32/ClockImpl.hpp>
-#else
- #include <SFML/System/Unix/ClockImpl.hpp>
-#endif
-
-
-namespace sf
-{
-////////////////////////////////////////////////////////////
-Clock::Clock() :
-m_startTime(priv::ClockImpl::getCurrentTime())
-{
-}
-
-
-////////////////////////////////////////////////////////////
-Time Clock::getElapsedTime() const
-{
- return priv::ClockImpl::getCurrentTime() - m_startTime;
-}
-
-
-////////////////////////////////////////////////////////////
-Time Clock::restart()
-{
- Time now = priv::ClockImpl::getCurrentTime();
- Time elapsed = now - m_startTime;
- m_startTime = now;
-
- return elapsed;
-}
-
-} // namespace sf
+//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com) +// +// This software is provided 'as-is', without any express or implied warranty. +// In no event will the authors be held liable for any damages arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it freely, +// subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; +// you must not claim that you wrote the original software. +// If you use this software in a product, an acknowledgment +// in the product documentation would be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, +// and must not be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. +// +//////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include <SFML/System/Clock.hpp> + +#if defined(SFML_SYSTEM_WINDOWS) + #include <SFML/System/Win32/ClockImpl.hpp> +#else + #include <SFML/System/Unix/ClockImpl.hpp> +#endif + + +namespace sf +{ +//////////////////////////////////////////////////////////// +Clock::Clock() : +m_startTime(priv::ClockImpl::getCurrentTime()) +{ +} + + +//////////////////////////////////////////////////////////// +Time Clock::getElapsedTime() const +{ + return priv::ClockImpl::getCurrentTime() - m_startTime; +} + + +//////////////////////////////////////////////////////////// +Time Clock::restart() +{ + Time now = priv::ClockImpl::getCurrentTime(); + Time elapsed = now - m_startTime; + m_startTime = now; + + return elapsed; +} + +} // namespace sf diff --git a/src/SFML/System/Err.cpp b/src/SFML/System/Err.cpp index a1224dd..1a38986 100644 --- a/src/SFML/System/Err.cpp +++ b/src/SFML/System/Err.cpp @@ -1,110 +1,110 @@ -////////////////////////////////////////////////////////////
-//
-// SFML - Simple and Fast Multimedia Library
-// Copyright (C) 2007-2013 Laurent Gomila (laurent.gom@gmail.com)
-//
-// This software is provided 'as-is', without any express or implied warranty.
-// In no event will the authors be held liable for any damages arising from the use of this software.
-//
-// Permission is granted to anyone to use this software for any purpose,
-// including commercial applications, and to alter it and redistribute it freely,
-// subject to the following restrictions:
-//
-// 1. The origin of this software must not be misrepresented;
-// you must not claim that you wrote the original software.
-// If you use this software in a product, an acknowledgment
-// in the product documentation would be appreciated but is not required.
-//
-// 2. Altered source versions must be plainly marked as such,
-// and must not be misrepresented as being the original software.
-//
-// 3. This notice may not be removed or altered from any source distribution.
-//
-////////////////////////////////////////////////////////////
-
-////////////////////////////////////////////////////////////
-// Headers
-////////////////////////////////////////////////////////////
-#include <SFML/System/Err.hpp>
-#include <streambuf>
-#include <cstdio>
-
-
-namespace
-{
-// This class will be used as the default streambuf of sf::Err,
-// it outputs to stderr by default (to keep the default behaviour)
-class DefaultErrStreamBuf : public std::streambuf
-{
-public :
-
- DefaultErrStreamBuf()
- {
- // Allocate the write buffer
- static const int size = 64;
- char* buffer = new char[size];
- setp(buffer, buffer + size);
- }
-
- ~DefaultErrStreamBuf()
- {
- // Synchronize
- sync();
-
- // Delete the write buffer
- delete[] pbase();
- }
-
-private :
-
- virtual int overflow(int character)
- {
- if ((character != EOF) && (pptr() != epptr()))
- {
- // Valid character
- return sputc(static_cast<char>(character));
- }
- else if (character != EOF)
- {
- // Not enough space in the buffer: synchronize output and try again
- sync();
- return overflow(character);
- }
- else
- {
- // Invalid character: synchronize output
- return sync();
- }
- }
-
- virtual int sync()
- {
- // Check if there is something into the write buffer
- if (pbase() != pptr())
- {
- // Print the contents of the write buffer into the standard error output
- std::size_t size = static_cast<int>(pptr() - pbase());
- fwrite(pbase(), 1, size, stderr);
-
- // Reset the pointer position to the beginning of the write buffer
- setp(pbase(), epptr());
- }
-
- return 0;
- }
-};
-}
-
-namespace sf
-{
-////////////////////////////////////////////////////////////
-std::ostream& err()
-{
- static DefaultErrStreamBuf buffer;
- static std::ostream stream(&buffer);
-
- return stream;
-}
-
-
-} // namespace sf
+//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com) +// +// This software is provided 'as-is', without any express or implied warranty. +// In no event will the authors be held liable for any damages arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it freely, +// subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; +// you must not claim that you wrote the original software. +// If you use this software in a product, an acknowledgment +// in the product documentation would be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, +// and must not be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. +// +//////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include <SFML/System/Err.hpp> +#include <streambuf> +#include <cstdio> + + +namespace +{ +// This class will be used as the default streambuf of sf::Err, +// it outputs to stderr by default (to keep the default behavior) +class DefaultErrStreamBuf : public std::streambuf +{ +public: + + DefaultErrStreamBuf() + { + // Allocate the write buffer + static const int size = 64; + char* buffer = new char[size]; + setp(buffer, buffer + size); + } + + ~DefaultErrStreamBuf() + { + // Synchronize + sync(); + + // Delete the write buffer + delete[] pbase(); + } + +private: + + virtual int overflow(int character) + { + if ((character != EOF) && (pptr() != epptr())) + { + // Valid character + return sputc(static_cast<char>(character)); + } + else if (character != EOF) + { + // Not enough space in the buffer: synchronize output and try again + sync(); + return overflow(character); + } + else + { + // Invalid character: synchronize output + return sync(); + } + } + + virtual int sync() + { + // Check if there is something into the write buffer + if (pbase() != pptr()) + { + // Print the contents of the write buffer into the standard error output + std::size_t size = static_cast<int>(pptr() - pbase()); + fwrite(pbase(), 1, size, stderr); + + // Reset the pointer position to the beginning of the write buffer + setp(pbase(), epptr()); + } + + return 0; + } +}; +} + +namespace sf +{ +//////////////////////////////////////////////////////////// +std::ostream& err() +{ + static DefaultErrStreamBuf buffer; + static std::ostream stream(&buffer); + + return stream; +} + + +} // namespace sf diff --git a/src/SFML/System/Lock.cpp b/src/SFML/System/Lock.cpp index 17b1aa2..68a85de 100644 --- a/src/SFML/System/Lock.cpp +++ b/src/SFML/System/Lock.cpp @@ -1,48 +1,48 @@ -////////////////////////////////////////////////////////////
-//
-// SFML - Simple and Fast Multimedia Library
-// Copyright (C) 2007-2013 Laurent Gomila (laurent.gom@gmail.com)
-//
-// This software is provided 'as-is', without any express or implied warranty.
-// In no event will the authors be held liable for any damages arising from the use of this software.
-//
-// Permission is granted to anyone to use this software for any purpose,
-// including commercial applications, and to alter it and redistribute it freely,
-// subject to the following restrictions:
-//
-// 1. The origin of this software must not be misrepresented;
-// you must not claim that you wrote the original software.
-// If you use this software in a product, an acknowledgment
-// in the product documentation would be appreciated but is not required.
-//
-// 2. Altered source versions must be plainly marked as such,
-// and must not be misrepresented as being the original software.
-//
-// 3. This notice may not be removed or altered from any source distribution.
-//
-////////////////////////////////////////////////////////////
-
-////////////////////////////////////////////////////////////
-// Headers
-////////////////////////////////////////////////////////////
-#include <SFML/System/Lock.hpp>
-#include <SFML/System/Mutex.hpp>
-
-
-namespace sf
-{
-////////////////////////////////////////////////////////////
-Lock::Lock(Mutex& mutex) :
-m_mutex(mutex)
-{
- m_mutex.lock();
-}
-
-
-////////////////////////////////////////////////////////////
-Lock::~Lock()
-{
- m_mutex.unlock();
-}
-
-} // namespace sf
+//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com) +// +// This software is provided 'as-is', without any express or implied warranty. +// In no event will the authors be held liable for any damages arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it freely, +// subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; +// you must not claim that you wrote the original software. +// If you use this software in a product, an acknowledgment +// in the product documentation would be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, +// and must not be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. +// +//////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include <SFML/System/Lock.hpp> +#include <SFML/System/Mutex.hpp> + + +namespace sf +{ +//////////////////////////////////////////////////////////// +Lock::Lock(Mutex& mutex) : +m_mutex(mutex) +{ + m_mutex.lock(); +} + + +//////////////////////////////////////////////////////////// +Lock::~Lock() +{ + m_mutex.unlock(); +} + +} // namespace sf diff --git a/src/SFML/System/Mutex.cpp b/src/SFML/System/Mutex.cpp index e08e25b..c339004 100644 --- a/src/SFML/System/Mutex.cpp +++ b/src/SFML/System/Mutex.cpp @@ -1,66 +1,66 @@ -////////////////////////////////////////////////////////////
-//
-// SFML - Simple and Fast Multimedia Library
-// Copyright (C) 2007-2013 Laurent Gomila (laurent.gom@gmail.com)
-//
-// This software is provided 'as-is', without any express or implied warranty.
-// In no event will the authors be held liable for any damages arising from the use of this software.
-//
-// Permission is granted to anyone to use this software for any purpose,
-// including commercial applications, and to alter it and redistribute it freely,
-// subject to the following restrictions:
-//
-// 1. The origin of this software must not be misrepresented;
-// you must not claim that you wrote the original software.
-// If you use this software in a product, an acknowledgment
-// in the product documentation would be appreciated but is not required.
-//
-// 2. Altered source versions must be plainly marked as such,
-// and must not be misrepresented as being the original software.
-//
-// 3. This notice may not be removed or altered from any source distribution.
-//
-////////////////////////////////////////////////////////////
-
-////////////////////////////////////////////////////////////
-// Headers
-////////////////////////////////////////////////////////////
-#include <SFML/System/Mutex.hpp>
-
-#if defined(SFML_SYSTEM_WINDOWS)
- #include <SFML/System/Win32/MutexImpl.hpp>
-#else
- #include <SFML/System/Unix/MutexImpl.hpp>
-#endif
-
-
-namespace sf
-{
-////////////////////////////////////////////////////////////
-Mutex::Mutex()
-{
- m_mutexImpl = new priv::MutexImpl;
-}
-
-
-////////////////////////////////////////////////////////////
-Mutex::~Mutex()
-{
- delete m_mutexImpl;
-}
-
-
-////////////////////////////////////////////////////////////
-void Mutex::lock()
-{
- m_mutexImpl->lock();
-}
-
-
-////////////////////////////////////////////////////////////
-void Mutex::unlock()
-{
- m_mutexImpl->unlock();
-}
-
-} // namespace sf
+//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com) +// +// This software is provided 'as-is', without any express or implied warranty. +// In no event will the authors be held liable for any damages arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it freely, +// subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; +// you must not claim that you wrote the original software. +// If you use this software in a product, an acknowledgment +// in the product documentation would be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, +// and must not be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. +// +//////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include <SFML/System/Mutex.hpp> + +#if defined(SFML_SYSTEM_WINDOWS) + #include <SFML/System/Win32/MutexImpl.hpp> +#else + #include <SFML/System/Unix/MutexImpl.hpp> +#endif + + +namespace sf +{ +//////////////////////////////////////////////////////////// +Mutex::Mutex() +{ + m_mutexImpl = new priv::MutexImpl; +} + + +//////////////////////////////////////////////////////////// +Mutex::~Mutex() +{ + delete m_mutexImpl; +} + + +//////////////////////////////////////////////////////////// +void Mutex::lock() +{ + m_mutexImpl->lock(); +} + + +//////////////////////////////////////////////////////////// +void Mutex::unlock() +{ + m_mutexImpl->unlock(); +} + +} // namespace sf diff --git a/src/SFML/System/Sleep.cpp b/src/SFML/System/Sleep.cpp index 9415ade..0bd375f 100644 --- a/src/SFML/System/Sleep.cpp +++ b/src/SFML/System/Sleep.cpp @@ -1,46 +1,46 @@ -////////////////////////////////////////////////////////////
-//
-// SFML - Simple and Fast Multimedia Library
-// Copyright (C) 2007-2013 Laurent Gomila (laurent.gom@gmail.com)
-//
-// This software is provided 'as-is', without any express or implied warranty.
-// In no event will the authors be held liable for any damages arising from the use of this software.
-//
-// Permission is granted to anyone to use this software for any purpose,
-// including commercial applications, and to alter it and redistribute it freely,
-// subject to the following restrictions:
-//
-// 1. The origin of this software must not be misrepresented;
-// you must not claim that you wrote the original software.
-// If you use this software in a product, an acknowledgment
-// in the product documentation would be appreciated but is not required.
-//
-// 2. Altered source versions must be plainly marked as such,
-// and must not be misrepresented as being the original software.
-//
-// 3. This notice may not be removed or altered from any source distribution.
-//
-////////////////////////////////////////////////////////////
-
-////////////////////////////////////////////////////////////
-// Headers
-////////////////////////////////////////////////////////////
-#include <SFML/System/Sleep.hpp>
-
-#if defined(SFML_SYSTEM_WINDOWS)
- #include <SFML/System/Win32/SleepImpl.hpp>
-#else
- #include <SFML/System/Unix/SleepImpl.hpp>
-#endif
-
-
-namespace sf
-{
-////////////////////////////////////////////////////////////
-void sleep(Time duration)
-{
- if (duration >= Time::Zero)
- priv::sleepImpl(duration);
-}
-
-} // namespace sf
+//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com) +// +// This software is provided 'as-is', without any express or implied warranty. +// In no event will the authors be held liable for any damages arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it freely, +// subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; +// you must not claim that you wrote the original software. +// If you use this software in a product, an acknowledgment +// in the product documentation would be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, +// and must not be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. +// +//////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include <SFML/System/Sleep.hpp> + +#if defined(SFML_SYSTEM_WINDOWS) + #include <SFML/System/Win32/SleepImpl.hpp> +#else + #include <SFML/System/Unix/SleepImpl.hpp> +#endif + + +namespace sf +{ +//////////////////////////////////////////////////////////// +void sleep(Time duration) +{ + if (duration >= Time::Zero) + priv::sleepImpl(duration); +} + +} // namespace sf diff --git a/src/SFML/System/String.cpp b/src/SFML/System/String.cpp index b4ee135..f0753dc 100644 --- a/src/SFML/System/String.cpp +++ b/src/SFML/System/String.cpp @@ -1,335 +1,400 @@ -////////////////////////////////////////////////////////////
-//
-// SFML - Simple and Fast Multimedia Library
-// Copyright (C) 2007-2013 Laurent Gomila (laurent.gom@gmail.com)
-//
-// This software is provided 'as-is', without any express or implied warranty.
-// In no event will the authors be held liable for any damages arising from the use of this software.
-//
-// Permission is granted to anyone to use this software for any purpose,
-// including commercial applications, and to alter it and redistribute it freely,
-// subject to the following restrictions:
-//
-// 1. The origin of this software must not be misrepresented;
-// you must not claim that you wrote the original software.
-// If you use this software in a product, an acknowledgment
-// in the product documentation would be appreciated but is not required.
-//
-// 2. Altered source versions must be plainly marked as such,
-// and must not be misrepresented as being the original software.
-//
-// 3. This notice may not be removed or altered from any source distribution.
-//
-////////////////////////////////////////////////////////////
-
-////////////////////////////////////////////////////////////
-// Headers
-////////////////////////////////////////////////////////////
-#include <SFML/System/String.hpp>
-#include <SFML/System/Utf.hpp>
-#include <iterator>
-#include <cstring>
-
-
-namespace sf
-{
-////////////////////////////////////////////////////////////
-const std::size_t String::InvalidPos = std::basic_string<Uint32>::npos;
-
-
-////////////////////////////////////////////////////////////
-String::String()
-{
-}
-
-
-////////////////////////////////////////////////////////////
-String::String(char ansiChar, const std::locale& locale)
-{
- m_string += Utf32::decodeAnsi(ansiChar, locale);
-}
-
-
-////////////////////////////////////////////////////////////
-String::String(wchar_t wideChar)
-{
- m_string += Utf32::decodeWide(wideChar);
-}
-
-
-////////////////////////////////////////////////////////////
-String::String(Uint32 utf32Char)
-{
- m_string += utf32Char;
-}
-
-
-////////////////////////////////////////////////////////////
-String::String(const char* ansiString, const std::locale& locale)
-{
- if (ansiString)
- {
- std::size_t length = strlen(ansiString);
- if (length > 0)
- {
- m_string.reserve(length + 1);
- Utf32::fromAnsi(ansiString, ansiString + length, std::back_inserter(m_string), locale);
- }
- }
-}
-
-
-////////////////////////////////////////////////////////////
-String::String(const std::string& ansiString, const std::locale& locale)
-{
- m_string.reserve(ansiString.length() + 1);
- Utf32::fromAnsi(ansiString.begin(), ansiString.end(), std::back_inserter(m_string), locale);
-}
-
-
-////////////////////////////////////////////////////////////
-String::String(const wchar_t* wideString)
-{
- if (wideString)
- {
- std::size_t length = std::wcslen(wideString);
- if (length > 0)
- {
- m_string.reserve(length + 1);
- Utf32::fromWide(wideString, wideString + length, std::back_inserter(m_string));
- }
- }
-}
-
-
-////////////////////////////////////////////////////////////
-String::String(const std::wstring& wideString)
-{
- m_string.reserve(wideString.length() + 1);
- Utf32::fromWide(wideString.begin(), wideString.end(), std::back_inserter(m_string));
-}
-
-
-////////////////////////////////////////////////////////////
-String::String(const Uint32* utf32String)
-{
- if (utf32String)
- m_string = utf32String;
-}
-
-
-////////////////////////////////////////////////////////////
-String::String(const std::basic_string<Uint32>& utf32String) :
-m_string(utf32String)
-{
-}
-
-
-////////////////////////////////////////////////////////////
-String::String(const String& copy) :
-m_string(copy.m_string)
-{
-}
-
-
-////////////////////////////////////////////////////////////
-String::operator std::string() const
-{
- return toAnsiString();
-}
-
-
-////////////////////////////////////////////////////////////
-String::operator std::wstring() const
-{
- return toWideString();
-}
-
-
-////////////////////////////////////////////////////////////
-std::string String::toAnsiString(const std::locale& locale) const
-{
- // Prepare the output string
- std::string output;
- output.reserve(m_string.length() + 1);
-
- // Convert
- Utf32::toAnsi(m_string.begin(), m_string.end(), std::back_inserter(output), 0, locale);
-
- return output;
-}
-
-
-////////////////////////////////////////////////////////////
-std::wstring String::toWideString() const
-{
- // Prepare the output string
- std::wstring output;
- output.reserve(m_string.length() + 1);
-
- // Convert
- Utf32::toWide(m_string.begin(), m_string.end(), std::back_inserter(output), 0);
-
- return output;
-}
-
-
-////////////////////////////////////////////////////////////
-String& String::operator =(const String& right)
-{
- m_string = right.m_string;
- return *this;
-}
-
-
-////////////////////////////////////////////////////////////
-String& String::operator +=(const String& right)
-{
- m_string += right.m_string;
- return *this;
-}
-
-
-////////////////////////////////////////////////////////////
-Uint32 String::operator [](std::size_t index) const
-{
- return m_string[index];
-}
-
-
-////////////////////////////////////////////////////////////
-Uint32& String::operator [](std::size_t index)
-{
- return m_string[index];
-}
-
-
-////////////////////////////////////////////////////////////
-void String::clear()
-{
- m_string.clear();
-}
-
-
-////////////////////////////////////////////////////////////
-std::size_t String::getSize() const
-{
- return m_string.size();
-}
-
-
-////////////////////////////////////////////////////////////
-bool String::isEmpty() const
-{
- return m_string.empty();
-}
-
-
-////////////////////////////////////////////////////////////
-void String::erase(std::size_t position, std::size_t count)
-{
- m_string.erase(position, count);
-}
-
-
-////////////////////////////////////////////////////////////
-void String::insert(std::size_t position, const String& str)
-{
- m_string.insert(position, str.m_string);
-}
-
-
-////////////////////////////////////////////////////////////
-std::size_t String::find(const String& str, std::size_t start) const
-{
- return m_string.find(str.m_string, start);
-}
-
-
-////////////////////////////////////////////////////////////
-const Uint32* String::getData() const
-{
- return m_string.c_str();
-}
-
-
-////////////////////////////////////////////////////////////
-String::Iterator String::begin()
-{
- return m_string.begin();
-}
-
-
-////////////////////////////////////////////////////////////
-String::ConstIterator String::begin() const
-{
- return m_string.begin();
-}
-
-
-////////////////////////////////////////////////////////////
-String::Iterator String::end()
-{
- return m_string.end();
-}
-
-
-////////////////////////////////////////////////////////////
-String::ConstIterator String::end() const
-{
- return m_string.end();
-}
-
-
-////////////////////////////////////////////////////////////
-bool operator ==(const String& left, const String& right)
-{
- return left.m_string == right.m_string;
-}
-
-
-////////////////////////////////////////////////////////////
-bool operator !=(const String& left, const String& right)
-{
- return !(left == right);
-}
-
-
-////////////////////////////////////////////////////////////
-bool operator <(const String& left, const String& right)
-{
- return left.m_string < right.m_string;
-}
-
-
-////////////////////////////////////////////////////////////
-bool operator >(const String& left, const String& right)
-{
- return right < left;
-}
-
-
-////////////////////////////////////////////////////////////
-bool operator <=(const String& left, const String& right)
-{
- return !(right < left);
-}
-
-
-////////////////////////////////////////////////////////////
-bool operator >=(const String& left, const String& right)
-{
- return !(left < right);
-}
-
-
-////////////////////////////////////////////////////////////
-String operator +(const String& left, const String& right)
-{
- String string = left;
- string += right;
-
- return string;
-}
-
-} // namespace sf
+//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com) +// +// This software is provided 'as-is', without any express or implied warranty. +// In no event will the authors be held liable for any damages arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it freely, +// subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; +// you must not claim that you wrote the original software. +// If you use this software in a product, an acknowledgment +// in the product documentation would be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, +// and must not be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. +// +//////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include <SFML/System/String.hpp> +#include <SFML/System/Utf.hpp> +#include <iterator> +#include <cstring> + + +namespace sf +{ +//////////////////////////////////////////////////////////// +const std::size_t String::InvalidPos = std::basic_string<Uint32>::npos; + + +//////////////////////////////////////////////////////////// +String::String() +{ +} + + +//////////////////////////////////////////////////////////// +String::String(char ansiChar, const std::locale& locale) +{ + m_string += Utf32::decodeAnsi(ansiChar, locale); +} + + +//////////////////////////////////////////////////////////// +String::String(wchar_t wideChar) +{ + m_string += Utf32::decodeWide(wideChar); +} + + +//////////////////////////////////////////////////////////// +String::String(Uint32 utf32Char) +{ + m_string += utf32Char; +} + + +//////////////////////////////////////////////////////////// +String::String(const char* ansiString, const std::locale& locale) +{ + if (ansiString) + { + std::size_t length = strlen(ansiString); + if (length > 0) + { + m_string.reserve(length + 1); + Utf32::fromAnsi(ansiString, ansiString + length, std::back_inserter(m_string), locale); + } + } +} + + +//////////////////////////////////////////////////////////// +String::String(const std::string& ansiString, const std::locale& locale) +{ + m_string.reserve(ansiString.length() + 1); + Utf32::fromAnsi(ansiString.begin(), ansiString.end(), std::back_inserter(m_string), locale); +} + + +//////////////////////////////////////////////////////////// +String::String(const wchar_t* wideString) +{ + if (wideString) + { + std::size_t length = std::wcslen(wideString); + if (length > 0) + { + m_string.reserve(length + 1); + Utf32::fromWide(wideString, wideString + length, std::back_inserter(m_string)); + } + } +} + + +//////////////////////////////////////////////////////////// +String::String(const std::wstring& wideString) +{ + m_string.reserve(wideString.length() + 1); + Utf32::fromWide(wideString.begin(), wideString.end(), std::back_inserter(m_string)); +} + + +//////////////////////////////////////////////////////////// +String::String(const Uint32* utf32String) +{ + if (utf32String) + m_string = utf32String; +} + + +//////////////////////////////////////////////////////////// +String::String(const std::basic_string<Uint32>& utf32String) : +m_string(utf32String) +{ +} + + +//////////////////////////////////////////////////////////// +String::String(const String& copy) : +m_string(copy.m_string) +{ +} + + +//////////////////////////////////////////////////////////// +String::operator std::string() const +{ + return toAnsiString(); +} + + +//////////////////////////////////////////////////////////// +String::operator std::wstring() const +{ + return toWideString(); +} + + +//////////////////////////////////////////////////////////// +std::string String::toAnsiString(const std::locale& locale) const +{ + // Prepare the output string + std::string output; + output.reserve(m_string.length() + 1); + + // Convert + Utf32::toAnsi(m_string.begin(), m_string.end(), std::back_inserter(output), 0, locale); + + return output; +} + + +//////////////////////////////////////////////////////////// +std::wstring String::toWideString() const +{ + // Prepare the output string + std::wstring output; + output.reserve(m_string.length() + 1); + + // Convert + Utf32::toWide(m_string.begin(), m_string.end(), std::back_inserter(output), 0); + + return output; +} + + +//////////////////////////////////////////////////////////// +std::basic_string<Uint8> String::toUtf8() const +{ + // Prepare the output string + std::basic_string<Uint8> output; + output.reserve(m_string.length()); + + // Convert + Utf32::toUtf8(m_string.begin(), m_string.end(), std::back_inserter(output)); + + return output; +} + + +//////////////////////////////////////////////////////////// +std::basic_string<Uint16> String::toUtf16() const +{ + // Prepare the output string + std::basic_string<Uint16> output; + output.reserve(m_string.length()); + + // Convert + Utf32::toUtf16(m_string.begin(), m_string.end(), std::back_inserter(output)); + + return output; +} + + +//////////////////////////////////////////////////////////// +std::basic_string<Uint32> String::toUtf32() const +{ + return m_string; +} + + +//////////////////////////////////////////////////////////// +String& String::operator =(const String& right) +{ + m_string = right.m_string; + return *this; +} + + +//////////////////////////////////////////////////////////// +String& String::operator +=(const String& right) +{ + m_string += right.m_string; + return *this; +} + + +//////////////////////////////////////////////////////////// +Uint32 String::operator [](std::size_t index) const +{ + return m_string[index]; +} + + +//////////////////////////////////////////////////////////// +Uint32& String::operator [](std::size_t index) +{ + return m_string[index]; +} + + +//////////////////////////////////////////////////////////// +void String::clear() +{ + m_string.clear(); +} + + +//////////////////////////////////////////////////////////// +std::size_t String::getSize() const +{ + return m_string.size(); +} + + +//////////////////////////////////////////////////////////// +bool String::isEmpty() const +{ + return m_string.empty(); +} + + +//////////////////////////////////////////////////////////// +void String::erase(std::size_t position, std::size_t count) +{ + m_string.erase(position, count); +} + + +//////////////////////////////////////////////////////////// +void String::insert(std::size_t position, const String& str) +{ + m_string.insert(position, str.m_string); +} + + +//////////////////////////////////////////////////////////// +std::size_t String::find(const String& str, std::size_t start) const +{ + return m_string.find(str.m_string, start); +} + + +//////////////////////////////////////////////////////////// +void String::replace(std::size_t position, std::size_t length, const String& replaceWith) +{ + m_string.replace(position, length, replaceWith.m_string); +} + + +//////////////////////////////////////////////////////////// +void String::replace(const String& searchFor, const String& replaceWith) +{ + std::size_t step = replaceWith.getSize(); + std::size_t len = searchFor.getSize(); + std::size_t pos = find(searchFor); + + // Replace each occurrence of search + while (pos != InvalidPos) + { + replace(pos, len, replaceWith); + pos = find(searchFor, pos + step); + } +} + + +//////////////////////////////////////////////////////////// +String String::substring(std::size_t position, std::size_t length) const +{ + return m_string.substr(position, length); +} + + +//////////////////////////////////////////////////////////// +const Uint32* String::getData() const +{ + return m_string.c_str(); +} + + +//////////////////////////////////////////////////////////// +String::Iterator String::begin() +{ + return m_string.begin(); +} + + +//////////////////////////////////////////////////////////// +String::ConstIterator String::begin() const +{ + return m_string.begin(); +} + + +//////////////////////////////////////////////////////////// +String::Iterator String::end() +{ + return m_string.end(); +} + + +//////////////////////////////////////////////////////////// +String::ConstIterator String::end() const +{ + return m_string.end(); +} + + +//////////////////////////////////////////////////////////// +bool operator ==(const String& left, const String& right) +{ + return left.m_string == right.m_string; +} + + +//////////////////////////////////////////////////////////// +bool operator !=(const String& left, const String& right) +{ + return !(left == right); +} + + +//////////////////////////////////////////////////////////// +bool operator <(const String& left, const String& right) +{ + return left.m_string < right.m_string; +} + + +//////////////////////////////////////////////////////////// +bool operator >(const String& left, const String& right) +{ + return right < left; +} + + +//////////////////////////////////////////////////////////// +bool operator <=(const String& left, const String& right) +{ + return !(right < left); +} + + +//////////////////////////////////////////////////////////// +bool operator >=(const String& left, const String& right) +{ + return !(left < right); +} + + +//////////////////////////////////////////////////////////// +String operator +(const String& left, const String& right) +{ + String string = left; + string += right; + + return string; +} + +} // namespace sf diff --git a/src/SFML/System/Thread.cpp b/src/SFML/System/Thread.cpp index 69bf077..4345802 100644 --- a/src/SFML/System/Thread.cpp +++ b/src/SFML/System/Thread.cpp @@ -1,86 +1,86 @@ -////////////////////////////////////////////////////////////
-//
-// SFML - Simple and Fast Multimedia Library
-// Copyright (C) 2007-2013 Laurent Gomila (laurent.gom@gmail.com)
-//
-// This software is provided 'as-is', without any express or implied warranty.
-// In no event will the authors be held liable for any damages arising from the use of this software.
-//
-// Permission is granted to anyone to use this software for any purpose,
-// including commercial applications, and to alter it and redistribute it freely,
-// subject to the following restrictions:
-//
-// 1. The origin of this software must not be misrepresented;
-// you must not claim that you wrote the original software.
-// If you use this software in a product, an acknowledgment
-// in the product documentation would be appreciated but is not required.
-//
-// 2. Altered source versions must be plainly marked as such,
-// and must not be misrepresented as being the original software.
-//
-// 3. This notice may not be removed or altered from any source distribution.
-//
-////////////////////////////////////////////////////////////
-
-////////////////////////////////////////////////////////////
-// Headers
-////////////////////////////////////////////////////////////
-#include <SFML/System/Thread.hpp>
-
-
-#if defined(SFML_SYSTEM_WINDOWS)
- #include <SFML/System/Win32/ThreadImpl.hpp>
-#else
- #include <SFML/System/Unix/ThreadImpl.hpp>
-#endif
-
-
-namespace sf
-{
-////////////////////////////////////////////////////////////
-Thread::~Thread()
-{
- wait();
- delete m_entryPoint;
-}
-
-
-////////////////////////////////////////////////////////////
-void Thread::launch()
-{
- wait();
- m_impl = new priv::ThreadImpl(this);
-}
-
-
-////////////////////////////////////////////////////////////
-void Thread::wait()
-{
- if (m_impl)
- {
- m_impl->wait();
- delete m_impl;
- m_impl = NULL;
- }
-}
-
-
-////////////////////////////////////////////////////////////
-void Thread::terminate()
-{
- if (m_impl)
- {
- m_impl->terminate();
- delete m_impl;
- m_impl = NULL;
- }
-}
-
-
-////////////////////////////////////////////////////////////
-void Thread::run()
-{
- m_entryPoint->run();
-}
-
-} // namespace sf
+//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com) +// +// This software is provided 'as-is', without any express or implied warranty. +// In no event will the authors be held liable for any damages arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it freely, +// subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; +// you must not claim that you wrote the original software. +// If you use this software in a product, an acknowledgment +// in the product documentation would be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, +// and must not be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. +// +//////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include <SFML/System/Thread.hpp> + + +#if defined(SFML_SYSTEM_WINDOWS) + #include <SFML/System/Win32/ThreadImpl.hpp> +#else + #include <SFML/System/Unix/ThreadImpl.hpp> +#endif + + +namespace sf +{ +//////////////////////////////////////////////////////////// +Thread::~Thread() +{ + wait(); + delete m_entryPoint; +} + + +//////////////////////////////////////////////////////////// +void Thread::launch() +{ + wait(); + m_impl = new priv::ThreadImpl(this); +} + + +//////////////////////////////////////////////////////////// +void Thread::wait() +{ + if (m_impl) + { + m_impl->wait(); + delete m_impl; + m_impl = NULL; + } +} + + +//////////////////////////////////////////////////////////// +void Thread::terminate() +{ + if (m_impl) + { + m_impl->terminate(); + delete m_impl; + m_impl = NULL; + } +} + + +//////////////////////////////////////////////////////////// +void Thread::run() +{ + m_entryPoint->run(); +} + +} // namespace sf diff --git a/src/SFML/System/ThreadLocal.cpp b/src/SFML/System/ThreadLocal.cpp index 0d134db..bac8229 100644 --- a/src/SFML/System/ThreadLocal.cpp +++ b/src/SFML/System/ThreadLocal.cpp @@ -1,67 +1,67 @@ -////////////////////////////////////////////////////////////
-//
-// SFML - Simple and Fast Multimedia Library
-// Copyright (C) 2007-2013 Laurent Gomila (laurent.gom@gmail.com)
-//
-// This software is provided 'as-is', without any express or implied warranty.
-// In no event will the authors be held liable for any damages arising from the use of this software.
-//
-// Permission is granted to anyone to use this software for any purpose,
-// including commercial applications, and to alter it and redistribute it freely,
-// subject to the following restrictions:
-//
-// 1. The origin of this software must not be misrepresented;
-// you must not claim that you wrote the original software.
-// If you use this software in a product, an acknowledgment
-// in the product documentation would be appreciated but is not required.
-//
-// 2. Altered source versions must be plainly marked as such,
-// and must not be misrepresented as being the original software.
-//
-// 3. This notice may not be removed or altered from any source distribution.
-//
-////////////////////////////////////////////////////////////
-
-////////////////////////////////////////////////////////////
-// Headers
-////////////////////////////////////////////////////////////
-#include <SFML/System/ThreadLocal.hpp>
-
-#if defined(SFML_SYSTEM_WINDOWS)
- #include <SFML/System/Win32/ThreadLocalImpl.hpp>
-#else
- #include <SFML/System/Unix/ThreadLocalImpl.hpp>
-#endif
-
-
-namespace sf
-{
-////////////////////////////////////////////////////////////
-ThreadLocal::ThreadLocal(void* value)
-{
- m_impl = new priv::ThreadLocalImpl;
- setValue(value);
-}
-
-
-////////////////////////////////////////////////////////////
-ThreadLocal::~ThreadLocal()
-{
- delete m_impl;
-}
-
-
-////////////////////////////////////////////////////////////
-void ThreadLocal::setValue(void* value)
-{
- m_impl->setValue(value);
-}
-
-
-////////////////////////////////////////////////////////////
-void* ThreadLocal::getValue() const
-{
- return m_impl->getValue();
-}
-
-} // namespace sf
+//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com) +// +// This software is provided 'as-is', without any express or implied warranty. +// In no event will the authors be held liable for any damages arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it freely, +// subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; +// you must not claim that you wrote the original software. +// If you use this software in a product, an acknowledgment +// in the product documentation would be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, +// and must not be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. +// +//////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include <SFML/System/ThreadLocal.hpp> + +#if defined(SFML_SYSTEM_WINDOWS) + #include <SFML/System/Win32/ThreadLocalImpl.hpp> +#else + #include <SFML/System/Unix/ThreadLocalImpl.hpp> +#endif + + +namespace sf +{ +//////////////////////////////////////////////////////////// +ThreadLocal::ThreadLocal(void* value) +{ + m_impl = new priv::ThreadLocalImpl; + setValue(value); +} + + +//////////////////////////////////////////////////////////// +ThreadLocal::~ThreadLocal() +{ + delete m_impl; +} + + +//////////////////////////////////////////////////////////// +void ThreadLocal::setValue(void* value) +{ + m_impl->setValue(value); +} + + +//////////////////////////////////////////////////////////// +void* ThreadLocal::getValue() const +{ + return m_impl->getValue(); +} + +} // namespace sf diff --git a/src/SFML/System/Time.cpp b/src/SFML/System/Time.cpp index 69fd78e..6eeaa30 100644 --- a/src/SFML/System/Time.cpp +++ b/src/SFML/System/Time.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2013 Laurent Gomila (laurent.gom@gmail.com) +// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. @@ -236,4 +236,25 @@ Time& operator /=(Time& left, Int64 right) return left = left / right; } + +//////////////////////////////////////////////////////////// +float operator /(Time left, Time right) +{ + return left.asSeconds() / right.asSeconds(); +} + + +//////////////////////////////////////////////////////////// +Time operator %(Time left, Time right) +{ + return microseconds(left.asMicroseconds() % right.asMicroseconds()); +} + + +//////////////////////////////////////////////////////////// +Time& operator %=(Time& left, Time right) +{ + return left = left % right; +} + } // namespace sf diff --git a/src/SFML/System/Unix/ClockImpl.cpp b/src/SFML/System/Unix/ClockImpl.cpp index 813eec4..4ee8ddf 100644 --- a/src/SFML/System/Unix/ClockImpl.cpp +++ b/src/SFML/System/Unix/ClockImpl.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2013 Laurent Gomila (laurent.gom@gmail.com) +// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. @@ -26,7 +26,7 @@ // Headers //////////////////////////////////////////////////////////// #include <SFML/System/Unix/ClockImpl.hpp> -#ifdef SFML_SYSTEM_MACOS +#if defined(SFML_SYSTEM_MACOS) || defined(SFML_SYSTEM_IOS) #include <mach/mach_time.h> #else #include <time.h> @@ -40,7 +40,7 @@ namespace priv //////////////////////////////////////////////////////////// Time ClockImpl::getCurrentTime() { -#ifdef SFML_SYSTEM_MACOS +#if defined(SFML_SYSTEM_MACOS) || defined(SFML_SYSTEM_IOS) // Mac OS X specific implementation (it doesn't support clock_gettime) static mach_timebase_info_data_t frequency = {0, 0}; diff --git a/src/SFML/System/Unix/ClockImpl.hpp b/src/SFML/System/Unix/ClockImpl.hpp index e55f5e9..1420b3e 100644 --- a/src/SFML/System/Unix/ClockImpl.hpp +++ b/src/SFML/System/Unix/ClockImpl.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2013 Laurent Gomila (laurent.gom@gmail.com) +// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. @@ -37,12 +37,12 @@ namespace sf namespace priv { //////////////////////////////////////////////////////////// -/// \brief Unix implementaton of sf::Clock +/// \brief Unix implementation of sf::Clock /// //////////////////////////////////////////////////////////// class ClockImpl { -public : +public: //////////////////////////////////////////////////////////// /// \brief Get the current time diff --git a/src/SFML/System/Unix/MutexImpl.cpp b/src/SFML/System/Unix/MutexImpl.cpp index 8382dca..235393f 100644 --- a/src/SFML/System/Unix/MutexImpl.cpp +++ b/src/SFML/System/Unix/MutexImpl.cpp @@ -1,69 +1,69 @@ -////////////////////////////////////////////////////////////
-//
-// SFML - Simple and Fast Multimedia Library
-// Copyright (C) 2007-2013 Laurent Gomila (laurent.gom@gmail.com)
-//
-// This software is provided 'as-is', without any express or implied warranty.
-// In no event will the authors be held liable for any damages arising from the use of this software.
-//
-// Permission is granted to anyone to use this software for any purpose,
-// including commercial applications, and to alter it and redistribute it freely,
-// subject to the following restrictions:
-//
-// 1. The origin of this software must not be misrepresented;
-// you must not claim that you wrote the original software.
-// If you use this software in a product, an acknowledgment
-// in the product documentation would be appreciated but is not required.
-//
-// 2. Altered source versions must be plainly marked as such,
-// and must not be misrepresented as being the original software.
-//
-// 3. This notice may not be removed or altered from any source distribution.
-//
-////////////////////////////////////////////////////////////
-
-////////////////////////////////////////////////////////////
-// Headers
-////////////////////////////////////////////////////////////
-#include <SFML/System/Unix/MutexImpl.hpp>
-
-
-namespace sf
-{
-namespace priv
-{
-////////////////////////////////////////////////////////////
-MutexImpl::MutexImpl()
-{
- // Make it recursive to follow the expected behaviour
- pthread_mutexattr_t attributes;
- pthread_mutexattr_init(&attributes);
- pthread_mutexattr_settype(&attributes, PTHREAD_MUTEX_RECURSIVE);
-
- pthread_mutex_init(&m_mutex, &attributes);
-}
-
-
-////////////////////////////////////////////////////////////
-MutexImpl::~MutexImpl()
-{
- pthread_mutex_destroy(&m_mutex);
-}
-
-
-////////////////////////////////////////////////////////////
-void MutexImpl::lock()
-{
- pthread_mutex_lock(&m_mutex);
-}
-
-
-////////////////////////////////////////////////////////////
-void MutexImpl::unlock()
-{
- pthread_mutex_unlock(&m_mutex);
-}
-
-} // namespace priv
-
-} // namespace sf
+//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com) +// +// This software is provided 'as-is', without any express or implied warranty. +// In no event will the authors be held liable for any damages arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it freely, +// subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; +// you must not claim that you wrote the original software. +// If you use this software in a product, an acknowledgment +// in the product documentation would be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, +// and must not be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. +// +//////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include <SFML/System/Unix/MutexImpl.hpp> + + +namespace sf +{ +namespace priv +{ +//////////////////////////////////////////////////////////// +MutexImpl::MutexImpl() +{ + // Make it recursive to follow the expected behavior + pthread_mutexattr_t attributes; + pthread_mutexattr_init(&attributes); + pthread_mutexattr_settype(&attributes, PTHREAD_MUTEX_RECURSIVE); + + pthread_mutex_init(&m_mutex, &attributes); +} + + +//////////////////////////////////////////////////////////// +MutexImpl::~MutexImpl() +{ + pthread_mutex_destroy(&m_mutex); +} + + +//////////////////////////////////////////////////////////// +void MutexImpl::lock() +{ + pthread_mutex_lock(&m_mutex); +} + + +//////////////////////////////////////////////////////////// +void MutexImpl::unlock() +{ + pthread_mutex_unlock(&m_mutex); +} + +} // namespace priv + +} // namespace sf diff --git a/src/SFML/System/Unix/MutexImpl.hpp b/src/SFML/System/Unix/MutexImpl.hpp index b6f728e..03cb32e 100644 --- a/src/SFML/System/Unix/MutexImpl.hpp +++ b/src/SFML/System/Unix/MutexImpl.hpp @@ -1,83 +1,83 @@ -////////////////////////////////////////////////////////////
-//
-// SFML - Simple and Fast Multimedia Library
-// Copyright (C) 2007-2013 Laurent Gomila (laurent.gom@gmail.com)
-//
-// This software is provided 'as-is', without any express or implied warranty.
-// In no event will the authors be held liable for any damages arising from the use of this software.
-//
-// Permission is granted to anyone to use this software for any purpose,
-// including commercial applications, and to alter it and redistribute it freely,
-// subject to the following restrictions:
-//
-// 1. The origin of this software must not be misrepresented;
-// you must not claim that you wrote the original software.
-// If you use this software in a product, an acknowledgment
-// in the product documentation would be appreciated but is not required.
-//
-// 2. Altered source versions must be plainly marked as such,
-// and must not be misrepresented as being the original software.
-//
-// 3. This notice may not be removed or altered from any source distribution.
-//
-////////////////////////////////////////////////////////////
-
-#ifndef SFML_MUTEXIMPL_HPP
-#define SFML_MUTEXIMPL_HPP
-
-////////////////////////////////////////////////////////////
-// Headers
-////////////////////////////////////////////////////////////
-#include <SFML/System/NonCopyable.hpp>
-#include <pthread.h>
-
-
-namespace sf
-{
-namespace priv
-{
-////////////////////////////////////////////////////////////
-/// \brief Unix implementation of mutexes
-////////////////////////////////////////////////////////////
-class MutexImpl : NonCopyable
-{
-public :
-
- ////////////////////////////////////////////////////////////
- /// \brief Default constructor
- ///
- ////////////////////////////////////////////////////////////
- MutexImpl();
-
- ////////////////////////////////////////////////////////////
- /// \brief Destructor
- ///
- ////////////////////////////////////////////////////////////
- ~MutexImpl();
-
- ////////////////////////////////////////////////////////////
- /// \brief Lock the mutex
- ///
- ////////////////////////////////////////////////////////////
- void lock();
-
- ////////////////////////////////////////////////////////////
- /// \brief Unlock the mutex
- ///
- ////////////////////////////////////////////////////////////
- void unlock();
-
-private :
-
- ////////////////////////////////////////////////////////////
- // Member data
- ////////////////////////////////////////////////////////////
- pthread_mutex_t m_mutex; ///< pthread handle of the mutex
-};
-
-} // namespace priv
-
-} // namespace sf
-
-
-#endif // SFML_MUTEXIMPL_HPP
+//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com) +// +// This software is provided 'as-is', without any express or implied warranty. +// In no event will the authors be held liable for any damages arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it freely, +// subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; +// you must not claim that you wrote the original software. +// If you use this software in a product, an acknowledgment +// in the product documentation would be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, +// and must not be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. +// +//////////////////////////////////////////////////////////// + +#ifndef SFML_MUTEXIMPL_HPP +#define SFML_MUTEXIMPL_HPP + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include <SFML/System/NonCopyable.hpp> +#include <pthread.h> + + +namespace sf +{ +namespace priv +{ +//////////////////////////////////////////////////////////// +/// \brief Unix implementation of mutexes +//////////////////////////////////////////////////////////// +class MutexImpl : NonCopyable +{ +public: + + //////////////////////////////////////////////////////////// + /// \brief Default constructor + /// + //////////////////////////////////////////////////////////// + MutexImpl(); + + //////////////////////////////////////////////////////////// + /// \brief Destructor + /// + //////////////////////////////////////////////////////////// + ~MutexImpl(); + + //////////////////////////////////////////////////////////// + /// \brief Lock the mutex + /// + //////////////////////////////////////////////////////////// + void lock(); + + //////////////////////////////////////////////////////////// + /// \brief Unlock the mutex + /// + //////////////////////////////////////////////////////////// + void unlock(); + +private: + + //////////////////////////////////////////////////////////// + // Member data + //////////////////////////////////////////////////////////// + pthread_mutex_t m_mutex; ///< pthread handle of the mutex +}; + +} // namespace priv + +} // namespace sf + + +#endif // SFML_MUTEXIMPL_HPP diff --git a/src/SFML/System/Unix/SleepImpl.cpp b/src/SFML/System/Unix/SleepImpl.cpp index d817d58..08d00f8 100644 --- a/src/SFML/System/Unix/SleepImpl.cpp +++ b/src/SFML/System/Unix/SleepImpl.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2013 Laurent Gomila (laurent.gom@gmail.com) +// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. @@ -26,9 +26,8 @@ // Headers //////////////////////////////////////////////////////////// #include <SFML/System/Unix/SleepImpl.hpp> -#include <pthread.h> -#include <unistd.h> -#include <sys/time.h> +#include <errno.h> +#include <time.h> namespace sf @@ -38,38 +37,21 @@ namespace priv //////////////////////////////////////////////////////////// void sleepImpl(Time time) { - // usleep is not reliable enough (it might block the - // whole process instead of just the current thread) - // so we must use pthread_cond_timedwait instead - - // this implementation is inspired from Qt - Uint64 usecs = time.asMicroseconds(); - // get the current time - timeval tv; - gettimeofday(&tv, NULL); - - // construct the time limit (current time + time to wait) + // Construct the time to wait timespec ti; - ti.tv_nsec = (tv.tv_usec + (usecs % 1000000)) * 1000; - ti.tv_sec = tv.tv_sec + (usecs / 1000000) + (ti.tv_nsec / 1000000000); - ti.tv_nsec %= 1000000000; - - // create a mutex and thread condition - pthread_mutex_t mutex; - pthread_mutex_init(&mutex, 0); - pthread_cond_t condition; - pthread_cond_init(&condition, 0); - - // wait... - pthread_mutex_lock(&mutex); - pthread_cond_timedwait(&condition, &mutex, &ti); - pthread_mutex_unlock(&mutex); - - // destroy the mutex and condition - pthread_cond_destroy(&condition); - pthread_mutex_destroy(&mutex); + ti.tv_nsec = (usecs % 1000000) * 1000; + ti.tv_sec = usecs / 1000000; + + // Wait... + // If nanosleep returns -1, we check errno. If it is EINTR + // nanosleep was interrupted and has set ti to the remaining + // duration. We continue sleeping until the complete duration + // has passed. We stop sleeping if it was due to an error. + while ((nanosleep(&ti, &ti) == -1) && (errno == EINTR)) + { + } } } // namespace priv diff --git a/src/SFML/System/Unix/SleepImpl.hpp b/src/SFML/System/Unix/SleepImpl.hpp index 02142e4..d0d38bc 100644 --- a/src/SFML/System/Unix/SleepImpl.hpp +++ b/src/SFML/System/Unix/SleepImpl.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2013 Laurent Gomila (laurent.gom@gmail.com) +// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/System/Unix/ThreadImpl.cpp b/src/SFML/System/Unix/ThreadImpl.cpp index 663fb71..0d94dfa 100644 --- a/src/SFML/System/Unix/ThreadImpl.cpp +++ b/src/SFML/System/Unix/ThreadImpl.cpp @@ -1,85 +1,94 @@ -////////////////////////////////////////////////////////////
-//
-// SFML - Simple and Fast Multimedia Library
-// Copyright (C) 2007-2013 Laurent Gomila (laurent.gom@gmail.com)
-//
-// This software is provided 'as-is', without any express or implied warranty.
-// In no event will the authors be held liable for any damages arising from the use of this software.
-//
-// Permission is granted to anyone to use this software for any purpose,
-// including commercial applications, and to alter it and redistribute it freely,
-// subject to the following restrictions:
-//
-// 1. The origin of this software must not be misrepresented;
-// you must not claim that you wrote the original software.
-// If you use this software in a product, an acknowledgment
-// in the product documentation would be appreciated but is not required.
-//
-// 2. Altered source versions must be plainly marked as such,
-// and must not be misrepresented as being the original software.
-//
-// 3. This notice may not be removed or altered from any source distribution.
-//
-////////////////////////////////////////////////////////////
-
-////////////////////////////////////////////////////////////
-// Headers
-////////////////////////////////////////////////////////////
-#include <SFML/System/Unix/ThreadImpl.hpp>
-#include <SFML/System/Thread.hpp>
-#include <iostream>
-#include <cassert>
-
-
-namespace sf
-{
-namespace priv
-{
-////////////////////////////////////////////////////////////
-ThreadImpl::ThreadImpl(Thread* owner) :
-m_isActive(true)
-{
- m_isActive = pthread_create(&m_thread, NULL, &ThreadImpl::entryPoint, owner) == 0;
-
- if (!m_isActive)
- std::cerr << "Failed to create thread" << std::endl;
-}
-
-
-////////////////////////////////////////////////////////////
-void ThreadImpl::wait()
-{
- if (m_isActive)
- {
- assert(pthread_equal(pthread_self(), m_thread) == 0); // A thread cannot wait for itself!
- pthread_join(m_thread, NULL);
- }
-}
-
-
-////////////////////////////////////////////////////////////
-void ThreadImpl::terminate()
-{
- if (m_isActive)
- pthread_cancel(m_thread);
-}
-
-
-////////////////////////////////////////////////////////////
-void* ThreadImpl::entryPoint(void* userData)
-{
- // The Thread instance is stored in the user data
- Thread* owner = static_cast<Thread*>(userData);
-
- // Tell the thread to handle cancel requests immediatly
- pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
-
- // Forward to the owner
- owner->run();
-
- return NULL;
-}
-
-} // namespace priv
-
-} // namespace sf
+//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com) +// +// This software is provided 'as-is', without any express or implied warranty. +// In no event will the authors be held liable for any damages arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it freely, +// subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; +// you must not claim that you wrote the original software. +// If you use this software in a product, an acknowledgment +// in the product documentation would be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, +// and must not be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. +// +//////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include <SFML/System/Unix/ThreadImpl.hpp> +#include <SFML/System/Thread.hpp> +#include <iostream> +#include <cassert> + + +namespace sf +{ +namespace priv +{ +//////////////////////////////////////////////////////////// +ThreadImpl::ThreadImpl(Thread* owner) : +m_isActive(true) +{ + m_isActive = pthread_create(&m_thread, NULL, &ThreadImpl::entryPoint, owner) == 0; + + if (!m_isActive) + std::cerr << "Failed to create thread" << std::endl; +} + + +//////////////////////////////////////////////////////////// +void ThreadImpl::wait() +{ + if (m_isActive) + { + assert(pthread_equal(pthread_self(), m_thread) == 0); // A thread cannot wait for itself! + pthread_join(m_thread, NULL); + } +} + + +//////////////////////////////////////////////////////////// +void ThreadImpl::terminate() +{ + if (m_isActive) + { + #ifndef SFML_SYSTEM_ANDROID + pthread_cancel(m_thread); + #else + // See http://stackoverflow.com/questions/4610086/pthread-cancel-al + pthread_kill(m_thread, SIGUSR1); + #endif + } +} + + +//////////////////////////////////////////////////////////// +void* ThreadImpl::entryPoint(void* userData) +{ + // The Thread instance is stored in the user data + Thread* owner = static_cast<Thread*>(userData); + + #ifndef SFML_SYSTEM_ANDROID + // Tell the thread to handle cancel requests immediately + pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL); + #endif + + // Forward to the owner + owner->run(); + + return NULL; +} + +} // namespace priv + +} // namespace sf diff --git a/src/SFML/System/Unix/ThreadImpl.hpp b/src/SFML/System/Unix/ThreadImpl.hpp index 5bf32d0..d9e7bc9 100644 --- a/src/SFML/System/Unix/ThreadImpl.hpp +++ b/src/SFML/System/Unix/ThreadImpl.hpp @@ -1,92 +1,93 @@ -////////////////////////////////////////////////////////////
-//
-// SFML - Simple and Fast Multimedia Library
-// Copyright (C) 2007-2013 Laurent Gomila (laurent.gom@gmail.com)
-//
-// This software is provided 'as-is', without any express or implied warranty.
-// In no event will the authors be held liable for any damages arising from the use of this software.
-//
-// Permission is granted to anyone to use this software for any purpose,
-// including commercial applications, and to alter it and redistribute it freely,
-// subject to the following restrictions:
-//
-// 1. The origin of this software must not be misrepresented;
-// you must not claim that you wrote the original software.
-// If you use this software in a product, an acknowledgment
-// in the product documentation would be appreciated but is not required.
-//
-// 2. Altered source versions must be plainly marked as such,
-// and must not be misrepresented as being the original software.
-//
-// 3. This notice may not be removed or altered from any source distribution.
-//
-////////////////////////////////////////////////////////////
-
-#ifndef SFML_THREADIMPL_HPP
-#define SFML_THREADIMPL_HPP
-
-////////////////////////////////////////////////////////////
-// Headers
-////////////////////////////////////////////////////////////
-#include <SFML/System/NonCopyable.hpp>
-#include <pthread.h>
-
-
-namespace sf
-{
-class Thread;
-
-namespace priv
-{
-////////////////////////////////////////////////////////////
-/// \brief Unix implementation of threads
-////////////////////////////////////////////////////////////
-class ThreadImpl : NonCopyable
-{
-public :
-
- ////////////////////////////////////////////////////////////
- /// \brief Default constructor, launch the thread
- ///
- /// \param owner The Thread instance to run
- ///
- ////////////////////////////////////////////////////////////
- ThreadImpl(Thread* owner);
-
- ////////////////////////////////////////////////////////////
- /// \brief Wait until the thread finishes
- ///
- ////////////////////////////////////////////////////////////
- void wait();
-
- ////////////////////////////////////////////////////////////
- /// \brief Terminate the thread
- ///
- ////////////////////////////////////////////////////////////
- void terminate();
-
-private :
-
- ////////////////////////////////////////////////////////////
- /// \brief Global entry point for all threads
- ///
- /// \param userData User-defined data (contains the Thread instance)
- ///
- /// \return Os specific error code
- ///
- ////////////////////////////////////////////////////////////
- static void* entryPoint(void* userData);
-
- ////////////////////////////////////////////////////////////
- // Member data
- ////////////////////////////////////////////////////////////
- pthread_t m_thread; ///< pthread thread instance
- bool m_isActive; ///< Thread state (active or inactive)
-};
-
-} // namespace priv
-
-} // namespace sf
-
-
-#endif // SFML_THREADIMPL_HPP
+//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com) +// +// This software is provided 'as-is', without any express or implied warranty. +// In no event will the authors be held liable for any damages arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it freely, +// subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; +// you must not claim that you wrote the original software. +// If you use this software in a product, an acknowledgment +// in the product documentation would be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, +// and must not be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. +// +//////////////////////////////////////////////////////////// + +#ifndef SFML_THREADIMPL_HPP +#define SFML_THREADIMPL_HPP + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include <SFML/Config.hpp> +#include <SFML/System/NonCopyable.hpp> +#include <pthread.h> + + +namespace sf +{ +class Thread; + +namespace priv +{ +//////////////////////////////////////////////////////////// +/// \brief Unix implementation of threads +//////////////////////////////////////////////////////////// +class ThreadImpl : NonCopyable +{ +public: + + //////////////////////////////////////////////////////////// + /// \brief Default constructor, launch the thread + /// + /// \param owner The Thread instance to run + /// + //////////////////////////////////////////////////////////// + ThreadImpl(Thread* owner); + + //////////////////////////////////////////////////////////// + /// \brief Wait until the thread finishes + /// + //////////////////////////////////////////////////////////// + void wait(); + + //////////////////////////////////////////////////////////// + /// \brief Terminate the thread + /// + //////////////////////////////////////////////////////////// + void terminate(); + +private: + + //////////////////////////////////////////////////////////// + /// \brief Global entry point for all threads + /// + /// \param userData User-defined data (contains the Thread instance) + /// + /// \return Os specific error code + /// + //////////////////////////////////////////////////////////// + static void* entryPoint(void* userData); + + //////////////////////////////////////////////////////////// + // Member data + //////////////////////////////////////////////////////////// + pthread_t m_thread; ///< pthread thread instance + bool m_isActive; ///< Thread state (active or inactive) +}; + +} // namespace priv + +} // namespace sf + + +#endif // SFML_THREADIMPL_HPP diff --git a/src/SFML/System/Unix/ThreadLocalImpl.cpp b/src/SFML/System/Unix/ThreadLocalImpl.cpp index 7b2ae6d..5ebb5a0 100644 --- a/src/SFML/System/Unix/ThreadLocalImpl.cpp +++ b/src/SFML/System/Unix/ThreadLocalImpl.cpp @@ -1,64 +1,64 @@ -////////////////////////////////////////////////////////////
-//
-// SFML - Simple and Fast Multimedia Library
-// Copyright (C) 2007-2013 Laurent Gomila (laurent.gom@gmail.com)
-//
-// This software is provided 'as-is', without any express or implied warranty.
-// In no event will the authors be held liable for any damages arising from the use of this software.
-//
-// Permission is granted to anyone to use this software for any purpose,
-// including commercial applications, and to alter it and redistribute it freely,
-// subject to the following restrictions:
-//
-// 1. The origin of this software must not be misrepresented;
-// you must not claim that you wrote the original software.
-// If you use this software in a product, an acknowledgment
-// in the product documentation would be appreciated but is not required.
-//
-// 2. Altered source versions must be plainly marked as such,
-// and must not be misrepresented as being the original software.
-//
-// 3. This notice may not be removed or altered from any source distribution.
-//
-////////////////////////////////////////////////////////////
-
-////////////////////////////////////////////////////////////
-// Headers
-////////////////////////////////////////////////////////////
-#include <SFML/System/Unix/ThreadLocalImpl.hpp>
-
-
-namespace sf
-{
-namespace priv
-{
-////////////////////////////////////////////////////////////
-ThreadLocalImpl::ThreadLocalImpl()
-{
- pthread_key_create(&m_key, NULL);
-}
-
-
-////////////////////////////////////////////////////////////
-ThreadLocalImpl::~ThreadLocalImpl()
-{
- pthread_key_delete(m_key);
-}
-
-
-////////////////////////////////////////////////////////////
-void ThreadLocalImpl::setValue(void* value)
-{
- pthread_setspecific(m_key, value);
-}
-
-
-////////////////////////////////////////////////////////////
-void* ThreadLocalImpl::getValue() const
-{
- return pthread_getspecific(m_key);
-}
-
-} // namespace priv
-
-} // namespace sf
+//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com) +// +// This software is provided 'as-is', without any express or implied warranty. +// In no event will the authors be held liable for any damages arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it freely, +// subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; +// you must not claim that you wrote the original software. +// If you use this software in a product, an acknowledgment +// in the product documentation would be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, +// and must not be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. +// +//////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include <SFML/System/Unix/ThreadLocalImpl.hpp> + + +namespace sf +{ +namespace priv +{ +//////////////////////////////////////////////////////////// +ThreadLocalImpl::ThreadLocalImpl() +{ + pthread_key_create(&m_key, NULL); +} + + +//////////////////////////////////////////////////////////// +ThreadLocalImpl::~ThreadLocalImpl() +{ + pthread_key_delete(m_key); +} + + +//////////////////////////////////////////////////////////// +void ThreadLocalImpl::setValue(void* value) +{ + pthread_setspecific(m_key, value); +} + + +//////////////////////////////////////////////////////////// +void* ThreadLocalImpl::getValue() const +{ + return pthread_getspecific(m_key); +} + +} // namespace priv + +} // namespace sf diff --git a/src/SFML/System/Unix/ThreadLocalImpl.hpp b/src/SFML/System/Unix/ThreadLocalImpl.hpp index 4d547fb..07abdff 100644 --- a/src/SFML/System/Unix/ThreadLocalImpl.hpp +++ b/src/SFML/System/Unix/ThreadLocalImpl.hpp @@ -1,87 +1,87 @@ -////////////////////////////////////////////////////////////
-//
-// SFML - Simple and Fast Multimedia Library
-// Copyright (C) 2007-2013 Laurent Gomila (laurent.gom@gmail.com)
-//
-// This software is provided 'as-is', without any express or implied warranty.
-// In no event will the authors be held liable for any damages arising from the use of this software.
-//
-// Permission is granted to anyone to use this software for any purpose,
-// including commercial applications, and to alter it and redistribute it freely,
-// subject to the following restrictions:
-//
-// 1. The origin of this software must not be misrepresented;
-// you must not claim that you wrote the original software.
-// If you use this software in a product, an acknowledgment
-// in the product documentation would be appreciated but is not required.
-//
-// 2. Altered source versions must be plainly marked as such,
-// and must not be misrepresented as being the original software.
-//
-// 3. This notice may not be removed or altered from any source distribution.
-//
-////////////////////////////////////////////////////////////
-
-#ifndef SFML_THREADLOCALIMPL_HPP
-#define SFML_THREADLOCALIMPL_HPP
-
-////////////////////////////////////////////////////////////
-// Headers
-////////////////////////////////////////////////////////////
-#include <SFML/System/NonCopyable.hpp>
-#include <pthread.h>
-
-
-namespace sf
-{
-namespace priv
-{
-////////////////////////////////////////////////////////////
-/// \brief Unix implementation of thread-local storage
-////////////////////////////////////////////////////////////
-class ThreadLocalImpl : NonCopyable
-{
-public :
-
- ////////////////////////////////////////////////////////////
- /// \brief Default constructor -- allocate the storage
- ///
- ////////////////////////////////////////////////////////////
- ThreadLocalImpl();
-
- ////////////////////////////////////////////////////////////
- /// \brief Destructor -- free the storage
- ///
- ////////////////////////////////////////////////////////////
- ~ThreadLocalImpl();
-
- ////////////////////////////////////////////////////////////
- /// \brief Set the thread-specific value of the variable
- ///
- /// \param value Value of the variable for this thread
- ///
- ////////////////////////////////////////////////////////////
- void setValue(void* value);
-
- ////////////////////////////////////////////////////////////
- /// \brief Retrieve the thread-specific value of the variable
- ///
- /// \return Value of the variable for this thread
- ///
- ////////////////////////////////////////////////////////////
- void* getValue() const;
-
-private :
-
- ////////////////////////////////////////////////////////////
- // Member data
- ////////////////////////////////////////////////////////////
- pthread_key_t m_key; ///< Index of our thread-local storage slot
-};
-
-} // namespace priv
-
-} // namespace sf
-
-
-#endif // SFML_THREADLOCALIMPL_HPP
+//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com) +// +// This software is provided 'as-is', without any express or implied warranty. +// In no event will the authors be held liable for any damages arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it freely, +// subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; +// you must not claim that you wrote the original software. +// If you use this software in a product, an acknowledgment +// in the product documentation would be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, +// and must not be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. +// +//////////////////////////////////////////////////////////// + +#ifndef SFML_THREADLOCALIMPL_HPP +#define SFML_THREADLOCALIMPL_HPP + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include <SFML/System/NonCopyable.hpp> +#include <pthread.h> + + +namespace sf +{ +namespace priv +{ +//////////////////////////////////////////////////////////// +/// \brief Unix implementation of thread-local storage +//////////////////////////////////////////////////////////// +class ThreadLocalImpl : NonCopyable +{ +public: + + //////////////////////////////////////////////////////////// + /// \brief Default constructor -- allocate the storage + /// + //////////////////////////////////////////////////////////// + ThreadLocalImpl(); + + //////////////////////////////////////////////////////////// + /// \brief Destructor -- free the storage + /// + //////////////////////////////////////////////////////////// + ~ThreadLocalImpl(); + + //////////////////////////////////////////////////////////// + /// \brief Set the thread-specific value of the variable + /// + /// \param value Value of the variable for this thread + /// + //////////////////////////////////////////////////////////// + void setValue(void* value); + + //////////////////////////////////////////////////////////// + /// \brief Retrieve the thread-specific value of the variable + /// + /// \return Value of the variable for this thread + /// + //////////////////////////////////////////////////////////// + void* getValue() const; + +private: + + //////////////////////////////////////////////////////////// + // Member data + //////////////////////////////////////////////////////////// + pthread_key_t m_key; ///< Index of our thread-local storage slot +}; + +} // namespace priv + +} // namespace sf + + +#endif // SFML_THREADLOCALIMPL_HPP diff --git a/src/SFML/System/Win32/ClockImpl.cpp b/src/SFML/System/Win32/ClockImpl.cpp index c3cb711..5b197a4 100644 --- a/src/SFML/System/Win32/ClockImpl.cpp +++ b/src/SFML/System/Win32/ClockImpl.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2013 Laurent Gomila (laurent.gom@gmail.com) +// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. @@ -34,7 +34,7 @@ namespace LARGE_INTEGER getFrequency() { LARGE_INTEGER frequency; - QueryPerformanceFrequency(&frequency); + QueryPerformanceFrequency(&frequency); return frequency; } } diff --git a/src/SFML/System/Win32/ClockImpl.hpp b/src/SFML/System/Win32/ClockImpl.hpp index d7e3863..f01708a 100644 --- a/src/SFML/System/Win32/ClockImpl.hpp +++ b/src/SFML/System/Win32/ClockImpl.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2013 Laurent Gomila (laurent.gom@gmail.com) +// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. @@ -37,12 +37,12 @@ namespace sf namespace priv { //////////////////////////////////////////////////////////// -/// \brief Windows implementaton of sf::Clock +/// \brief Windows implementation of sf::Clock /// //////////////////////////////////////////////////////////// class ClockImpl { -public : +public: //////////////////////////////////////////////////////////// /// \brief Get the current time diff --git a/src/SFML/System/Win32/MutexImpl.cpp b/src/SFML/System/Win32/MutexImpl.cpp index 7e7f0c3..f000e8d 100644 --- a/src/SFML/System/Win32/MutexImpl.cpp +++ b/src/SFML/System/Win32/MutexImpl.cpp @@ -1,64 +1,64 @@ -////////////////////////////////////////////////////////////
-//
-// SFML - Simple and Fast Multimedia Library
-// Copyright (C) 2007-2013 Laurent Gomila (laurent.gom@gmail.com)
-//
-// This software is provided 'as-is', without any express or implied warranty.
-// In no event will the authors be held liable for any damages arising from the use of this software.
-//
-// Permission is granted to anyone to use this software for any purpose,
-// including commercial applications, and to alter it and redistribute it freely,
-// subject to the following restrictions:
-//
-// 1. The origin of this software must not be misrepresented;
-// you must not claim that you wrote the original software.
-// If you use this software in a product, an acknowledgment
-// in the product documentation would be appreciated but is not required.
-//
-// 2. Altered source versions must be plainly marked as such,
-// and must not be misrepresented as being the original software.
-//
-// 3. This notice may not be removed or altered from any source distribution.
-//
-////////////////////////////////////////////////////////////
-
-////////////////////////////////////////////////////////////
-// Headers
-////////////////////////////////////////////////////////////
-#include <SFML/System/Win32/MutexImpl.hpp>
-
-
-namespace sf
-{
-namespace priv
-{
-////////////////////////////////////////////////////////////
-MutexImpl::MutexImpl()
-{
- InitializeCriticalSection(&m_mutex);
-}
-
-
-////////////////////////////////////////////////////////////
-MutexImpl::~MutexImpl()
-{
- DeleteCriticalSection(&m_mutex);
-}
-
-
-////////////////////////////////////////////////////////////
-void MutexImpl::lock()
-{
- EnterCriticalSection(&m_mutex);
-}
-
-
-////////////////////////////////////////////////////////////
-void MutexImpl::unlock()
-{
- LeaveCriticalSection(&m_mutex);
-}
-
-} // namespace priv
-
-} // namespace sf
+//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com) +// +// This software is provided 'as-is', without any express or implied warranty. +// In no event will the authors be held liable for any damages arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it freely, +// subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; +// you must not claim that you wrote the original software. +// If you use this software in a product, an acknowledgment +// in the product documentation would be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, +// and must not be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. +// +//////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include <SFML/System/Win32/MutexImpl.hpp> + + +namespace sf +{ +namespace priv +{ +//////////////////////////////////////////////////////////// +MutexImpl::MutexImpl() +{ + InitializeCriticalSection(&m_mutex); +} + + +//////////////////////////////////////////////////////////// +MutexImpl::~MutexImpl() +{ + DeleteCriticalSection(&m_mutex); +} + + +//////////////////////////////////////////////////////////// +void MutexImpl::lock() +{ + EnterCriticalSection(&m_mutex); +} + + +//////////////////////////////////////////////////////////// +void MutexImpl::unlock() +{ + LeaveCriticalSection(&m_mutex); +} + +} // namespace priv + +} // namespace sf diff --git a/src/SFML/System/Win32/MutexImpl.hpp b/src/SFML/System/Win32/MutexImpl.hpp index db78fb1..9604a5b 100644 --- a/src/SFML/System/Win32/MutexImpl.hpp +++ b/src/SFML/System/Win32/MutexImpl.hpp @@ -1,83 +1,83 @@ -////////////////////////////////////////////////////////////
-//
-// SFML - Simple and Fast Multimedia Library
-// Copyright (C) 2007-2013 Laurent Gomila (laurent.gom@gmail.com)
-//
-// This software is provided 'as-is', without any express or implied warranty.
-// In no event will the authors be held liable for any damages arising from the use of this software.
-//
-// Permission is granted to anyone to use this software for any purpose,
-// including commercial applications, and to alter it and redistribute it freely,
-// subject to the following restrictions:
-//
-// 1. The origin of this software must not be misrepresented;
-// you must not claim that you wrote the original software.
-// If you use this software in a product, an acknowledgment
-// in the product documentation would be appreciated but is not required.
-//
-// 2. Altered source versions must be plainly marked as such,
-// and must not be misrepresented as being the original software.
-//
-// 3. This notice may not be removed or altered from any source distribution.
-//
-////////////////////////////////////////////////////////////
-
-#ifndef SFML_MUTEXIMPL_HPP
-#define SFML_MUTEXIMPL_HPP
-
-////////////////////////////////////////////////////////////
-// Headers
-////////////////////////////////////////////////////////////
-#include <SFML/System/NonCopyable.hpp>
-#include <windows.h>
-
-
-namespace sf
-{
-namespace priv
-{
-////////////////////////////////////////////////////////////
-/// \brief Windows implementation of mutexes
-////////////////////////////////////////////////////////////
-class MutexImpl : NonCopyable
-{
-public :
-
- ////////////////////////////////////////////////////////////
- /// \brief Default constructor
- ///
- ////////////////////////////////////////////////////////////
- MutexImpl();
-
- ////////////////////////////////////////////////////////////
- /// \brief Destructor
- ///
- ////////////////////////////////////////////////////////////
- ~MutexImpl();
-
- ////////////////////////////////////////////////////////////
- /// \brief Lock the mutex
- ///
- ////////////////////////////////////////////////////////////
- void lock();
-
- ////////////////////////////////////////////////////////////
- /// \brief Unlock the mutex
- ///
- ////////////////////////////////////////////////////////////
- void unlock();
-
-private :
-
- ////////////////////////////////////////////////////////////
- // Member data
- ////////////////////////////////////////////////////////////
- CRITICAL_SECTION m_mutex; ///< Win32 handle of the mutex
-};
-
-} // namespace priv
-
-} // namespace sf
-
-
-#endif // SFML_MUTEXIMPL_HPP
+//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com) +// +// This software is provided 'as-is', without any express or implied warranty. +// In no event will the authors be held liable for any damages arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it freely, +// subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; +// you must not claim that you wrote the original software. +// If you use this software in a product, an acknowledgment +// in the product documentation would be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, +// and must not be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. +// +//////////////////////////////////////////////////////////// + +#ifndef SFML_MUTEXIMPL_HPP +#define SFML_MUTEXIMPL_HPP + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include <SFML/System/NonCopyable.hpp> +#include <windows.h> + + +namespace sf +{ +namespace priv +{ +//////////////////////////////////////////////////////////// +/// \brief Windows implementation of mutexes +//////////////////////////////////////////////////////////// +class MutexImpl : NonCopyable +{ +public: + + //////////////////////////////////////////////////////////// + /// \brief Default constructor + /// + //////////////////////////////////////////////////////////// + MutexImpl(); + + //////////////////////////////////////////////////////////// + /// \brief Destructor + /// + //////////////////////////////////////////////////////////// + ~MutexImpl(); + + //////////////////////////////////////////////////////////// + /// \brief Lock the mutex + /// + //////////////////////////////////////////////////////////// + void lock(); + + //////////////////////////////////////////////////////////// + /// \brief Unlock the mutex + /// + //////////////////////////////////////////////////////////// + void unlock(); + +private: + + //////////////////////////////////////////////////////////// + // Member data + //////////////////////////////////////////////////////////// + CRITICAL_SECTION m_mutex; ///< Win32 handle of the mutex +}; + +} // namespace priv + +} // namespace sf + + +#endif // SFML_MUTEXIMPL_HPP diff --git a/src/SFML/System/Win32/SleepImpl.cpp b/src/SFML/System/Win32/SleepImpl.cpp index c3acda6..6f7106f 100644 --- a/src/SFML/System/Win32/SleepImpl.cpp +++ b/src/SFML/System/Win32/SleepImpl.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2013 Laurent Gomila (laurent.gom@gmail.com) +// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. @@ -36,7 +36,18 @@ namespace priv //////////////////////////////////////////////////////////// void sleepImpl(Time time) { + // Get the supported timer resolutions on this system + TIMECAPS tc; + timeGetDevCaps(&tc, sizeof(TIMECAPS)); + + // Set the timer resolution to the minimum for the Sleep call + timeBeginPeriod(tc.wPeriodMin); + + // Wait... ::Sleep(time.asMilliseconds()); + + // Reset the timer resolution back to the system default + timeEndPeriod(tc.wPeriodMin); } } // namespace priv diff --git a/src/SFML/System/Win32/SleepImpl.hpp b/src/SFML/System/Win32/SleepImpl.hpp index e6f4c99..c0fbe54 100644 --- a/src/SFML/System/Win32/SleepImpl.hpp +++ b/src/SFML/System/Win32/SleepImpl.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2013 Laurent Gomila (laurent.gom@gmail.com) +// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/src/SFML/System/Win32/ThreadImpl.cpp b/src/SFML/System/Win32/ThreadImpl.cpp index be80ed4..1697702 100644 --- a/src/SFML/System/Win32/ThreadImpl.cpp +++ b/src/SFML/System/Win32/ThreadImpl.cpp @@ -1,93 +1,93 @@ -////////////////////////////////////////////////////////////
-//
-// SFML - Simple and Fast Multimedia Library
-// Copyright (C) 2007-2013 Laurent Gomila (laurent.gom@gmail.com)
-//
-// This software is provided 'as-is', without any express or implied warranty.
-// In no event will the authors be held liable for any damages arising from the use of this software.
-//
-// Permission is granted to anyone to use this software for any purpose,
-// including commercial applications, and to alter it and redistribute it freely,
-// subject to the following restrictions:
-//
-// 1. The origin of this software must not be misrepresented;
-// you must not claim that you wrote the original software.
-// If you use this software in a product, an acknowledgment
-// in the product documentation would be appreciated but is not required.
-//
-// 2. Altered source versions must be plainly marked as such,
-// and must not be misrepresented as being the original software.
-//
-// 3. This notice may not be removed or altered from any source distribution.
-//
-////////////////////////////////////////////////////////////
-
-////////////////////////////////////////////////////////////
-// Headers
-////////////////////////////////////////////////////////////
-#include <SFML/System/Win32/ThreadImpl.hpp>
-#include <SFML/System/Thread.hpp>
-#include <SFML/System/Err.hpp>
-#include <cassert>
-#include <process.h>
-
-
-namespace sf
-{
-namespace priv
-{
-////////////////////////////////////////////////////////////
-ThreadImpl::ThreadImpl(Thread* owner)
-{
- m_thread = reinterpret_cast<HANDLE>(_beginthreadex(NULL, 0, &ThreadImpl::entryPoint, owner, 0, &m_threadId));
-
- if (!m_thread)
- err() << "Failed to create thread" << std::endl;
-}
-
-
-////////////////////////////////////////////////////////////
-ThreadImpl::~ThreadImpl()
-{
- if (m_thread)
- CloseHandle(m_thread);
-}
-
-
-////////////////////////////////////////////////////////////
-void ThreadImpl::wait()
-{
- if (m_thread)
- {
- assert(m_threadId != GetCurrentThreadId()); // A thread cannot wait for itself!
- WaitForSingleObject(m_thread, INFINITE);
- }
-}
-
-
-////////////////////////////////////////////////////////////
-void ThreadImpl::terminate()
-{
- if (m_thread)
- TerminateThread(m_thread, 0);
-}
-
-
-////////////////////////////////////////////////////////////
-unsigned int __stdcall ThreadImpl::entryPoint(void* userData)
-{
- // The Thread instance is stored in the user data
- Thread* owner = static_cast<Thread*>(userData);
-
- // Forward to the owner
- owner->run();
-
- // Optional, but it is cleaner
- _endthreadex(0);
-
- return 0;
-}
-
-} // namespace priv
-
-} // namespace sf
+//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com) +// +// This software is provided 'as-is', without any express or implied warranty. +// In no event will the authors be held liable for any damages arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it freely, +// subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; +// you must not claim that you wrote the original software. +// If you use this software in a product, an acknowledgment +// in the product documentation would be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, +// and must not be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. +// +//////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include <SFML/System/Win32/ThreadImpl.hpp> +#include <SFML/System/Thread.hpp> +#include <SFML/System/Err.hpp> +#include <cassert> +#include <process.h> + + +namespace sf +{ +namespace priv +{ +//////////////////////////////////////////////////////////// +ThreadImpl::ThreadImpl(Thread* owner) +{ + m_thread = reinterpret_cast<HANDLE>(_beginthreadex(NULL, 0, &ThreadImpl::entryPoint, owner, 0, &m_threadId)); + + if (!m_thread) + err() << "Failed to create thread" << std::endl; +} + + +//////////////////////////////////////////////////////////// +ThreadImpl::~ThreadImpl() +{ + if (m_thread) + CloseHandle(m_thread); +} + + +//////////////////////////////////////////////////////////// +void ThreadImpl::wait() +{ + if (m_thread) + { + assert(m_threadId != GetCurrentThreadId()); // A thread cannot wait for itself! + WaitForSingleObject(m_thread, INFINITE); + } +} + + +//////////////////////////////////////////////////////////// +void ThreadImpl::terminate() +{ + if (m_thread) + TerminateThread(m_thread, 0); +} + + +//////////////////////////////////////////////////////////// +unsigned int __stdcall ThreadImpl::entryPoint(void* userData) +{ + // The Thread instance is stored in the user data + Thread* owner = static_cast<Thread*>(userData); + + // Forward to the owner + owner->run(); + + // Optional, but it is cleaner + _endthreadex(0); + + return 0; +} + +} // namespace priv + +} // namespace sf diff --git a/src/SFML/System/Win32/ThreadImpl.hpp b/src/SFML/System/Win32/ThreadImpl.hpp index 196494f..00df619 100644 --- a/src/SFML/System/Win32/ThreadImpl.hpp +++ b/src/SFML/System/Win32/ThreadImpl.hpp @@ -1,98 +1,109 @@ -////////////////////////////////////////////////////////////
-//
-// SFML - Simple and Fast Multimedia Library
-// Copyright (C) 2007-2013 Laurent Gomila (laurent.gom@gmail.com)
-//
-// This software is provided 'as-is', without any express or implied warranty.
-// In no event will the authors be held liable for any damages arising from the use of this software.
-//
-// Permission is granted to anyone to use this software for any purpose,
-// including commercial applications, and to alter it and redistribute it freely,
-// subject to the following restrictions:
-//
-// 1. The origin of this software must not be misrepresented;
-// you must not claim that you wrote the original software.
-// If you use this software in a product, an acknowledgment
-// in the product documentation would be appreciated but is not required.
-//
-// 2. Altered source versions must be plainly marked as such,
-// and must not be misrepresented as being the original software.
-//
-// 3. This notice may not be removed or altered from any source distribution.
-//
-////////////////////////////////////////////////////////////
-
-#ifndef SFML_THREADIMPL_HPP
-#define SFML_THREADIMPL_HPP
-
-////////////////////////////////////////////////////////////
-// Headers
-////////////////////////////////////////////////////////////
-#include <SFML/System/NonCopyable.hpp>
-#include <windows.h>
-
-
-namespace sf
-{
-class Thread;
-
-namespace priv
-{
-////////////////////////////////////////////////////////////
-/// \brief Windows implementation of threads
-////////////////////////////////////////////////////////////
-class ThreadImpl : NonCopyable
-{
-public :
-
- ////////////////////////////////////////////////////////////
- /// \brief Default constructor, launch the thread
- ///
- /// \param owner The Thread instance to run
- ///
- ////////////////////////////////////////////////////////////
- ThreadImpl(Thread* owner);
-
- ////////////////////////////////////////////////////////////
- /// \brief Destructor
- ///
- ////////////////////////////////////////////////////////////
- ~ThreadImpl();
-
- ////////////////////////////////////////////////////////////
- /// \brief Wait until the thread finishes
- ///
- ////////////////////////////////////////////////////////////
- void wait();
-
- ////////////////////////////////////////////////////////////
- /// \brief Terminate the thread
- ///
- ////////////////////////////////////////////////////////////
- void terminate();
-
-private :
-
- ////////////////////////////////////////////////////////////
- /// \brief Global entry point for all threads
- ///
- /// \param userData User-defined data (contains the Thread instance)
- ///
- /// \return OS specific error code
- ///
- ////////////////////////////////////////////////////////////
- static unsigned int __stdcall entryPoint(void* userData);
-
- ////////////////////////////////////////////////////////////
- // Member data
- ////////////////////////////////////////////////////////////
- HANDLE m_thread; ///< Win32 thread handle
- unsigned int m_threadId; ///< Win32 thread identifier
-};
-
-} // namespace priv
-
-} // namespace sf
-
-
-#endif // SFML_THREADIMPL_HPP
+//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com) +// +// This software is provided 'as-is', without any express or implied warranty. +// In no event will the authors be held liable for any damages arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it freely, +// subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; +// you must not claim that you wrote the original software. +// If you use this software in a product, an acknowledgment +// in the product documentation would be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, +// and must not be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. +// +//////////////////////////////////////////////////////////// + +#ifndef SFML_THREADIMPL_HPP +#define SFML_THREADIMPL_HPP + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include <SFML/System/NonCopyable.hpp> +#include <windows.h> + +// Fix for unaligned stack with clang and GCC on Windows XP 32-bit +#if defined(SFML_SYSTEM_WINDOWS) && (defined(__clang__) || defined(__GNUC__)) + + #define ALIGN_STACK __attribute__((__force_align_arg_pointer__)) + +#else + + #define ALIGN_STACK + +#endif + + +namespace sf +{ +class Thread; + +namespace priv +{ +//////////////////////////////////////////////////////////// +/// \brief Windows implementation of threads +//////////////////////////////////////////////////////////// +class ThreadImpl : NonCopyable +{ +public: + + //////////////////////////////////////////////////////////// + /// \brief Default constructor, launch the thread + /// + /// \param owner The Thread instance to run + /// + //////////////////////////////////////////////////////////// + ThreadImpl(Thread* owner); + + //////////////////////////////////////////////////////////// + /// \brief Destructor + /// + //////////////////////////////////////////////////////////// + ~ThreadImpl(); + + //////////////////////////////////////////////////////////// + /// \brief Wait until the thread finishes + /// + //////////////////////////////////////////////////////////// + void wait(); + + //////////////////////////////////////////////////////////// + /// \brief Terminate the thread + /// + //////////////////////////////////////////////////////////// + void terminate(); + +private: + + //////////////////////////////////////////////////////////// + /// \brief Global entry point for all threads + /// + /// \param userData User-defined data (contains the Thread instance) + /// + /// \return OS specific error code + /// + //////////////////////////////////////////////////////////// + ALIGN_STACK static unsigned int __stdcall entryPoint(void* userData); + + //////////////////////////////////////////////////////////// + // Member data + //////////////////////////////////////////////////////////// + HANDLE m_thread; ///< Win32 thread handle + unsigned int m_threadId; ///< Win32 thread identifier +}; + +} // namespace priv + +} // namespace sf + + +#endif // SFML_THREADIMPL_HPP diff --git a/src/SFML/System/Win32/ThreadLocalImpl.cpp b/src/SFML/System/Win32/ThreadLocalImpl.cpp index a4d850e..f617e84 100644 --- a/src/SFML/System/Win32/ThreadLocalImpl.cpp +++ b/src/SFML/System/Win32/ThreadLocalImpl.cpp @@ -1,64 +1,64 @@ -////////////////////////////////////////////////////////////
-//
-// SFML - Simple and Fast Multimedia Library
-// Copyright (C) 2007-2013 Laurent Gomila (laurent.gom@gmail.com)
-//
-// This software is provided 'as-is', without any express or implied warranty.
-// In no event will the authors be held liable for any damages arising from the use of this software.
-//
-// Permission is granted to anyone to use this software for any purpose,
-// including commercial applications, and to alter it and redistribute it freely,
-// subject to the following restrictions:
-//
-// 1. The origin of this software must not be misrepresented;
-// you must not claim that you wrote the original software.
-// If you use this software in a product, an acknowledgment
-// in the product documentation would be appreciated but is not required.
-//
-// 2. Altered source versions must be plainly marked as such,
-// and must not be misrepresented as being the original software.
-//
-// 3. This notice may not be removed or altered from any source distribution.
-//
-////////////////////////////////////////////////////////////
-
-////////////////////////////////////////////////////////////
-// Headers
-////////////////////////////////////////////////////////////
-#include <SFML/System/Win32/ThreadLocalImpl.hpp>
-
-
-namespace sf
-{
-namespace priv
-{
-////////////////////////////////////////////////////////////
-ThreadLocalImpl::ThreadLocalImpl()
-{
- m_index = TlsAlloc();
-}
-
-
-////////////////////////////////////////////////////////////
-ThreadLocalImpl::~ThreadLocalImpl()
-{
- TlsFree(m_index);
-}
-
-
-////////////////////////////////////////////////////////////
-void ThreadLocalImpl::setValue(void* value)
-{
- TlsSetValue(m_index, value);
-}
-
-
-////////////////////////////////////////////////////////////
-void* ThreadLocalImpl::getValue() const
-{
- return TlsGetValue(m_index);
-}
-
-} // namespace priv
-
-} // namespace sf
+//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com) +// +// This software is provided 'as-is', without any express or implied warranty. +// In no event will the authors be held liable for any damages arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it freely, +// subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; +// you must not claim that you wrote the original software. +// If you use this software in a product, an acknowledgment +// in the product documentation would be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, +// and must not be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. +// +//////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include <SFML/System/Win32/ThreadLocalImpl.hpp> + + +namespace sf +{ +namespace priv +{ +//////////////////////////////////////////////////////////// +ThreadLocalImpl::ThreadLocalImpl() +{ + m_index = TlsAlloc(); +} + + +//////////////////////////////////////////////////////////// +ThreadLocalImpl::~ThreadLocalImpl() +{ + TlsFree(m_index); +} + + +//////////////////////////////////////////////////////////// +void ThreadLocalImpl::setValue(void* value) +{ + TlsSetValue(m_index, value); +} + + +//////////////////////////////////////////////////////////// +void* ThreadLocalImpl::getValue() const +{ + return TlsGetValue(m_index); +} + +} // namespace priv + +} // namespace sf diff --git a/src/SFML/System/Win32/ThreadLocalImpl.hpp b/src/SFML/System/Win32/ThreadLocalImpl.hpp index d6606f6..83060b1 100644 --- a/src/SFML/System/Win32/ThreadLocalImpl.hpp +++ b/src/SFML/System/Win32/ThreadLocalImpl.hpp @@ -1,87 +1,87 @@ -////////////////////////////////////////////////////////////
-//
-// SFML - Simple and Fast Multimedia Library
-// Copyright (C) 2007-2013 Laurent Gomila (laurent.gom@gmail.com)
-//
-// This software is provided 'as-is', without any express or implied warranty.
-// In no event will the authors be held liable for any damages arising from the use of this software.
-//
-// Permission is granted to anyone to use this software for any purpose,
-// including commercial applications, and to alter it and redistribute it freely,
-// subject to the following restrictions:
-//
-// 1. The origin of this software must not be misrepresented;
-// you must not claim that you wrote the original software.
-// If you use this software in a product, an acknowledgment
-// in the product documentation would be appreciated but is not required.
-//
-// 2. Altered source versions must be plainly marked as such,
-// and must not be misrepresented as being the original software.
-//
-// 3. This notice may not be removed or altered from any source distribution.
-//
-////////////////////////////////////////////////////////////
-
-#ifndef SFML_THREADLOCALIMPL_HPP
-#define SFML_THREADLOCALIMPL_HPP
-
-////////////////////////////////////////////////////////////
-// Headers
-////////////////////////////////////////////////////////////
-#include <SFML/System/NonCopyable.hpp>
-#include <windows.h>
-
-
-namespace sf
-{
-namespace priv
-{
-////////////////////////////////////////////////////////////
-/// \brief Windows implementation of thread-local storage
-////////////////////////////////////////////////////////////
-class ThreadLocalImpl : NonCopyable
-{
-public :
-
- ////////////////////////////////////////////////////////////
- /// \brief Default constructor -- allocate the storage
- ///
- ////////////////////////////////////////////////////////////
- ThreadLocalImpl();
-
- ////////////////////////////////////////////////////////////
- /// \brief Destructor -- free the storage
- ///
- ////////////////////////////////////////////////////////////
- ~ThreadLocalImpl();
-
- ////////////////////////////////////////////////////////////
- /// \brief Set the thread-specific value of the variable
- ///
- /// \param value Value of the variable for this thread
- ///
- ////////////////////////////////////////////////////////////
- void setValue(void* value);
-
- ////////////////////////////////////////////////////////////
- /// \brief Retrieve the thread-specific value of the variable
- ///
- /// \return Value of the variable for this thread
- ///
- ////////////////////////////////////////////////////////////
- void* getValue() const;
-
-private :
-
- ////////////////////////////////////////////////////////////
- // Member data
- ////////////////////////////////////////////////////////////
- DWORD m_index; ///< Index of our thread-local storage slot
-};
-
-} // namespace priv
-
-} // namespace sf
-
-
-#endif // SFML_THREADLOCALIMPL_HPP
+//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com) +// +// This software is provided 'as-is', without any express or implied warranty. +// In no event will the authors be held liable for any damages arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it freely, +// subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; +// you must not claim that you wrote the original software. +// If you use this software in a product, an acknowledgment +// in the product documentation would be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, +// and must not be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. +// +//////////////////////////////////////////////////////////// + +#ifndef SFML_THREADLOCALIMPL_HPP +#define SFML_THREADLOCALIMPL_HPP + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include <SFML/System/NonCopyable.hpp> +#include <windows.h> + + +namespace sf +{ +namespace priv +{ +//////////////////////////////////////////////////////////// +/// \brief Windows implementation of thread-local storage +//////////////////////////////////////////////////////////// +class ThreadLocalImpl : NonCopyable +{ +public: + + //////////////////////////////////////////////////////////// + /// \brief Default constructor -- allocate the storage + /// + //////////////////////////////////////////////////////////// + ThreadLocalImpl(); + + //////////////////////////////////////////////////////////// + /// \brief Destructor -- free the storage + /// + //////////////////////////////////////////////////////////// + ~ThreadLocalImpl(); + + //////////////////////////////////////////////////////////// + /// \brief Set the thread-specific value of the variable + /// + /// \param value Value of the variable for this thread + /// + //////////////////////////////////////////////////////////// + void setValue(void* value); + + //////////////////////////////////////////////////////////// + /// \brief Retrieve the thread-specific value of the variable + /// + /// \return Value of the variable for this thread + /// + //////////////////////////////////////////////////////////// + void* getValue() const; + +private: + + //////////////////////////////////////////////////////////// + // Member data + //////////////////////////////////////////////////////////// + DWORD m_index; ///< Index of our thread-local storage slot +}; + +} // namespace priv + +} // namespace sf + + +#endif // SFML_THREADLOCALIMPL_HPP |