Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00025
00028
00029 #ifndef THOR_RESOURCEKEYTRAITS_HPP
00030 #define THOR_RESOURCEKEYTRAITS_HPP
00031
00032 #include <Thor/Config.hpp>
00033 #include <Thor/Detail/Metaprogramming.hpp>
00034
00035 #include <string>
00036
00037
00038 namespace sf
00039 {
00040
00041 class Image;
00042 class Texture;
00043 class Font;
00044 class Shader;
00045 class Music;
00046 class SoundBuffer;
00047
00048 class InputStream;
00049
00050 }
00051
00052
00053 namespace thor
00054 {
00055 namespace Resources
00056 {
00057
00058 class ImageKey;
00059 class TextureKey;
00060 class FontKey;
00061 class ShaderKey;
00062 class SoundBufferKey;
00063 class MusicKey;
00064
00065 }
00066 }
00067
00068
00069
00070
00071 namespace thor
00072 {
00073
00076
00077 namespace Resources
00078 {
00079
00094 template <class Resource>
00095 struct KeyTraits;
00096
00097 }
00098
00099
00105 #define THOR_MAP_RESOURCEKEY(Resource, ResourceKey) \
00106 namespace thor \
00107 { \
00108 namespace Resources \
00109 { \
00110 template <> \
00111 struct KeyTraits< Resource > \
00112 { \
00113 typedef ResourceKey Type; \
00114 }; \
00115 } \
00116 }
00117
00119
00120 }
00121
00122
00123 THOR_MAP_RESOURCEKEY(sf::Image, ImageKey)
00124 THOR_MAP_RESOURCEKEY(sf::Texture, TextureKey)
00125 THOR_MAP_RESOURCEKEY(sf::Font, FontKey)
00126 THOR_MAP_RESOURCEKEY(sf::Shader, ShaderKey)
00127 THOR_MAP_RESOURCEKEY(sf::SoundBuffer, SoundBufferKey)
00128 THOR_MAP_RESOURCEKEY(sf::Music, MusicKey)
00129
00130
00131
00132
00133
00134 namespace thor
00135 {
00136 namespace detail
00137 {
00138
00139 struct KeyInfoAccessor
00140 {
00141
00142 template <class Key>
00143 static const std::string& Get(const Key& key, Int2Type<true>)
00144 {
00145 return key.mKey;
00146 }
00147
00148
00149 template <class Key>
00150 static const std::string& Get(const Key&, Int2Type<false>)
00151 {
00152 static const std::string emptyString = "";
00153 return emptyString;
00154 }
00155 };
00156
00157
00158 template <class Key>
00159 const std::string& GetKeyInfo(const Key& key)
00160 {
00161 using std::tr1::is_same;
00162
00163 const bool builtin =
00164 is_same<Key, Resources::ImageKey>::value
00165 || is_same<Key, Resources::TextureKey>::value
00166 || is_same<Key, Resources::FontKey>::value
00167 || is_same<Key, Resources::ShaderKey>::value
00168 || is_same<Key, Resources::SoundBufferKey>::value
00169 || is_same<Key, Resources::MusicKey>::value;
00170
00171 return KeyInfoAccessor::Get(key, Int2Type<builtin>());
00172 }
00173
00174 }
00175 }
00176
00177 #endif // THOR_RESOURCEKEYTRAITS_HPP