Multi-line svn commit, see body.
[shibboleth/cpp-xmltooling.git] / xmltooling / base.h
index bc24a43..106816f 100644 (file)
  * 
  * @param proper    the proper name of the attribute
  * @param upcased   the upcased name of the attribute
+ * @param def       the default/presumed value, if no explicit value has been set
  */
-#define DECL_BOOLEAN_ATTRIB(proper,upcased) \
+#define DECL_BOOLEAN_ATTRIB(proper,upcased,def) \
     public: \
         XMLTOOLING_DOXYGEN(proper attribute name) \
         static const XMLCh upcased##_ATTRIB_NAME[]; \
-        XMLTOOLING_DOXYGEN(Returns the proper attribute after a NULL indicator.) \
-        virtual std::pair<bool,bool> proper() const=0; \
+        XMLTOOLING_DOXYGEN(Returns the proper attribute or def if not set.) \
+        bool proper() const { \
+            switch (get##proper()) { \
+                case xmltooling::XMLConstants::XML_BOOL_TRUE: \
+                case xmltooling::XMLConstants::XML_BOOL_ONE: \
+                    return true; \
+                case xmltooling::XMLConstants::XML_BOOL_FALSE: \
+                case xmltooling::XMLConstants::XML_BOOL_ZERO: \
+                    return false; \
+                default: \
+                    return def; \
+            } \
+        } \
+        XMLTOOLING_DOXYGEN(Returns the proper attribute as an explicit enumerated value.) \
+        virtual xmltooling::XMLConstants::xmltooling_bool_t get##proper() const=0; \
         XMLTOOLING_DOXYGEN(Sets the proper attribute using an enumerated value.) \
         virtual void proper(xmltooling::XMLConstants::xmltooling_bool_t value)=0; \
         XMLTOOLING_DOXYGEN(Sets the proper attribute.) \
     IMPL_XMLOBJECT_ATTRIB(proper,XMLCh)
 
 /**
+ * Implements get/set methods and a private member for a string XML attribute,
+ * plus a getXMLID override.
+ * 
+ * @param proper    the proper name of the attribute
+ */
+#define IMPL_ID_ATTRIB(proper) \
+    IMPL_XMLOBJECT_ATTRIB(proper,XMLCh) \
+    const XMLCh* getXMLID() const { \
+        return m_##proper; \
+    }
+
+/**
  * Implements get/set methods and a private member for a DateTime XML attribute.
  * 
  * @param proper    the proper name of the attribute
         XMLCh* m_##proper; \
     public: \
         pair<bool,int> get##proper() const { \
-            return make_pair((m_##proper!=NULL),(m_##proper!=NULL ? XMLString::parseInt(m_##proper): NULL)); \
+            return make_pair((m_##proper!=NULL),(m_##proper!=NULL ? XMLString::parseInt(m_##proper): 0)); \
         } \
         void set##proper(const XMLCh* proper) { \
             m_##proper = prepareForAssignment(m_##proper,proper); \
     protected: \
         XMLConstants::xmltooling_bool_t m_##proper; \
     public: \
-        pair<bool,bool> proper() const { \
-            return make_pair( \
-                (m_##proper!=XMLConstants::XML_BOOL_NULL), \
-                (m_##proper==XMLConstants::XML_BOOL_TRUE || m_##proper==XMLConstants::XML_BOOL_ONE) \
-                ); \
+        XMLConstants::xmltooling_bool_t get##proper() const { \
+            return m_##proper; \
         } \
         void proper(XMLConstants::xmltooling_bool_t value) { \
             if (m_##proper != value) { \
     }
 
 /**
- * Declares aliased get/set methods for named XML element content.
+ * Declares aliased get/set methods for named XML element simple content.
  * 
  * @param proper    the proper name to label the element's content
  */
-#define DECL_XMLOBJECT_CONTENT(proper) \
+#define DECL_SIMPLE_CONTENT(proper) \
     XMLTOOLING_DOXYGEN(Returns proper.) \
     const XMLCh* get##proper() const { \
         return getTextContent(); \
     }
 
 /**
- * Implements marshalling/unmarshalling for element content.
- */
-#define IMPL_XMLOBJECT_CONTENT \
-    protected: \
-        void marshallElementContent(DOMElement* domElement) const { \
-            if(getTextContent()) { \
-                domElement->appendChild(domElement->getOwnerDocument()->createTextNode(getTextContent())); \
-            } \
-        } \
-        void processElementContent(const XMLCh* elementContent) { \
-            setTextContent(elementContent); \
-        }
-
-
-/**
  * Implements cloning methods for an XMLObject specialization implementation class.
  * 
  * @param cname    the name of the XMLObject specialization
  * @param desc      documentation for class
  */
 #define DECL_XMLOBJECT_SIMPLE(linkage,cname,proper,desc) \
-    BEGIN_XMLOBJECT(linkage,cname,xmltooling::SimpleElement,desc); \
-        DECL_XMLOBJECT_CONTENT(proper); \
+    BEGIN_XMLOBJECT(linkage,cname,xmltooling::XMLObject,desc); \
+        DECL_SIMPLE_CONTENT(proper); \
     END_XMLOBJECT
 
 /**
     class linkage cname##Impl \
         : public virtual cname, \
             public xmltooling::AbstractSimpleElement, \
-            public xmltooling::AbstractChildlessElement, \
             public xmltooling::AbstractDOMCachingXMLObject, \
             public xmltooling::AbstractXMLObjectMarshaller, \
             public xmltooling::AbstractXMLObjectUnmarshaller \
                 xmltooling::AbstractSimpleElement(src), \
                 xmltooling::AbstractDOMCachingXMLObject(src) {} \
         IMPL_XMLOBJECT_CLONE(cname) \
-        IMPL_XMLOBJECT_CONTENT \
     }
     
 /**