38 #ifndef H_OGF_BASIC_TYPES_BASIC_FACTORY_H
39 #define H_OGF_BASIC_TYPES_BASIC_FACTORY_H
57 virtual BASE* create() = 0 ;
60 template <
class BASE,
class T>
63 virtual BASE* create() {
return new T() ; }
68 typedef std::map<std::string, SmartPointer<BasicFactory<T> > > FactoriesMap ;
71 ogf_assert(map_.find(name) == map_.end()) ;
74 void unregister_factory(
const std::string& name) {
75 auto it = map_.find(name) ;
76 ogf_assert(it != map_.end()) ;
79 bool factory_is_bound(
const std::string& name)
const {
80 return(map_.find(name) != map_.end()) ;
82 void list_factory_names(std::vector<std::string>& names)
const {
84 for(
auto& it : map_) {
85 names.push_back(it.first) ;
88 std::string factory_names()
const {
89 std::string result =
"";
90 for(
auto& it : map_) {
91 if(result.length() != 0) {
98 T* create(
const std::string& name) {
99 auto it = map_.find(name) ;
100 ogf_assert(it != map_.end()) ;
101 return it->second->create() ;
111 virtual BASE* create(ARG x) = 0 ;
114 template <
class BASE,
class T,
class ARG>
117 virtual BASE* create(ARG x) {
return new T(x) ; }
122 typedef std::map<std::string, SmartPointer<BasicFactoryWithArg<T,ARG> > > FactoriesMap ;
125 ogf_assert(map_.find(name) == map_.end()) ;
128 void unregister_factory(
const std::string& name) {
129 auto it = map_.find(name) ;
130 ogf_assert(it != map_.end()) ;
133 bool factory_is_bound(
const std::string& name)
const {
134 return(map_.find(name) != map_.end()) ;
136 void list_factory_names(std::vector<std::string>& names)
const {
138 for(
auto& it : map_) {
139 names.push_back(it.first) ;
142 std::string factory_names()
const {
143 std::string result =
"";
144 for(
auto& it : map_) {
145 if(result.length() != 0) {
152 T* create(
const std::string& name, ARG x) {
153 auto it = map_.find(name) ;
154 ogf_assert(it != map_.end()) ;
155 return it->second->create(x) ;
Base class for reference-counted objects.
Global Graphite namespace.
Definitions common to all include files in the basic library.