coeng

view src/comp.cc @ 4:49a2e70ac455

foo
author John Tsiombikas <nuclear@member.fsf.org>
date Tue, 10 Feb 2015 17:21:30 +0200
parents 66d1762eb203
children 2f872a179914
line source
1 #include <stdio.h>
2 #include <map>
3 #include <string>
4 #include "comp.h"
6 static std::map<std::string, Component *(*)()> *early_comp_cons;
7 static std::map<std::string, Component *(*)()> comp_cons;
9 Component::Component()
10 {
11 name = "unknown";
12 gobj = 0;
13 upd_prio = 0;
14 }
16 Component::~Component()
17 {
18 }
20 const char *Component::get_name() const
21 {
22 return name;
23 }
25 void Component::update()
26 {
27 }
29 bool Component::operator <(const Component &c) const
30 {
31 return upd_prio < c.upd_prio;
32 }
35 void register_component(const char *name, Component *(*cons_func)())
36 {
37 if(!early_comp_cons) {
38 early_comp_cons = new std::map<std::string, Component *(*)()>;
39 }
41 if(!(*early_comp_cons)[name]) {
42 printf("register component: %s\n", name);
43 (*early_comp_cons)[name] = cons_func;
44 }
45 }
47 Component *create_component(const char *name)
48 {
49 if(early_comp_cons) {
50 comp_cons = std::move(*early_comp_cons);
51 delete early_comp_cons;
52 early_comp_cons = 0;
53 }
55 Component *(*cons)() = comp_cons[name];
56 if(cons) {
57 return cons();
58 }
59 return 0;
60 }