Katana Plug-in APIs 0.1

ShaderInfoCache.h

00001 // Copyright (c) 2013 The Foundry Visionmongers Ltd. All Rights Reserved.
00002 
00003 #ifndef FNRENDERERINFO_SHADERINFOCACHE_H
00004 #define FNRENDERERINFO_SHADERINFOCACHE_H
00005 
00006 #include <FnAttribute/FnAttribute.h>
00007 #include <FnRendererInfo/FnRendererInfoAPI.h>
00008 
00009 #include <map>
00010 
00011 #include <iostream>
00012 
00013 namespace Foundry
00014 {
00015 namespace Katana
00016 {
00017 namespace RendererInfo
00018 {
00027     template<typename TShaderInfoType>
00028     class FNRENDERERINFO_API ShaderInfoCache
00029     {
00030     public:
00031 
00035         typedef typename std::map<std::string, TShaderInfoType>::const_iterator Iterator;
00036 
00042         bool isEmpty() const;
00043 
00047         void flush();
00048 
00055         void addShaderInfo(const std::string& shaderName, const TShaderInfoType& shaderInfo);
00056 
00063         const TShaderInfoType& getShaderInfo(const std::string& shaderName) const;
00064 
00069         Iterator begin() const;
00070 
00075         Iterator end() const;
00076 
00081         void setNullValue(const TShaderInfoType& nullValue);
00082 
00083     private:
00084 
00085         typedef std::map<std::string, TShaderInfoType> ShaderInfoMap;
00086 
00087         TShaderInfoType _nullValue;
00088 
00089         ShaderInfoMap _shaderInfo;
00090     };
00095 template<typename TShaderInfoType>
00096 bool ShaderInfoCache<TShaderInfoType>::isEmpty() const
00097 {
00098     return _shaderInfo.empty();
00099 }
00100 
00101 template<typename TShaderInfoType>
00102 void ShaderInfoCache<TShaderInfoType>::flush()
00103 {
00104     _shaderInfo.clear();
00105 }
00106 
00107 template<typename TShaderInfoType>
00108 void ShaderInfoCache<TShaderInfoType>::addShaderInfo(const std::string& shaderName,
00109                                                      const TShaderInfoType& shaderInfo)
00110 {
00111     if (!shaderName.empty())
00112     {
00113         _shaderInfo[shaderName] = shaderInfo;
00114     }
00115 }
00116 
00117 template<typename TShaderInfoType>
00118 const TShaderInfoType& ShaderInfoCache<TShaderInfoType>::getShaderInfo(const std::string& shaderName) const
00119 {
00120     // Get the shader's TShaderInfoType inside _shaderInfo
00121     typename ShaderInfoMap::const_iterator iter=_shaderInfo.find(shaderName);
00122     if (iter == _shaderInfo.end())
00123     {
00124         return _nullValue;
00125     }
00126 
00127     return (*iter).second;
00128 }
00129 
00130 template<typename TShaderInfoType>
00131 typename ShaderInfoCache<TShaderInfoType>::Iterator ShaderInfoCache<TShaderInfoType>::begin() const
00132 {
00133     return _shaderInfo.begin();
00134 }
00135 
00136 template<typename TShaderInfoType>
00137 typename ShaderInfoCache<TShaderInfoType>::Iterator ShaderInfoCache<TShaderInfoType>::end() const
00138 {
00139     return _shaderInfo.end();
00140 }
00141 
00142 template<typename TShaderInfoType>
00143 void ShaderInfoCache<TShaderInfoType>::setNullValue(const TShaderInfoType& nullValue)
00144 {
00145     _nullValue = nullValue;
00146 }
00147 
00148 }
00149 }
00150 }
00151 
00152 namespace FnKat = Foundry::Katana;
00153 
00154 #endif
 All Classes Functions Variables Typedefs Enumerations Enumerator