Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Many ways to do it .</p> <p>You could do with simple overloading :</p> <pre><code>bool add(Shader *ptr){ return addShader(ptr); } bool add(Mesh *ptr){ return addMesh(ptr); } bool add(Texture *ptr){ return addTexture(ptr); } </code></pre> <p>or if you want to use templates, just make the add and get methods template methods and specialize </p> <pre><code>template&lt;class T&gt; void add(T *ptr){ } </code></pre> <p>and for each resource type</p> <pre><code>template&lt;&gt; ResourceManager&lt;Texture&gt;::add(Texture *ptr){ return addTexture(ptr); } template&lt;&gt; ResourceManager&lt;Shader&gt;::add(Shader *ptr){ return addShader(ptr); } template&lt;&gt; ResourceManager&lt;Mesh&gt;::add(Mesh *ptr){ return addMesh(ptr); } </code></pre> <p>Another cleaner option would be to make a template method which would return the target container </p> <pre><code>template&lt;typename T&gt; std::map&lt;std::string, std::auto_ptr&lt;typename T&gt; &gt; &amp;getContainer(){ } </code></pre> <p>Specialize it to return the good container given the type</p> <pre><code>template&lt;&gt; std::map&lt;std::string, std::auto_ptr&lt;Mesh&gt; &gt; &amp;ResourceManager::getContainer&lt;Mesh&gt;(){ return meshes_map; } template&lt;&gt; std::map&lt;std::string, std::auto_ptr&lt;Texture&gt; &gt; &amp;ResourceManager::getContainer&lt;Texture&gt;(){ return textures_map; } template&lt;&gt; std::map&lt;std::string, std::auto_ptr&lt;Shader&gt; &gt; &amp;ResourceManager::getContainer&lt;Shader&gt;(){ return shader_map; } </code></pre> <p>This would boil down the get method for example to something like:</p> <pre><code> template&lt;typename T&gt; T* get(const std::string &amp;name){ return getContainer&lt;T&gt;().get(name); } </code></pre> <p>Disclaimer: that is just a quickie, i did'nt compiled it.Ask if you have more questions</p> <p>Edit concerning your compilation error: You call <code>resourceManager.release&lt;Shader&gt;(sh);</code> For the picture, replace E with Shader in the release method and you'll see that it cannot compile . release(textures, ptr) For your release method to compile you have to cast explicitely ie:</p> <pre><code>template&lt;class E&gt; inline void release(E *ptr) { if(typeid(E) == typeid(Shader)) { release&lt;shaders_map, Shader&gt;(shaders, (Shader*)((void*)ptr)); return; } else if(typeid(E) == typeid(Mesh)) { release&lt;meshes_map, Mesh&gt;(meshes, (Mesh*)((void*)ptr)); return; } else if(typeid(E) == typeid(Texture)) { release&lt;textures_map, Texture&gt;(textures, (Texture*)((void*)ptr)); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload