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

IdDict.cxx

Go to the documentation of this file.
00001 // $Header: /nfs/slac/g/glast/ground/cvs/xmlUtil/src/id/IdDict.cxx,v 1.10 2002/04/05 18:26:44 jrb Exp $
00002 
00003 #include <dom/DOMString.hpp>
00004 #include <dom/DOM_NodeList.hpp>
00005 #include "xml/Dom.h"
00006 #include "xmlUtil/id/IdDict.h"
00007 #include "xmlUtil/id/DictFieldMan.h"
00008 #include "xmlUtil/id/DictField.h"
00009 #include "xmlUtil/id/DictNode.h"
00010 #include "xmlUtil/id/DictValidVisitor.h"
00011 #include <assert.h>
00012 namespace xmlUtil {
00013   IdDict::IdDict(DOM_Element elt)  {
00014     // Check that element has the right tag name: idDict
00015     // Caller probably will have done this already
00016     assert(elt.getTagName().equals("idDict"));
00017 
00018     // Store information from attributes
00019     m_name = std::string(xml::Dom::getAttribute(elt, "name"));
00020 
00021     std::string intVal = xml::Dom::getAttribute(elt, "major");
00022     m_major = atoi(intVal.c_str());
00023 
00024     intVal = xml::Dom::getAttribute(elt, "minor");
00025     m_minor = atoi(intVal.c_str());
00026 
00027     intVal = xml::Dom::getAttribute(elt, "patch");
00028     m_patch = atoi(intVal.c_str());
00029 
00030     // Check number of children.  This is an upper bound
00031     // on number of fields we have to store
00032     int size = (elt.getChildNodes()).getLength();
00033     m_fieldMan = new DictFieldMan(size);
00034                 
00035     DOM_Element fieldElt = xml::Dom::getFirstChildElement(elt);
00036 
00037     // Register all the fields
00038     while ((fieldElt.getNodeName()).equals("field")) {
00039       //      DOM_Element fieldElt = static_cast<DOM_Element&>(fieldNode);
00040       DictField* field = new DictField(fieldElt);
00041       m_fieldMan->signup(field);
00042       fieldElt = xml::Dom::getSiblingElement(fieldElt);
00043     }
00044     // Finally make the hierarchy of constraints on Identifiers
00045     m_root = new DictNode(fieldElt, 0, m_fieldMan);
00046   }
00047 
00048   IdDict::~IdDict() {
00049     /* First get rid of hierarchy of nodes, then get rid of
00050        our DictFieldMan object. The latter will delete all the
00051        fields
00052     */
00053     delete m_root;
00054     delete m_fieldMan;
00055   }
00056 
00057   bool IdDict::accept(DictVisitor *vis) {
00058     return accept(vis, 0xffffffff);
00059   }
00060 
00061 
00062   bool IdDict::accept(DictVisitor *vis, unsigned mask) {
00063     bool status = true;
00064 
00065     if (!vis->visitDict(this)) return false;
00066 
00067     if (mask & nodeHierarchy) 
00068       status = m_root->accept(vis);
00069 
00070     if (status && (mask & fieldManager)) {
00071       status &= m_fieldMan->accept(vis);
00072     }
00073     return status;
00074   }
00075 
00076 
00077   bool IdDict::isValid()  {
00078     DictValidVisitor visitor;
00079 
00080     accept(&visitor);
00081     return visitor.wasValid();
00082   }
00083 
00084   bool IdDict::idOk(const Identifier& id) const {
00085     return m_root->allowIdentifier(id);
00086   }
00087 
00088   bool IdDict::idOk(const NamedId& id) const {
00089     return m_root->allowNamedId(id);
00090   }
00091 
00092   bool IdDict::nameSeqOk(const NameSeq& seq) const {
00093     return m_root->allowNameSeq(seq);
00094   }
00095 
00096   // all the work is in DictNode::allowIdentifier(const Identifier&, NamedId*)
00097   NamedId *  IdDict::getNamedId(const Identifier& id) const {
00098     NamedId *named = new NamedId;
00099     m_root->allowIdentifier(id, named);
00100     return named;
00101   }
00102 
00103   bool IdDict::addChild(DictNode* parent, DictNode* newNode) {
00104     /* Started to write something to add field if not already
00105        registered, but whoever has created newNode should
00106        already have done this */
00107     return parent->addChild(newNode);
00108   }
00109 
00110 
00111 }

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