ulfben icon

Sample "Big Five" implementation for SDL_Surface

ulfben | PRO | 10/14/17 01:26:10 PM UTC | 0 ⭐ | 919 👁️ | Never ⏰ | []
C++ |

990 B

|

None

|

0 👍

/

0 👎

#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

  • Gyqizv icon
    04/02/26 06:14:40 PM UTC
    text |

    0 B

    |

    0 👍

    /

    0 👎

    Best t33n active cpx link daily updates!
     Copy and paste the link in a new browser tab and then hit enter!
     https://crazyporn.@xxx/members/157354/?asgtbndr=1&play=true&spon=adworld&zone=400
     Remove the @ 
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎