Update copyright.
[shibboleth/cpp-xmltooling.git] / xmltooling / AbstractSimpleElement.h
1 /*
2  *  Copyright 2001-2007 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/AbstractSimpleElement.h
19  * 
20  * AbstractXMLObject mixin that implements a simple string-based content model 
21  */
22
23 #ifndef __xmltooling_abssimpleel_h__
24 #define __xmltooling_abssimpleel_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 a simple string-based content model.
37      * Inherit from this class to support string-based element content.
38      */
39     class XMLTOOL_API AbstractSimpleElement : public virtual AbstractXMLObject
40     {
41     public:
42         virtual ~AbstractSimpleElement() {
43             XMLString::release(&m_value);
44         }
45         
46         bool hasChildren() const {
47             return false;
48         }
49
50         const std::list<XMLObject*>& getOrderedChildren() const {
51             return m_no_children;
52         }
53
54         void removeChild(XMLObject* child);
55
56         virtual const XMLCh* getTextContent(unsigned int position=0) const {
57             return (position==0) ? m_value : NULL;
58         }
59         
60         virtual void setTextContent(const XMLCh* value, unsigned int position=0) {
61             if (position > 0)
62                 throw XMLObjectException("Cannot set text content in simple element at position > 0.");
63             m_value=prepareForAssignment(m_value,value);
64         }
65         
66     protected:
67         AbstractSimpleElement() : m_value(NULL) {}
68         
69         /** Copy constructor. */
70         AbstractSimpleElement(const AbstractSimpleElement& src)
71             : AbstractXMLObject(src), m_value(XMLString::replicate(src.m_value)) {}
72
73     private:
74         XMLCh* m_value;
75
76         static std::list<XMLObject*> m_no_children;
77     };
78     
79 };
80
81 #if defined (_MSC_VER)
82     #pragma warning( pop )
83 #endif
84
85 #endif /* __xmltooling_abssimpleel_h__ */