Game Develop C++ Platform: ObjInstancesHolder.h Source File

| Game Develop C++ Platform Platform for developing native games based on OpenGL and SFML with Game Develop

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Groups Pages
ObjInstancesHolder.h
1 #ifndef OBJINSTANCESHOLDER_H
2 #define OBJINSTANCESHOLDER_H
3
4 #include <string>
5 #include <vector>
6 #include <map>
7 #include <boost/shared_ptr.hpp>
8 #include <boost/unordered_map.hpp>
9 class RuntimeObject;
10
11 typedef std::vector < boost::shared_ptr<RuntimeObject> > RuntimeObjList;
12 typedef boost::shared_ptr<RuntimeObject> RuntimeObjSPtr;
13
20 class GD_API ObjInstancesHolder
21 {
22 public:
23 ObjInstancesHolder() {};
24 virtual ~ObjInstancesHolder() {};
25
29 void AddObject(const RuntimeObjSPtr & object);
30
34 inline const RuntimeObjList & GetObjects(const std::string & name)
35 {
36 return objectsInstances[name];
37 }
41 std::vector<RuntimeObject*> GetObjectsRawPointers(const std::string & name);
42
46 inline RuntimeObjList GetAllObjects()
47 {
48 RuntimeObjList objList;
49
50 for (boost::unordered_map<std::string, RuntimeObjList>::iterator it = objectsInstances.begin() ; it != objectsInstances.end(); ++it )
51 copy(it->second.begin(), it->second.end(), back_inserter(objList));
52
53 return objList;
54 }
55
65 inline void RemoveObject(const RuntimeObjSPtr & object)
66 {
67 for (boost::unordered_map<std::string, RuntimeObjList>::iterator it = objectsInstances.begin() ; it != objectsInstances.end(); ++it )
68 {
69 RuntimeObjList & associatedList = it->second;
70 associatedList.erase(std::remove(associatedList.begin(), associatedList.end(), object), associatedList.end());
71 }
72 for (boost::unordered_map<std::string, std::vector<RuntimeObject*> >::iterator it = objectsRawPointersInstances.begin() ; it != objectsRawPointersInstances.end(); ++it )
73 {
74 std::vector<RuntimeObject*> & associatedList = it->second;
75 associatedList.erase(std::remove(associatedList.begin(), associatedList.end(), object.get()), associatedList.end());
76 }
77 }
78
82 inline void RemoveObjects(const std::string & name)
83 {
84 objectsInstances[name].clear();
85 objectsRawPointersInstances[name].clear();
86 }
87
91 void ObjectNameHasChanged(RuntimeObject * object);
92
97 ObjInstancesHolder CopyAndCloneAllObjects() const;
98
102 inline void Clear()
103 {
104 objectsInstances.clear();
105 objectsRawPointersInstances.clear();
106 }
107
108 private:
109
110 boost::unordered_map<std::string, RuntimeObjList > objectsInstances;
111 boost::unordered_map<std::string, std::vector<RuntimeObject*> > objectsRawPointersInstances;
112 };
113
114 #endif // OBJINSTANCESHOLDER_H
115