X-Git-Url: http://www.project-moonshot.org/gitweb/?a=blobdiff_plain;f=xmltooling%2Fbase.h;h=106816ff48da4fb384c6f14f896ccec2c4cff8fc;hb=77769b2e300d1295b8a5d717d9ede50e27d70cea;hp=92509af99b272ec5c6417a5add7292c061629aba;hpb=3782107c4e6b36fd394ef2ee96618105d5f5c33f;p=shibboleth%2Fcpp-xmltooling.git diff --git a/xmltooling/base.h b/xmltooling/base.h index 92509af..106816f 100644 --- a/xmltooling/base.h +++ b/xmltooling/base.h @@ -229,7 +229,7 @@ */ #define BEGIN_XMLOBJECT(linkage,cname,base,desc) \ XMLTOOLING_DOXYGEN(desc) \ - class linkage cname : public virtual base, public virtual xmltooling::ValidatingXMLObject { \ + class linkage cname : public virtual base { \ protected: \ cname() {} \ public: \ @@ -252,7 +252,56 @@ */ #define BEGIN_XMLOBJECT2(linkage,cname,base,base2,desc) \ XMLTOOLING_DOXYGEN(desc) \ - class linkage cname : public virtual base, public virtual base2, public virtual xmltooling::ValidatingXMLObject { \ + class linkage cname : public virtual base, public virtual base2 { \ + protected: \ + cname() {} \ + public: \ + virtual ~cname() {} \ + XMLTOOLING_DOXYGEN(Type-specific clone method.) \ + virtual cname* clone##cname() const=0; \ + XMLTOOLING_DOXYGEN(Element local name) \ + static const XMLCh LOCAL_NAME[] + +/** + * Begins the declaration of an XMLObject specialization with three base classes. + * Basic boilerplate includes a protected constructor, empty virtual destructor, + * and Unicode constants for the default associated element's name and prefix. + * + * @param linkage linkage specifier for the class + * @param cname the name of the class to declare + * @param base the first base class to derive from using public virtual inheritance + * @param base2 the second base class to derive from using public virtual inheritance + * @param base3 the third base class to derive from using public virtual inheritance + * @param desc documentation comment for class + */ +#define BEGIN_XMLOBJECT3(linkage,cname,base,base2,base3,desc) \ + XMLTOOLING_DOXYGEN(desc) \ + class linkage cname : public virtual base, public virtual base2, public virtual base3 { \ + protected: \ + cname() {} \ + public: \ + virtual ~cname() {} \ + XMLTOOLING_DOXYGEN(Type-specific clone method.) \ + virtual cname* clone##cname() const=0; \ + XMLTOOLING_DOXYGEN(Element local name) \ + static const XMLCh LOCAL_NAME[] + +/** + * Begins the declaration of an XMLObject specialization with four base classes. + * Basic boilerplate includes a protected constructor, empty virtual destructor, + * and Unicode constants for the default associated element's name and prefix. + * + * @param linkage linkage specifier for the class + * @param cname the name of the class to declare + * @param base the first base class to derive from using public virtual inheritance + * @param base2 the second base class to derive from using public virtual inheritance + * @param base3 the third base class to derive from using public virtual inheritance + * @param base4 the fourth base class to derive from using public virtual inheritance + * @param desc documentation comment for class + */ +#define BEGIN_XMLOBJECT4(linkage,cname,base,base2,base3,base4,desc) \ + XMLTOOLING_DOXYGEN(desc) \ + class linkage cname : public virtual base, public virtual base2, public virtual base3, public virtual base4 { \ protected: \ cname() {} \ public: \ @@ -300,6 +349,8 @@ */ #define DECL_DATETIME_ATTRIB(proper,upcased) \ DECL_XMLOBJECT_ATTRIB(proper,upcased,xmltooling::DateTime); \ + XMLTOOLING_DOXYGEN(Returns the proper attribute in epoch form.) \ + virtual time_t get##proper##Epoch() const=0; \ XMLTOOLING_DOXYGEN(Sets the proper attribute.) \ virtual void set##proper(time_t proper)=0; \ XMLTOOLING_DOXYGEN(Sets the proper attribute.) \ @@ -327,13 +378,27 @@ * * @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 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.) \ @@ -390,20 +455,50 @@ IMPL_XMLOBJECT_ATTRIB(proper,XMLCh) /** - * Implements get/set methods and a private member for a DateTime XML attribute. + * 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_DATETIME_ATTRIB(proper) \ - IMPL_XMLOBJECT_ATTRIB(proper,xmltooling::DateTime); \ - void set##proper(time_t proper) { \ - m_##proper = prepareForAssignment(m_##proper,proper); \ - } \ - void set##proper(const XMLCh* proper) { \ - m_##proper = prepareForAssignment(m_##proper,proper); \ +#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 + * @param fallback epoch to return when attribute is NULL + */ +#define IMPL_DATETIME_ATTRIB(proper,fallback) \ + protected: \ + DateTime* m_##proper; \ + time_t m_##proper##Epoch; \ + public: \ + const DateTime* get##proper() const { \ + return m_##proper; \ + } \ + time_t get##proper##Epoch() const { \ + return m_##proper ? m_##proper##Epoch : fallback; \ + } \ + void set##proper(const DateTime* proper) { \ + m_##proper = prepareForAssignment(m_##proper,proper); \ + if (m_##proper) \ + m_##proper##Epoch=m_##proper->getEpoch(); \ + } \ + void set##proper(time_t proper) { \ + m_##proper = prepareForAssignment(m_##proper,proper); \ + m_##proper##Epoch = proper; \ + } \ + void set##proper(const XMLCh* proper) { \ + m_##proper = prepareForAssignment(m_##proper,proper); \ + if (m_##proper) \ + m_##proper##Epoch=m_##proper->getEpoch(); \ + } + +/** * Implements get/set methods and a private member for an integer XML attribute. * * @param proper the proper name of the attribute @@ -413,7 +508,7 @@ XMLCh* m_##proper; \ public: \ pair 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); \ @@ -434,11 +529,8 @@ protected: \ XMLConstants::xmltooling_bool_t m_##proper; \ public: \ - pair 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) { \ @@ -869,11 +961,11 @@ } /** - * 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(); \ @@ -906,21 +998,6 @@ } /** - * 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 @@ -949,8 +1026,8 @@ * @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 /** @@ -964,9 +1041,7 @@ class linkage cname##Impl \ : public virtual cname, \ public xmltooling::AbstractSimpleElement, \ - public xmltooling::AbstractChildlessElement, \ public xmltooling::AbstractDOMCachingXMLObject, \ - public xmltooling::AbstractValidatingXMLObject, \ public xmltooling::AbstractXMLObjectMarshaller, \ public xmltooling::AbstractXMLObjectUnmarshaller \ { \ @@ -978,10 +1053,8 @@ cname##Impl(const cname##Impl& src) \ : xmltooling::AbstractXMLObject(src), \ xmltooling::AbstractSimpleElement(src), \ - xmltooling::AbstractDOMCachingXMLObject(src), \ - xmltooling::AbstractValidatingXMLObject(src) {} \ + xmltooling::AbstractDOMCachingXMLObject(src) {} \ IMPL_XMLOBJECT_CLONE(cname) \ - IMPL_XMLOBJECT_CONTENT \ } /** @@ -1058,9 +1131,6 @@ { \ public: \ virtual ~cname##SchemaValidator() {} \ - virtual cname##SchemaValidator* clone() const { \ - return new cname##SchemaValidator(); \ - } \ virtual void validate(const xmltooling::XMLObject* xmlObject) const { \ const cname* ptr=dynamic_cast(xmlObject); \ if (!ptr) \ @@ -1078,9 +1148,6 @@ { \ public: \ virtual ~cname##SchemaValidator() {} \ - virtual cname##SchemaValidator* clone() const { \ - return new cname##SchemaValidator(); \ - } \ virtual void validate(const xmltooling::XMLObject* xmlObject) const { \ const cname* ptr=dynamic_cast(xmlObject); \ if (!ptr) \