CMS 3D CMS Logo

DDXMLElementRegistry Class Reference

This is a base class for Registering DDXMLElements. More...

#include <DetectorDescription/Parser/src/DDXMLElementRegistry.h>

Inheritance diagram for DDXMLElementRegistry:

DDLElementRegistry

List of all members.

Public Types

typedef std::map< std::string,
DDXMLElement * > 
RegistryMap

Public Member Functions

DDXMLElementgetElement (const std::string &name)
 THE most important part. Getting the pointer to a given element type.
std::string getElementName (DDXMLElement *theElement)
 Get the name given a pointer. This may not be needed...
void registerElement (const std::string &name, DDXMLElement *)
 This allows other Elements to register themselves with the static registry.
void stream (std::ostream &os) const
virtual ~DDXMLElementRegistry ()
 Destructor.

Protected Member Functions

 DDXMLElementRegistry ()
 Private constructor for singleton.

Private Attributes

RegistryMap registry_

Friends

std::ostream & operator<< (std::ostream &os, const DDXMLElementRegistry &element)


Detailed Description

This is a base class for Registering DDXMLElements.

DDXMLElementRegistry.h - description ------------------- begin: Wed Mar 27 2002 email: case@ucdhep.ucdavis.edu

This class is registry of DDXMLElements. It is used wherever you want to register and retrieve DDXMLElements so that using getElement you can get a pointer to a DDXMLElement based on the name of the XML Element.

Definition at line 29 of file DDXMLElementRegistry.h.


Member Typedef Documentation

typedef std::map<std::string, DDXMLElement*> DDXMLElementRegistry::RegistryMap

Definition at line 36 of file DDXMLElementRegistry.h.


Constructor & Destructor Documentation

DDXMLElementRegistry::~DDXMLElementRegistry (  )  [virtual]

Destructor.

Definition at line 39 of file DDXMLElementRegistry.cc.

References find(), it, and registry_.

00040 {
00041   // Complicated cleanup.  I keep track of DDXMLElements that have
00042   // already been deleted using this vector.  Then delete them one-by-one.
00043   std::vector<DDXMLElement*> toDelete;
00044   for ( RegistryMap::const_iterator it = registry_.begin(); it != registry_.end(); ++it) {
00045     std::vector<DDXMLElement*>::const_iterator deleteIt = std::find(toDelete.begin(), toDelete.end(), it->second);
00046     if ( deleteIt == toDelete.end() ) {
00047       toDelete.push_back(it->second);
00048       delete it->second;
00049     }
00050   }
00051 }

DDXMLElementRegistry::DDXMLElementRegistry (  )  [protected]

Private constructor for singleton.

Definition at line 34 of file DDXMLElementRegistry.cc.

00035 {
00036   //  registry_ = new RegistryMap;
00037 }


Member Function Documentation

DDXMLElement * DDXMLElementRegistry::getElement ( const std::string &  name  ) 

THE most important part. Getting the pointer to a given element type.

If this is called with a DDXMLElementRegistry pointer, it will simply return a pointer if already registered or NULL, no instantiating.

Reimplemented in DDLElementRegistry.

Definition at line 65 of file DDXMLElementRegistry.cc.

References DCOUT_V, lat::endl(), it, NULL, and registry_.

00066 {
00067   DCOUT_V('P',  "DDXMLElementRegistry::getElement " << name << std::endl);
00068   RegistryMap::iterator it = registry_.find(name);
00069   DDXMLElement* myret = NULL;
00070   if (it != registry_.end())
00071     myret = it->second;
00072   DCOUT_V('P',  "DDXMLElementRegistry::getElement " << name << std::endl);
00073   return myret;
00074 }

std::string DDXMLElementRegistry::getElementName ( DDXMLElement theElement  ) 

Get the name given a pointer. This may not be needed...

Definition at line 77 of file DDXMLElementRegistry.cc.

References it, and registry_.

00078 {
00079   std::string ret = "";
00080   for (RegistryMap::const_iterator it = registry_.begin(); it != registry_.end(); ++it)
00081     if (it->second == theElementBase)
00082       ret = it->first;
00083   return ret;
00084 }

void DDXMLElementRegistry::registerElement ( const std::string &  name,
DDXMLElement element 
)

This allows other Elements to register themselves with the static registry.

Definition at line 58 of file DDXMLElementRegistry.cc.

References DCOUT_V, and registry_.

Referenced by DDLElementRegistry::getElement(), and DDLElementRegistry::instance().

00059 {
00060   DCOUT_V('P',"DDXMLElementRegistry::registerElementBase: "  << name << " at " << element);
00061   registry_[name] = element;
00062 }

void DDXMLElementRegistry::stream ( std::ostream &  os  )  const

Definition at line 92 of file DDXMLElementRegistry.cc.

References lat::endl(), it, and registry_.

Referenced by operator<<().

00093 {
00094   os << "Output of current Element Registry:" << std::endl;
00095   for (RegistryMap::const_iterator it=registry_.begin(); it != registry_.end(); ++it)
00096     os << it->first <<  " at address " << it->second << std::endl;
00097 }                        


Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  os,
const DDXMLElementRegistry element 
) [friend]

Definition at line 86 of file DDXMLElementRegistry.cc.

00087 {
00088   element.stream(os);
00089   return os;
00090 }


Member Data Documentation

RegistryMap DDXMLElementRegistry::registry_ [private]

Definition at line 69 of file DDXMLElementRegistry.h.

Referenced by getElement(), getElementName(), registerElement(), stream(), and ~DDXMLElementRegistry().


The documentation for this class was generated from the following files:
Generated on Tue Jun 9 18:18:21 2009 for CMSSW by  doxygen 1.5.4