mirror of
https://github.com/AntoineHX/LivingMachine.git
synced 2025-05-04 13:50:46 +02:00
Ajout de la bibli SFML (A)
This commit is contained in:
parent
73704e5139
commit
cca7498ca2
204 changed files with 26813 additions and 0 deletions
117
code/SFML-2.4.2/include/SFML/System/Clock.hpp
Normal file
117
code/SFML-2.4.2/include/SFML/System/Clock.hpp
Normal file
|
@ -0,0 +1,117 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org)
|
||||
//
|
||||
// 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_CLOCK_HPP
|
||||
#define SFML_CLOCK_HPP
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/System/Export.hpp>
|
||||
#include <SFML/System/Time.hpp>
|
||||
|
||||
|
||||
namespace sf
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Utility class that measures the elapsed time
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
class SFML_SYSTEM_API Clock
|
||||
{
|
||||
public:
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Default constructor
|
||||
///
|
||||
/// The clock starts automatically after being constructed.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Clock();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the elapsed time
|
||||
///
|
||||
/// This function returns the time elapsed since the last call
|
||||
/// to restart() (or the construction of the instance if restart()
|
||||
/// has not been called).
|
||||
///
|
||||
/// \return Time elapsed
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Time getElapsedTime() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Restart the clock
|
||||
///
|
||||
/// This function puts the time counter back to zero.
|
||||
/// It also returns the time elapsed since the clock was started.
|
||||
///
|
||||
/// \return Time elapsed
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Time restart();
|
||||
|
||||
private:
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Member data
|
||||
////////////////////////////////////////////////////////////
|
||||
Time m_startTime; ///< Time of last reset, in microseconds
|
||||
};
|
||||
|
||||
} // namespace sf
|
||||
|
||||
|
||||
#endif // SFML_CLOCK_HPP
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \class sf::Clock
|
||||
/// \ingroup system
|
||||
///
|
||||
/// sf::Clock is a lightweight class for measuring time.
|
||||
///
|
||||
/// Its provides the most precise time that the underlying
|
||||
/// OS can achieve (generally microseconds or nanoseconds).
|
||||
/// It also ensures monotonicity, which means that the returned
|
||||
/// time can never go backward, even if the system time is
|
||||
/// changed.
|
||||
///
|
||||
/// Usage example:
|
||||
/// \code
|
||||
/// sf::Clock clock;
|
||||
/// ...
|
||||
/// Time time1 = clock.getElapsedTime();
|
||||
/// ...
|
||||
/// Time time2 = clock.restart();
|
||||
/// \endcode
|
||||
///
|
||||
/// The sf::Time value returned by the clock can then be
|
||||
/// converted to a number of seconds, milliseconds or even
|
||||
/// microseconds.
|
||||
///
|
||||
/// \see sf::Time
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
80
code/SFML-2.4.2/include/SFML/System/Err.hpp
Normal file
80
code/SFML-2.4.2/include/SFML/System/Err.hpp
Normal file
|
@ -0,0 +1,80 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org)
|
||||
//
|
||||
// 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_ERR_HPP
|
||||
#define SFML_ERR_HPP
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/System/Export.hpp>
|
||||
#include <ostream>
|
||||
|
||||
|
||||
namespace sf
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Standard stream used by SFML to output warnings and errors
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_SYSTEM_API std::ostream& err();
|
||||
|
||||
} // namespace sf
|
||||
|
||||
|
||||
#endif // SFML_ERR_HPP
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \fn sf::err
|
||||
/// \ingroup system
|
||||
///
|
||||
/// By default, sf::err() outputs to the same location as std::cerr,
|
||||
/// (-> the stderr descriptor) which is the console if there's
|
||||
/// one available.
|
||||
///
|
||||
/// It is a standard std::ostream instance, so it supports all the
|
||||
/// insertion operations defined by the STL
|
||||
/// (operator <<, manipulators, etc.).
|
||||
///
|
||||
/// sf::err() can be redirected to write to another output, independently
|
||||
/// of std::cerr, by using the rdbuf() function provided by the
|
||||
/// std::ostream class.
|
||||
///
|
||||
/// Example:
|
||||
/// \code
|
||||
/// // Redirect to a file
|
||||
/// std::ofstream file("sfml-log.txt");
|
||||
/// std::streambuf* previous = sf::err().rdbuf(file.rdbuf());
|
||||
///
|
||||
/// // Redirect to nothing
|
||||
/// sf::err().rdbuf(NULL);
|
||||
///
|
||||
/// // Restore the original output
|
||||
/// sf::err().rdbuf(previous);
|
||||
/// \endcode
|
||||
///
|
||||
/// \return Reference to std::ostream representing the SFML error stream
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
48
code/SFML-2.4.2/include/SFML/System/Export.hpp
Normal file
48
code/SFML-2.4.2/include/SFML/System/Export.hpp
Normal file
|
@ -0,0 +1,48 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org)
|
||||
//
|
||||
// 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_SYSTEM_EXPORT_HPP
|
||||
#define SFML_SYSTEM_EXPORT_HPP
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Config.hpp>
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Define portable import / export macros
|
||||
////////////////////////////////////////////////////////////
|
||||
#if defined(SFML_SYSTEM_EXPORTS)
|
||||
|
||||
#define SFML_SYSTEM_API SFML_API_EXPORT
|
||||
|
||||
#else
|
||||
|
||||
#define SFML_SYSTEM_API SFML_API_IMPORT
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#endif // SFML_SYSTEM_EXPORT_HPP
|
169
code/SFML-2.4.2/include/SFML/System/FileInputStream.hpp
Normal file
169
code/SFML-2.4.2/include/SFML/System/FileInputStream.hpp
Normal file
|
@ -0,0 +1,169 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org)
|
||||
//
|
||||
// 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_FILEINPUTSTREAM_HPP
|
||||
#define SFML_FILEINPUTSTREAM_HPP
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Config.hpp>
|
||||
#include <SFML/System/Export.hpp>
|
||||
#include <SFML/System/InputStream.hpp>
|
||||
#include <SFML/System/NonCopyable.hpp>
|
||||
#include <cstdio>
|
||||
#include <string>
|
||||
|
||||
#ifdef ANDROID
|
||||
namespace sf
|
||||
{
|
||||
namespace priv
|
||||
{
|
||||
class SFML_SYSTEM_API ResourceStream;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
namespace sf
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Implementation of input stream based on a file
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
class SFML_SYSTEM_API FileInputStream : public InputStream, NonCopyable
|
||||
{
|
||||
public:
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Default constructor
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
FileInputStream();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Default destructor
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual ~FileInputStream();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Open the stream from a file path
|
||||
///
|
||||
/// \param filename Name of the file to open
|
||||
///
|
||||
/// \return True on success, false on error
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
bool open(const std::string& filename);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Read data from the stream
|
||||
///
|
||||
/// After reading, the stream's reading position must be
|
||||
/// advanced by the amount of bytes read.
|
||||
///
|
||||
/// \param data Buffer where to copy the read data
|
||||
/// \param size Desired number of bytes to read
|
||||
///
|
||||
/// \return The number of bytes actually read, or -1 on error
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual Int64 read(void* data, Int64 size);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Change the current reading position
|
||||
///
|
||||
/// \param position The position to seek to, from the beginning
|
||||
///
|
||||
/// \return The position actually sought to, or -1 on error
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual Int64 seek(Int64 position);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the current reading position in the stream
|
||||
///
|
||||
/// \return The current position, or -1 on error.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual Int64 tell();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Return the size of the stream
|
||||
///
|
||||
/// \return The total number of bytes available in the stream, or -1 on error
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual Int64 getSize();
|
||||
|
||||
private:
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Member data
|
||||
////////////////////////////////////////////////////////////
|
||||
#ifdef ANDROID
|
||||
priv::ResourceStream* m_file;
|
||||
#else
|
||||
std::FILE* m_file; ///< stdio file stream
|
||||
#endif
|
||||
};
|
||||
|
||||
} // namespace sf
|
||||
|
||||
|
||||
#endif // SFML_FILEINPUTSTREAM_HPP
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \class sf::FileInputStream
|
||||
/// \ingroup system
|
||||
///
|
||||
/// This class is a specialization of InputStream that
|
||||
/// reads from a file on disk.
|
||||
///
|
||||
/// It wraps a file in the common InputStream interface
|
||||
/// and therefore allows to use generic classes or functions
|
||||
/// that accept such a stream, with a file on disk as the data
|
||||
/// source.
|
||||
///
|
||||
/// In addition to the virtual functions inherited from
|
||||
/// InputStream, FileInputStream adds a function to
|
||||
/// specify the file to open.
|
||||
///
|
||||
/// SFML resource classes can usually be loaded directly from
|
||||
/// a filename, so this class shouldn't be useful to you unless
|
||||
/// you create your own algorithms that operate on an InputStream.
|
||||
///
|
||||
/// Usage example:
|
||||
/// \code
|
||||
/// void process(InputStream& stream);
|
||||
///
|
||||
/// FileInputStream stream;
|
||||
/// if (stream.open("some_file.dat"))
|
||||
/// process(stream);
|
||||
/// \endcode
|
||||
///
|
||||
/// InputStream, MemoryInputStream
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
152
code/SFML-2.4.2/include/SFML/System/InputStream.hpp
Normal file
152
code/SFML-2.4.2/include/SFML/System/InputStream.hpp
Normal file
|
@ -0,0 +1,152 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org)
|
||||
//
|
||||
// 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_INPUTSTREAM_HPP
|
||||
#define SFML_INPUTSTREAM_HPP
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Config.hpp>
|
||||
#include <SFML/System/Export.hpp>
|
||||
|
||||
|
||||
namespace sf
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Abstract class for custom file input streams
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
class SFML_SYSTEM_API InputStream
|
||||
{
|
||||
public:
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Virtual destructor
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual ~InputStream() {}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Read data from the stream
|
||||
///
|
||||
/// After reading, the stream's reading position must be
|
||||
/// advanced by the amount of bytes read.
|
||||
///
|
||||
/// \param data Buffer where to copy the read data
|
||||
/// \param size Desired number of bytes to read
|
||||
///
|
||||
/// \return The number of bytes actually read, or -1 on error
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual Int64 read(void* data, Int64 size) = 0;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Change the current reading position
|
||||
///
|
||||
/// \param position The position to seek to, from the beginning
|
||||
///
|
||||
/// \return The position actually sought to, or -1 on error
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual Int64 seek(Int64 position) = 0;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the current reading position in the stream
|
||||
///
|
||||
/// \return The current position, or -1 on error.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual Int64 tell() = 0;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Return the size of the stream
|
||||
///
|
||||
/// \return The total number of bytes available in the stream, or -1 on error
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual Int64 getSize() = 0;
|
||||
};
|
||||
|
||||
} // namespace sf
|
||||
|
||||
|
||||
#endif // SFML_INPUTSTREAM_HPP
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \class sf::InputStream
|
||||
/// \ingroup system
|
||||
///
|
||||
/// This class allows users to define their own file input sources
|
||||
/// from which SFML can load resources.
|
||||
///
|
||||
/// SFML resource classes like sf::Texture and
|
||||
/// sf::SoundBuffer provide loadFromFile and loadFromMemory functions,
|
||||
/// which read data from conventional sources. However, if you
|
||||
/// have data coming from a different source (over a network,
|
||||
/// embedded, encrypted, compressed, etc) you can derive your
|
||||
/// own class from sf::InputStream and load SFML resources with
|
||||
/// their loadFromStream function.
|
||||
///
|
||||
/// Usage example:
|
||||
/// \code
|
||||
/// // custom stream class that reads from inside a zip file
|
||||
/// class ZipStream : public sf::InputStream
|
||||
/// {
|
||||
/// public:
|
||||
///
|
||||
/// ZipStream(std::string archive);
|
||||
///
|
||||
/// bool open(std::string filename);
|
||||
///
|
||||
/// Int64 read(void* data, Int64 size);
|
||||
///
|
||||
/// Int64 seek(Int64 position);
|
||||
///
|
||||
/// Int64 tell();
|
||||
///
|
||||
/// Int64 getSize();
|
||||
///
|
||||
/// private:
|
||||
///
|
||||
/// ...
|
||||
/// };
|
||||
///
|
||||
/// // now you can load textures...
|
||||
/// sf::Texture texture;
|
||||
/// ZipStream stream("resources.zip");
|
||||
/// stream.open("images/img.png");
|
||||
/// texture.loadFromStream(stream);
|
||||
///
|
||||
/// // musics...
|
||||
/// sf::Music music;
|
||||
/// ZipStream stream("resources.zip");
|
||||
/// stream.open("musics/msc.ogg");
|
||||
/// music.openFromStream(stream);
|
||||
///
|
||||
/// // etc.
|
||||
/// \endcode
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
139
code/SFML-2.4.2/include/SFML/System/Lock.hpp
Normal file
139
code/SFML-2.4.2/include/SFML/System/Lock.hpp
Normal file
|
@ -0,0 +1,139 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org)
|
||||
//
|
||||
// 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_LOCK_HPP
|
||||
#define SFML_LOCK_HPP
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/System/Export.hpp>
|
||||
#include <SFML/System/NonCopyable.hpp>
|
||||
|
||||
|
||||
namespace sf
|
||||
{
|
||||
class Mutex;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Automatic wrapper for locking and unlocking mutexes
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
class SFML_SYSTEM_API Lock : NonCopyable
|
||||
{
|
||||
public:
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Construct the lock with a target mutex
|
||||
///
|
||||
/// The mutex passed to sf::Lock is automatically locked.
|
||||
///
|
||||
/// \param mutex Mutex to lock
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
explicit Lock(Mutex& mutex);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Destructor
|
||||
///
|
||||
/// The destructor of sf::Lock automatically unlocks its mutex.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
~Lock();
|
||||
|
||||
private:
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Member data
|
||||
////////////////////////////////////////////////////////////
|
||||
Mutex& m_mutex; ///< Mutex to lock / unlock
|
||||
};
|
||||
|
||||
} // namespace sf
|
||||
|
||||
|
||||
#endif // SFML_LOCK_HPP
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \class sf::Lock
|
||||
/// \ingroup system
|
||||
///
|
||||
/// sf::Lock is a RAII wrapper for sf::Mutex. By unlocking
|
||||
/// it in its destructor, it ensures that the mutex will
|
||||
/// always be released when the current scope (most likely
|
||||
/// a function) ends.
|
||||
/// This is even more important when an exception or an early
|
||||
/// return statement can interrupt the execution flow of the
|
||||
/// function.
|
||||
///
|
||||
/// For maximum robustness, sf::Lock should always be used
|
||||
/// to lock/unlock a mutex.
|
||||
///
|
||||
/// Usage example:
|
||||
/// \code
|
||||
/// sf::Mutex mutex;
|
||||
///
|
||||
/// void function()
|
||||
/// {
|
||||
/// sf::Lock lock(mutex); // mutex is now locked
|
||||
///
|
||||
/// functionThatMayThrowAnException(); // mutex is unlocked if this function throws
|
||||
///
|
||||
/// if (someCondition)
|
||||
/// return; // mutex is unlocked
|
||||
///
|
||||
/// } // mutex is unlocked
|
||||
/// \endcode
|
||||
///
|
||||
/// Because the mutex is not explicitly unlocked in the code,
|
||||
/// it may remain locked longer than needed. If the region
|
||||
/// of the code that needs to be protected by the mutex is
|
||||
/// not the entire function, a good practice is to create a
|
||||
/// smaller, inner scope so that the lock is limited to this
|
||||
/// part of the code.
|
||||
///
|
||||
/// \code
|
||||
/// sf::Mutex mutex;
|
||||
///
|
||||
/// void function()
|
||||
/// {
|
||||
/// {
|
||||
/// sf::Lock lock(mutex);
|
||||
/// codeThatRequiresProtection();
|
||||
///
|
||||
/// } // mutex is unlocked here
|
||||
///
|
||||
/// codeThatDoesntCareAboutTheMutex();
|
||||
/// }
|
||||
/// \endcode
|
||||
///
|
||||
/// Having a mutex locked longer than required is a bad practice
|
||||
/// which can lead to bad performances. Don't forget that when
|
||||
/// a mutex is locked, other threads may be waiting doing nothing
|
||||
/// until it is released.
|
||||
///
|
||||
/// \see sf::Mutex
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
148
code/SFML-2.4.2/include/SFML/System/MemoryInputStream.hpp
Normal file
148
code/SFML-2.4.2/include/SFML/System/MemoryInputStream.hpp
Normal file
|
@ -0,0 +1,148 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org)
|
||||
//
|
||||
// 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_MEMORYINPUTSTREAM_HPP
|
||||
#define SFML_MEMORYINPUTSTREAM_HPP
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Config.hpp>
|
||||
#include <SFML/System/InputStream.hpp>
|
||||
#include <SFML/System/Export.hpp>
|
||||
#include <cstdlib>
|
||||
|
||||
|
||||
namespace sf
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Implementation of input stream based on a memory chunk
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
class SFML_SYSTEM_API MemoryInputStream : public InputStream
|
||||
{
|
||||
public:
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Default constructor
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
MemoryInputStream();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Open the stream from its data
|
||||
///
|
||||
/// \param data Pointer to the data in memory
|
||||
/// \param sizeInBytes Size of the data, in bytes
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void open(const void* data, std::size_t sizeInBytes);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Read data from the stream
|
||||
///
|
||||
/// After reading, the stream's reading position must be
|
||||
/// advanced by the amount of bytes read.
|
||||
///
|
||||
/// \param data Buffer where to copy the read data
|
||||
/// \param size Desired number of bytes to read
|
||||
///
|
||||
/// \return The number of bytes actually read, or -1 on error
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual Int64 read(void* data, Int64 size);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Change the current reading position
|
||||
///
|
||||
/// \param position The position to seek to, from the beginning
|
||||
///
|
||||
/// \return The position actually sought to, or -1 on error
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual Int64 seek(Int64 position);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the current reading position in the stream
|
||||
///
|
||||
/// \return The current position, or -1 on error.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual Int64 tell();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Return the size of the stream
|
||||
///
|
||||
/// \return The total number of bytes available in the stream, or -1 on error
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual Int64 getSize();
|
||||
|
||||
private:
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Member data
|
||||
////////////////////////////////////////////////////////////
|
||||
const char* m_data; ///< Pointer to the data in memory
|
||||
Int64 m_size; ///< Total size of the data
|
||||
Int64 m_offset; ///< Current reading position
|
||||
};
|
||||
|
||||
} // namespace sf
|
||||
|
||||
|
||||
#endif // SFML_MEMORYINPUTSTREAM_HPP
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \class sf::MemoryInputStream
|
||||
/// \ingroup system
|
||||
///
|
||||
/// This class is a specialization of InputStream that
|
||||
/// reads from data in memory.
|
||||
///
|
||||
/// It wraps a memory chunk in the common InputStream interface
|
||||
/// and therefore allows to use generic classes or functions
|
||||
/// that accept such a stream, with content already loaded in memory.
|
||||
///
|
||||
/// In addition to the virtual functions inherited from
|
||||
/// InputStream, MemoryInputStream adds a function to
|
||||
/// specify the pointer and size of the data in memory.
|
||||
///
|
||||
/// SFML resource classes can usually be loaded directly from
|
||||
/// memory, so this class shouldn't be useful to you unless
|
||||
/// you create your own algorithms that operate on an InputStream.
|
||||
///
|
||||
/// Usage example:
|
||||
/// \code
|
||||
/// void process(InputStream& stream);
|
||||
///
|
||||
/// MemoryInputStream stream;
|
||||
/// stream.open(thePtr, theSize);
|
||||
/// process(stream);
|
||||
/// \endcode
|
||||
///
|
||||
/// InputStream, FileInputStream
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
148
code/SFML-2.4.2/include/SFML/System/Mutex.hpp
Normal file
148
code/SFML-2.4.2/include/SFML/System/Mutex.hpp
Normal file
|
@ -0,0 +1,148 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org)
|
||||
//
|
||||
// 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_MUTEX_HPP
|
||||
#define SFML_MUTEX_HPP
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/System/Export.hpp>
|
||||
#include <SFML/System/NonCopyable.hpp>
|
||||
|
||||
|
||||
namespace sf
|
||||
{
|
||||
namespace priv
|
||||
{
|
||||
class MutexImpl;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Blocks concurrent access to shared resources
|
||||
/// from multiple threads
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
class SFML_SYSTEM_API Mutex : NonCopyable
|
||||
{
|
||||
public:
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Default constructor
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Mutex();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Destructor
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
~Mutex();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Lock the mutex
|
||||
///
|
||||
/// If the mutex is already locked in another thread,
|
||||
/// this call will block the execution until the mutex
|
||||
/// is released.
|
||||
///
|
||||
/// \see unlock
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void lock();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Unlock the mutex
|
||||
///
|
||||
/// \see lock
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void unlock();
|
||||
|
||||
private:
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Member data
|
||||
////////////////////////////////////////////////////////////
|
||||
priv::MutexImpl* m_mutexImpl; ///< OS-specific implementation
|
||||
};
|
||||
|
||||
} // namespace sf
|
||||
|
||||
|
||||
#endif // SFML_MUTEX_HPP
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \class sf::Mutex
|
||||
/// \ingroup system
|
||||
///
|
||||
/// Mutex stands for "MUTual EXclusion". A mutex is a
|
||||
/// synchronization object, used when multiple threads are involved.
|
||||
///
|
||||
/// When you want to protect a part of the code from being accessed
|
||||
/// simultaneously by multiple threads, you typically use a
|
||||
/// mutex. When a thread is locked by a mutex, any other thread
|
||||
/// trying to lock it will be blocked until the mutex is released
|
||||
/// by the thread that locked it. This way, you can allow only
|
||||
/// one thread at a time to access a critical region of your code.
|
||||
///
|
||||
/// Usage example:
|
||||
/// \code
|
||||
/// Database database; // this is a critical resource that needs some protection
|
||||
/// sf::Mutex mutex;
|
||||
///
|
||||
/// void thread1()
|
||||
/// {
|
||||
/// mutex.lock(); // this call will block the thread if the mutex is already locked by thread2
|
||||
/// database.write(...);
|
||||
/// mutex.unlock(); // if thread2 was waiting, it will now be unblocked
|
||||
/// }
|
||||
///
|
||||
/// void thread2()
|
||||
/// {
|
||||
/// mutex.lock(); // this call will block the thread if the mutex is already locked by thread1
|
||||
/// database.write(...);
|
||||
/// mutex.unlock(); // if thread1 was waiting, it will now be unblocked
|
||||
/// }
|
||||
/// \endcode
|
||||
///
|
||||
/// Be very careful with mutexes. A bad usage can lead to bad problems,
|
||||
/// like deadlocks (two threads are waiting for each other and the
|
||||
/// application is globally stuck).
|
||||
///
|
||||
/// To make the usage of mutexes more robust, particularly in
|
||||
/// environments where exceptions can be thrown, you should
|
||||
/// use the helper class sf::Lock to lock/unlock mutexes.
|
||||
///
|
||||
/// SFML mutexes are recursive, which means that you can lock
|
||||
/// a mutex multiple times in the same thread without creating
|
||||
/// a deadlock. In this case, the first call to lock() behaves
|
||||
/// as usual, and the following ones have no effect.
|
||||
/// However, you must call unlock() exactly as many times as you
|
||||
/// called lock(). If you don't, the mutex won't be released.
|
||||
///
|
||||
/// \see sf::Lock
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
62
code/SFML-2.4.2/include/SFML/System/NativeActivity.hpp
Normal file
62
code/SFML-2.4.2/include/SFML/System/NativeActivity.hpp
Normal file
|
@ -0,0 +1,62 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org)
|
||||
//
|
||||
// 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_NATIVEACTIVITY_HPP
|
||||
#define SFML_NATIVEACTIVITY_HPP
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/System/Export.hpp>
|
||||
|
||||
|
||||
#if !defined(SFML_SYSTEM_ANDROID)
|
||||
#error NativeActivity.hpp: This header is Android only.
|
||||
#endif
|
||||
|
||||
|
||||
struct ANativeActivity;
|
||||
|
||||
namespace sf
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \ingroup system
|
||||
/// \brief Return a pointer to the Android native activity
|
||||
///
|
||||
/// You shouldn't have to use this function, unless you want
|
||||
/// to implement very specific details, that SFML doesn't
|
||||
/// support, or to use a workaround for a known issue.
|
||||
///
|
||||
/// \return Pointer to Android native activity structure
|
||||
///
|
||||
/// \sfplatform{Android,SFML/System/NativeActivity.hpp}
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_SYSTEM_API ANativeActivity* getNativeActivity();
|
||||
|
||||
} // namespace sf
|
||||
|
||||
|
||||
#endif // SFML_NATIVEACTIVITY_HPP
|
129
code/SFML-2.4.2/include/SFML/System/NonCopyable.hpp
Normal file
129
code/SFML-2.4.2/include/SFML/System/NonCopyable.hpp
Normal file
|
@ -0,0 +1,129 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org)
|
||||
//
|
||||
// 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_NONCOPYABLE_HPP
|
||||
#define SFML_NONCOPYABLE_HPP
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/System/Export.hpp>
|
||||
|
||||
|
||||
namespace sf
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Utility class that makes any derived
|
||||
/// class non-copyable
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
class SFML_SYSTEM_API NonCopyable
|
||||
{
|
||||
protected:
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Default constructor
|
||||
///
|
||||
/// Because this class has a copy constructor, the compiler
|
||||
/// will not automatically generate the default constructor.
|
||||
/// That's why we must define it explicitly.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
NonCopyable() {}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Default destructor
|
||||
///
|
||||
/// By declaring a protected destructor it's impossible to
|
||||
/// call delete on a pointer of sf::NonCopyable, thus
|
||||
/// preventing possible resource leaks.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
~NonCopyable() {}
|
||||
|
||||
private:
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Disabled copy constructor
|
||||
///
|
||||
/// By making the copy constructor private, the compiler will
|
||||
/// trigger an error if anyone outside tries to use it.
|
||||
/// To prevent NonCopyable or friend classes from using it,
|
||||
/// we also give no definition, so that the linker will
|
||||
/// produce an error if the first protection was inefficient.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
NonCopyable(const NonCopyable&);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Disabled assignment operator
|
||||
///
|
||||
/// By making the assignment operator private, the compiler will
|
||||
/// trigger an error if anyone outside tries to use it.
|
||||
/// To prevent NonCopyable or friend classes from using it,
|
||||
/// we also give no definition, so that the linker will
|
||||
/// produce an error if the first protection was inefficient.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
NonCopyable& operator =(const NonCopyable&);
|
||||
};
|
||||
|
||||
} // namespace sf
|
||||
|
||||
|
||||
#endif // SFML_NONCOPYABLE_HPP
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \class sf::NonCopyable
|
||||
/// \ingroup system
|
||||
///
|
||||
/// This class makes its instances non-copyable, by explicitly
|
||||
/// disabling its copy constructor and its assignment operator.
|
||||
///
|
||||
/// To create a non-copyable class, simply inherit from
|
||||
/// sf::NonCopyable.
|
||||
///
|
||||
/// The type of inheritance (public or private) doesn't matter,
|
||||
/// the copy constructor and assignment operator are declared private
|
||||
/// in sf::NonCopyable so they will end up being inaccessible in both
|
||||
/// cases. Thus you can use a shorter syntax for inheriting from it
|
||||
/// (see below).
|
||||
///
|
||||
/// Usage example:
|
||||
/// \code
|
||||
/// class MyNonCopyableClass : sf::NonCopyable
|
||||
/// {
|
||||
/// ...
|
||||
/// };
|
||||
/// \endcode
|
||||
///
|
||||
/// Deciding whether the instances of a class can be copied
|
||||
/// or not is a very important design choice. You are strongly
|
||||
/// encouraged to think about it before writing a class,
|
||||
/// and to use sf::NonCopyable when necessary to prevent
|
||||
/// many potential future errors when using it. This is also
|
||||
/// a very important indication to users of your class.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
52
code/SFML-2.4.2/include/SFML/System/Sleep.hpp
Normal file
52
code/SFML-2.4.2/include/SFML/System/Sleep.hpp
Normal file
|
@ -0,0 +1,52 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org)
|
||||
//
|
||||
// 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_SLEEP_HPP
|
||||
#define SFML_SLEEP_HPP
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/System/Export.hpp>
|
||||
#include <SFML/System/Time.hpp>
|
||||
|
||||
|
||||
namespace sf
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \ingroup system
|
||||
/// \brief Make the current thread sleep for a given duration
|
||||
///
|
||||
/// sf::sleep is the best way to block a program or one of its
|
||||
/// threads, as it doesn't consume any CPU power.
|
||||
///
|
||||
/// \param duration Time to sleep
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void SFML_SYSTEM_API sleep(Time duration);
|
||||
|
||||
} // namespace sf
|
||||
|
||||
|
||||
#endif // SFML_SLEEP_HPP
|
669
code/SFML-2.4.2/include/SFML/System/String.hpp
Normal file
669
code/SFML-2.4.2/include/SFML/System/String.hpp
Normal file
|
@ -0,0 +1,669 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org)
|
||||
//
|
||||
// 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_STRING_HPP
|
||||
#define SFML_STRING_HPP
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/System/Export.hpp>
|
||||
#include <SFML/System/Utf.hpp>
|
||||
#include <iterator>
|
||||
#include <locale>
|
||||
#include <string>
|
||||
|
||||
|
||||
namespace sf
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Utility string class that automatically handles
|
||||
/// conversions between types and encodings
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
class SFML_SYSTEM_API String
|
||||
{
|
||||
public:
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Types
|
||||
////////////////////////////////////////////////////////////
|
||||
typedef std::basic_string<Uint32>::iterator Iterator; ///< Iterator type
|
||||
typedef std::basic_string<Uint32>::const_iterator ConstIterator; ///< Read-only iterator type
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Static member data
|
||||
////////////////////////////////////////////////////////////
|
||||
static const std::size_t InvalidPos; ///< Represents an invalid position in the string
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Default constructor
|
||||
///
|
||||
/// This constructor creates an empty string.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
String();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Construct from a single ANSI character and a locale
|
||||
///
|
||||
/// The source character is converted to UTF-32 according
|
||||
/// to the given locale.
|
||||
///
|
||||
/// \param ansiChar ANSI character to convert
|
||||
/// \param locale Locale to use for conversion
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
String(char ansiChar, const std::locale& locale = std::locale());
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Construct from single wide character
|
||||
///
|
||||
/// \param wideChar Wide character to convert
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
String(wchar_t wideChar);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Construct from single UTF-32 character
|
||||
///
|
||||
/// \param utf32Char UTF-32 character to convert
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
String(Uint32 utf32Char);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Construct from a null-terminated C-style ANSI string and a locale
|
||||
///
|
||||
/// The source string is converted to UTF-32 according
|
||||
/// to the given locale.
|
||||
///
|
||||
/// \param ansiString ANSI string to convert
|
||||
/// \param locale Locale to use for conversion
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
String(const char* ansiString, const std::locale& locale = std::locale());
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Construct from an ANSI string and a locale
|
||||
///
|
||||
/// The source string is converted to UTF-32 according
|
||||
/// to the given locale.
|
||||
///
|
||||
/// \param ansiString ANSI string to convert
|
||||
/// \param locale Locale to use for conversion
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
String(const std::string& ansiString, const std::locale& locale = std::locale());
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Construct from null-terminated C-style wide string
|
||||
///
|
||||
/// \param wideString Wide string to convert
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
String(const wchar_t* wideString);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Construct from a wide string
|
||||
///
|
||||
/// \param wideString Wide string to convert
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
String(const std::wstring& wideString);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Construct from a null-terminated C-style UTF-32 string
|
||||
///
|
||||
/// \param utf32String UTF-32 string to assign
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
String(const Uint32* utf32String);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Construct from an UTF-32 string
|
||||
///
|
||||
/// \param utf32String UTF-32 string to assign
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
String(const std::basic_string<Uint32>& utf32String);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Copy constructor
|
||||
///
|
||||
/// \param copy Instance to copy
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
String(const String& copy);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Create a new sf::String from a UTF-8 encoded string
|
||||
///
|
||||
/// \param begin Forward iterator to the beginning of the UTF-8 sequence
|
||||
/// \param end Forward iterator to the end of the UTF-8 sequence
|
||||
///
|
||||
/// \return A sf::String containing the source string
|
||||
///
|
||||
/// \see fromUtf16, fromUtf32
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
static String fromUtf8(T begin, T end);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Create a new sf::String from a UTF-16 encoded string
|
||||
///
|
||||
/// \param begin Forward iterator to the beginning of the UTF-16 sequence
|
||||
/// \param end Forward iterator to the end of the UTF-16 sequence
|
||||
///
|
||||
/// \return A sf::String containing the source string
|
||||
///
|
||||
/// \see fromUtf8, fromUtf32
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
static String fromUtf16(T begin, T end);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Create a new sf::String from a UTF-32 encoded string
|
||||
///
|
||||
/// This function is provided for consistency, it is equivalent to
|
||||
/// using the constructors that takes a const sf::Uint32* or
|
||||
/// a std::basic_string<sf::Uint32>.
|
||||
///
|
||||
/// \param begin Forward iterator to the beginning of the UTF-32 sequence
|
||||
/// \param end Forward iterator to the end of the UTF-32 sequence
|
||||
///
|
||||
/// \return A sf::String containing the source string
|
||||
///
|
||||
/// \see fromUtf8, fromUtf16
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
static String fromUtf32(T begin, T end);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Implicit conversion operator to std::string (ANSI string)
|
||||
///
|
||||
/// The current global locale is used for conversion. If you
|
||||
/// want to explicitly specify a locale, see toAnsiString.
|
||||
/// Characters that do not fit in the target encoding are
|
||||
/// discarded from the returned string.
|
||||
/// This operator is defined for convenience, and is equivalent
|
||||
/// to calling toAnsiString().
|
||||
///
|
||||
/// \return Converted ANSI string
|
||||
///
|
||||
/// \see toAnsiString, operator std::wstring
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
operator std::string() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Implicit conversion operator to std::wstring (wide string)
|
||||
///
|
||||
/// Characters that do not fit in the target encoding are
|
||||
/// discarded from the returned string.
|
||||
/// This operator is defined for convenience, and is equivalent
|
||||
/// to calling toWideString().
|
||||
///
|
||||
/// \return Converted wide string
|
||||
///
|
||||
/// \see toWideString, operator std::string
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
operator std::wstring() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Convert the Unicode string to an ANSI string
|
||||
///
|
||||
/// The UTF-32 string is converted to an ANSI string in
|
||||
/// the encoding defined by \a locale.
|
||||
/// Characters that do not fit in the target encoding are
|
||||
/// discarded from the returned string.
|
||||
///
|
||||
/// \param locale Locale to use for conversion
|
||||
///
|
||||
/// \return Converted ANSI string
|
||||
///
|
||||
/// \see toWideString, operator std::string
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
std::string toAnsiString(const std::locale& locale = std::locale()) const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Convert the Unicode string to a wide string
|
||||
///
|
||||
/// Characters that do not fit in the target encoding are
|
||||
/// discarded from the returned string.
|
||||
///
|
||||
/// \return Converted wide string
|
||||
///
|
||||
/// \see toAnsiString, operator std::wstring
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
std::wstring toWideString() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Convert the Unicode string to a UTF-8 string
|
||||
///
|
||||
/// \return Converted UTF-8 string
|
||||
///
|
||||
/// \see toUtf16, toUtf32
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
std::basic_string<Uint8> toUtf8() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Convert the Unicode string to a UTF-16 string
|
||||
///
|
||||
/// \return Converted UTF-16 string
|
||||
///
|
||||
/// \see toUtf8, toUtf32
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
std::basic_string<Uint16> toUtf16() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Convert the Unicode string to a UTF-32 string
|
||||
///
|
||||
/// This function doesn't perform any conversion, since the
|
||||
/// string is already stored as UTF-32 internally.
|
||||
///
|
||||
/// \return Converted UTF-32 string
|
||||
///
|
||||
/// \see toUtf8, toUtf16
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
std::basic_string<Uint32> toUtf32() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Overload of assignment operator
|
||||
///
|
||||
/// \param right Instance to assign
|
||||
///
|
||||
/// \return Reference to self
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
String& operator =(const String& right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Overload of += operator to append an UTF-32 string
|
||||
///
|
||||
/// \param right String to append
|
||||
///
|
||||
/// \return Reference to self
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
String& operator +=(const String& right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Overload of [] operator to access a character by its position
|
||||
///
|
||||
/// This function provides read-only access to characters.
|
||||
/// Note: the behavior is undefined if \a index is out of range.
|
||||
///
|
||||
/// \param index Index of the character to get
|
||||
///
|
||||
/// \return Character at position \a index
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Uint32 operator [](std::size_t index) const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Overload of [] operator to access a character by its position
|
||||
///
|
||||
/// This function provides read and write access to characters.
|
||||
/// Note: the behavior is undefined if \a index is out of range.
|
||||
///
|
||||
/// \param index Index of the character to get
|
||||
///
|
||||
/// \return Reference to the character at position \a index
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Uint32& operator [](std::size_t index);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Clear the string
|
||||
///
|
||||
/// This function removes all the characters from the string.
|
||||
///
|
||||
/// \see isEmpty, erase
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void clear();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the size of the string
|
||||
///
|
||||
/// \return Number of characters in the string
|
||||
///
|
||||
/// \see isEmpty
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
std::size_t getSize() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Check whether the string is empty or not
|
||||
///
|
||||
/// \return True if the string is empty (i.e. contains no character)
|
||||
///
|
||||
/// \see clear, getSize
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
bool isEmpty() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Erase one or more characters from the string
|
||||
///
|
||||
/// This function removes a sequence of \a count characters
|
||||
/// starting from \a position.
|
||||
///
|
||||
/// \param position Position of the first character to erase
|
||||
/// \param count Number of characters to erase
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void erase(std::size_t position, std::size_t count = 1);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Insert one or more characters into the string
|
||||
///
|
||||
/// This function inserts the characters of \a str
|
||||
/// into the string, starting from \a position.
|
||||
///
|
||||
/// \param position Position of insertion
|
||||
/// \param str Characters to insert
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void insert(std::size_t position, const String& str);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Find a sequence of one or more characters in the string
|
||||
///
|
||||
/// This function searches for the characters of \a str
|
||||
/// in the string, starting from \a start.
|
||||
///
|
||||
/// \param str Characters to find
|
||||
/// \param start Where to begin searching
|
||||
///
|
||||
/// \return Position of \a str in the string, or String::InvalidPos if not found
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
std::size_t find(const String& str, std::size_t start = 0) const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Replace a substring with another string
|
||||
///
|
||||
/// This function replaces the substring that starts at index \a position
|
||||
/// and spans \a length characters with the string \a replaceWith.
|
||||
///
|
||||
/// \param position Index of the first character to be replaced
|
||||
/// \param length Number of characters to replace. You can pass InvalidPos to
|
||||
/// replace all characters until the end of the string.
|
||||
/// \param replaceWith String that replaces the given substring.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void replace(std::size_t position, std::size_t length, const String& replaceWith);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Replace all occurrences of a substring with a replacement string
|
||||
///
|
||||
/// This function replaces all occurrences of \a searchFor in this string
|
||||
/// with the string \a replaceWith.
|
||||
///
|
||||
/// \param searchFor The value being searched for
|
||||
/// \param replaceWith The value that replaces found \a searchFor values
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void replace(const String& searchFor, const String& replaceWith);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Return a part of the string
|
||||
///
|
||||
/// This function returns the substring that starts at index \a position
|
||||
/// and spans \a length characters.
|
||||
///
|
||||
/// \param position Index of the first character
|
||||
/// \param length Number of characters to include in the substring (if
|
||||
/// the string is shorter, as many characters as possible
|
||||
/// are included). \ref InvalidPos can be used to include all
|
||||
/// characters until the end of the string.
|
||||
///
|
||||
/// \return String object containing a substring of this object
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
String substring(std::size_t position, std::size_t length = InvalidPos) const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get a pointer to the C-style array of characters
|
||||
///
|
||||
/// This functions provides a read-only access to a
|
||||
/// null-terminated C-style representation of the string.
|
||||
/// The returned pointer is temporary and is meant only for
|
||||
/// immediate use, thus it is not recommended to store it.
|
||||
///
|
||||
/// \return Read-only pointer to the array of characters
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
const Uint32* getData() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Return an iterator to the beginning of the string
|
||||
///
|
||||
/// \return Read-write iterator to the beginning of the string characters
|
||||
///
|
||||
/// \see end
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Iterator begin();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Return an iterator to the beginning of the string
|
||||
///
|
||||
/// \return Read-only iterator to the beginning of the string characters
|
||||
///
|
||||
/// \see end
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
ConstIterator begin() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Return an iterator to the end of the string
|
||||
///
|
||||
/// The end iterator refers to 1 position past the last character;
|
||||
/// thus it represents an invalid character and should never be
|
||||
/// accessed.
|
||||
///
|
||||
/// \return Read-write iterator to the end of the string characters
|
||||
///
|
||||
/// \see begin
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Iterator end();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Return an iterator to the end of the string
|
||||
///
|
||||
/// The end iterator refers to 1 position past the last character;
|
||||
/// thus it represents an invalid character and should never be
|
||||
/// accessed.
|
||||
///
|
||||
/// \return Read-only iterator to the end of the string characters
|
||||
///
|
||||
/// \see begin
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
ConstIterator end() const;
|
||||
|
||||
private:
|
||||
|
||||
friend SFML_SYSTEM_API bool operator ==(const String& left, const String& right);
|
||||
friend SFML_SYSTEM_API bool operator <(const String& left, const String& right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Member data
|
||||
////////////////////////////////////////////////////////////
|
||||
std::basic_string<Uint32> m_string; ///< Internal string of UTF-32 characters
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \relates String
|
||||
/// \brief Overload of == operator to compare two UTF-32 strings
|
||||
///
|
||||
/// \param left Left operand (a string)
|
||||
/// \param right Right operand (a string)
|
||||
///
|
||||
/// \return True if both strings are equal
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_SYSTEM_API bool operator ==(const String& left, const String& right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \relates String
|
||||
/// \brief Overload of != operator to compare two UTF-32 strings
|
||||
///
|
||||
/// \param left Left operand (a string)
|
||||
/// \param right Right operand (a string)
|
||||
///
|
||||
/// \return True if both strings are different
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_SYSTEM_API bool operator !=(const String& left, const String& right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \relates String
|
||||
/// \brief Overload of < operator to compare two UTF-32 strings
|
||||
///
|
||||
/// \param left Left operand (a string)
|
||||
/// \param right Right operand (a string)
|
||||
///
|
||||
/// \return True if \a left is lexicographically before \a right
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_SYSTEM_API bool operator <(const String& left, const String& right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \relates String
|
||||
/// \brief Overload of > operator to compare two UTF-32 strings
|
||||
///
|
||||
/// \param left Left operand (a string)
|
||||
/// \param right Right operand (a string)
|
||||
///
|
||||
/// \return True if \a left is lexicographically after \a right
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_SYSTEM_API bool operator >(const String& left, const String& right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \relates String
|
||||
/// \brief Overload of <= operator to compare two UTF-32 strings
|
||||
///
|
||||
/// \param left Left operand (a string)
|
||||
/// \param right Right operand (a string)
|
||||
///
|
||||
/// \return True if \a left is lexicographically before or equivalent to \a right
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_SYSTEM_API bool operator <=(const String& left, const String& right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \relates String
|
||||
/// \brief Overload of >= operator to compare two UTF-32 strings
|
||||
///
|
||||
/// \param left Left operand (a string)
|
||||
/// \param right Right operand (a string)
|
||||
///
|
||||
/// \return True if \a left is lexicographically after or equivalent to \a right
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_SYSTEM_API bool operator >=(const String& left, const String& right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \relates String
|
||||
/// \brief Overload of binary + operator to concatenate two strings
|
||||
///
|
||||
/// \param left Left operand (a string)
|
||||
/// \param right Right operand (a string)
|
||||
///
|
||||
/// \return Concatenated string
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_SYSTEM_API String operator +(const String& left, const String& right);
|
||||
|
||||
#include <SFML/System/String.inl>
|
||||
|
||||
} // namespace sf
|
||||
|
||||
|
||||
#endif // SFML_STRING_HPP
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \class sf::String
|
||||
/// \ingroup system
|
||||
///
|
||||
/// sf::String is a utility string class defined mainly for
|
||||
/// convenience. It is a Unicode string (implemented using
|
||||
/// UTF-32), thus it can store any character in the world
|
||||
/// (European, Chinese, Arabic, Hebrew, etc.).
|
||||
///
|
||||
/// It automatically handles conversions from/to ANSI and
|
||||
/// wide strings, so that you can work with standard string
|
||||
/// classes and still be compatible with functions taking a
|
||||
/// sf::String.
|
||||
///
|
||||
/// \code
|
||||
/// sf::String s;
|
||||
///
|
||||
/// std::string s1 = s; // automatically converted to ANSI string
|
||||
/// std::wstring s2 = s; // automatically converted to wide string
|
||||
/// s = "hello"; // automatically converted from ANSI string
|
||||
/// s = L"hello"; // automatically converted from wide string
|
||||
/// s += 'a'; // automatically converted from ANSI string
|
||||
/// s += L'a'; // automatically converted from wide string
|
||||
/// \endcode
|
||||
///
|
||||
/// Conversions involving ANSI strings use the default user locale. However
|
||||
/// it is possible to use a custom locale if necessary:
|
||||
/// \code
|
||||
/// std::locale locale;
|
||||
/// sf::String s;
|
||||
/// ...
|
||||
/// std::string s1 = s.toAnsiString(locale);
|
||||
/// s = sf::String("hello", locale);
|
||||
/// \endcode
|
||||
///
|
||||
/// sf::String defines the most important functions of the
|
||||
/// standard std::string class: removing, random access, iterating,
|
||||
/// appending, comparing, etc. However it is a simple class
|
||||
/// provided for convenience, and you may have to consider using
|
||||
/// a more optimized class if your program requires complex string
|
||||
/// handling. The automatic conversion functions will then take
|
||||
/// care of converting your string to sf::String whenever SFML
|
||||
/// requires it.
|
||||
///
|
||||
/// Please note that SFML also defines a low-level, generic
|
||||
/// interface for Unicode handling, see the sf::Utf classes.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
53
code/SFML-2.4.2/include/SFML/System/String.inl
Normal file
53
code/SFML-2.4.2/include/SFML/System/String.inl
Normal file
|
@ -0,0 +1,53 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org)
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
String String::fromUtf8(T begin, T end)
|
||||
{
|
||||
String string;
|
||||
Utf8::toUtf32(begin, end, std::back_inserter(string.m_string));
|
||||
return string;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
String String::fromUtf16(T begin, T end)
|
||||
{
|
||||
String string;
|
||||
Utf16::toUtf32(begin, end, std::back_inserter(string.m_string));
|
||||
return string;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
String String::fromUtf32(T begin, T end)
|
||||
{
|
||||
String string;
|
||||
string.m_string.assign(begin, end);
|
||||
return string;
|
||||
}
|
282
code/SFML-2.4.2/include/SFML/System/Thread.hpp
Normal file
282
code/SFML-2.4.2/include/SFML/System/Thread.hpp
Normal file
|
@ -0,0 +1,282 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org)
|
||||
//
|
||||
// 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_THREAD_HPP
|
||||
#define SFML_THREAD_HPP
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/System/Export.hpp>
|
||||
#include <SFML/System/NonCopyable.hpp>
|
||||
#include <cstdlib>
|
||||
|
||||
|
||||
namespace sf
|
||||
{
|
||||
namespace priv
|
||||
{
|
||||
class ThreadImpl;
|
||||
struct ThreadFunc;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Utility class to manipulate threads
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
class SFML_SYSTEM_API Thread : NonCopyable
|
||||
{
|
||||
public:
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Construct the thread from a functor with no argument
|
||||
///
|
||||
/// This constructor works for function objects, as well
|
||||
/// as free functions.
|
||||
///
|
||||
/// Use this constructor for this kind of function:
|
||||
/// \code
|
||||
/// void function();
|
||||
///
|
||||
/// // --- or ----
|
||||
///
|
||||
/// struct Functor
|
||||
/// {
|
||||
/// void operator()();
|
||||
/// };
|
||||
/// \endcode
|
||||
/// Note: this does *not* run the thread, use launch().
|
||||
///
|
||||
/// \param function Functor or free function to use as the entry point of the thread
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename F>
|
||||
Thread(F function);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Construct the thread from a functor with an argument
|
||||
///
|
||||
/// This constructor works for function objects, as well
|
||||
/// as free functions.
|
||||
/// It is a template, which means that the argument can
|
||||
/// have any type (int, std::string, void*, Toto, ...).
|
||||
///
|
||||
/// Use this constructor for this kind of function:
|
||||
/// \code
|
||||
/// void function(int arg);
|
||||
///
|
||||
/// // --- or ----
|
||||
///
|
||||
/// struct Functor
|
||||
/// {
|
||||
/// void operator()(std::string arg);
|
||||
/// };
|
||||
/// \endcode
|
||||
/// Note: this does *not* run the thread, use launch().
|
||||
///
|
||||
/// \param function Functor or free function to use as the entry point of the thread
|
||||
/// \param argument argument to forward to the function
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename F, typename A>
|
||||
Thread(F function, A argument);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Construct the thread from a member function and an object
|
||||
///
|
||||
/// This constructor is a template, which means that you can
|
||||
/// use it with any class.
|
||||
/// Use this constructor for this kind of function:
|
||||
/// \code
|
||||
/// class MyClass
|
||||
/// {
|
||||
/// public:
|
||||
///
|
||||
/// void function();
|
||||
/// };
|
||||
/// \endcode
|
||||
/// Note: this does *not* run the thread, use launch().
|
||||
///
|
||||
/// \param function Entry point of the thread
|
||||
/// \param object Pointer to the object to use
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename C>
|
||||
Thread(void(C::*function)(), C* object);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Destructor
|
||||
///
|
||||
/// This destructor calls wait(), so that the internal thread
|
||||
/// cannot survive after its sf::Thread instance is destroyed.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
~Thread();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Run the thread
|
||||
///
|
||||
/// This function starts the entry point passed to the
|
||||
/// thread's constructor, and returns immediately.
|
||||
/// After this function returns, the thread's function is
|
||||
/// running in parallel to the calling code.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void launch();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Wait until the thread finishes
|
||||
///
|
||||
/// This function will block the execution until the
|
||||
/// thread's function ends.
|
||||
/// Warning: if the thread function never ends, the calling
|
||||
/// thread will block forever.
|
||||
/// If this function is called from its owner thread, it
|
||||
/// returns without doing anything.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void wait();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Terminate the thread
|
||||
///
|
||||
/// This function immediately stops the thread, without waiting
|
||||
/// for its function to finish.
|
||||
/// Terminating a thread with this function is not safe,
|
||||
/// and can lead to local variables not being destroyed
|
||||
/// on some operating systems. You should rather try to make
|
||||
/// the thread function terminate by itself.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void terminate();
|
||||
|
||||
private:
|
||||
|
||||
friend class priv::ThreadImpl;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Internal entry point of the thread
|
||||
///
|
||||
/// This function is called by the thread implementation.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void run();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Member data
|
||||
////////////////////////////////////////////////////////////
|
||||
priv::ThreadImpl* m_impl; ///< OS-specific implementation of the thread
|
||||
priv::ThreadFunc* m_entryPoint; ///< Abstraction of the function to run
|
||||
};
|
||||
|
||||
#include <SFML/System/Thread.inl>
|
||||
|
||||
} // namespace sf
|
||||
|
||||
#endif // SFML_THREAD_HPP
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \class sf::Thread
|
||||
/// \ingroup system
|
||||
///
|
||||
/// Threads provide a way to run multiple parts of the code
|
||||
/// in parallel. When you launch a new thread, the execution
|
||||
/// is split and both the new thread and the caller run
|
||||
/// in parallel.
|
||||
///
|
||||
/// To use a sf::Thread, you construct it directly with the
|
||||
/// function to execute as the entry point of the thread.
|
||||
/// sf::Thread has multiple template constructors, which means
|
||||
/// that you can use several types of entry points:
|
||||
/// \li non-member functions with no argument
|
||||
/// \li non-member functions with one argument of any type
|
||||
/// \li functors with no argument (this one is particularly useful for compatibility with boost/std::%bind)
|
||||
/// \li functors with one argument of any type
|
||||
/// \li member functions from any class with no argument
|
||||
///
|
||||
/// The function argument, if any, is copied in the sf::Thread
|
||||
/// instance, as well as the functor (if the corresponding
|
||||
/// constructor is used). Class instances, however, are passed
|
||||
/// by pointer so you must make sure that the object won't be
|
||||
/// destroyed while the thread is still using it.
|
||||
///
|
||||
/// The thread ends when its function is terminated. If the
|
||||
/// owner sf::Thread instance is destroyed before the
|
||||
/// thread is finished, the destructor will wait (see wait())
|
||||
///
|
||||
/// Usage examples:
|
||||
/// \code
|
||||
/// // example 1: non member function with one argument
|
||||
///
|
||||
/// void threadFunc(int argument)
|
||||
/// {
|
||||
/// ...
|
||||
/// }
|
||||
///
|
||||
/// sf::Thread thread(&threadFunc, 5);
|
||||
/// thread.launch(); // start the thread (internally calls threadFunc(5))
|
||||
/// \endcode
|
||||
///
|
||||
/// \code
|
||||
/// // example 2: member function
|
||||
///
|
||||
/// class Task
|
||||
/// {
|
||||
/// public:
|
||||
/// void run()
|
||||
/// {
|
||||
/// ...
|
||||
/// }
|
||||
/// };
|
||||
///
|
||||
/// Task task;
|
||||
/// sf::Thread thread(&Task::run, &task);
|
||||
/// thread.launch(); // start the thread (internally calls task.run())
|
||||
/// \endcode
|
||||
///
|
||||
/// \code
|
||||
/// // example 3: functor
|
||||
///
|
||||
/// struct Task
|
||||
/// {
|
||||
/// void operator()()
|
||||
/// {
|
||||
/// ...
|
||||
/// }
|
||||
/// };
|
||||
///
|
||||
/// sf::Thread thread(Task());
|
||||
/// thread.launch(); // start the thread (internally calls operator() on the Task instance)
|
||||
/// \endcode
|
||||
///
|
||||
/// Creating parallel threads of execution can be dangerous:
|
||||
/// all threads inside the same process share the same memory space,
|
||||
/// which means that you may end up accessing the same variable
|
||||
/// from multiple threads at the same time. To prevent this
|
||||
/// kind of situations, you can use mutexes (see sf::Mutex).
|
||||
///
|
||||
/// \see sf::Mutex
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
90
code/SFML-2.4.2/include/SFML/System/Thread.inl
Normal file
90
code/SFML-2.4.2/include/SFML/System/Thread.inl
Normal file
|
@ -0,0 +1,90 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org)
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
namespace priv
|
||||
{
|
||||
// Base class for abstract thread functions
|
||||
struct ThreadFunc
|
||||
{
|
||||
virtual ~ThreadFunc() {}
|
||||
virtual void run() = 0;
|
||||
};
|
||||
|
||||
// Specialization using a functor (including free functions) with no argument
|
||||
template <typename T>
|
||||
struct ThreadFunctor : ThreadFunc
|
||||
{
|
||||
ThreadFunctor(T functor) : m_functor(functor) {}
|
||||
virtual void run() {m_functor();}
|
||||
T m_functor;
|
||||
};
|
||||
|
||||
// Specialization using a functor (including free functions) with one argument
|
||||
template <typename F, typename A>
|
||||
struct ThreadFunctorWithArg : ThreadFunc
|
||||
{
|
||||
ThreadFunctorWithArg(F function, A arg) : m_function(function), m_arg(arg) {}
|
||||
virtual void run() {m_function(m_arg);}
|
||||
F m_function;
|
||||
A m_arg;
|
||||
};
|
||||
|
||||
// Specialization using a member function
|
||||
template <typename C>
|
||||
struct ThreadMemberFunc : ThreadFunc
|
||||
{
|
||||
ThreadMemberFunc(void(C::*function)(), C* object) : m_function(function), m_object(object) {}
|
||||
virtual void run() {(m_object->*m_function)();}
|
||||
void(C::*m_function)();
|
||||
C* m_object;
|
||||
};
|
||||
|
||||
} // namespace priv
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename F>
|
||||
Thread::Thread(F functor) :
|
||||
m_impl (NULL),
|
||||
m_entryPoint(new priv::ThreadFunctor<F>(functor))
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename F, typename A>
|
||||
Thread::Thread(F function, A argument) :
|
||||
m_impl (NULL),
|
||||
m_entryPoint(new priv::ThreadFunctorWithArg<F, A>(function, argument))
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename C>
|
||||
Thread::Thread(void(C::*function)(), C* object) :
|
||||
m_impl (NULL),
|
||||
m_entryPoint(new priv::ThreadMemberFunc<C>(function, object))
|
||||
{
|
||||
}
|
103
code/SFML-2.4.2/include/SFML/System/ThreadLocal.hpp
Normal file
103
code/SFML-2.4.2/include/SFML/System/ThreadLocal.hpp
Normal file
|
@ -0,0 +1,103 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org)
|
||||
//
|
||||
// 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_THREADLOCAL_HPP
|
||||
#define SFML_THREADLOCAL_HPP
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/System/Export.hpp>
|
||||
#include <SFML/System/NonCopyable.hpp>
|
||||
#include <cstdlib>
|
||||
|
||||
|
||||
namespace sf
|
||||
{
|
||||
namespace priv
|
||||
{
|
||||
class ThreadLocalImpl;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Defines variables with thread-local storage
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
class SFML_SYSTEM_API ThreadLocal : NonCopyable
|
||||
{
|
||||
public:
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Default constructor
|
||||
///
|
||||
/// \param value Optional value to initialize the variable
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
ThreadLocal(void* value = NULL);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Destructor
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
~ThreadLocal();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Set the thread-specific value of the variable
|
||||
///
|
||||
/// \param value Value of the variable for the current thread
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void setValue(void* value);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Retrieve the thread-specific value of the variable
|
||||
///
|
||||
/// \return Value of the variable for the current thread
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void* getValue() const;
|
||||
|
||||
private:
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Member data
|
||||
////////////////////////////////////////////////////////////
|
||||
priv::ThreadLocalImpl* m_impl; ///< Pointer to the OS specific implementation
|
||||
};
|
||||
|
||||
} // namespace sf
|
||||
|
||||
|
||||
#endif // SFML_THREADLOCAL_HPP
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \class sf::ThreadLocal
|
||||
/// \ingroup system
|
||||
///
|
||||
/// This class manipulates void* parameters and thus is not
|
||||
/// appropriate for strongly-typed variables. You should rather
|
||||
/// use the sf::ThreadLocalPtr template class.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
158
code/SFML-2.4.2/include/SFML/System/ThreadLocalPtr.hpp
Normal file
158
code/SFML-2.4.2/include/SFML/System/ThreadLocalPtr.hpp
Normal file
|
@ -0,0 +1,158 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org)
|
||||
//
|
||||
// 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_THREADLOCALPTR_HPP
|
||||
#define SFML_THREADLOCALPTR_HPP
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/System/ThreadLocal.hpp>
|
||||
|
||||
|
||||
namespace sf
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Pointer to a thread-local variable
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
class ThreadLocalPtr : private ThreadLocal
|
||||
{
|
||||
public:
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Default constructor
|
||||
///
|
||||
/// \param value Optional value to initialize the variable
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
ThreadLocalPtr(T* value = NULL);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Overload of unary operator *
|
||||
///
|
||||
/// Like raw pointers, applying the * operator returns a
|
||||
/// reference to the pointed-to object.
|
||||
///
|
||||
/// \return Reference to the thread-local variable
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
T& operator *() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Overload of operator ->
|
||||
///
|
||||
/// Similarly to raw pointers, applying the -> operator
|
||||
/// returns the pointed-to object.
|
||||
///
|
||||
/// \return Pointer to the thread-local variable
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
T* operator ->() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Conversion operator to implicitly convert the
|
||||
/// pointer to its raw pointer type (T*)
|
||||
///
|
||||
/// \return Pointer to the actual object
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
operator T*() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Assignment operator for a raw pointer parameter
|
||||
///
|
||||
/// \param value Pointer to assign
|
||||
///
|
||||
/// \return Reference to self
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
ThreadLocalPtr<T>& operator =(T* value);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Assignment operator for a ThreadLocalPtr parameter
|
||||
///
|
||||
/// \param right ThreadLocalPtr to assign
|
||||
///
|
||||
/// \return Reference to self
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
ThreadLocalPtr<T>& operator =(const ThreadLocalPtr<T>& right);
|
||||
};
|
||||
|
||||
} // namespace sf
|
||||
|
||||
#include <SFML/System/ThreadLocalPtr.inl>
|
||||
|
||||
|
||||
#endif // SFML_THREADLOCALPTR_HPP
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \class sf::ThreadLocalPtr
|
||||
/// \ingroup system
|
||||
///
|
||||
/// sf::ThreadLocalPtr is a type-safe wrapper for storing
|
||||
/// pointers to thread-local variables. A thread-local
|
||||
/// variable holds a different value for each different
|
||||
/// thread, unlike normal variables that are shared.
|
||||
///
|
||||
/// Its usage is completely transparent, so that it is similar
|
||||
/// to manipulating the raw pointer directly (like any smart pointer).
|
||||
///
|
||||
/// Usage example:
|
||||
/// \code
|
||||
/// MyClass object1;
|
||||
/// MyClass object2;
|
||||
/// sf::ThreadLocalPtr<MyClass> objectPtr;
|
||||
///
|
||||
/// void thread1()
|
||||
/// {
|
||||
/// objectPtr = &object1; // doesn't impact thread2
|
||||
/// ...
|
||||
/// }
|
||||
///
|
||||
/// void thread2()
|
||||
/// {
|
||||
/// objectPtr = &object2; // doesn't impact thread1
|
||||
/// ...
|
||||
/// }
|
||||
///
|
||||
/// int main()
|
||||
/// {
|
||||
/// // Create and launch the two threads
|
||||
/// sf::Thread t1(&thread1);
|
||||
/// sf::Thread t2(&thread2);
|
||||
/// t1.launch();
|
||||
/// t2.launch();
|
||||
///
|
||||
/// return 0;
|
||||
/// }
|
||||
/// \endcode
|
||||
///
|
||||
/// ThreadLocalPtr is designed for internal use; however you
|
||||
/// can use it if you feel like it fits well your implementation.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
77
code/SFML-2.4.2/include/SFML/System/ThreadLocalPtr.inl
Normal file
77
code/SFML-2.4.2/include/SFML/System/ThreadLocalPtr.inl
Normal file
|
@ -0,0 +1,77 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org)
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
namespace sf
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
ThreadLocalPtr<T>::ThreadLocalPtr(T* value) :
|
||||
ThreadLocal(value)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
T& ThreadLocalPtr<T>::operator *() const
|
||||
{
|
||||
return *static_cast<T*>(getValue());
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
T* ThreadLocalPtr<T>::operator ->() const
|
||||
{
|
||||
return static_cast<T*>(getValue());
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
ThreadLocalPtr<T>::operator T*() const
|
||||
{
|
||||
return static_cast<T*>(getValue());
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
ThreadLocalPtr<T>& ThreadLocalPtr<T>::operator =(T* value)
|
||||
{
|
||||
setValue(value);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
ThreadLocalPtr<T>& ThreadLocalPtr<T>::operator =(const ThreadLocalPtr<T>& right)
|
||||
{
|
||||
setValue(right.getValue());
|
||||
return *this;
|
||||
}
|
||||
|
||||
} // namespace sf
|
488
code/SFML-2.4.2/include/SFML/System/Time.hpp
Normal file
488
code/SFML-2.4.2/include/SFML/System/Time.hpp
Normal file
|
@ -0,0 +1,488 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org)
|
||||
//
|
||||
// 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_TIME_HPP
|
||||
#define SFML_TIME_HPP
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/System/Export.hpp>
|
||||
|
||||
|
||||
namespace sf
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Represents a time value
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
class SFML_SYSTEM_API Time
|
||||
{
|
||||
public:
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Default constructor
|
||||
///
|
||||
/// Sets the time value to zero.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Time();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Return the time value as a number of seconds
|
||||
///
|
||||
/// \return Time in seconds
|
||||
///
|
||||
/// \see asMilliseconds, asMicroseconds
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
float asSeconds() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Return the time value as a number of milliseconds
|
||||
///
|
||||
/// \return Time in milliseconds
|
||||
///
|
||||
/// \see asSeconds, asMicroseconds
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Int32 asMilliseconds() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Return the time value as a number of microseconds
|
||||
///
|
||||
/// \return Time in microseconds
|
||||
///
|
||||
/// \see asSeconds, asMilliseconds
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Int64 asMicroseconds() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Static member data
|
||||
////////////////////////////////////////////////////////////
|
||||
static const Time Zero; ///< Predefined "zero" time value
|
||||
|
||||
private:
|
||||
|
||||
friend SFML_SYSTEM_API Time seconds(float);
|
||||
friend SFML_SYSTEM_API Time milliseconds(Int32);
|
||||
friend SFML_SYSTEM_API Time microseconds(Int64);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Construct from a number of microseconds
|
||||
///
|
||||
/// This function is internal. To construct time values,
|
||||
/// use sf::seconds, sf::milliseconds or sf::microseconds instead.
|
||||
///
|
||||
/// \param microseconds Number of microseconds
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
explicit Time(Int64 microseconds);
|
||||
|
||||
private:
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Member data
|
||||
////////////////////////////////////////////////////////////
|
||||
Int64 m_microseconds; ///< Time value stored as microseconds
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \relates Time
|
||||
/// \brief Construct a time value from a number of seconds
|
||||
///
|
||||
/// \param amount Number of seconds
|
||||
///
|
||||
/// \return Time value constructed from the amount of seconds
|
||||
///
|
||||
/// \see milliseconds, microseconds
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_SYSTEM_API Time seconds(float amount);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \relates Time
|
||||
/// \brief Construct a time value from a number of milliseconds
|
||||
///
|
||||
/// \param amount Number of milliseconds
|
||||
///
|
||||
/// \return Time value constructed from the amount of milliseconds
|
||||
///
|
||||
/// \see seconds, microseconds
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_SYSTEM_API Time milliseconds(Int32 amount);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \relates Time
|
||||
/// \brief Construct a time value from a number of microseconds
|
||||
///
|
||||
/// \param amount Number of microseconds
|
||||
///
|
||||
/// \return Time value constructed from the amount of microseconds
|
||||
///
|
||||
/// \see seconds, milliseconds
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_SYSTEM_API Time microseconds(Int64 amount);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \relates Time
|
||||
/// \brief Overload of == operator to compare two time values
|
||||
///
|
||||
/// \param left Left operand (a time)
|
||||
/// \param right Right operand (a time)
|
||||
///
|
||||
/// \return True if both time values are equal
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_SYSTEM_API bool operator ==(Time left, Time right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \relates Time
|
||||
/// \brief Overload of != operator to compare two time values
|
||||
///
|
||||
/// \param left Left operand (a time)
|
||||
/// \param right Right operand (a time)
|
||||
///
|
||||
/// \return True if both time values are different
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_SYSTEM_API bool operator !=(Time left, Time right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \relates Time
|
||||
/// \brief Overload of < operator to compare two time values
|
||||
///
|
||||
/// \param left Left operand (a time)
|
||||
/// \param right Right operand (a time)
|
||||
///
|
||||
/// \return True if \a left is lesser than \a right
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_SYSTEM_API bool operator <(Time left, Time right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \relates Time
|
||||
/// \brief Overload of > operator to compare two time values
|
||||
///
|
||||
/// \param left Left operand (a time)
|
||||
/// \param right Right operand (a time)
|
||||
///
|
||||
/// \return True if \a left is greater than \a right
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_SYSTEM_API bool operator >(Time left, Time right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \relates Time
|
||||
/// \brief Overload of <= operator to compare two time values
|
||||
///
|
||||
/// \param left Left operand (a time)
|
||||
/// \param right Right operand (a time)
|
||||
///
|
||||
/// \return True if \a left is lesser or equal than \a right
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_SYSTEM_API bool operator <=(Time left, Time right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \relates Time
|
||||
/// \brief Overload of >= operator to compare two time values
|
||||
///
|
||||
/// \param left Left operand (a time)
|
||||
/// \param right Right operand (a time)
|
||||
///
|
||||
/// \return True if \a left is greater or equal than \a right
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_SYSTEM_API bool operator >=(Time left, Time right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \relates Time
|
||||
/// \brief Overload of unary - operator to negate a time value
|
||||
///
|
||||
/// \param right Right operand (a time)
|
||||
///
|
||||
/// \return Opposite of the time value
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_SYSTEM_API Time operator -(Time right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \relates Time
|
||||
/// \brief Overload of binary + operator to add two time values
|
||||
///
|
||||
/// \param left Left operand (a time)
|
||||
/// \param right Right operand (a time)
|
||||
///
|
||||
/// \return Sum of the two times values
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_SYSTEM_API Time operator +(Time left, Time right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \relates Time
|
||||
/// \brief Overload of binary += operator to add/assign two time values
|
||||
///
|
||||
/// \param left Left operand (a time)
|
||||
/// \param right Right operand (a time)
|
||||
///
|
||||
/// \return Sum of the two times values
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_SYSTEM_API Time& operator +=(Time& left, Time right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \relates Time
|
||||
/// \brief Overload of binary - operator to subtract two time values
|
||||
///
|
||||
/// \param left Left operand (a time)
|
||||
/// \param right Right operand (a time)
|
||||
///
|
||||
/// \return Difference of the two times values
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_SYSTEM_API Time operator -(Time left, Time right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \relates Time
|
||||
/// \brief Overload of binary -= operator to subtract/assign two time values
|
||||
///
|
||||
/// \param left Left operand (a time)
|
||||
/// \param right Right operand (a time)
|
||||
///
|
||||
/// \return Difference of the two times values
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_SYSTEM_API Time& operator -=(Time& left, Time right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \relates Time
|
||||
/// \brief Overload of binary * operator to scale a time value
|
||||
///
|
||||
/// \param left Left operand (a time)
|
||||
/// \param right Right operand (a number)
|
||||
///
|
||||
/// \return \a left multiplied by \a right
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_SYSTEM_API Time operator *(Time left, float right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \relates Time
|
||||
/// \brief Overload of binary * operator to scale a time value
|
||||
///
|
||||
/// \param left Left operand (a time)
|
||||
/// \param right Right operand (a number)
|
||||
///
|
||||
/// \return \a left multiplied by \a right
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_SYSTEM_API Time operator *(Time left, Int64 right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \relates Time
|
||||
/// \brief Overload of binary * operator to scale a time value
|
||||
///
|
||||
/// \param left Left operand (a number)
|
||||
/// \param right Right operand (a time)
|
||||
///
|
||||
/// \return \a left multiplied by \a right
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_SYSTEM_API Time operator *(float left, Time right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \relates Time
|
||||
/// \brief Overload of binary * operator to scale a time value
|
||||
///
|
||||
/// \param left Left operand (a number)
|
||||
/// \param right Right operand (a time)
|
||||
///
|
||||
/// \return \a left multiplied by \a right
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_SYSTEM_API Time operator *(Int64 left, Time right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \relates Time
|
||||
/// \brief Overload of binary *= operator to scale/assign a time value
|
||||
///
|
||||
/// \param left Left operand (a time)
|
||||
/// \param right Right operand (a number)
|
||||
///
|
||||
/// \return \a left multiplied by \a right
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_SYSTEM_API Time& operator *=(Time& left, float right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \relates Time
|
||||
/// \brief Overload of binary *= operator to scale/assign a time value
|
||||
///
|
||||
/// \param left Left operand (a time)
|
||||
/// \param right Right operand (a number)
|
||||
///
|
||||
/// \return \a left multiplied by \a right
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_SYSTEM_API Time& operator *=(Time& left, Int64 right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \relates Time
|
||||
/// \brief Overload of binary / operator to scale a time value
|
||||
///
|
||||
/// \param left Left operand (a time)
|
||||
/// \param right Right operand (a number)
|
||||
///
|
||||
/// \return \a left divided by \a right
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_SYSTEM_API Time operator /(Time left, float right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \relates Time
|
||||
/// \brief Overload of binary / operator to scale a time value
|
||||
///
|
||||
/// \param left Left operand (a time)
|
||||
/// \param right Right operand (a number)
|
||||
///
|
||||
/// \return \a left divided by \a right
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_SYSTEM_API Time operator /(Time left, Int64 right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \relates Time
|
||||
/// \brief Overload of binary /= operator to scale/assign a time value
|
||||
///
|
||||
/// \param left Left operand (a time)
|
||||
/// \param right Right operand (a number)
|
||||
///
|
||||
/// \return \a left divided by \a right
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_SYSTEM_API Time& operator /=(Time& left, float right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \relates Time
|
||||
/// \brief Overload of binary /= operator to scale/assign a time value
|
||||
///
|
||||
/// \param left Left operand (a time)
|
||||
/// \param right Right operand (a number)
|
||||
///
|
||||
/// \return \a left divided by \a right
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_SYSTEM_API Time& operator /=(Time& left, Int64 right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \relates Time
|
||||
/// \brief Overload of binary / operator to compute the ratio of two time values
|
||||
///
|
||||
/// \param left Left operand (a time)
|
||||
/// \param right Right operand (a time)
|
||||
///
|
||||
/// \return \a left divided by \a right
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_SYSTEM_API float operator /(Time left, Time right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \relates Time
|
||||
/// \brief Overload of binary % operator to compute remainder of a time value
|
||||
///
|
||||
/// \param left Left operand (a time)
|
||||
/// \param right Right operand (a time)
|
||||
///
|
||||
/// \return \a left modulo \a right
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_SYSTEM_API Time operator %(Time left, Time right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \relates Time
|
||||
/// \brief Overload of binary %= operator to compute/assign remainder of a time value
|
||||
///
|
||||
/// \param left Left operand (a time)
|
||||
/// \param right Right operand (a time)
|
||||
///
|
||||
/// \return \a left modulo \a right
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_SYSTEM_API Time& operator %=(Time& left, Time right);
|
||||
|
||||
} // namespace sf
|
||||
|
||||
|
||||
#endif // SFML_TIME_HPP
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \class sf::Time
|
||||
/// \ingroup system
|
||||
///
|
||||
/// sf::Time encapsulates a time value in a flexible way.
|
||||
/// It allows to define a time value either as a number of
|
||||
/// seconds, milliseconds or microseconds. It also works the
|
||||
/// other way round: you can read a time value as either
|
||||
/// a number of seconds, milliseconds or microseconds.
|
||||
///
|
||||
/// By using such a flexible interface, the API doesn't
|
||||
/// impose any fixed type or resolution for time values,
|
||||
/// and let the user choose its own favorite representation.
|
||||
///
|
||||
/// Time values support the usual mathematical operations:
|
||||
/// you can add or subtract two times, multiply or divide
|
||||
/// a time by a number, compare two times, etc.
|
||||
///
|
||||
/// Since they represent a time span and not an absolute time
|
||||
/// value, times can also be negative.
|
||||
///
|
||||
/// Usage example:
|
||||
/// \code
|
||||
/// sf::Time t1 = sf::seconds(0.1f);
|
||||
/// Int32 milli = t1.asMilliseconds(); // 100
|
||||
///
|
||||
/// sf::Time t2 = sf::milliseconds(30);
|
||||
/// Int64 micro = t2.asMicroseconds(); // 30000
|
||||
///
|
||||
/// sf::Time t3 = sf::microseconds(-800000);
|
||||
/// float sec = t3.asSeconds(); // -0.8
|
||||
/// \endcode
|
||||
///
|
||||
/// \code
|
||||
/// void update(sf::Time elapsed)
|
||||
/// {
|
||||
/// position += speed * elapsed.asSeconds();
|
||||
/// }
|
||||
///
|
||||
/// update(sf::milliseconds(100));
|
||||
/// \endcode
|
||||
///
|
||||
/// \see sf::Clock
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
763
code/SFML-2.4.2/include/SFML/System/Utf.hpp
Normal file
763
code/SFML-2.4.2/include/SFML/System/Utf.hpp
Normal file
|
@ -0,0 +1,763 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org)
|
||||
//
|
||||
// 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_UTF_HPP
|
||||
#define SFML_UTF_HPP
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Config.hpp>
|
||||
#include <algorithm>
|
||||
#include <locale>
|
||||
#include <string>
|
||||
#include <cstdlib>
|
||||
|
||||
|
||||
namespace sf
|
||||
{
|
||||
template <unsigned int N>
|
||||
class Utf;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Specialization of the Utf template for UTF-8
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <>
|
||||
class Utf<8>
|
||||
{
|
||||
public:
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Decode a single UTF-8 character
|
||||
///
|
||||
/// Decoding a character means finding its unique 32-bits
|
||||
/// code (called the codepoint) in the Unicode standard.
|
||||
///
|
||||
/// \param begin Iterator pointing to the beginning of the input sequence
|
||||
/// \param end Iterator pointing to the end of the input sequence
|
||||
/// \param output Codepoint of the decoded UTF-8 character
|
||||
/// \param replacement Replacement character to use in case the UTF-8 sequence is invalid
|
||||
///
|
||||
/// \return Iterator pointing to one past the last read element of the input sequence
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In>
|
||||
static In decode(In begin, In end, Uint32& output, Uint32 replacement = 0);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Encode a single UTF-8 character
|
||||
///
|
||||
/// Encoding a character means converting a unique 32-bits
|
||||
/// code (called the codepoint) in the target encoding, UTF-8.
|
||||
///
|
||||
/// \param input Codepoint to encode as UTF-8
|
||||
/// \param output Iterator pointing to the beginning of the output sequence
|
||||
/// \param replacement Replacement for characters not convertible to UTF-8 (use 0 to skip them)
|
||||
///
|
||||
/// \return Iterator to the end of the output sequence which has been written
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename Out>
|
||||
static Out encode(Uint32 input, Out output, Uint8 replacement = 0);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Advance to the next UTF-8 character
|
||||
///
|
||||
/// This function is necessary for multi-elements encodings, as
|
||||
/// a single character may use more than 1 storage element.
|
||||
///
|
||||
/// \param begin Iterator pointing to the beginning of the input sequence
|
||||
/// \param end Iterator pointing to the end of the input sequence
|
||||
///
|
||||
/// \return Iterator pointing to one past the last read element of the input sequence
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In>
|
||||
static In next(In begin, In end);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Count the number of characters of a UTF-8 sequence
|
||||
///
|
||||
/// This function is necessary for multi-elements encodings, as
|
||||
/// a single character may use more than 1 storage element, thus the
|
||||
/// total size can be different from (begin - end).
|
||||
///
|
||||
/// \param begin Iterator pointing to the beginning of the input sequence
|
||||
/// \param end Iterator pointing to the end of the input sequence
|
||||
///
|
||||
/// \return Iterator pointing to one past the last read element of the input sequence
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In>
|
||||
static std::size_t count(In begin, In end);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Convert an ANSI characters range to UTF-8
|
||||
///
|
||||
/// The current global locale will be used by default, unless you
|
||||
/// pass a custom one in the \a locale parameter.
|
||||
///
|
||||
/// \param begin Iterator pointing to the beginning of the input sequence
|
||||
/// \param end Iterator pointing to the end of the input sequence
|
||||
/// \param output Iterator pointing to the beginning of the output sequence
|
||||
/// \param locale Locale to use for conversion
|
||||
///
|
||||
/// \return Iterator to the end of the output sequence which has been written
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
static Out fromAnsi(In begin, In end, Out output, const std::locale& locale = std::locale());
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Convert a wide characters range to UTF-8
|
||||
///
|
||||
/// \param begin Iterator pointing to the beginning of the input sequence
|
||||
/// \param end Iterator pointing to the end of the input sequence
|
||||
/// \param output Iterator pointing to the beginning of the output sequence
|
||||
///
|
||||
/// \return Iterator to the end of the output sequence which has been written
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
static Out fromWide(In begin, In end, Out output);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Convert a latin-1 (ISO-5589-1) characters range to UTF-8
|
||||
///
|
||||
/// \param begin Iterator pointing to the beginning of the input sequence
|
||||
/// \param end Iterator pointing to the end of the input sequence
|
||||
/// \param output Iterator pointing to the beginning of the output sequence
|
||||
///
|
||||
/// \return Iterator to the end of the output sequence which has been written
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
static Out fromLatin1(In begin, In end, Out output);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Convert an UTF-8 characters range to ANSI characters
|
||||
///
|
||||
/// The current global locale will be used by default, unless you
|
||||
/// pass a custom one in the \a locale parameter.
|
||||
///
|
||||
/// \param begin Iterator pointing to the beginning of the input sequence
|
||||
/// \param end Iterator pointing to the end of the input sequence
|
||||
/// \param output Iterator pointing to the beginning of the output sequence
|
||||
/// \param replacement Replacement for characters not convertible to ANSI (use 0 to skip them)
|
||||
/// \param locale Locale to use for conversion
|
||||
///
|
||||
/// \return Iterator to the end of the output sequence which has been written
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
static Out toAnsi(In begin, In end, Out output, char replacement = 0, const std::locale& locale = std::locale());
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Convert an UTF-8 characters range to wide characters
|
||||
///
|
||||
/// \param begin Iterator pointing to the beginning of the input sequence
|
||||
/// \param end Iterator pointing to the end of the input sequence
|
||||
/// \param output Iterator pointing to the beginning of the output sequence
|
||||
/// \param replacement Replacement for characters not convertible to wide (use 0 to skip them)
|
||||
///
|
||||
/// \return Iterator to the end of the output sequence which has been written
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
static Out toWide(In begin, In end, Out output, wchar_t replacement = 0);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Convert an UTF-8 characters range to latin-1 (ISO-5589-1) characters
|
||||
///
|
||||
/// \param begin Iterator pointing to the beginning of the input sequence
|
||||
/// \param end Iterator pointing to the end of the input sequence
|
||||
/// \param output Iterator pointing to the beginning of the output sequence
|
||||
/// \param replacement Replacement for characters not convertible to wide (use 0 to skip them)
|
||||
///
|
||||
/// \return Iterator to the end of the output sequence which has been written
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
static Out toLatin1(In begin, In end, Out output, char replacement = 0);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Convert a UTF-8 characters range to UTF-8
|
||||
///
|
||||
/// This functions does nothing more than a direct copy;
|
||||
/// it is defined only to provide the same interface as other
|
||||
/// specializations of the sf::Utf<> template, and allow
|
||||
/// generic code to be written on top of it.
|
||||
///
|
||||
/// \param begin Iterator pointing to the beginning of the input sequence
|
||||
/// \param end Iterator pointing to the end of the input sequence
|
||||
/// \param output Iterator pointing to the beginning of the output sequence
|
||||
///
|
||||
/// \return Iterator to the end of the output sequence which has been written
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
static Out toUtf8(In begin, In end, Out output);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Convert a UTF-8 characters range to UTF-16
|
||||
///
|
||||
/// \param begin Iterator pointing to the beginning of the input sequence
|
||||
/// \param end Iterator pointing to the end of the input sequence
|
||||
/// \param output Iterator pointing to the beginning of the output sequence
|
||||
///
|
||||
/// \return Iterator to the end of the output sequence which has been written
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
static Out toUtf16(In begin, In end, Out output);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Convert a UTF-8 characters range to UTF-32
|
||||
///
|
||||
/// \param begin Iterator pointing to the beginning of the input sequence
|
||||
/// \param end Iterator pointing to the end of the input sequence
|
||||
/// \param output Iterator pointing to the beginning of the output sequence
|
||||
///
|
||||
/// \return Iterator to the end of the output sequence which has been written
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
static Out toUtf32(In begin, In end, Out output);
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Specialization of the Utf template for UTF-16
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <>
|
||||
class Utf<16>
|
||||
{
|
||||
public:
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Decode a single UTF-16 character
|
||||
///
|
||||
/// Decoding a character means finding its unique 32-bits
|
||||
/// code (called the codepoint) in the Unicode standard.
|
||||
///
|
||||
/// \param begin Iterator pointing to the beginning of the input sequence
|
||||
/// \param end Iterator pointing to the end of the input sequence
|
||||
/// \param output Codepoint of the decoded UTF-16 character
|
||||
/// \param replacement Replacement character to use in case the UTF-8 sequence is invalid
|
||||
///
|
||||
/// \return Iterator pointing to one past the last read element of the input sequence
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In>
|
||||
static In decode(In begin, In end, Uint32& output, Uint32 replacement = 0);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Encode a single UTF-16 character
|
||||
///
|
||||
/// Encoding a character means converting a unique 32-bits
|
||||
/// code (called the codepoint) in the target encoding, UTF-16.
|
||||
///
|
||||
/// \param input Codepoint to encode as UTF-16
|
||||
/// \param output Iterator pointing to the beginning of the output sequence
|
||||
/// \param replacement Replacement for characters not convertible to UTF-16 (use 0 to skip them)
|
||||
///
|
||||
/// \return Iterator to the end of the output sequence which has been written
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename Out>
|
||||
static Out encode(Uint32 input, Out output, Uint16 replacement = 0);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Advance to the next UTF-16 character
|
||||
///
|
||||
/// This function is necessary for multi-elements encodings, as
|
||||
/// a single character may use more than 1 storage element.
|
||||
///
|
||||
/// \param begin Iterator pointing to the beginning of the input sequence
|
||||
/// \param end Iterator pointing to the end of the input sequence
|
||||
///
|
||||
/// \return Iterator pointing to one past the last read element of the input sequence
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In>
|
||||
static In next(In begin, In end);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Count the number of characters of a UTF-16 sequence
|
||||
///
|
||||
/// This function is necessary for multi-elements encodings, as
|
||||
/// a single character may use more than 1 storage element, thus the
|
||||
/// total size can be different from (begin - end).
|
||||
///
|
||||
/// \param begin Iterator pointing to the beginning of the input sequence
|
||||
/// \param end Iterator pointing to the end of the input sequence
|
||||
///
|
||||
/// \return Iterator pointing to one past the last read element of the input sequence
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In>
|
||||
static std::size_t count(In begin, In end);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Convert an ANSI characters range to UTF-16
|
||||
///
|
||||
/// The current global locale will be used by default, unless you
|
||||
/// pass a custom one in the \a locale parameter.
|
||||
///
|
||||
/// \param begin Iterator pointing to the beginning of the input sequence
|
||||
/// \param end Iterator pointing to the end of the input sequence
|
||||
/// \param output Iterator pointing to the beginning of the output sequence
|
||||
/// \param locale Locale to use for conversion
|
||||
///
|
||||
/// \return Iterator to the end of the output sequence which has been written
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
static Out fromAnsi(In begin, In end, Out output, const std::locale& locale = std::locale());
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Convert a wide characters range to UTF-16
|
||||
///
|
||||
/// \param begin Iterator pointing to the beginning of the input sequence
|
||||
/// \param end Iterator pointing to the end of the input sequence
|
||||
/// \param output Iterator pointing to the beginning of the output sequence
|
||||
///
|
||||
/// \return Iterator to the end of the output sequence which has been written
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
static Out fromWide(In begin, In end, Out output);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Convert a latin-1 (ISO-5589-1) characters range to UTF-16
|
||||
///
|
||||
/// \param begin Iterator pointing to the beginning of the input sequence
|
||||
/// \param end Iterator pointing to the end of the input sequence
|
||||
/// \param output Iterator pointing to the beginning of the output sequence
|
||||
///
|
||||
/// \return Iterator to the end of the output sequence which has been written
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
static Out fromLatin1(In begin, In end, Out output);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Convert an UTF-16 characters range to ANSI characters
|
||||
///
|
||||
/// The current global locale will be used by default, unless you
|
||||
/// pass a custom one in the \a locale parameter.
|
||||
///
|
||||
/// \param begin Iterator pointing to the beginning of the input sequence
|
||||
/// \param end Iterator pointing to the end of the input sequence
|
||||
/// \param output Iterator pointing to the beginning of the output sequence
|
||||
/// \param replacement Replacement for characters not convertible to ANSI (use 0 to skip them)
|
||||
/// \param locale Locale to use for conversion
|
||||
///
|
||||
/// \return Iterator to the end of the output sequence which has been written
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
static Out toAnsi(In begin, In end, Out output, char replacement = 0, const std::locale& locale = std::locale());
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Convert an UTF-16 characters range to wide characters
|
||||
///
|
||||
/// \param begin Iterator pointing to the beginning of the input sequence
|
||||
/// \param end Iterator pointing to the end of the input sequence
|
||||
/// \param output Iterator pointing to the beginning of the output sequence
|
||||
/// \param replacement Replacement for characters not convertible to wide (use 0 to skip them)
|
||||
///
|
||||
/// \return Iterator to the end of the output sequence which has been written
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
static Out toWide(In begin, In end, Out output, wchar_t replacement = 0);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Convert an UTF-16 characters range to latin-1 (ISO-5589-1) characters
|
||||
///
|
||||
/// \param begin Iterator pointing to the beginning of the input sequence
|
||||
/// \param end Iterator pointing to the end of the input sequence
|
||||
/// \param output Iterator pointing to the beginning of the output sequence
|
||||
/// \param replacement Replacement for characters not convertible to wide (use 0 to skip them)
|
||||
///
|
||||
/// \return Iterator to the end of the output sequence which has been written
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
static Out toLatin1(In begin, In end, Out output, char replacement = 0);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Convert a UTF-16 characters range to UTF-8
|
||||
///
|
||||
/// \param begin Iterator pointing to the beginning of the input sequence
|
||||
/// \param end Iterator pointing to the end of the input sequence
|
||||
/// \param output Iterator pointing to the beginning of the output sequence
|
||||
///
|
||||
/// \return Iterator to the end of the output sequence which has been written
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
static Out toUtf8(In begin, In end, Out output);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Convert a UTF-16 characters range to UTF-16
|
||||
///
|
||||
/// This functions does nothing more than a direct copy;
|
||||
/// it is defined only to provide the same interface as other
|
||||
/// specializations of the sf::Utf<> template, and allow
|
||||
/// generic code to be written on top of it.
|
||||
///
|
||||
/// \param begin Iterator pointing to the beginning of the input sequence
|
||||
/// \param end Iterator pointing to the end of the input sequence
|
||||
/// \param output Iterator pointing to the beginning of the output sequence
|
||||
///
|
||||
/// \return Iterator to the end of the output sequence which has been written
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
static Out toUtf16(In begin, In end, Out output);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Convert a UTF-16 characters range to UTF-32
|
||||
///
|
||||
/// \param begin Iterator pointing to the beginning of the input sequence
|
||||
/// \param end Iterator pointing to the end of the input sequence
|
||||
/// \param output Iterator pointing to the beginning of the output sequence
|
||||
///
|
||||
/// \return Iterator to the end of the output sequence which has been written
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
static Out toUtf32(In begin, In end, Out output);
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Specialization of the Utf template for UTF-32
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <>
|
||||
class Utf<32>
|
||||
{
|
||||
public:
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Decode a single UTF-32 character
|
||||
///
|
||||
/// Decoding a character means finding its unique 32-bits
|
||||
/// code (called the codepoint) in the Unicode standard.
|
||||
/// For UTF-32, the character value is the same as the codepoint.
|
||||
///
|
||||
/// \param begin Iterator pointing to the beginning of the input sequence
|
||||
/// \param end Iterator pointing to the end of the input sequence
|
||||
/// \param output Codepoint of the decoded UTF-32 character
|
||||
/// \param replacement Replacement character to use in case the UTF-8 sequence is invalid
|
||||
///
|
||||
/// \return Iterator pointing to one past the last read element of the input sequence
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In>
|
||||
static In decode(In begin, In end, Uint32& output, Uint32 replacement = 0);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Encode a single UTF-32 character
|
||||
///
|
||||
/// Encoding a character means converting a unique 32-bits
|
||||
/// code (called the codepoint) in the target encoding, UTF-32.
|
||||
/// For UTF-32, the codepoint is the same as the character value.
|
||||
///
|
||||
/// \param input Codepoint to encode as UTF-32
|
||||
/// \param output Iterator pointing to the beginning of the output sequence
|
||||
/// \param replacement Replacement for characters not convertible to UTF-32 (use 0 to skip them)
|
||||
///
|
||||
/// \return Iterator to the end of the output sequence which has been written
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename Out>
|
||||
static Out encode(Uint32 input, Out output, Uint32 replacement = 0);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Advance to the next UTF-32 character
|
||||
///
|
||||
/// This function is trivial for UTF-32, which can store
|
||||
/// every character in a single storage element.
|
||||
///
|
||||
/// \param begin Iterator pointing to the beginning of the input sequence
|
||||
/// \param end Iterator pointing to the end of the input sequence
|
||||
///
|
||||
/// \return Iterator pointing to one past the last read element of the input sequence
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In>
|
||||
static In next(In begin, In end);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Count the number of characters of a UTF-32 sequence
|
||||
///
|
||||
/// This function is trivial for UTF-32, which can store
|
||||
/// every character in a single storage element.
|
||||
///
|
||||
/// \param begin Iterator pointing to the beginning of the input sequence
|
||||
/// \param end Iterator pointing to the end of the input sequence
|
||||
///
|
||||
/// \return Iterator pointing to one past the last read element of the input sequence
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In>
|
||||
static std::size_t count(In begin, In end);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Convert an ANSI characters range to UTF-32
|
||||
///
|
||||
/// The current global locale will be used by default, unless you
|
||||
/// pass a custom one in the \a locale parameter.
|
||||
///
|
||||
/// \param begin Iterator pointing to the beginning of the input sequence
|
||||
/// \param end Iterator pointing to the end of the input sequence
|
||||
/// \param output Iterator pointing to the beginning of the output sequence
|
||||
/// \param locale Locale to use for conversion
|
||||
///
|
||||
/// \return Iterator to the end of the output sequence which has been written
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
static Out fromAnsi(In begin, In end, Out output, const std::locale& locale = std::locale());
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Convert a wide characters range to UTF-32
|
||||
///
|
||||
/// \param begin Iterator pointing to the beginning of the input sequence
|
||||
/// \param end Iterator pointing to the end of the input sequence
|
||||
/// \param output Iterator pointing to the beginning of the output sequence
|
||||
///
|
||||
/// \return Iterator to the end of the output sequence which has been written
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
static Out fromWide(In begin, In end, Out output);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Convert a latin-1 (ISO-5589-1) characters range to UTF-32
|
||||
///
|
||||
/// \param begin Iterator pointing to the beginning of the input sequence
|
||||
/// \param end Iterator pointing to the end of the input sequence
|
||||
/// \param output Iterator pointing to the beginning of the output sequence
|
||||
///
|
||||
/// \return Iterator to the end of the output sequence which has been written
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
static Out fromLatin1(In begin, In end, Out output);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Convert an UTF-32 characters range to ANSI characters
|
||||
///
|
||||
/// The current global locale will be used by default, unless you
|
||||
/// pass a custom one in the \a locale parameter.
|
||||
///
|
||||
/// \param begin Iterator pointing to the beginning of the input sequence
|
||||
/// \param end Iterator pointing to the end of the input sequence
|
||||
/// \param output Iterator pointing to the beginning of the output sequence
|
||||
/// \param replacement Replacement for characters not convertible to ANSI (use 0 to skip them)
|
||||
/// \param locale Locale to use for conversion
|
||||
///
|
||||
/// \return Iterator to the end of the output sequence which has been written
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
static Out toAnsi(In begin, In end, Out output, char replacement = 0, const std::locale& locale = std::locale());
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Convert an UTF-32 characters range to wide characters
|
||||
///
|
||||
/// \param begin Iterator pointing to the beginning of the input sequence
|
||||
/// \param end Iterator pointing to the end of the input sequence
|
||||
/// \param output Iterator pointing to the beginning of the output sequence
|
||||
/// \param replacement Replacement for characters not convertible to wide (use 0 to skip them)
|
||||
///
|
||||
/// \return Iterator to the end of the output sequence which has been written
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
static Out toWide(In begin, In end, Out output, wchar_t replacement = 0);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Convert an UTF-16 characters range to latin-1 (ISO-5589-1) characters
|
||||
///
|
||||
/// \param begin Iterator pointing to the beginning of the input sequence
|
||||
/// \param end Iterator pointing to the end of the input sequence
|
||||
/// \param output Iterator pointing to the beginning of the output sequence
|
||||
/// \param replacement Replacement for characters not convertible to wide (use 0 to skip them)
|
||||
///
|
||||
/// \return Iterator to the end of the output sequence which has been written
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
static Out toLatin1(In begin, In end, Out output, char replacement = 0);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Convert a UTF-32 characters range to UTF-8
|
||||
///
|
||||
/// \param begin Iterator pointing to the beginning of the input sequence
|
||||
/// \param end Iterator pointing to the end of the input sequence
|
||||
/// \param output Iterator pointing to the beginning of the output sequence
|
||||
///
|
||||
/// \return Iterator to the end of the output sequence which has been written
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
static Out toUtf8(In begin, In end, Out output);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Convert a UTF-32 characters range to UTF-16
|
||||
///
|
||||
/// \param begin Iterator pointing to the beginning of the input sequence
|
||||
/// \param end Iterator pointing to the end of the input sequence
|
||||
/// \param output Iterator pointing to the beginning of the output sequence
|
||||
///
|
||||
/// \return Iterator to the end of the output sequence which has been written
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
static Out toUtf16(In begin, In end, Out output);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Convert a UTF-32 characters range to UTF-32
|
||||
///
|
||||
/// This functions does nothing more than a direct copy;
|
||||
/// it is defined only to provide the same interface as other
|
||||
/// specializations of the sf::Utf<> template, and allow
|
||||
/// generic code to be written on top of it.
|
||||
///
|
||||
/// \param begin Iterator pointing to the beginning of the input sequence
|
||||
/// \param end Iterator pointing to the end of the input sequence
|
||||
/// \param output Iterator pointing to the beginning of the output sequence
|
||||
///
|
||||
/// \return Iterator to the end of the output sequence which has been written
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
static Out toUtf32(In begin, In end, Out output);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Decode a single ANSI character to UTF-32
|
||||
///
|
||||
/// This function does not exist in other specializations
|
||||
/// of sf::Utf<>, it is defined for convenience (it is used by
|
||||
/// several other conversion functions).
|
||||
///
|
||||
/// \param input Input ANSI character
|
||||
/// \param locale Locale to use for conversion
|
||||
///
|
||||
/// \return Converted character
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In>
|
||||
static Uint32 decodeAnsi(In input, const std::locale& locale = std::locale());
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Decode a single wide character to UTF-32
|
||||
///
|
||||
/// This function does not exist in other specializations
|
||||
/// of sf::Utf<>, it is defined for convenience (it is used by
|
||||
/// several other conversion functions).
|
||||
///
|
||||
/// \param input Input wide character
|
||||
///
|
||||
/// \return Converted character
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In>
|
||||
static Uint32 decodeWide(In input);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Encode a single UTF-32 character to ANSI
|
||||
///
|
||||
/// This function does not exist in other specializations
|
||||
/// of sf::Utf<>, it is defined for convenience (it is used by
|
||||
/// several other conversion functions).
|
||||
///
|
||||
/// \param codepoint Iterator pointing to the beginning of the input sequence
|
||||
/// \param output Iterator pointing to the beginning of the output sequence
|
||||
/// \param replacement Replacement if the input character is not convertible to ANSI (use 0 to skip it)
|
||||
/// \param locale Locale to use for conversion
|
||||
///
|
||||
/// \return Iterator to the end of the output sequence which has been written
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename Out>
|
||||
static Out encodeAnsi(Uint32 codepoint, Out output, char replacement = 0, const std::locale& locale = std::locale());
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Encode a single UTF-32 character to wide
|
||||
///
|
||||
/// This function does not exist in other specializations
|
||||
/// of sf::Utf<>, it is defined for convenience (it is used by
|
||||
/// several other conversion functions).
|
||||
///
|
||||
/// \param codepoint Iterator pointing to the beginning of the input sequence
|
||||
/// \param output Iterator pointing to the beginning of the output sequence
|
||||
/// \param replacement Replacement if the input character is not convertible to wide (use 0 to skip it)
|
||||
///
|
||||
/// \return Iterator to the end of the output sequence which has been written
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename Out>
|
||||
static Out encodeWide(Uint32 codepoint, Out output, wchar_t replacement = 0);
|
||||
};
|
||||
|
||||
#include <SFML/System/Utf.inl>
|
||||
|
||||
// Make typedefs to get rid of the template syntax
|
||||
typedef Utf<8> Utf8;
|
||||
typedef Utf<16> Utf16;
|
||||
typedef Utf<32> Utf32;
|
||||
|
||||
} // namespace sf
|
||||
|
||||
|
||||
#endif // SFML_UTF_HPP
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \class sf::Utf
|
||||
/// \ingroup system
|
||||
///
|
||||
/// Utility class providing generic functions for UTF conversions.
|
||||
///
|
||||
/// sf::Utf is a low-level, generic interface for counting, iterating,
|
||||
/// encoding and decoding Unicode characters and strings. It is able
|
||||
/// to handle ANSI, wide, latin-1, UTF-8, UTF-16 and UTF-32 encodings.
|
||||
///
|
||||
/// sf::Utf<X> functions are all static, these classes are not meant to
|
||||
/// be instantiated. All the functions are template, so that you
|
||||
/// can use any character / string type for a given encoding.
|
||||
///
|
||||
/// It has 3 specializations:
|
||||
/// \li sf::Utf<8> (typedef'd to sf::Utf8)
|
||||
/// \li sf::Utf<16> (typedef'd to sf::Utf16)
|
||||
/// \li sf::Utf<32> (typedef'd to sf::Utf32)
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
752
code/SFML-2.4.2/include/SFML/System/Utf.inl
Normal file
752
code/SFML-2.4.2/include/SFML/System/Utf.inl
Normal file
|
@ -0,0 +1,752 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org)
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// References:
|
||||
//
|
||||
// http://www.unicode.org/
|
||||
// http://www.unicode.org/Public/PROGRAMS/CVTUTF/ConvertUTF.c
|
||||
// http://www.unicode.org/Public/PROGRAMS/CVTUTF/ConvertUTF.h
|
||||
// http://people.w3.org/rishida/scripts/uniview/conversion
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In>
|
||||
In Utf<8>::decode(In begin, In end, Uint32& output, Uint32 replacement)
|
||||
{
|
||||
// Some useful precomputed data
|
||||
static const int trailing[256] =
|
||||
{
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5
|
||||
};
|
||||
static const Uint32 offsets[6] =
|
||||
{
|
||||
0x00000000, 0x00003080, 0x000E2080, 0x03C82080, 0xFA082080, 0x82082080
|
||||
};
|
||||
|
||||
// decode the character
|
||||
int trailingBytes = trailing[static_cast<Uint8>(*begin)];
|
||||
if (begin + trailingBytes < end)
|
||||
{
|
||||
output = 0;
|
||||
switch (trailingBytes)
|
||||
{
|
||||
case 5: output += static_cast<Uint8>(*begin++); output <<= 6;
|
||||
case 4: output += static_cast<Uint8>(*begin++); output <<= 6;
|
||||
case 3: output += static_cast<Uint8>(*begin++); output <<= 6;
|
||||
case 2: output += static_cast<Uint8>(*begin++); output <<= 6;
|
||||
case 1: output += static_cast<Uint8>(*begin++); output <<= 6;
|
||||
case 0: output += static_cast<Uint8>(*begin++);
|
||||
}
|
||||
output -= offsets[trailingBytes];
|
||||
}
|
||||
else
|
||||
{
|
||||
// Incomplete character
|
||||
begin = end;
|
||||
output = replacement;
|
||||
}
|
||||
|
||||
return begin;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename Out>
|
||||
Out Utf<8>::encode(Uint32 input, Out output, Uint8 replacement)
|
||||
{
|
||||
// Some useful precomputed data
|
||||
static const Uint8 firstBytes[7] =
|
||||
{
|
||||
0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC
|
||||
};
|
||||
|
||||
// encode the character
|
||||
if ((input > 0x0010FFFF) || ((input >= 0xD800) && (input <= 0xDBFF)))
|
||||
{
|
||||
// Invalid character
|
||||
if (replacement)
|
||||
*output++ = replacement;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Valid character
|
||||
|
||||
// Get the number of bytes to write
|
||||
std::size_t bytestoWrite = 1;
|
||||
if (input < 0x80) bytestoWrite = 1;
|
||||
else if (input < 0x800) bytestoWrite = 2;
|
||||
else if (input < 0x10000) bytestoWrite = 3;
|
||||
else if (input <= 0x0010FFFF) bytestoWrite = 4;
|
||||
|
||||
// Extract the bytes to write
|
||||
Uint8 bytes[4];
|
||||
switch (bytestoWrite)
|
||||
{
|
||||
case 4: bytes[3] = static_cast<Uint8>((input | 0x80) & 0xBF); input >>= 6;
|
||||
case 3: bytes[2] = static_cast<Uint8>((input | 0x80) & 0xBF); input >>= 6;
|
||||
case 2: bytes[1] = static_cast<Uint8>((input | 0x80) & 0xBF); input >>= 6;
|
||||
case 1: bytes[0] = static_cast<Uint8> (input | firstBytes[bytestoWrite]);
|
||||
}
|
||||
|
||||
// Add them to the output
|
||||
output = std::copy(bytes, bytes + bytestoWrite, output);
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In>
|
||||
In Utf<8>::next(In begin, In end)
|
||||
{
|
||||
Uint32 codepoint;
|
||||
return decode(begin, end, codepoint);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In>
|
||||
std::size_t Utf<8>::count(In begin, In end)
|
||||
{
|
||||
std::size_t length = 0;
|
||||
while (begin < end)
|
||||
{
|
||||
begin = next(begin, end);
|
||||
++length;
|
||||
}
|
||||
|
||||
return length;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
Out Utf<8>::fromAnsi(In begin, In end, Out output, const std::locale& locale)
|
||||
{
|
||||
while (begin < end)
|
||||
{
|
||||
Uint32 codepoint = Utf<32>::decodeAnsi(*begin++, locale);
|
||||
output = encode(codepoint, output);
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
Out Utf<8>::fromWide(In begin, In end, Out output)
|
||||
{
|
||||
while (begin < end)
|
||||
{
|
||||
Uint32 codepoint = Utf<32>::decodeWide(*begin++);
|
||||
output = encode(codepoint, output);
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
Out Utf<8>::fromLatin1(In begin, In end, Out output)
|
||||
{
|
||||
// Latin-1 is directly compatible with Unicode encodings,
|
||||
// and can thus be treated as (a sub-range of) UTF-32
|
||||
while (begin < end)
|
||||
output = encode(*begin++, output);
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
Out Utf<8>::toAnsi(In begin, In end, Out output, char replacement, const std::locale& locale)
|
||||
{
|
||||
while (begin < end)
|
||||
{
|
||||
Uint32 codepoint;
|
||||
begin = decode(begin, end, codepoint);
|
||||
output = Utf<32>::encodeAnsi(codepoint, output, replacement, locale);
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
Out Utf<8>::toWide(In begin, In end, Out output, wchar_t replacement)
|
||||
{
|
||||
while (begin < end)
|
||||
{
|
||||
Uint32 codepoint;
|
||||
begin = decode(begin, end, codepoint);
|
||||
output = Utf<32>::encodeWide(codepoint, output, replacement);
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
Out Utf<8>::toLatin1(In begin, In end, Out output, char replacement)
|
||||
{
|
||||
// Latin-1 is directly compatible with Unicode encodings,
|
||||
// and can thus be treated as (a sub-range of) UTF-32
|
||||
while (begin < end)
|
||||
{
|
||||
Uint32 codepoint;
|
||||
begin = decode(begin, end, codepoint);
|
||||
*output++ = codepoint < 256 ? static_cast<char>(codepoint) : replacement;
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
Out Utf<8>::toUtf8(In begin, In end, Out output)
|
||||
{
|
||||
return std::copy(begin, end, output);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
Out Utf<8>::toUtf16(In begin, In end, Out output)
|
||||
{
|
||||
while (begin < end)
|
||||
{
|
||||
Uint32 codepoint;
|
||||
begin = decode(begin, end, codepoint);
|
||||
output = Utf<16>::encode(codepoint, output);
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
Out Utf<8>::toUtf32(In begin, In end, Out output)
|
||||
{
|
||||
while (begin < end)
|
||||
{
|
||||
Uint32 codepoint;
|
||||
begin = decode(begin, end, codepoint);
|
||||
*output++ = codepoint;
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In>
|
||||
In Utf<16>::decode(In begin, In end, Uint32& output, Uint32 replacement)
|
||||
{
|
||||
Uint16 first = *begin++;
|
||||
|
||||
// If it's a surrogate pair, first convert to a single UTF-32 character
|
||||
if ((first >= 0xD800) && (first <= 0xDBFF))
|
||||
{
|
||||
if (begin < end)
|
||||
{
|
||||
Uint32 second = *begin++;
|
||||
if ((second >= 0xDC00) && (second <= 0xDFFF))
|
||||
{
|
||||
// The second element is valid: convert the two elements to a UTF-32 character
|
||||
output = static_cast<Uint32>(((first - 0xD800) << 10) + (second - 0xDC00) + 0x0010000);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Invalid character
|
||||
output = replacement;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Invalid character
|
||||
begin = end;
|
||||
output = replacement;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// We can make a direct copy
|
||||
output = first;
|
||||
}
|
||||
|
||||
return begin;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename Out>
|
||||
Out Utf<16>::encode(Uint32 input, Out output, Uint16 replacement)
|
||||
{
|
||||
if (input <= 0xFFFF)
|
||||
{
|
||||
// The character can be copied directly, we just need to check if it's in the valid range
|
||||
if ((input >= 0xD800) && (input <= 0xDFFF))
|
||||
{
|
||||
// Invalid character (this range is reserved)
|
||||
if (replacement)
|
||||
*output++ = replacement;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Valid character directly convertible to a single UTF-16 character
|
||||
*output++ = static_cast<Uint16>(input);
|
||||
}
|
||||
}
|
||||
else if (input > 0x0010FFFF)
|
||||
{
|
||||
// Invalid character (greater than the maximum Unicode value)
|
||||
if (replacement)
|
||||
*output++ = replacement;
|
||||
}
|
||||
else
|
||||
{
|
||||
// The input character will be converted to two UTF-16 elements
|
||||
input -= 0x0010000;
|
||||
*output++ = static_cast<Uint16>((input >> 10) + 0xD800);
|
||||
*output++ = static_cast<Uint16>((input & 0x3FFUL) + 0xDC00);
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In>
|
||||
In Utf<16>::next(In begin, In end)
|
||||
{
|
||||
Uint32 codepoint;
|
||||
return decode(begin, end, codepoint);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In>
|
||||
std::size_t Utf<16>::count(In begin, In end)
|
||||
{
|
||||
std::size_t length = 0;
|
||||
while (begin < end)
|
||||
{
|
||||
begin = next(begin, end);
|
||||
++length;
|
||||
}
|
||||
|
||||
return length;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
Out Utf<16>::fromAnsi(In begin, In end, Out output, const std::locale& locale)
|
||||
{
|
||||
while (begin < end)
|
||||
{
|
||||
Uint32 codepoint = Utf<32>::decodeAnsi(*begin++, locale);
|
||||
output = encode(codepoint, output);
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
Out Utf<16>::fromWide(In begin, In end, Out output)
|
||||
{
|
||||
while (begin < end)
|
||||
{
|
||||
Uint32 codepoint = Utf<32>::decodeWide(*begin++);
|
||||
output = encode(codepoint, output);
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
Out Utf<16>::fromLatin1(In begin, In end, Out output)
|
||||
{
|
||||
// Latin-1 is directly compatible with Unicode encodings,
|
||||
// and can thus be treated as (a sub-range of) UTF-32
|
||||
return std::copy(begin, end, output);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
Out Utf<16>::toAnsi(In begin, In end, Out output, char replacement, const std::locale& locale)
|
||||
{
|
||||
while (begin < end)
|
||||
{
|
||||
Uint32 codepoint;
|
||||
begin = decode(begin, end, codepoint);
|
||||
output = Utf<32>::encodeAnsi(codepoint, output, replacement, locale);
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
Out Utf<16>::toWide(In begin, In end, Out output, wchar_t replacement)
|
||||
{
|
||||
while (begin < end)
|
||||
{
|
||||
Uint32 codepoint;
|
||||
begin = decode(begin, end, codepoint);
|
||||
output = Utf<32>::encodeWide(codepoint, output, replacement);
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
Out Utf<16>::toLatin1(In begin, In end, Out output, char replacement)
|
||||
{
|
||||
// Latin-1 is directly compatible with Unicode encodings,
|
||||
// and can thus be treated as (a sub-range of) UTF-32
|
||||
while (begin < end)
|
||||
{
|
||||
*output++ = *begin < 256 ? static_cast<char>(*begin) : replacement;
|
||||
begin++;
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
Out Utf<16>::toUtf8(In begin, In end, Out output)
|
||||
{
|
||||
while (begin < end)
|
||||
{
|
||||
Uint32 codepoint;
|
||||
begin = decode(begin, end, codepoint);
|
||||
output = Utf<8>::encode(codepoint, output);
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
Out Utf<16>::toUtf16(In begin, In end, Out output)
|
||||
{
|
||||
return std::copy(begin, end, output);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
Out Utf<16>::toUtf32(In begin, In end, Out output)
|
||||
{
|
||||
while (begin < end)
|
||||
{
|
||||
Uint32 codepoint;
|
||||
begin = decode(begin, end, codepoint);
|
||||
*output++ = codepoint;
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In>
|
||||
In Utf<32>::decode(In begin, In /*end*/, Uint32& output, Uint32 /*replacement*/)
|
||||
{
|
||||
output = *begin++;
|
||||
return begin;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename Out>
|
||||
Out Utf<32>::encode(Uint32 input, Out output, Uint32 /*replacement*/)
|
||||
{
|
||||
*output++ = input;
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In>
|
||||
In Utf<32>::next(In begin, In /*end*/)
|
||||
{
|
||||
return ++begin;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In>
|
||||
std::size_t Utf<32>::count(In begin, In end)
|
||||
{
|
||||
return begin - end;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
Out Utf<32>::fromAnsi(In begin, In end, Out output, const std::locale& locale)
|
||||
{
|
||||
while (begin < end)
|
||||
*output++ = decodeAnsi(*begin++, locale);
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
Out Utf<32>::fromWide(In begin, In end, Out output)
|
||||
{
|
||||
while (begin < end)
|
||||
*output++ = decodeWide(*begin++);
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
Out Utf<32>::fromLatin1(In begin, In end, Out output)
|
||||
{
|
||||
// Latin-1 is directly compatible with Unicode encodings,
|
||||
// and can thus be treated as (a sub-range of) UTF-32
|
||||
return std::copy(begin, end, output);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
Out Utf<32>::toAnsi(In begin, In end, Out output, char replacement, const std::locale& locale)
|
||||
{
|
||||
while (begin < end)
|
||||
output = encodeAnsi(*begin++, output, replacement, locale);
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
Out Utf<32>::toWide(In begin, In end, Out output, wchar_t replacement)
|
||||
{
|
||||
while (begin < end)
|
||||
output = encodeWide(*begin++, output, replacement);
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
Out Utf<32>::toLatin1(In begin, In end, Out output, char replacement)
|
||||
{
|
||||
// Latin-1 is directly compatible with Unicode encodings,
|
||||
// and can thus be treated as (a sub-range of) UTF-32
|
||||
while (begin < end)
|
||||
{
|
||||
*output++ = *begin < 256 ? static_cast<char>(*begin) : replacement;
|
||||
begin++;
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
Out Utf<32>::toUtf8(In begin, In end, Out output)
|
||||
{
|
||||
while (begin < end)
|
||||
output = Utf<8>::encode(*begin++, output);
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
Out Utf<32>::toUtf16(In begin, In end, Out output)
|
||||
{
|
||||
while (begin < end)
|
||||
output = Utf<16>::encode(*begin++, output);
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
Out Utf<32>::toUtf32(In begin, In end, Out output)
|
||||
{
|
||||
return std::copy(begin, end, output);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In>
|
||||
Uint32 Utf<32>::decodeAnsi(In input, const std::locale& locale)
|
||||
{
|
||||
// On Windows, GCC's standard library (glibc++) has almost
|
||||
// no support for Unicode stuff. As a consequence, in this
|
||||
// context we can only use the default locale and ignore
|
||||
// the one passed as parameter.
|
||||
|
||||
#if defined(SFML_SYSTEM_WINDOWS) && /* if Windows ... */ \
|
||||
(defined(__GLIBCPP__) || defined (__GLIBCXX__)) && /* ... and standard library is glibc++ ... */ \
|
||||
!(defined(__SGI_STL_PORT) || defined(_STLPORT_VERSION)) /* ... and STLPort is not used on top of it */
|
||||
|
||||
(void)locale; // to avoid warnings
|
||||
|
||||
wchar_t character = 0;
|
||||
mbtowc(&character, &input, 1);
|
||||
return static_cast<Uint32>(character);
|
||||
|
||||
#else
|
||||
|
||||
// Get the facet of the locale which deals with character conversion
|
||||
const std::ctype<wchar_t>& facet = std::use_facet< std::ctype<wchar_t> >(locale);
|
||||
|
||||
// Use the facet to convert each character of the input string
|
||||
return static_cast<Uint32>(facet.widen(input));
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In>
|
||||
Uint32 Utf<32>::decodeWide(In input)
|
||||
{
|
||||
// The encoding of wide characters is not well defined and is left to the system;
|
||||
// however we can safely assume that it is UCS-2 on Windows and
|
||||
// UCS-4 on Unix systems.
|
||||
// In both cases, a simple copy is enough (UCS-2 is a subset of UCS-4,
|
||||
// and UCS-4 *is* UTF-32).
|
||||
|
||||
return input;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename Out>
|
||||
Out Utf<32>::encodeAnsi(Uint32 codepoint, Out output, char replacement, const std::locale& locale)
|
||||
{
|
||||
// On Windows, gcc's standard library (glibc++) has almost
|
||||
// no support for Unicode stuff. As a consequence, in this
|
||||
// context we can only use the default locale and ignore
|
||||
// the one passed as parameter.
|
||||
|
||||
#if defined(SFML_SYSTEM_WINDOWS) && /* if Windows ... */ \
|
||||
(defined(__GLIBCPP__) || defined (__GLIBCXX__)) && /* ... and standard library is glibc++ ... */ \
|
||||
!(defined(__SGI_STL_PORT) || defined(_STLPORT_VERSION)) /* ... and STLPort is not used on top of it */
|
||||
|
||||
(void)locale; // to avoid warnings
|
||||
|
||||
char character = 0;
|
||||
if (wctomb(&character, static_cast<wchar_t>(codepoint)) >= 0)
|
||||
*output++ = character;
|
||||
else if (replacement)
|
||||
*output++ = replacement;
|
||||
|
||||
return output;
|
||||
|
||||
#else
|
||||
|
||||
// Get the facet of the locale which deals with character conversion
|
||||
const std::ctype<wchar_t>& facet = std::use_facet< std::ctype<wchar_t> >(locale);
|
||||
|
||||
// Use the facet to convert each character of the input string
|
||||
*output++ = facet.narrow(static_cast<wchar_t>(codepoint), replacement);
|
||||
|
||||
return output;
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename Out>
|
||||
Out Utf<32>::encodeWide(Uint32 codepoint, Out output, wchar_t replacement)
|
||||
{
|
||||
// The encoding of wide characters is not well defined and is left to the system;
|
||||
// however we can safely assume that it is UCS-2 on Windows and
|
||||
// UCS-4 on Unix systems.
|
||||
// For UCS-2 we need to check if the source characters fits in (UCS-2 is a subset of UCS-4).
|
||||
// For UCS-4 we can do a direct copy (UCS-4 *is* UTF-32).
|
||||
|
||||
switch (sizeof(wchar_t))
|
||||
{
|
||||
case 4:
|
||||
{
|
||||
*output++ = static_cast<wchar_t>(codepoint);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
if ((codepoint <= 0xFFFF) && ((codepoint < 0xD800) || (codepoint > 0xDFFF)))
|
||||
{
|
||||
*output++ = static_cast<wchar_t>(codepoint);
|
||||
}
|
||||
else if (replacement)
|
||||
{
|
||||
*output++ = replacement;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
301
code/SFML-2.4.2/include/SFML/System/Vector2.hpp
Normal file
301
code/SFML-2.4.2/include/SFML/System/Vector2.hpp
Normal file
|
@ -0,0 +1,301 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org)
|
||||
//
|
||||
// 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_VECTOR2_HPP
|
||||
#define SFML_VECTOR2_HPP
|
||||
|
||||
|
||||
namespace sf
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Utility template class for manipulating
|
||||
/// 2-dimensional vectors
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
class Vector2
|
||||
{
|
||||
public:
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Default constructor
|
||||
///
|
||||
/// Creates a Vector2(0, 0).
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Vector2();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Construct the vector from its coordinates
|
||||
///
|
||||
/// \param X X coordinate
|
||||
/// \param Y Y coordinate
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Vector2(T X, T Y);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Construct the vector from another type of vector
|
||||
///
|
||||
/// This constructor doesn't replace the copy constructor,
|
||||
/// it's called only when U != T.
|
||||
/// A call to this constructor will fail to compile if U
|
||||
/// is not convertible to T.
|
||||
///
|
||||
/// \param vector Vector to convert
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename U>
|
||||
explicit Vector2(const Vector2<U>& vector);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Member data
|
||||
////////////////////////////////////////////////////////////
|
||||
T x; ///< X coordinate of the vector
|
||||
T y; ///< Y coordinate of the vector
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \relates Vector2
|
||||
/// \brief Overload of unary operator -
|
||||
///
|
||||
/// \param right Vector to negate
|
||||
///
|
||||
/// \return Memberwise opposite of the vector
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
Vector2<T> operator -(const Vector2<T>& right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \relates Vector2
|
||||
/// \brief Overload of binary operator +=
|
||||
///
|
||||
/// This operator performs a memberwise addition of both vectors,
|
||||
/// and assigns the result to \a left.
|
||||
///
|
||||
/// \param left Left operand (a vector)
|
||||
/// \param right Right operand (a vector)
|
||||
///
|
||||
/// \return Reference to \a left
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
Vector2<T>& operator +=(Vector2<T>& left, const Vector2<T>& right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \relates Vector2
|
||||
/// \brief Overload of binary operator -=
|
||||
///
|
||||
/// This operator performs a memberwise subtraction of both vectors,
|
||||
/// and assigns the result to \a left.
|
||||
///
|
||||
/// \param left Left operand (a vector)
|
||||
/// \param right Right operand (a vector)
|
||||
///
|
||||
/// \return Reference to \a left
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
Vector2<T>& operator -=(Vector2<T>& left, const Vector2<T>& right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \relates Vector2
|
||||
/// \brief Overload of binary operator +
|
||||
///
|
||||
/// \param left Left operand (a vector)
|
||||
/// \param right Right operand (a vector)
|
||||
///
|
||||
/// \return Memberwise addition of both vectors
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
Vector2<T> operator +(const Vector2<T>& left, const Vector2<T>& right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \relates Vector2
|
||||
/// \brief Overload of binary operator -
|
||||
///
|
||||
/// \param left Left operand (a vector)
|
||||
/// \param right Right operand (a vector)
|
||||
///
|
||||
/// \return Memberwise subtraction of both vectors
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
Vector2<T> operator -(const Vector2<T>& left, const Vector2<T>& right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \relates Vector2
|
||||
/// \brief Overload of binary operator *
|
||||
///
|
||||
/// \param left Left operand (a vector)
|
||||
/// \param right Right operand (a scalar value)
|
||||
///
|
||||
/// \return Memberwise multiplication by \a right
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
Vector2<T> operator *(const Vector2<T>& left, T right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \relates Vector2
|
||||
/// \brief Overload of binary operator *
|
||||
///
|
||||
/// \param left Left operand (a scalar value)
|
||||
/// \param right Right operand (a vector)
|
||||
///
|
||||
/// \return Memberwise multiplication by \a left
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
Vector2<T> operator *(T left, const Vector2<T>& right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \relates Vector2
|
||||
/// \brief Overload of binary operator *=
|
||||
///
|
||||
/// This operator performs a memberwise multiplication by \a right,
|
||||
/// and assigns the result to \a left.
|
||||
///
|
||||
/// \param left Left operand (a vector)
|
||||
/// \param right Right operand (a scalar value)
|
||||
///
|
||||
/// \return Reference to \a left
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
Vector2<T>& operator *=(Vector2<T>& left, T right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \relates Vector2
|
||||
/// \brief Overload of binary operator /
|
||||
///
|
||||
/// \param left Left operand (a vector)
|
||||
/// \param right Right operand (a scalar value)
|
||||
///
|
||||
/// \return Memberwise division by \a right
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
Vector2<T> operator /(const Vector2<T>& left, T right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \relates Vector2
|
||||
/// \brief Overload of binary operator /=
|
||||
///
|
||||
/// This operator performs a memberwise division by \a right,
|
||||
/// and assigns the result to \a left.
|
||||
///
|
||||
/// \param left Left operand (a vector)
|
||||
/// \param right Right operand (a scalar value)
|
||||
///
|
||||
/// \return Reference to \a left
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
Vector2<T>& operator /=(Vector2<T>& left, T right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \relates Vector2
|
||||
/// \brief Overload of binary operator ==
|
||||
///
|
||||
/// This operator compares strict equality between two vectors.
|
||||
///
|
||||
/// \param left Left operand (a vector)
|
||||
/// \param right Right operand (a vector)
|
||||
///
|
||||
/// \return True if \a left is equal to \a right
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
bool operator ==(const Vector2<T>& left, const Vector2<T>& right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \relates Vector2
|
||||
/// \brief Overload of binary operator !=
|
||||
///
|
||||
/// This operator compares strict difference between two vectors.
|
||||
///
|
||||
/// \param left Left operand (a vector)
|
||||
/// \param right Right operand (a vector)
|
||||
///
|
||||
/// \return True if \a left is not equal to \a right
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
bool operator !=(const Vector2<T>& left, const Vector2<T>& right);
|
||||
|
||||
#include <SFML/System/Vector2.inl>
|
||||
|
||||
// Define the most common types
|
||||
typedef Vector2<int> Vector2i;
|
||||
typedef Vector2<unsigned int> Vector2u;
|
||||
typedef Vector2<float> Vector2f;
|
||||
|
||||
} // namespace sf
|
||||
|
||||
|
||||
#endif // SFML_VECTOR2_HPP
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \class sf::Vector2
|
||||
/// \ingroup system
|
||||
///
|
||||
/// sf::Vector2 is a simple class that defines a mathematical
|
||||
/// vector with two coordinates (x and y). It can be used to
|
||||
/// represent anything that has two dimensions: a size, a point,
|
||||
/// a velocity, etc.
|
||||
///
|
||||
/// The template parameter T is the type of the coordinates. It
|
||||
/// can be any type that supports arithmetic operations (+, -, /, *)
|
||||
/// and comparisons (==, !=), for example int or float.
|
||||
///
|
||||
/// You generally don't have to care about the templated form (sf::Vector2<T>),
|
||||
/// the most common specializations have special typedefs:
|
||||
/// \li sf::Vector2<float> is sf::Vector2f
|
||||
/// \li sf::Vector2<int> is sf::Vector2i
|
||||
/// \li sf::Vector2<unsigned int> is sf::Vector2u
|
||||
///
|
||||
/// The sf::Vector2 class has a small and simple interface, its x and y members
|
||||
/// can be accessed directly (there are no accessors like setX(), getX()) and it
|
||||
/// contains no mathematical function like dot product, cross product, length, etc.
|
||||
///
|
||||
/// Usage example:
|
||||
/// \code
|
||||
/// sf::Vector2f v1(16.5f, 24.f);
|
||||
/// v1.x = 18.2f;
|
||||
/// float y = v1.y;
|
||||
///
|
||||
/// sf::Vector2f v2 = v1 * 5.f;
|
||||
/// sf::Vector2f v3;
|
||||
/// v3 = v1 + v2;
|
||||
///
|
||||
/// bool different = (v2 != v3);
|
||||
/// \endcode
|
||||
///
|
||||
/// Note: for 3-dimensional vectors, see sf::Vector3.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
161
code/SFML-2.4.2/include/SFML/System/Vector2.inl
Normal file
161
code/SFML-2.4.2/include/SFML/System/Vector2.inl
Normal file
|
@ -0,0 +1,161 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org)
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
inline Vector2<T>::Vector2() :
|
||||
x(0),
|
||||
y(0)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
inline Vector2<T>::Vector2(T X, T Y) :
|
||||
x(X),
|
||||
y(Y)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
template <typename U>
|
||||
inline Vector2<T>::Vector2(const Vector2<U>& vector) :
|
||||
x(static_cast<T>(vector.x)),
|
||||
y(static_cast<T>(vector.y))
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
inline Vector2<T> operator -(const Vector2<T>& right)
|
||||
{
|
||||
return Vector2<T>(-right.x, -right.y);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
inline Vector2<T>& operator +=(Vector2<T>& left, const Vector2<T>& right)
|
||||
{
|
||||
left.x += right.x;
|
||||
left.y += right.y;
|
||||
|
||||
return left;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
inline Vector2<T>& operator -=(Vector2<T>& left, const Vector2<T>& right)
|
||||
{
|
||||
left.x -= right.x;
|
||||
left.y -= right.y;
|
||||
|
||||
return left;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
inline Vector2<T> operator +(const Vector2<T>& left, const Vector2<T>& right)
|
||||
{
|
||||
return Vector2<T>(left.x + right.x, left.y + right.y);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
inline Vector2<T> operator -(const Vector2<T>& left, const Vector2<T>& right)
|
||||
{
|
||||
return Vector2<T>(left.x - right.x, left.y - right.y);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
inline Vector2<T> operator *(const Vector2<T>& left, T right)
|
||||
{
|
||||
return Vector2<T>(left.x * right, left.y * right);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
inline Vector2<T> operator *(T left, const Vector2<T>& right)
|
||||
{
|
||||
return Vector2<T>(right.x * left, right.y * left);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
inline Vector2<T>& operator *=(Vector2<T>& left, T right)
|
||||
{
|
||||
left.x *= right;
|
||||
left.y *= right;
|
||||
|
||||
return left;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
inline Vector2<T> operator /(const Vector2<T>& left, T right)
|
||||
{
|
||||
return Vector2<T>(left.x / right, left.y / right);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
inline Vector2<T>& operator /=(Vector2<T>& left, T right)
|
||||
{
|
||||
left.x /= right;
|
||||
left.y /= right;
|
||||
|
||||
return left;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
inline bool operator ==(const Vector2<T>& left, const Vector2<T>& right)
|
||||
{
|
||||
return (left.x == right.x) && (left.y == right.y);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
inline bool operator !=(const Vector2<T>& left, const Vector2<T>& right)
|
||||
{
|
||||
return (left.x != right.x) || (left.y != right.y);
|
||||
}
|
302
code/SFML-2.4.2/include/SFML/System/Vector3.hpp
Normal file
302
code/SFML-2.4.2/include/SFML/System/Vector3.hpp
Normal file
|
@ -0,0 +1,302 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org)
|
||||
//
|
||||
// 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_VECTOR3_HPP
|
||||
#define SFML_VECTOR3_HPP
|
||||
|
||||
|
||||
namespace sf
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Utility template class for manipulating
|
||||
/// 3-dimensional vectors
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
class Vector3
|
||||
{
|
||||
public:
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Default constructor
|
||||
///
|
||||
/// Creates a Vector3(0, 0, 0).
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Vector3();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Construct the vector from its coordinates
|
||||
///
|
||||
/// \param X X coordinate
|
||||
/// \param Y Y coordinate
|
||||
/// \param Z Z coordinate
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Vector3(T X, T Y, T Z);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Construct the vector from another type of vector
|
||||
///
|
||||
/// This constructor doesn't replace the copy constructor,
|
||||
/// it's called only when U != T.
|
||||
/// A call to this constructor will fail to compile if U
|
||||
/// is not convertible to T.
|
||||
///
|
||||
/// \param vector Vector to convert
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename U>
|
||||
explicit Vector3(const Vector3<U>& vector);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Member data
|
||||
////////////////////////////////////////////////////////////
|
||||
T x; ///< X coordinate of the vector
|
||||
T y; ///< Y coordinate of the vector
|
||||
T z; ///< Z coordinate of the vector
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \relates Vector3
|
||||
/// \brief Overload of unary operator -
|
||||
///
|
||||
/// \param left Vector to negate
|
||||
///
|
||||
/// \return Memberwise opposite of the vector
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
Vector3<T> operator -(const Vector3<T>& left);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \relates Vector3
|
||||
/// \brief Overload of binary operator +=
|
||||
///
|
||||
/// This operator performs a memberwise addition of both vectors,
|
||||
/// and assigns the result to \a left.
|
||||
///
|
||||
/// \param left Left operand (a vector)
|
||||
/// \param right Right operand (a vector)
|
||||
///
|
||||
/// \return Reference to \a left
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
Vector3<T>& operator +=(Vector3<T>& left, const Vector3<T>& right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \relates Vector3
|
||||
/// \brief Overload of binary operator -=
|
||||
///
|
||||
/// This operator performs a memberwise subtraction of both vectors,
|
||||
/// and assigns the result to \a left.
|
||||
///
|
||||
/// \param left Left operand (a vector)
|
||||
/// \param right Right operand (a vector)
|
||||
///
|
||||
/// \return Reference to \a left
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
Vector3<T>& operator -=(Vector3<T>& left, const Vector3<T>& right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \relates Vector3
|
||||
/// \brief Overload of binary operator +
|
||||
///
|
||||
/// \param left Left operand (a vector)
|
||||
/// \param right Right operand (a vector)
|
||||
///
|
||||
/// \return Memberwise addition of both vectors
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
Vector3<T> operator +(const Vector3<T>& left, const Vector3<T>& right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \relates Vector3
|
||||
/// \brief Overload of binary operator -
|
||||
///
|
||||
/// \param left Left operand (a vector)
|
||||
/// \param right Right operand (a vector)
|
||||
///
|
||||
/// \return Memberwise subtraction of both vectors
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
Vector3<T> operator -(const Vector3<T>& left, const Vector3<T>& right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \relates Vector3
|
||||
/// \brief Overload of binary operator *
|
||||
///
|
||||
/// \param left Left operand (a vector)
|
||||
/// \param right Right operand (a scalar value)
|
||||
///
|
||||
/// \return Memberwise multiplication by \a right
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
Vector3<T> operator *(const Vector3<T>& left, T right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \relates Vector3
|
||||
/// \brief Overload of binary operator *
|
||||
///
|
||||
/// \param left Left operand (a scalar value)
|
||||
/// \param right Right operand (a vector)
|
||||
///
|
||||
/// \return Memberwise multiplication by \a left
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
Vector3<T> operator *(T left, const Vector3<T>& right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \relates Vector3
|
||||
/// \brief Overload of binary operator *=
|
||||
///
|
||||
/// This operator performs a memberwise multiplication by \a right,
|
||||
/// and assigns the result to \a left.
|
||||
///
|
||||
/// \param left Left operand (a vector)
|
||||
/// \param right Right operand (a scalar value)
|
||||
///
|
||||
/// \return Reference to \a left
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
Vector3<T>& operator *=(Vector3<T>& left, T right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \relates Vector3
|
||||
/// \brief Overload of binary operator /
|
||||
///
|
||||
/// \param left Left operand (a vector)
|
||||
/// \param right Right operand (a scalar value)
|
||||
///
|
||||
/// \return Memberwise division by \a right
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
Vector3<T> operator /(const Vector3<T>& left, T right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \relates Vector3
|
||||
/// \brief Overload of binary operator /=
|
||||
///
|
||||
/// This operator performs a memberwise division by \a right,
|
||||
/// and assigns the result to \a left.
|
||||
///
|
||||
/// \param left Left operand (a vector)
|
||||
/// \param right Right operand (a scalar value)
|
||||
///
|
||||
/// \return Reference to \a left
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
Vector3<T>& operator /=(Vector3<T>& left, T right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \relates Vector3
|
||||
/// \brief Overload of binary operator ==
|
||||
///
|
||||
/// This operator compares strict equality between two vectors.
|
||||
///
|
||||
/// \param left Left operand (a vector)
|
||||
/// \param right Right operand (a vector)
|
||||
///
|
||||
/// \return True if \a left is equal to \a right
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
bool operator ==(const Vector3<T>& left, const Vector3<T>& right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \relates Vector3
|
||||
/// \brief Overload of binary operator !=
|
||||
///
|
||||
/// This operator compares strict difference between two vectors.
|
||||
///
|
||||
/// \param left Left operand (a vector)
|
||||
/// \param right Right operand (a vector)
|
||||
///
|
||||
/// \return True if \a left is not equal to \a right
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
bool operator !=(const Vector3<T>& left, const Vector3<T>& right);
|
||||
|
||||
#include <SFML/System/Vector3.inl>
|
||||
|
||||
// Define the most common types
|
||||
typedef Vector3<int> Vector3i;
|
||||
typedef Vector3<float> Vector3f;
|
||||
|
||||
} // namespace sf
|
||||
|
||||
|
||||
#endif // SFML_VECTOR3_HPP
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \class sf::Vector3
|
||||
/// \ingroup system
|
||||
///
|
||||
/// sf::Vector3 is a simple class that defines a mathematical
|
||||
/// vector with three coordinates (x, y and z). It can be used to
|
||||
/// represent anything that has three dimensions: a size, a point,
|
||||
/// a velocity, etc.
|
||||
///
|
||||
/// The template parameter T is the type of the coordinates. It
|
||||
/// can be any type that supports arithmetic operations (+, -, /, *)
|
||||
/// and comparisons (==, !=), for example int or float.
|
||||
///
|
||||
/// You generally don't have to care about the templated form (sf::Vector3<T>),
|
||||
/// the most common specializations have special typedefs:
|
||||
/// \li sf::Vector3<float> is sf::Vector3f
|
||||
/// \li sf::Vector3<int> is sf::Vector3i
|
||||
///
|
||||
/// The sf::Vector3 class has a small and simple interface, its x and y members
|
||||
/// can be accessed directly (there are no accessors like setX(), getX()) and it
|
||||
/// contains no mathematical function like dot product, cross product, length, etc.
|
||||
///
|
||||
/// Usage example:
|
||||
/// \code
|
||||
/// sf::Vector3f v1(16.5f, 24.f, -8.2f);
|
||||
/// v1.x = 18.2f;
|
||||
/// float y = v1.y;
|
||||
/// float z = v1.z;
|
||||
///
|
||||
/// sf::Vector3f v2 = v1 * 5.f;
|
||||
/// sf::Vector3f v3;
|
||||
/// v3 = v1 + v2;
|
||||
///
|
||||
/// bool different = (v2 != v3);
|
||||
/// \endcode
|
||||
///
|
||||
/// Note: for 2-dimensional vectors, see sf::Vector2.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
168
code/SFML-2.4.2/include/SFML/System/Vector3.inl
Normal file
168
code/SFML-2.4.2/include/SFML/System/Vector3.inl
Normal file
|
@ -0,0 +1,168 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org)
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
inline Vector3<T>::Vector3() :
|
||||
x(0),
|
||||
y(0),
|
||||
z(0)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
inline Vector3<T>::Vector3(T X, T Y, T Z) :
|
||||
x(X),
|
||||
y(Y),
|
||||
z(Z)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
template <typename U>
|
||||
inline Vector3<T>::Vector3(const Vector3<U>& vector) :
|
||||
x(static_cast<T>(vector.x)),
|
||||
y(static_cast<T>(vector.y)),
|
||||
z(static_cast<T>(vector.z))
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
inline Vector3<T> operator -(const Vector3<T>& left)
|
||||
{
|
||||
return Vector3<T>(-left.x, -left.y, -left.z);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
inline Vector3<T>& operator +=(Vector3<T>& left, const Vector3<T>& right)
|
||||
{
|
||||
left.x += right.x;
|
||||
left.y += right.y;
|
||||
left.z += right.z;
|
||||
|
||||
return left;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
inline Vector3<T>& operator -=(Vector3<T>& left, const Vector3<T>& right)
|
||||
{
|
||||
left.x -= right.x;
|
||||
left.y -= right.y;
|
||||
left.z -= right.z;
|
||||
|
||||
return left;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
inline Vector3<T> operator +(const Vector3<T>& left, const Vector3<T>& right)
|
||||
{
|
||||
return Vector3<T>(left.x + right.x, left.y + right.y, left.z + right.z);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
inline Vector3<T> operator -(const Vector3<T>& left, const Vector3<T>& right)
|
||||
{
|
||||
return Vector3<T>(left.x - right.x, left.y - right.y, left.z - right.z);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
inline Vector3<T> operator *(const Vector3<T>& left, T right)
|
||||
{
|
||||
return Vector3<T>(left.x * right, left.y * right, left.z * right);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
inline Vector3<T> operator *(T left, const Vector3<T>& right)
|
||||
{
|
||||
return Vector3<T>(right.x * left, right.y * left, right.z * left);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
inline Vector3<T>& operator *=(Vector3<T>& left, T right)
|
||||
{
|
||||
left.x *= right;
|
||||
left.y *= right;
|
||||
left.z *= right;
|
||||
|
||||
return left;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
inline Vector3<T> operator /(const Vector3<T>& left, T right)
|
||||
{
|
||||
return Vector3<T>(left.x / right, left.y / right, left.z / right);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
inline Vector3<T>& operator /=(Vector3<T>& left, T right)
|
||||
{
|
||||
left.x /= right;
|
||||
left.y /= right;
|
||||
left.z /= right;
|
||||
|
||||
return left;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
inline bool operator ==(const Vector3<T>& left, const Vector3<T>& right)
|
||||
{
|
||||
return (left.x == right.x) && (left.y == right.y) && (left.z == right.z);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
inline bool operator !=(const Vector3<T>& left, const Vector3<T>& right)
|
||||
{
|
||||
return (left.x != right.x) || (left.y != right.y) || (left.z != right.z);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue