void Factory::registerType(const std::string& tag, AbstractHyperGraphElementCreator* c) { CreatorMap::const_iterator foundIt = _creator.find(tag); if (foundIt != _creator.end()) { cerr << "FACTORY WARNING: Overwriting Vertex tag " << tag << endl; assert(0); } TagLookup::const_iterator tagIt = _tagLookup.find(c->name()); if (tagIt != _tagLookup.end()) { cerr << "FACTORY WARNING: Registering same class for two tags " << c->name() << endl; assert(0); } CreatorInformation ci; ci.creator = c; #ifdef DEBUG_FACTORY cerr << "# Factory " << (void*)this << " constructing type " << tag << " "; #endif // construct an element once to figur out its type HyperGraph::HyperGraphElement* element = c->construct(); ci.elementTypeBit = element->elementType(); #ifdef DEBUG_FACTORY cerr << "done." << endl; cerr << "# Factory " << (void*)this << " registering " << tag; cerr << " " << (void*) c << " "; switch (element->elementType()) { case HyperGraph::HGET_VERTEX: cerr << " -> Vertex"; break; case HyperGraph::HGET_EDGE: cerr << " -> Edge"; break; case HyperGraph::HGET_PARAMETER: cerr << " -> Parameter"; break; case HyperGraph::HGET_CACHE: cerr << " -> Cache"; break; case HyperGraph::HGET_DATA: cerr << " -> Data"; break; default: assert(0 && "Unknown element type occured, fix elementTypes"); break; } cerr << endl; #endif _creator[tag] = ci; _tagLookup[c->name()] = tag; delete element; }
bool ParameterContainer::read(std::istream& is, const std::map<std::string, std::string>* _renamedTypesLookup){ stringstream currentLine; string token; Factory* factory = Factory::instance(); HyperGraph::GraphElemBitset elemBitset; elemBitset[HyperGraph::HGET_PARAMETER] = 1; while (1) { int bytesRead = readLine(is, currentLine); if (bytesRead == -1) break; currentLine >> token; if (bytesRead == 0 || token.size() == 0 || token[0] == '#') continue; if (_renamedTypesLookup && _renamedTypesLookup->size()>0){ map<string, string>::const_iterator foundIt = _renamedTypesLookup->find(token); if (foundIt != _renamedTypesLookup->end()) { token = foundIt->second; } } HyperGraph::HyperGraphElement* element = factory->construct(token, elemBitset); if (! element) // not a parameter or otherwise unknown tag continue; assert(element->elementType() == HyperGraph::HGET_PARAMETER && "Should be a param"); Parameter* p = static_cast<Parameter*>(element); int pid; currentLine >> pid; p->setId(pid); bool r = p->read(currentLine); if (! r) { cerr << __PRETTY_FUNCTION__ << ": Error reading data " << token << " for parameter " << pid << endl; delete p; } else { if (! addParameter(p) ){ cerr << __PRETTY_FUNCTION__ << ": Parameter of type:" << token << " id:" << pid << " already defined" << endl; } } } // while read line return true; }