coeng
changeset 4:49a2e70ac455
foo
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Tue, 10 Feb 2015 17:21:30 +0200 |
parents | 66d1762eb203 |
children | 0e5da17d589c |
files | Makefile src/comp.cc |
diffstat | 2 files changed, 16 insertions(+), 4 deletions(-) [+] |
line diff
1.1 --- a/Makefile Thu Feb 05 23:20:20 2015 +0200 1.2 +++ b/Makefile Tue Feb 10 17:21:30 2015 +0200 1.3 @@ -5,8 +5,8 @@ 1.4 warn = -pedantic -Wall 1.5 dbg = -g 1.6 1.7 -CXXFLAGS = $(warn) $(dbg) 1.8 -LDFLAGS = $(libgl) -lm -lvmath 1.9 +CXXFLAGS = -std=c++11 $(warn) $(dbg) 1.10 +LDFLAGS = $(libgl) -lm -lvmath -lpthread 1.11 1.12 ifeq ($(shell uname -s), Darwin) 1.13 libgl = -framework OpenGL -framework GLUT -lGLEW
2.1 --- a/src/comp.cc Thu Feb 05 23:20:20 2015 +0200 2.2 +++ b/src/comp.cc Tue Feb 10 17:21:30 2015 +0200 2.3 @@ -1,7 +1,9 @@ 2.4 +#include <stdio.h> 2.5 #include <map> 2.6 #include <string> 2.7 #include "comp.h" 2.8 2.9 +static std::map<std::string, Component *(*)()> *early_comp_cons; 2.10 static std::map<std::string, Component *(*)()> comp_cons; 2.11 2.12 Component::Component() 2.13 @@ -32,14 +34,24 @@ 2.14 2.15 void register_component(const char *name, Component *(*cons_func)()) 2.16 { 2.17 - if(!comp_cons[name]) { 2.18 + if(!early_comp_cons) { 2.19 + early_comp_cons = new std::map<std::string, Component *(*)()>; 2.20 + } 2.21 + 2.22 + if(!(*early_comp_cons)[name]) { 2.23 printf("register component: %s\n", name); 2.24 - comp_cons[name] = cons_func; 2.25 + (*early_comp_cons)[name] = cons_func; 2.26 } 2.27 } 2.28 2.29 Component *create_component(const char *name) 2.30 { 2.31 + if(early_comp_cons) { 2.32 + comp_cons = std::move(*early_comp_cons); 2.33 + delete early_comp_cons; 2.34 + early_comp_cons = 0; 2.35 + } 2.36 + 2.37 Component *(*cons)() = comp_cons[name]; 2.38 if(cons) { 2.39 return cons();