00001
00002
00003 #include "xmlUtil/id/DictFieldMan.h"
00004 #include "xmlUtil/id/DictField.h"
00005 #include <utility>
00006 #include <algorithm>
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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);
00029 #else
00030 m_reg = new Registry();
00031 #endif
00032 }
00033
00034 DictFieldMan::~DictFieldMan() {
00035
00036
00037
00038
00039 for (RegIterator it = m_reg->begin(); it != m_reg->end(); ++it) {
00040 delete it->second;
00041 }
00042 m_reg->clear();
00043
00044
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
00054
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
00063 }
00064
00065 bool DictFieldMan::accept(DictVisitor *vis) {
00066
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 }