00001
00002
00003 #ifndef MiX_NODECONTAINER_H_
00004 #define MiX_NODECONTAINER_H_
00005
00006 #include "NodeList.h"
00007 #include "Node.h"
00008
00009 namespace MiX{
00010
00011 template <class charT,class char_traits,class xml_traits>
00012 class NodeContainer : virtual public Node<charT,char_traits,xml_traits>{
00013 public:
00014 MiX_Template_Typedef(charT,char_traits,xml_traits);
00015 typedef NodeContainer<charT,char_traits,xml_traits> this_type;
00016 protected:
00017 nodelist_type children_;
00018 void addChild(node_type* node);
00019
00020 std::map<string_type,string_type> name_to_url_;
00021
00022 void cloneChildren(this_type& dest) const{
00023 typename nodelist_type::const_iterator it = getChildren().begin();
00024 typename nodelist_type::const_iterator last = getChildren().end();
00025 for( ; it!=last ; ++it ){
00026 (*it)->clone(dest,dest.getChildren().end());
00027 }
00028 }
00029
00030 protected:
00032 NodeContainer() : node_type(),children_() { };
00038 NodeContainer(const this_type& src){ };
00040 template <class Pred>
00041 typename nodelist_type::iterator search(Pred pred,int index){
00042 int i = 0;
00043 typename nodelist_type::iterator it,first,last=getChildren().end();
00044 for ( first=getChildren().begin(); it!=last ; first=++it,++i ){
00045 it = std::find_if(first,last,pred);
00046 if( i==index ) break;
00047 }
00048 return it;
00049 }
00050 public:
00052 virtual ~NodeContainer() throw();
00054 nodelist_type& getChildren(){ return children_; };
00056 const nodelist_type& getChildren() const { return children_; };
00057
00059 bool hasAttribute(const string_type& nm);
00061 bool hasAttribute(const string_type& nm,const string_type& ns);
00063 attribute_type& getAttribute(const string_type& nm,const string_type& ns);
00065 attribute_type& getAttribute(const string_type& nm);
00067 element_type& getElement(const string_type& name,int index);
00069 element_type& getElement(const string_type& name,const string_type& ns,int index);
00070
00076 nodelist_type getElementsByTagName(const string_type& tagname,const string_type& ns = string_type() );
00077
00079 void addNSName(const string_type& name,const string_type& url) {
00080 name_to_url_.insert(make_pair(name,url));
00081 }
00083 string_type queryURL(const string_type& name) const;
00085 string_type queryNSName(const string_type& url) const;
00086
00087 friend class DOM_Parser<charT,char_traits,xml_traits>;
00088 };
00089 }
00090
00091 #ifndef MiX_NODECONTAINER_CPP_
00092 #include "NodeContainer.cpp"
00093 #endif
00094
00095 #endif