forked from pioneerspacesim/pioneer
/
SDLWrappers.h
31 lines (22 loc) · 1.03 KB
/
SDLWrappers.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#ifndef _SDLWRAPPERS_H
#define _SDLWRAPPERS_H
#include "SmartPtr.h"
namespace FileSystem { class FileSource; }
struct SDL_Surface;
class SDLSurfacePtr : public SmartPtrBase<SDLSurfacePtr, SDL_Surface> {
typedef SmartPtrBase<SDLSurfacePtr, SDL_Surface> base_type;
private:
explicit SDLSurfacePtr(SDL_Surface *p): base_type(p) {}
public:
static SDLSurfacePtr WrapNew(SDL_Surface *p) { return SDLSurfacePtr(p); }
static SDLSurfacePtr WrapCopy(SDL_Surface *p) { if (p) { p->refcount += 1; } return SDLSurfacePtr(p); }
SDLSurfacePtr() {}
SDLSurfacePtr(const SDLSurfacePtr& b): base_type(b.Get())
{ if (this->m_ptr) this->m_ptr->refcount += 1; }
~SDLSurfacePtr() { SDL_FreeSurface(this->Release()); }
SDLSurfacePtr &operator=(const SDLSurfacePtr &b) { SDLSurfacePtr(b).Swap(*this); return *this; }
bool Unique() const { assert(this->m_ptr); return (this->m_ptr->refcount == 1); }
};
SDLSurfacePtr LoadSurfaceFromFile(const std::string &fname, FileSystem::FileSource &source);
SDLSurfacePtr LoadSurfaceFromFile(const std::string &fname);
#endif