// GsiAuthorizer.cxx #include "dial_gsi/GsiAuthorizer.h" #include "dataset_util/XmlElement.h" #include #include using std::string; using std::cout; using std::endl; using std::ostream; using dial::GsiAuthorizer; typedef GsiAuthorizer::Creator Creator; typedef GsiAuthorizer::CreatorList CreatorList; typedef std::map CreatorMap; //********************************************************************** // Local definitions. //********************************************************************** namespace { // Map of functions indexed by XML name. CreatorMap& creator_map() { static CreatorMap cmap; return cmap; } // List of known creators. CreatorList& creator_list() { static CreatorList clist; return clist; } } // end unnamed namespace //********************************************************************** // Static member functions. //********************************************************************** // Create a gsiauthorizer. GsiAuthorizer* GsiAuthorizer::create(const XmlElement& ele) { CreatorMap& cres = creator_map(); CreatorMap::const_iterator icre = cres.find(ele.name()); if ( icre == cres.end() ) { return 0; } Creator cre = icre->second; GsiAuthorizer* pgsi = cre(ele); return pgsi; } //********************************************************************** // Register a creator. int GsiAuthorizer::register_creator(std::string name, Creator pfun) { CreatorMap& cres = creator_map(); CreatorMap::const_iterator icre = cres.find(name); if ( icre != cres.end() ) { if ( icre->second == pfun ) return 0; return 1; } if ( pfun == 0 ) return 2; cres[name] = pfun; creator_list().push_back(name); return 0; } //********************************************************************** // Return the known creators. const CreatorList& GsiAuthorizer::creators() { return creator_list(); } //********************************************************************** // Return if a creator is registered. bool GsiAuthorizer::has_creator(std::string name) { CreatorMap& cres = creator_map(); CreatorMap::const_iterator icre = cres.find(name); return icre != cres.end(); } //********************************************************************** // Member functions. //********************************************************************** // Destructor GsiAuthorizer::~GsiAuthorizer() { } //********************************************************************** // Free functions. //********************************************************************** // Output stream ostream& operator<<(ostream &lhs, const GsiAuthorizer& rhs) { return rhs.ostr(lhs); }