Author: alink
Date: Fri May 8 02:25:19 2009
New Revision: 35478
URL: http://svn.gna.org/viewcvs/wesnoth?rev=35478&view=rev
Log:
use template to reduce some code redundancy
Modified:
trunk/src/image.hpp
Modified: trunk/src/image.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/image.hpp?rev=35478&r1=35477&r2=35478&view=diff
==============================================================================
--- trunk/src/image.hpp (original)
+++ trunk/src/image.hpp Fri May 8 02:25:19 2009
@@ -182,26 +182,16 @@
// loads the image it is pointing to from the disk
surface load_from_disk() const;
- bool in_cache(cache_type<surface>& cache) const
+ template <typename T>
+ bool in_cache(cache_type<T>& cache) const
{ return index_ == -1 ? false :
cache.get_element(index_).loaded; }
- surface locate_in_cache(cache_type<surface>& cache) const
- { return index_ == -1 ? surface() :
cache.get_element(index_).item; }
- void add_to_cache(cache_type<surface>& cache, const surface
&image) const
- { if(index_ != -1 ) cache.get_element(index_) =
cache_item<surface>(image); cache.on_load(index_); }
-
- bool in_cache(cache_type<bool>& cache) const
- { return index_ == -1 ? false :
cache.get_element(index_).loaded; }
- bool locate_in_cache(cache_type<bool>& cache) const
- { return index_ == -1 ? false :
cache.get_element(index_).item; }
- void add_to_cache(cache_type<bool>& cache, bool st) const
- { if(index_ != -1 ) cache.get_element(index_) =
cache_item<bool>(st); cache.on_load(index_); }
-
- bool in_cache(cache_type<locator>& cache) const
- { return index_ == -1 ? false :
cache.get_element(index_).loaded; cache.on_load(index_); }
- locator locate_in_cache(cache_type<locator>& cache) const
- { return index_ == -1 ? locator() :
cache.get_element(index_).item; }
- void add_to_cache(cache_type<locator>& cache, const locator
&image) const
- { if(index_ != -1) cache.get_element(index_) =
cache_item<locator>(image); }
+ template <typename T>
+ T locate_in_cache(cache_type<T>& cache) const
+ { return index_ == -1 ? T() :
cache.get_element(index_).item; }
+ template <typename T>
+ void add_to_cache(cache_type<T>& cache, const T &data) const
+ { if(index_ != -1 ) cache.get_element(index_) =
cache_item<T>(data); cache.on_load(index_); }
+
protected:
static int last_index_;
private:
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits