• Classes
  • Modules
  • Namespaces
  • Files
  • Related Pages
  • File List
  • File Members

NodeContainerImpl.h

Go to the documentation of this file.
00001 /*
00002  * Licensed to the Apache Software Foundation (ASF) under one or more
00003  * contributor license agreements.  See the NOTICE file distributed with
00004  * this work for additional information regarding copyright ownership.
00005  * The ASF licenses this file to You under the Apache License, Version 2.0
00006  * (the "License"); you may not use this file except in compliance with
00007  * the License.  You may obtain a copy of the License at
00008  * 
00009  *      http://www.apache.org/licenses/LICENSE-2.0
00010  * 
00011  * Unless required by applicable law or agreed to in writing, software
00012  * distributed under the License is distributed on an "AS IS" BASIS,
00013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  * See the License for the specific language governing permissions and
00015  * limitations under the License.
00016  */
00017 
00018 /*
00019  * $Id: NodeContainerImpl.h 568078 2007-08-21 11:43:25Z amassari $
00020  */
00021 
00022 #ifndef ___nodecontainerimpl_h___
00023 #define ___nodecontainerimpl_h___
00024 
00025 template <class T>
00026 class NodeContainerImpl
00027 {
00028 public:
00029 
00030         class iterator 
00031         {
00032         public:
00033                 iterator()
00034                         :m_container(NULL)
00035                         ,m_NextNodeIndex(0)
00036                         ,m_pIXMLDOMDocument(NULL)
00037                 {
00038                         VariantInit(&m_NextVar);
00039                         V_VT(&m_NextVar) = VT_NULL;
00040                 }       
00041 
00042                 iterator(const T* container,int idx,IXMLDOMDocument *p)
00043                         :m_container(container)
00044                         ,m_NextNodeIndex(idx)
00045                         ,m_pIXMLDOMDocument(p)
00046                 {
00047                         VariantInit(&m_NextVar);
00048                         V_VT(&m_NextVar) = VT_NULL;
00049                         if (m_pIXMLDOMDocument != NULL)
00050                                 m_pIXMLDOMDocument->AddRef();
00051                 }
00052 
00053                 ~iterator()
00054                 {
00055                         VariantClear(&m_NextVar);
00056                         if (m_pIXMLDOMDocument != NULL)
00057                                 m_pIXMLDOMDocument->Release();
00058                 }
00059                 
00060                 bool operator !=(const iterator& rhs)
00061                 {
00062                         return (m_NextNodeIndex != rhs.m_NextNodeIndex);
00063                 }
00064                 
00065                 iterator& operator=(const iterator& rhs)
00066                 {
00067                         if (this != &rhs) {
00068                                 if (m_pIXMLDOMDocument != NULL) {
00069                                         m_pIXMLDOMDocument->Release() ;
00070                                         m_pIXMLDOMDocument = NULL ;
00071                                 }
00072                                 m_container = rhs.m_container ;
00073                                 m_NextNodeIndex = rhs.m_NextNodeIndex ;
00074                                 m_NextVar = rhs.m_NextVar ;
00075                                 m_pIXMLDOMDocument = rhs.m_pIXMLDOMDocument ;
00076                                 if (m_pIXMLDOMDocument != NULL) {
00077                                         m_pIXMLDOMDocument->AddRef() ;
00078                                 }
00079                         }
00080                         return *this ;
00081                 }
00082 
00083 
00084                 VARIANT& operator*()
00085                 {
00086                         if (m_container == 0)
00087                                 return m_NextVar;
00088 
00089                         int length = m_container->getLength(); 
00090                         if (m_NextNodeIndex >= length)
00091                                 return m_NextVar;
00092                         
00093                         CComPtr<IXMLDOMNode> pNode;
00094                         HRESULT hr = wrapNode(m_pIXMLDOMDocument,m_container->item(m_NextNodeIndex),IID_IXMLDOMNode, reinterpret_cast<LPVOID *> (&pNode));
00095                         if (S_OK == hr) {
00096                                 CComQIPtr<IDispatch,&IID_IDispatch> pDisp(pNode);
00097                                 if (pNode) {
00098                                         VariantClear(&m_NextVar);
00099                                         V_VT(&m_NextVar)           = VT_DISPATCH;
00100                                         V_DISPATCH(&m_NextVar) = pDisp.Detach();
00101                                 }
00102                         }
00103 
00104                         return m_NextVar;
00105                 }
00106                 
00107                 iterator operator++(int)
00108                 {
00109                         return iterator(m_container,m_NextNodeIndex++,m_pIXMLDOMDocument);              
00110                 }
00111                 
00112         private:
00113 
00114                 const T*                 m_container;   
00115                 int                          m_NextNodeIndex;
00116                 IXMLDOMDocument *m_pIXMLDOMDocument;
00117                 VARIANT                  m_NextVar;
00118         };
00119 
00120         typedef iterator const_iterator;
00121 
00122         NodeContainerImpl()
00123                 :m_NextNodeIndex(0)
00124                 ,m_pIXMLDOMDocument(NULL)
00125         {}
00126 
00127         iterator begin()
00128         {
00129                 return iterator(m_container,0,m_pIXMLDOMDocument);
00130         }
00131         
00132         iterator end()
00133         {
00134                 if (m_container == 0)
00135                         return iterator(m_container,0,m_pIXMLDOMDocument);
00136                 else    
00137                         return iterator(m_container,m_container->getLength(),m_pIXMLDOMDocument);
00138         }
00139         
00140         void    SetOwnerDoc(IXMLDOMDocument     *p)
00141         {
00142                 m_pIXMLDOMDocument = p;
00143                 if (m_pIXMLDOMDocument != NULL)
00144                         m_pIXMLDOMDocument->AddRef();
00145         }
00146 
00147         T*                               m_container;
00148 
00149 protected:
00150 
00151         int                              m_NextNodeIndex;
00152         IXMLDOMDocument *m_pIXMLDOMDocument;
00153 
00154         void    ReleaseOwnerDoc()
00155         {
00156                 if (m_pIXMLDOMDocument != NULL) {
00157                         m_pIXMLDOMDocument->Release();
00158                         m_pIXMLDOMDocument = NULL;
00159                 }
00160         }
00161 };
00162 
00163 #endif // ___nodecontainerimpl_h___

Generated on Thu Jan 12 2012 23:13:51 for ACS-10.0 C++ API by  doxygen 1.7.0