49#ifdef G2O_DEBUG_FACTORY
59 const std::string& tag,
60 const std::shared_ptr<AbstractHyperGraphElementCreator>& c) {
61 CreatorMap::const_iterator foundIt =
_creator.find(
tag);
63 G2O_WARN(
"Factory: Overwriting Vertex tag {}",
tag);
66 TagLookup::const_iterator tagIt =
_tagLookup.find(c->name());
68 G2O_WARN(
"factory: Registering same class for two tags {}", c->name());
75#ifdef G2O_DEBUG_FACTORY
76 G2O_DEBUG(
"Factory {} constructing type {}",
static_cast<void*
>(
this),
tag);
82#ifdef G2O_DEBUG_FACTORY
84 G2O_DEBUG(
"Factory {} registering {}",
static_cast<void*
>(
this),
tag);
87 case HyperGraph::HGET_VERTEX:
90 case HyperGraph::HGET_EDGE:
93 case HyperGraph::HGET_PARAMETER:
96 case HyperGraph::HGET_CACHE:
99 case HyperGraph::HGET_DATA:
103 assert(0 &&
"Unknown element type occurred, fix elementTypes");
108 _creator[
tag] = std::unique_ptr<CreatorInformation>(ci);
115 CreatorMap::iterator tagPosition =
_creator.find(
tag);
117 if (tagPosition !=
_creator.end()) {
118 const auto& c = tagPosition->second->creator;
121 TagLookup::iterator classPosition =
_tagLookup.find(c->name());
130 const std::string& tag)
const {
131 CreatorMap::const_iterator foundIt =
_creator.find(
tag);
133 return foundIt->second->creator->construct();
139 static std::string emptyStr(
"");
140 TagLookup::const_iterator foundIt =
_tagLookup.find(
typeid(*e).name());
141 if (foundIt !=
_tagLookup.end())
return foundIt->second;
147 for (CreatorMap::const_iterator it =
_creator.begin(); it !=
_creator.end();
149 types.push_back(it->first);
153 CreatorMap::const_iterator foundIt =
_creator.find(
tag);
155 if (elementType) *elementType = -1;
158 if (elementType) *elementType = foundIt->second->elementTypeBit;
163 std::unique_ptr<Factory> aux;
168 if (comment) os <<
"# ";
169 os <<
"types:" << endl;
170 for (CreatorMap::const_iterator it =
_creator.begin(); it !=
_creator.end();
172 if (comment) os <<
"#";
173 os <<
"\t" << it->first << endl;
178 const std::string& tag,
180 if (elemsToConstruct.none()) {
183 CreatorMap::const_iterator foundIt =
_creator.find(
tag);
184 if (foundIt !=
_creator.end() && foundIt->second->elementTypeBit >= 0 &&
185 elemsToConstruct.test(foundIt->second->elementTypeBit)) {
186 return foundIt->second->creator->construct();
create vertices and edges based on TAGs in, for example, a file
void unregisterType(const std::string &tag)
bool knowsTag(const std::string &tag, int *elementType=0) const
CreatorMap _creator
look-up map for the existing creators
void printRegisteredTypes(std::ostream &os, bool comment=false) const
static std::unique_ptr< Factory > factoryInstance
static Factory * instance()
return the instance
TagLookup _tagLookup
reverse look-up, class name to tag
HyperGraph::HyperGraphElement * construct(const std::string &tag) const
static void destroy()
free the instance
const std::string & tag(const HyperGraph::HyperGraphElement *v) const
return the TAG given a vertex
void fillKnownTypes(std::vector< std::string > &types) const
void registerType(const std::string &tag, const std::shared_ptr< AbstractHyperGraphElementCreator > &c)
std::bitset< HyperGraph::HGET_NUM_ELEMS > GraphElemBitset
virtual HyperGraphElementType elementType() const =0