https://issues.shibboleth.net/jira/browse/CPPXT-32
[shibboleth/cpp-xmltooling.git] / xmltooling / AbstractComplexElement.h
1 /*
2  *  Copyright 2001-2009 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/AbstractComplexElement.h
19  * 
20  * AbstractXMLObject mixin that implements children
21  */
22
23 #ifndef __xmltooling_abscomplexel_h__
24 #define __xmltooling_abscomplexel_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 children.
37      * Inherit from this class to implement an element with child objects and mixed content.
38      */
39     class XMLTOOL_API AbstractComplexElement : public virtual AbstractXMLObject
40     {
41     public:
42         virtual ~AbstractComplexElement();
43         
44         bool hasChildren() const;
45
46         const std::list<XMLObject*>& getOrderedChildren() const {
47             return m_children;
48         }
49
50         void removeChild(XMLObject* child);
51
52         const XMLCh* getTextContent(unsigned int position=0) const {
53             return (m_text.size() > position) ? m_text[position] : NULL; 
54         }
55         
56         void setTextContent(const XMLCh* value, unsigned int position=0);
57
58     protected:
59         AbstractComplexElement() {}
60         
61         /** Copy constructor. */
62         AbstractComplexElement(const AbstractComplexElement& src);
63
64         /**
65          * Underlying list of child objects.
66          * Manages the lifetime of the children.
67          */
68         std::list<XMLObject*> m_children;
69         
70         /**
71          * Interstitial text nodes.
72          * Needed to support mixed content, and preserve DOM whitespace across rebuilds.
73          */
74         std::vector<XMLCh*> m_text;
75     };
76     
77 };
78
79 #if defined (_MSC_VER)
80     #pragma warning( pop )
81 #endif
82
83 #endif /* __xmltooling_abscomplexel_h__ */