#pragma once
#include "SDL.h"
class Text;
class Surface{
public:
Surface(Text& text);
SDL_Surface* Surface::getSurface() const {
return _ptr;
}
//Destructor
Surface::~Surface() noexcept {
destroy();
}
// Copy constructor
Surface(const Surface& other){
_ptr = other.getSurface();
if (_ptr) {
_ptr->refcount++;
}
}
// Move constructor
Surface(Surface&& other) noexcept {
_ptr = other._ptr;
other._ptr = nullptr;
}
// Copy assignment operator
Surface& operator= (const Surface& other){
destroy();//delete previous value
_ptr = other.getSurface();
if (_ptr) {
_ptr->refcount++;
}
return *this;
}
// Move assignment operator
Surface& operator= (Surface&& other) noexcept {
destroy();
_ptr = other.getSurface();
other._ptr = nullptr;
return *this;
}
protected:
void destroy() noexcept {
if (_ptr) {
SDL_FreeSurface(_ptr);
_ptr = nullptr;
}
}
private:
SDL_Surface* _ptr = nullptr;
};
Comments
0 B
|0 👍
/0 👎
0 B
|👍
/👎