Pioneer
NodeCopyCache.h
Go to the documentation of this file.
1 // Copyright © 2008-2023 Pioneer Developers. See AUTHORS.txt for details
2 // Licensed under the terms of the GPL v3. See licenses/GPL-3.txt
3 
4 #ifndef SCENEGRAPH_NODECOPYCACHE_H
5 #define SCENEGRAPH_NODECOPYCACHE_H
6 
7 #include "RefCounted.h"
8 #include <map>
9 
10 namespace SceneGraph {
11 
12  class Node;
13 
14  class NodeCopyCache {
15  public:
16  template <typename T>
17  T *Copy(const T *origNode)
18  {
19  const bool doCache = origNode->GetRefCount() > 1;
20  if (doCache) {
21  std::map<const Node *, Node *>::const_iterator i = m_cache.find(origNode);
22  if (i != m_cache.end())
23  return static_cast<T *>((*i).second);
24  }
25  T *newNode = new T(*origNode, this);
26  if (doCache)
27  m_cache.insert(std::make_pair(origNode, newNode));
28  return newNode;
29  }
30 
31  private:
32  std::map<const Node *, Node *> m_cache;
33  };
34 
35 } // namespace SceneGraph
36 
37 #endif
Definition: NodeCopyCache.h:14
T * Copy(const T *origNode)
Definition: NodeCopyCache.h:17
Definition: CityOnPlanet.h:31