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