coeng

annotate 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
rev   line source
nuclear@4 1 #include <stdio.h>
nuclear@2 2 #include <map>
nuclear@2 3 #include <string>
nuclear@2 4 #include "comp.h"
nuclear@2 5
nuclear@4 6 static std::map<std::string, Component *(*)()> *early_comp_cons;
nuclear@2 7 static std::map<std::string, Component *(*)()> comp_cons;
nuclear@2 8
nuclear@2 9 Component::Component()
nuclear@2 10 {
nuclear@2 11 name = "unknown";
nuclear@2 12 gobj = 0;
nuclear@2 13 upd_prio = 0;
nuclear@2 14 }
nuclear@2 15
nuclear@2 16 Component::~Component()
nuclear@2 17 {
nuclear@2 18 }
nuclear@2 19
nuclear@2 20 const char *Component::get_name() const
nuclear@2 21 {
nuclear@2 22 return name;
nuclear@2 23 }
nuclear@2 24
nuclear@2 25 void Component::update()
nuclear@2 26 {
nuclear@2 27 }
nuclear@2 28
nuclear@2 29 bool Component::operator <(const Component &c) const
nuclear@2 30 {
nuclear@2 31 return upd_prio < c.upd_prio;
nuclear@2 32 }
nuclear@2 33
nuclear@2 34
nuclear@2 35 void register_component(const char *name, Component *(*cons_func)())
nuclear@2 36 {
nuclear@4 37 if(!early_comp_cons) {
nuclear@4 38 early_comp_cons = new std::map<std::string, Component *(*)()>;
nuclear@4 39 }
nuclear@4 40
nuclear@4 41 if(!(*early_comp_cons)[name]) {
nuclear@3 42 printf("register component: %s\n", name);
nuclear@4 43 (*early_comp_cons)[name] = cons_func;
nuclear@3 44 }
nuclear@2 45 }
nuclear@2 46
nuclear@2 47 Component *create_component(const char *name)
nuclear@2 48 {
nuclear@4 49 if(early_comp_cons) {
nuclear@4 50 comp_cons = std::move(*early_comp_cons);
nuclear@4 51 delete early_comp_cons;
nuclear@4 52 early_comp_cons = 0;
nuclear@4 53 }
nuclear@4 54
nuclear@2 55 Component *(*cons)() = comp_cons[name];
nuclear@2 56 if(cons) {
nuclear@2 57 return cons();
nuclear@2 58 }
nuclear@2 59 return 0;
nuclear@2 60 }