// DatasetCreator.cxx #include "dataset_base/DatasetCreator.h" #include #include #include #include #include #include "dataset_util/XmlElement.h" #include "dataset_id/EventIdList.h" #include "dataset_id/ContentIdList.h" #include "dataset_id/DatasetIdList.h" #include "dataset_base/Dataset.h" using std::string; using std::ostream; using std::map; using std::vector; using std::find; using std::endl; using dset::Dataset; using dset::DatasetCreator; //********************************************************************** // Local definitions. //********************************************************************** typedef DatasetCreator::FunPtr FunPtr; typedef map FunMap; typedef vector DtdList; namespace { // Map of functions indexed by XML name. FunMap& funs() { static FunMap fmap; return fmap; } } // end unnamed namespace //********************************************************************** // Static member functions. //********************************************************************** int DatasetCreator::insert(string cname, FunPtr pfun) { if ( pfun == 0 ) return -1; string name(cname); FunMap::const_iterator ifun = funs().find(name); if ( ifun != funs().end() ) { assert( ifun->first == name ); if ( ifun->second == pfun ) { return 0; } else { return 1; } } funs()[name] = pfun; return 0; } //********************************************************************** // Create a dataset. const Dataset* DatasetCreator::create(const XmlElement& ele, DatasetRepository* prep) { string ftype = ele.attribute("fulltype"); FunMap::const_iterator ifun = funs().find(ftype); if ( ifun == funs().end() ) { ifun = funs().find(ele.name()); if ( ifun == funs().end() ) { return 0; } } return ifun->second(ele, prep); } //********************************************************************** // Return registered names. DatasetCreator::NameList DatasetCreator::names() { NameList names; for ( FunMap::const_iterator ifun=funs().begin(); ifun!=funs().end(); ++ifun ) { names.push_back(ifun->first); } return names; } //********************************************************************** // Return if a name is registered. bool DatasetCreator::has(string name) { FunMap::const_iterator ifun = funs().find(name); return ifun != funs().end(); } //********************************************************************** // Display registered classes. void DatasetCreator::display(ostream& lhs) { FunMap::size_type nreg = funs().size(); lhs << "DatasetCreator has " << nreg << " registration"; if ( nreg != 1 ) lhs << "s"; if ( nreg != 0 ) lhs << ":"; for ( FunMap::const_iterator ifun=funs().begin(); ifun!=funs().end(); ++ifun ) { lhs << "\n "; lhs << ifun->first; } } //**********************************************************************