summaryrefslogtreecommitdiff
path: root/project2/common/sourceObject.cpp
blob: 09fe94e756bcbe36eb9abe5aa26d65710e0725b2 (plain)
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
#include <pch.hpp>
#include "sourceObject.h"
#include "exceptions.h"
#include "safeMapFind.h"
#include "scripts.h"

unsigned int SourceObject::loadOrder = 1;
SimpleMessageException(ComponentNotFound);

SourceObject::SourceObject(ScriptNodePtr p) :
	name(p ? p->value("name", "anon", NULL).as<std::string>() : "anon"),
	order(loadOrder++),
	script(p->script)
{
	script->namedComponents[name] = this;
}

SourceObject::SourceObject(const std::string & n) :
	name(n),
	order(loadOrder++),
	script(NULL)
{
}

void
SourceObject::loadComplete(const CommonObjects *)
{
}

void
SourceObject::send(int eventID) const
{
	for (Events::const_iterator i = events.lower_bound(eventID); i != events.upper_bound(eventID); i++) {
		i->second();
	}
}

void
SourceObject::registerFor(int eventID, const Event & event) const
{
	events.insert(Events::value_type(eventID, event));
}

SourceObject *
SourceObject::findComponent(const std::string & name) const
{
	return AdHoc::safeMapLookup<ComponentNotFound>(script->namedComponents, name);
}