Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

DictFieldMan.cxx

Go to the documentation of this file.
00001 // $Header
00002 
00003 #include "xmlUtil/id/DictFieldMan.h"
00004 #include "xmlUtil/id/DictField.h"
00005 #include <utility> 
00006 #include <algorithm>
00007 
00008 
00009 // g++ has hash_map; Visual Studio doesn't
00010 //#ifdef __GNUG__
00011 //#  include <hash_map>
00012 //#  define Registry hash_map<const char *, DictField*, hash<const char *>, eqstr>
00013 // otherwise might not have hash_map available, so use map, which
00014 // is overkill for our situation since we don't need sorting
00015 //#else        
00016 //#  include <Map>
00017 //#  define Registry  map<const char *, DictField*>
00018 //#endif
00019 
00020 
00021 namespace xmlUtil {
00022   typedef std::pair<const char *, DictField*> RegPair;
00023 
00024   typedef Registry::iterator RegIterator;
00025 
00026   DictFieldMan::DictFieldMan(int size) {
00027 #ifdef __GNUG__
00028     m_reg = new Registry(size);   //, hash<const char *>)  , eqstr);
00029 #else
00030     m_reg = new Registry();
00031 #endif
00032   }
00033 
00034   DictFieldMan::~DictFieldMan() {
00035     // All other objects containing references to the fields 
00036     // (e.g., DictNodes) should have been deleted already.
00037 
00038     // Get rid of all fields...
00039     for (RegIterator it = m_reg->begin(); it != m_reg->end(); ++it) {
00040       delete it->second;
00041     }
00042     m_reg->clear();
00043     
00044       // then delete registry
00045     delete m_reg;
00046   }
00047   
00048   void DictFieldMan::signup(DictField *field)  {
00049     m_reg->insert(RegPair((field->getName()).c_str(), field));
00050   }
00051 
00052   const DictField* const DictFieldMan::find(const std::string& name) const {
00053     // find returns an iterator over the hash map, so a pointer
00054     // to a pair<std::string, DictField *>
00055     Registry::iterator  found;
00056     found = m_reg->find(name.c_str());
00057     if (found != m_reg->end() ) {
00058       return (*found).second;
00059     }
00060     else return 0;
00061       
00062       // *(reg->find(name));
00063   }
00064 
00065   bool DictFieldMan::accept(DictVisitor *vis) {
00066     // iterate through fields
00067     
00068     for (Registry::iterator it = m_reg->begin(); it != m_reg->end(); ++it) {
00069       bool ok = ( (it->second)->accept(vis) );
00070       if (!ok) return false;
00071     }
00072     return vis->visitFieldMan(this);
00073 
00074   }
00075 
00076 }   // end namespace

Generated on Wed Oct 16 14:02:47 2002 by doxygen1.2.13.1 written by Dimitri van Heesch, © 1997-2001