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

DictNode.h

Go to the documentation of this file.
00001 // $Header: /nfs/slac/g/glast/ground/cvs/xmlUtil/xmlUtil/id/DictNode.h,v 1.10 2002/04/05 18:28:44 jrb Exp $
00002 #ifndef XMLUTIL_DICTNODE_H
00003 #define XMLUTIL_DICTNODE_H
00004 
00005 #include <dom/DOM_Element.hpp>
00006 #include "xmlUtil/id/DictObject.h"
00007 #include "xmlUtil/id/DictField.h"
00008 #include "xmlUtil/id/DictConstraints.h"
00009 #include "xmlUtil/id/NamedId.h"
00010 
00011 #include <vector>
00012 #include <algorithm>
00013 #include <iterator>
00014 #include <iostream>
00015 
00016 namespace xmlUtil {
00018 
00022   class DictFieldMan;
00023 
00024   class DictNode : public DictObject {
00025   public:
00028     DictNode(DOM_Element elt, DictNode* parent, DictFieldMan *fieldMan); 
00029     /* IN PROGRESS */
00030     ~DictNode();  // similarly, delete all children recursively /* TO DO */
00031     const DictField& getField() const {return *m_field;};
00032 
00033     // Following should be changed or add new function which
00034     //  returns local constraints if there are any,
00035     //  else if field has associated constraints, return pointer to that
00036     //  else return 0
00037     const DictConstraints& getValueConstraints() const { 
00038       return *m_myConstraints;};
00039     const DictConstraints& getParentConstraints() const {
00040       return *m_parConstraints;};
00041     bool accept(DictVisitor* vis);
00042 
00046     bool  consistentChildren();          
00047 
00050     bool  consistentParent();
00051 
00054     bool  consistentValues();
00055 
00056     // Maybe also need function to check that field ref points
00057     // to actual field definition?
00058 
00059     // Perhaps need to add validity functions here to check
00060     //    parent constraints, if any, make sense
00061     //    own constraints, if any, make sense
00062     bool  allowed(const unsigned value) const;  
00065     bool  allowedChild(std::string childField, unsigned childValue, 
00066                        unsigned myValue) const;
00069     bool  allowedChild(unsigned childValue, unsigned myValue) const;
00070 
00074     bool allowIdentifier(const Identifier& id, NamedId* named = 0);
00075 
00078     bool allowNamedId(const NamedId& nId);
00079 
00082     bool allowNameSeq(const NameSeq& seq) const;
00083 
00085     class No_Assignment {};
00086 
00087   private:
00088     friend class IdDict;
00089     friend class IdConverter;   //maybe
00090     friend struct POrder;
00091 
00092     // Might want to use some other form of collection for 
00093     // child DictNodes
00094     typedef std::vector<DictNode*> Nodes;
00095     typedef std::vector<DictNode*>::iterator NodeIterator;
00096     typedef std::vector<DictNode*>::const_iterator ConstNodeIterator;
00097 
00098     // Nested class allowing sorting of child nodes by m_minValue of
00099     // parent constraint
00100     struct POrder {
00101       bool operator()(DictNode* a, DictNode* b) {
00102         return ((a->getParentConstraints()).getMin() <
00103                 (b->getParentConstraints()).getMin()   ); }
00104     }; 
00105 
00106     const Nodes&     getChildren() const {return m_children;}
00107 
00109     static void   setOstream(std::ostream* out) {m_err = out;}
00110 
00111     // More constructor, for when dictionary is built dynamically
00112     // rather than from xml file
00113     /*    DictNode(DictField& field);                             TO DO
00114     DictNode(DictField& field, DictConstraints& parConstraints);  TO DO
00115     DictNode(DictField& field, DictConstraints& parConstraints,   TO DO
00116              DictConstraints& myConstraints);                     TO DO */
00117 
00120 
00124     bool  allowedChild(const DictNode* const thisChild, unsigned childValue,
00125                        unsigned myValue) const;
00126 
00127 
00129     bool allowIdentifier(Identifier::const_iterator idIt, 
00130                          Identifier::const_iterator end,
00131                          NamedId* named=0);
00132 
00134     bool allowNamedId(NamedId::FieldIt nIdIt,
00135                       NamedId::FieldIt end);
00136 
00137 
00139     bool allowNameSeq(NameSeq::const_iterator seqIt,
00140                       NameSeq::const_iterator end) const;
00141 
00142     bool  addChild(DictNode* child);
00143 
00144 
00147     bool  valuesDisjoint(ConstNodeIterator start, 
00148                          ConstNodeIterator last); 
00149 
00150 
00152     DictNode(const DictNode& toCopy);
00153 
00154     // Assignment of nodes is not allowed
00155     DictNode& operator=(const DictNode&); 
00156     void deepCopy(const DictNode& toCopy);
00157 
00159     DictNode() {};   
00160 
00161     Nodes            m_children;      
00162     const DictField* m_field;         
00163     const DictNode*  m_parent;        
00164     DictConstraints* m_parConstraints;
00165     DictConstraints* m_myConstraints; 
00166     static std::ostream* m_err;
00167 
00168   };       // end DictNode class definition
00169 }          // end namespace xmlUtil
00170 #endif

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