ed5862e3183b7e04be9d6909667a5838aecb9133
[shibboleth/cpp-xmltooling.git] / xmltooling / AbstractDOMCachingXMLObject.h
1 /*
2  *  Copyright 2001-2010 Internet2
3  * 
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 /**
18  * @file xmltooling/AbstractDOMCachingXMLObject.h
19  * 
20  * AbstractXMLObject mixin that implements DOM caching.
21  */
22
23 #ifndef __xmltooling_abstractdomxmlobj_h__
24 #define __xmltooling_abstractdomxmlobj_h__
25
26 #include <xmltooling/AbstractXMLObject.h>
27
28 #if defined (_MSC_VER)
29     #pragma warning( push )
30     #pragma warning( disable : 4250 4251 )
31 #endif
32
33 namespace xmltooling {
34
35     /**
36      * AbstractXMLObject mixin that implements DOM caching.
37      * Inherit from this class to implement standard DOM caching behavior.
38      */
39     class XMLTOOL_API AbstractDOMCachingXMLObject : public virtual AbstractXMLObject
40     {
41     public:
42         virtual ~AbstractDOMCachingXMLObject();
43
44         // Virtual function overrides.
45         xercesc::DOMElement* getDOM() const;
46         void setDOM(xercesc::DOMElement* dom, bool bindDocument=false) const;
47         void setDocument(xercesc::DOMDocument* doc) const;
48         void releaseDOM() const;
49         void releaseParentDOM(bool propagateRelease=true) const;
50         void releaseChildrenDOM(bool propagateRelease=true) const;
51         XMLObject* clone() const;
52         void detach();
53
54      protected:
55         AbstractDOMCachingXMLObject();
56
57         /** Copy constructor. */
58         AbstractDOMCachingXMLObject(const AbstractDOMCachingXMLObject& src);
59
60         /**
61          * If a DOM representation exists, this clones it into a new document.
62          * 
63          * @param doc   the document to clone into, or nullptr, in which case a new document is created
64          * @return  the cloned DOM
65          */
66         xercesc::DOMElement* cloneDOM(xercesc::DOMDocument* doc=nullptr) const;
67
68     private:
69         mutable xercesc::DOMElement* m_dom;
70         mutable xercesc::DOMDocument* m_document;
71     };
72     
73 };
74
75 #if defined (_MSC_VER)
76     #pragma warning( pop )
77 #endif
78
79 #endif /* __xmltooling_abstractdomxmlobj_h__ */