15 |
#include "object-registry.hpp" |
#include "object-registry.hpp" |
16 |
#include <map> |
#include <map> |
17 |
#include <string> |
#include <string> |
18 |
|
#include "log.hpp" |
19 |
namespace usata |
namespace usata |
20 |
{ |
{ |
21 |
std::auto_ptr<ObjectRegistry> ObjectRegistry::mInstance; |
|
22 |
|
ObjectRegistry *ObjectRegistry::Instance=0; |
23 |
|
|
24 |
|
ObjectRegistry::StaticKilla die; |
25 |
|
|
26 |
/** |
/** |
27 |
\ingroup impl |
\ingroup impl |
33 |
typedef std::map<std::string, BIOCF> BuiltinMap; |
typedef std::map<std::string, BIOCF> BuiltinMap; |
34 |
BuiltinMap builtins; |
BuiltinMap builtins; |
35 |
void add_builtin(const std::string&, BIOCF); |
void add_builtin(const std::string&, BIOCF); |
36 |
|
BIOCF lookup(const std::string& name) |
37 |
|
{ |
38 |
|
BIOCF retval = 0; |
39 |
|
BuiltinMap::iterator it = builtins.find(name); |
40 |
|
if (it != builtins.end()) |
41 |
|
{ |
42 |
|
retval = it->second; |
43 |
|
} |
44 |
|
return retval; |
45 |
|
} |
46 |
}; |
}; |
47 |
|
|
48 |
void |
void |
55 |
it->second = creation_func; |
it->second = creation_func; |
56 |
return; |
return; |
57 |
} |
} |
58 |
builtins.insert(std::make_pair(name,creation_func)); |
builtins.insert(BuiltinMap::value_type(name,creation_func)); |
59 |
return; |
return; |
60 |
} |
} |
61 |
|
|
62 |
|
void |
63 |
|
ObjectRegistry::die() |
64 |
|
{ |
65 |
|
if (Instance) |
66 |
|
delete Instance; |
67 |
|
Instance=0; |
68 |
|
} |
69 |
|
|
70 |
|
ObjectRegistry |
71 |
|
:: ~ObjectRegistry()throw() |
72 |
|
{ |
73 |
|
log::BufferedStream L(log::Level::DEBUG); |
74 |
|
L << "~ObjectRegistry" << log::commit; |
75 |
|
} |
76 |
|
|
77 |
ObjectRegistry* |
ObjectRegistry* |
78 |
ObjectRegistry::instance() |
ObjectRegistry::instance() |
79 |
{ |
{ |
80 |
if (mInstance.get()==0) |
if (!Instance) |
81 |
{ |
{ |
82 |
mInstance.reset(new ObjectRegistry); |
Instance = new ObjectRegistry; |
83 |
} |
} |
84 |
return mInstance.get(); |
return Instance; |
85 |
} |
} |
86 |
|
|
87 |
ObjectRegistry::ObjectRegistry() |
ObjectRegistry::ObjectRegistry() |
101 |
mImpl->add_builtin(name,func); |
mImpl->add_builtin(name,func); |
102 |
return; |
return; |
103 |
} |
} |
104 |
|
|
105 |
|
|
106 |
|
Object * |
107 |
|
ObjectRegistry::create(const std::string& name) |
108 |
|
{ |
109 |
|
BIOCF f = mImpl->lookup(name); |
110 |
|
|
111 |
|
if (f!=0) |
112 |
|
{ |
113 |
|
return f(); |
114 |
|
} |
115 |
|
|
116 |
|
return 0; |
117 |
|
} |
118 |
} |
} |
119 |
|
|