coeng

diff src/comp.cc @ 4:49a2e70ac455

foo
author John Tsiombikas <nuclear@member.fsf.org>
date Tue, 10 Feb 2015 17:21:30 +0200 (2015-02-10)
parents 66d1762eb203
children 2f872a179914
line diff
     1.1 --- a/src/comp.cc	Thu Feb 05 23:20:20 2015 +0200
     1.2 +++ b/src/comp.cc	Tue Feb 10 17:21:30 2015 +0200
     1.3 @@ -1,7 +1,9 @@
     1.4 +#include <stdio.h>
     1.5  #include <map>
     1.6  #include <string>
     1.7  #include "comp.h"
     1.8  
     1.9 +static std::map<std::string, Component *(*)()> *early_comp_cons;
    1.10  static std::map<std::string, Component *(*)()> comp_cons;
    1.11  
    1.12  Component::Component()
    1.13 @@ -32,14 +34,24 @@
    1.14  
    1.15  void register_component(const char *name, Component *(*cons_func)())
    1.16  {
    1.17 -	if(!comp_cons[name]) {
    1.18 +	if(!early_comp_cons) {
    1.19 +		early_comp_cons = new std::map<std::string, Component *(*)()>;
    1.20 +	}
    1.21 +
    1.22 +	if(!(*early_comp_cons)[name]) {
    1.23  		printf("register component: %s\n", name);
    1.24 -		comp_cons[name] = cons_func;
    1.25 +		(*early_comp_cons)[name] = cons_func;
    1.26  	}
    1.27  }
    1.28  
    1.29  Component *create_component(const char *name)
    1.30  {
    1.31 +	if(early_comp_cons) {
    1.32 +		comp_cons = std::move(*early_comp_cons);
    1.33 +		delete early_comp_cons;
    1.34 +		early_comp_cons = 0;
    1.35 +	}
    1.36 +
    1.37  	Component *(*cons)() = comp_cons[name];
    1.38  	if(cons) {
    1.39  		return cons();