blob: 202da6a0b40eba0451011556d87506dbe1335e67 (
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
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
 | #include <pch.hpp>
#include "transform.h"
#include "logger.h"
#include <boost/foreach.hpp>
class TransformTargetStorer : public Storer {
	public:
		TransformTargetStorer(TransformSource * ts) :
			transformSource(ts)
		{
		}
		boost::intrusive_ptr<IntrusivePtrBase> create(ScriptNodePtr p) const
		{
			return LoaderBase::getLoader<TransformTargetLoader, NotSupported>(p->get_name())->createFrom(p);
		}
		bool save(boost::intrusive_ptr<IntrusivePtrBase> o, ScriptNodePtr s)
		{
			TransformChainLinkPtr O = boost::dynamic_pointer_cast<TransformChainLink>(o);
			if (O) {
				transformSource->addTarget(O, s);
			}
			return O;
		}
	private:
		TransformSource * transformSource;
};
TransformSource::TransformSource()
{
}
TransformSource::TransformSource(ScriptNodePtr s)
{
	s->script->loader.addLoadTarget(s, new TransformTargetStorer(this));
}
TransformChainLink::~TransformChainLink()
{
}
typedef std::map<std::string, boost::shared_ptr<TransformLoader> > TransformLoaderMap;
void
TransformSource::addTarget(TransformChainLinkPtr tcl, ScriptNodePtr e)
{
	BOOST_FOREACH(const TransformLoaderMap::value_type & tl, *LoaderBase::objLoaders<TransformLoader>()) {
		TransformPtr t = tl.second->create();
		if (t->canTransform(this, tcl.get())) {
			if (e) {
				t->configure(e);
			}
			targets[tcl] = t;
			return;
		}
	}
	throw NotSupported("Couldn't find a suitable transformation");
}
void
TransformSource::doTransforms() const
{
	BOOST_FOREACH(const Targets::value_type & t, targets) {
		t.second->transform(this, t.first.get());
		if (const TransformSource * tr = dynamic_cast<const TransformSource *>(t.first.get())) {
			tr->doTransforms();
		}
	}
}
const Targets &
TransformSource::getTargets() const
{
	return targets;
}
 |