Advertisement
Vultraz

Untitled

Sep 12th, 2016
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.84 KB | None | 0 0
  1. static void free_sdl_surface(SDL_Surface* surf)
  2. {
  3.     if(surf) {
  4.         SDL_FreeSurface(surf);
  5.     }
  6. }
  7.  
  8. struct surface
  9. {
  10. public:
  11.     surface()
  12.         : surface_(nullptr)
  13.     {}
  14.  
  15.     surface(SDL_Surface *surf)
  16.         : surface_(surf, free_sdl_surface)
  17.     {}
  18.  
  19.     surface(const surface& o)
  20.         : surface_(o.surface_.get(), free_sdl_surface)
  21.     {}
  22.  
  23.     // DO I NEED THIS IT DOESN'T BUILD
  24.     surface& operator=(const SDL_Surface* s)
  25.     {
  26.         surface_ = std::make_shared(s);
  27.         return *this;
  28.     }
  29.  
  30.     surface& operator=(const surface& o)
  31.     {
  32.         surface_ = o.surface_;
  33.         return *this;
  34.     }
  35.  
  36.     operator SDL_Surface*() const { return surface_.get(); }
  37.  
  38.     SDL_Surface* get() const { return surface_.get(); }
  39.  
  40.     SDL_Surface* operator->() const { return surface_.get(); }
  41.  
  42.     bool null() const { return surface_.get() == nullptr; }
  43.  
  44. private:
  45.     std::shared_ptr<SDL_Surface> surface_;
  46. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement