From 218154cf0098de3f495e31ced489da24b7318638 Mon Sep 17 00:00:00 2001 From: Vittorio Romeo Date: Wed, 16 Feb 2022 15:06:05 +0000 Subject: [PATCH] Add move semantics to 'Font', 'Text,' and 'Image' --- include/SFML/Graphics/Font.hpp | 12 ++++++++++++ include/SFML/Graphics/Image.hpp | 24 ++++++++++++++++++++++++ include/SFML/Graphics/Text.hpp | 24 ++++++++++++++++++++++++ include/SFML/System/String.hpp | 12 ++++++++++++ src/SFML/Graphics/Font.cpp | 8 ++++++++ src/SFML/Graphics/Image.cpp | 16 ++++++++++++++++ src/SFML/Graphics/Text.cpp | 16 ++++++++++++++++ src/SFML/System/String.cpp | 8 ++++++++ 8 files changed, 120 insertions(+) diff --git a/include/SFML/Graphics/Font.hpp b/include/SFML/Graphics/Font.hpp index b1f822cb1..42ae89167 100644 --- a/include/SFML/Graphics/Font.hpp +++ b/include/SFML/Graphics/Font.hpp @@ -84,6 +84,18 @@ public: //////////////////////////////////////////////////////////// Font(const Font& copy); + //////////////////////////////////////////////////////////// + /// \brief Move constructor + /// + //////////////////////////////////////////////////////////// + Font(Font&&) noexcept; + + //////////////////////////////////////////////////////////// + /// \brief Move assignment + /// + //////////////////////////////////////////////////////////// + Font& operator=(Font&&) noexcept; + //////////////////////////////////////////////////////////// /// \brief Destructor /// diff --git a/include/SFML/Graphics/Image.hpp b/include/SFML/Graphics/Image.hpp index f006fa838..f3cac62b0 100644 --- a/include/SFML/Graphics/Image.hpp +++ b/include/SFML/Graphics/Image.hpp @@ -61,6 +61,30 @@ public: //////////////////////////////////////////////////////////// ~Image(); + //////////////////////////////////////////////////////////// + /// \brief Copy constructor + /// + //////////////////////////////////////////////////////////// + Image(const Image&); + + //////////////////////////////////////////////////////////// + /// \brief Copy assignment + /// + //////////////////////////////////////////////////////////// + Image& operator=(const Image&); + + //////////////////////////////////////////////////////////// + /// \brief Move constructor + /// + //////////////////////////////////////////////////////////// + Image(Image&&) noexcept; + + //////////////////////////////////////////////////////////// + /// \brief Move assignment + /// + //////////////////////////////////////////////////////////// + Image& operator=(Image&&) noexcept; + //////////////////////////////////////////////////////////// /// \brief Create the image and fill it with a unique color /// diff --git a/include/SFML/Graphics/Text.hpp b/include/SFML/Graphics/Text.hpp index 97c64eebf..19b6e480a 100644 --- a/include/SFML/Graphics/Text.hpp +++ b/include/SFML/Graphics/Text.hpp @@ -88,6 +88,30 @@ public: //////////////////////////////////////////////////////////// Text(const String& string, const Font& font, unsigned int characterSize = 30); + //////////////////////////////////////////////////////////// + /// \brief Copy constructor + /// + //////////////////////////////////////////////////////////// + Text(const Text&); + + //////////////////////////////////////////////////////////// + /// \brief Copy assignment + /// + //////////////////////////////////////////////////////////// + Text& operator=(const Text&); + + //////////////////////////////////////////////////////////// + /// \brief Move constructor + /// + //////////////////////////////////////////////////////////// + Text(Text&&) noexcept; + + //////////////////////////////////////////////////////////// + /// \brief Move assignment + /// + //////////////////////////////////////////////////////////// + Text& operator=(Text&&) noexcept; + //////////////////////////////////////////////////////////// /// \brief Set the text's string /// diff --git a/include/SFML/System/String.hpp b/include/SFML/System/String.hpp index d342d3dfd..48ab40d2b 100644 --- a/include/SFML/System/String.hpp +++ b/include/SFML/System/String.hpp @@ -157,6 +157,18 @@ public: //////////////////////////////////////////////////////////// String(const String& copy); + //////////////////////////////////////////////////////////// + /// \brief Move constructor + /// + //////////////////////////////////////////////////////////// + String(String&&) noexcept; + + //////////////////////////////////////////////////////////// + /// \brief Move assignment + /// + //////////////////////////////////////////////////////////// + String& operator=(String&&) noexcept; + //////////////////////////////////////////////////////////// /// \brief Create a new sf::String from a UTF-8 encoded string /// diff --git a/src/SFML/Graphics/Font.cpp b/src/SFML/Graphics/Font.cpp index a8f209149..a99605801 100644 --- a/src/SFML/Graphics/Font.cpp +++ b/src/SFML/Graphics/Font.cpp @@ -135,6 +135,14 @@ Font::~Font() } +//////////////////////////////////////////////////////////// +Font::Font(Font&&) noexcept = default; + + +//////////////////////////////////////////////////////////// +Font& Font::operator=(Font&&) noexcept = default; + + //////////////////////////////////////////////////////////// bool Font::loadFromFile(const std::string& filename) { diff --git a/src/SFML/Graphics/Image.cpp b/src/SFML/Graphics/Image.cpp index 9be7aec27..a5fe06f5a 100644 --- a/src/SFML/Graphics/Image.cpp +++ b/src/SFML/Graphics/Image.cpp @@ -53,6 +53,22 @@ Image::~Image() } +//////////////////////////////////////////////////////////// +Image::Image(const Image&) = default; + + +//////////////////////////////////////////////////////////// +Image& Image::operator=(const Image&) = default; + + +//////////////////////////////////////////////////////////// +Image::Image(Image&&) noexcept = default; + + +//////////////////////////////////////////////////////////// +Image& Image::operator=(Image&&) noexcept = default; + + //////////////////////////////////////////////////////////// void Image::create(unsigned int width, unsigned int height, const Color& color) { diff --git a/src/SFML/Graphics/Text.cpp b/src/SFML/Graphics/Text.cpp index b12a3ab7c..8bc1c20a7 100644 --- a/src/SFML/Graphics/Text.cpp +++ b/src/SFML/Graphics/Text.cpp @@ -118,6 +118,22 @@ m_fontTextureId (0) } +//////////////////////////////////////////////////////////// +Text::Text(const Text&) = default; + + +//////////////////////////////////////////////////////////// +Text& Text::operator=(const Text&) = default; + + +//////////////////////////////////////////////////////////// +Text::Text(Text&&) noexcept = default; + + +//////////////////////////////////////////////////////////// +Text& Text::operator=(Text&&) noexcept = default; + + //////////////////////////////////////////////////////////// void Text::setString(const String& string) { diff --git a/src/SFML/System/String.cpp b/src/SFML/System/String.cpp index 7e6c76501..3eb232b53 100644 --- a/src/SFML/System/String.cpp +++ b/src/SFML/System/String.cpp @@ -132,6 +132,14 @@ m_string(copy.m_string) } +//////////////////////////////////////////////////////////// +String::String(String&&) noexcept = default; + + +//////////////////////////////////////////////////////////// +String& String::operator=(String&&) noexcept = default; + + //////////////////////////////////////////////////////////// String::operator std::string() const {