File: EntityBreakdown.h

package info (click to toggle)
darkradiant 3.9.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 41,080 kB
  • sloc: cpp: 264,743; ansic: 10,659; python: 1,852; xml: 1,650; sh: 92; makefile: 21
file content (76 lines) | stat: -rw-r--r-- 1,286 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#pragma once

#include <map>
#include <string>
#include "iscenegraph.h"
#include "ientity.h"
#include "ieclass.h"

namespace scene
{

/** greebo: This object traverses the scenegraph on construction
 * 			counting all occurrences of each entity class.
 */
class EntityBreakdown :
	public scene::NodeVisitor
{
public:
	typedef std::map<std::string, std::size_t> Map;

private:
	Map _map;

public:
	EntityBreakdown()
	{
		_map.clear();
		GlobalSceneGraph().root()->traverse(*this);
	}

	bool pre(const scene::INodePtr& node) override
	{
		// Is this node an entity?
		Entity* entity = Node_getEntity(node);

		if (entity != nullptr)
		{
			IEntityClassConstPtr eclass = entity->getEntityClass();
			std::string ecName = eclass->getDeclName();

			auto found = _map.find(ecName);

			if (found == _map.end())
			{
				// Entity class not yet registered, create new entry
				_map.emplace(ecName, 1);
			}
			else
			{
				// Eclass is known, increase the counter
				found->second++;
			}
		}

		return true;
	}

	// Accessor method to retrieve the entity breakdown map
	const Map& getMap() const
	{
		return _map;
	}

	Map::const_iterator begin() const
	{
		return _map.begin();
	}

	Map::const_iterator end() const
	{
		return _map.end();
	}

}; // class EntityBreakdown

} // namespace