summaryrefslogtreecommitdiffabout
path: root/lib/sitespace.cc
blob: 0406d11d95a558ae22f4ad1707734f39372722b4 (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
#ifdef USE_PCH
 #include "pch.h"
#else
 #include <cassert>
 #include "sitecing/sitespace.h"
 #include "sitecing/sitecing_util.h"
#endif

namespace sitecing {

    sitespace::sitespace(configuration& c)
	: config(c), factory(c) { }

    sitespace::~sitespace() {
	for(sentenced_t::iterator i = sentenced.begin();i!=sentenced.end();++i) {
	    assert((*i)->chickens_used.empty());
	    delete *i;
	}
    }

    so_component sitespace::fetch(const string& c,sitecing_interface* scif) {
	execute_sentenced();
	string sobase = normalize_path(c);
	string sopath = factory.root_so+sobase+".so";
	config_options *co_build = config.lookup_config(sobase,config_options::flag_build);
	if( (!co_build) || co_build->build )
	    factory.make(sopath);
	components_t::iterator i = components.find(sopath);
	if(i!=components.end()) {
	    if(i->second->is_uptodate())
		return so_component(i->second,scif);
	    if(i->second->chickens_used.empty()) {
		delete i->second;
	    }else{
		sentenced.push_back(i->second);
	    }
	    components.erase(i);
	}
	pair<components_t::iterator,bool> ins = components.insert(components_t::value_type(sopath,new component_so(sopath)));
	return so_component(ins.first->second,scif);
    }

    void sitespace::execute_sentenced() {
	for(sentenced_t::iterator i = sentenced.begin();i!=sentenced.end();++i) {
	    if((*i)->chickens_used.empty()) {
		delete *i;
		sentenced.erase(i);
	    }
	}
    }

}