wesnoth-cvs-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Wesnoth-cvs-commits] wesnoth/src sdl_utils.cpp sdl_utils.hpp


From: Guillaume Melquiond
Subject: [Wesnoth-cvs-commits] wesnoth/src sdl_utils.cpp sdl_utils.hpp
Date: Fri, 03 Sep 2004 17:56:13 -0400

CVSROOT:        /cvsroot/wesnoth
Module name:    wesnoth
Branch:         
Changes by:     Guillaume Melquiond <address@hidden>    04/09/03 21:42:00

Modified files:
        src            : sdl_utils.cpp sdl_utils.hpp 

Log message:
        Cleanup of surface class: trivial functions should be inline, and a bit 
of reorganization.

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/sdl_utils.cpp.diff?tr1=1.56&tr2=1.57&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/sdl_utils.hpp.diff?tr1=1.42&tr2=1.43&r1=text&r2=text

Patches:
Index: wesnoth/src/sdl_utils.cpp
diff -u wesnoth/src/sdl_utils.cpp:1.56 wesnoth/src/sdl_utils.cpp:1.57
--- wesnoth/src/sdl_utils.cpp:1.56      Sun Aug 29 17:17:45 2004
+++ wesnoth/src/sdl_utils.cpp   Fri Sep  3 21:42:00 2004
@@ -1,4 +1,4 @@
-/* $Id: sdl_utils.cpp,v 1.56 2004/08/29 17:17:45 silene Exp $ */
+/* $Id: sdl_utils.cpp,v 1.57 2004/09/03 21:42:00 silene Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -57,17 +57,6 @@
 
 }
 
-void free_sdl_surface::operator()(SDL_Surface* surf) const
-{
-       if(surf != NULL)
-                SDL_FreeSurface(surf); 
-}
-
-surface::surface(SDL_Surface* surf) : surface_(surf)
-{
-}
-
-
 surface make_neutral_surface(surface surf)
 {
        if(surf == NULL) {
Index: wesnoth/src/sdl_utils.hpp
diff -u wesnoth/src/sdl_utils.hpp:1.42 wesnoth/src/sdl_utils.hpp:1.43
--- wesnoth/src/sdl_utils.hpp:1.42      Sun Aug 29 17:17:45 2004
+++ wesnoth/src/sdl_utils.hpp   Fri Sep  3 21:42:00 2004
@@ -1,4 +1,4 @@
-/* $Id: sdl_utils.hpp,v 1.42 2004/08/29 17:17:45 silene Exp $ */
+/* $Id: sdl_utils.hpp,v 1.43 2004/09/03 21:42:00 silene Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -36,62 +36,63 @@
 
 bool rects_overlap(const SDL_Rect& rect1, const SDL_Rect& rect2);
 
-struct free_sdl_surface {
-       void operator()(SDL_Surface* surface) const; 
-};
-
-
 struct surface
 {
 private:
-       inline int sdl_add_ref(SDL_Surface* surf);
+       static void sdl_add_ref(SDL_Surface *surf)
+       {
+               if (surf != NULL)
+                       ++surf->refcount;
+       }
+
+       struct free_sdl_surface {
+               void operator()(SDL_Surface *surf) const
+               {
+                       if (surf != NULL)
+                                SDL_FreeSurface(surf); 
+               }
+       };
+
        typedef util::scoped_resource<SDL_Surface*,free_sdl_surface> 
scoped_sdl_surface;
 public:
        surface() : surface_(NULL) 
        {}
 
-       surface(SDL_Surface* surf);
+       surface(SDL_Surface *surf) : surface_(surf)
+       {}
 
        surface(const surface& o) : surface_(o.surface_.get())
        {
-               sdl_add_ref(get());
+               sdl_add_ref(surface_.get());
+       }
+
+       void assign(const surface& o)
+       {
+               SDL_Surface *surf = o.surface_.get();
+               sdl_add_ref(surf); // need to be done before assign to avoid 
corruption on "a=a;"
+               surface_.assign(surf);
        }
 
        surface& operator=(const surface& o)
        {
-               surface_.assign(o.surface_.get());
-               sdl_add_ref(get());
+               assign(o);
                return *this;
        }
 
-       operator SDL_Surface*() const { return surface_; }
+       operator SDL_Surface*() const { return surface_.get(); }
 
        SDL_Surface* get() const { return surface_.get(); }
 
        SDL_Surface* operator->() const { return surface_.get(); }
 
-       void assign(const surface& o)
-       {
-               operator=(o);
-       }
-
        void assign(SDL_Surface* surf) { surface_.assign(surf); }
 
-       bool null() const { return get() == NULL; }
+       bool null() const { return surface_.get() == NULL; }
 
 private:
        scoped_sdl_surface surface_;
 };
 
-int surface::sdl_add_ref(SDL_Surface* surf)
-{
-       if(surf != NULL) {
-               return surf->refcount++;
-       } else {
-               return 0;
-       }
-}
-
 bool operator<(const surface& a, const surface& b);
 
 surface make_neutral_surface(surface surf);




reply via email to

[Prev in Thread] Current Thread [Next in Thread]