src/video/sdl_surface_ptr.hpp

Go to the documentation of this file.
00001 //  SuperTux
00002 //  Copyright (C) 2009 Ingo Ruhnke <grumbel@gmx.de>
00003 //
00004 //  This program is free software: you can redistribute it and/or modify
00005 //  it under the terms of the GNU General Public License as published by
00006 //  the Free Software Foundation, either version 3 of the License, or
00007 //  (at your option) any later version.
00008 //
00009 //  This program is distributed in the hope that it will be useful,
00010 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 //  GNU General Public License for more details.
00013 //
00014 //  You should have received a copy of the GNU General Public License
00015 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016 
00017 #ifndef HEADER_SUPERTUX_VIDEO_SDL_SURFACE_PTR_HPP
00018 #define HEADER_SUPERTUX_VIDEO_SDL_SURFACE_PTR_HPP
00019 
00020 #include <SDL.h>
00021 
00024 class SDLSurfacePtr
00025 {
00026 private:
00027   SDL_Surface* m_surface;
00028 
00029 public:
00030   SDLSurfacePtr() :
00031     m_surface(0)
00032   {}
00033 
00034   SDLSurfacePtr(SDL_Surface* surface) :
00035     m_surface(surface)
00036   {}
00037 
00038   ~SDLSurfacePtr() 
00039   {
00040     SDL_FreeSurface(m_surface);
00041   }
00042 
00043   SDL_Surface* operator->()
00044   {
00045     return m_surface;
00046   }
00047 
00048   void reset(SDL_Surface* surface)
00049   {
00050     SDL_FreeSurface(m_surface);
00051     m_surface = surface;
00052   }
00053 
00054   SDL_Surface* get()
00055   {
00056     return m_surface;
00057   }
00058 
00059   operator void*() {
00060     return m_surface;
00061   }
00062 
00063 private:
00064   SDLSurfacePtr(const SDLSurfacePtr&);
00065   SDLSurfacePtr& operator=(const SDLSurfacePtr&);
00066 };
00067 
00068 #endif
00069 
00070 /* EOF */

Generated on Mon Jun 9 03:38:24 2014 for SuperTux by  doxygen 1.5.1