X-Git-Url: http://www.project-moonshot.org/gitweb/?a=blobdiff_plain;f=xmltooling%2Fbase.h;h=664a6a0407a06dce02a60f21cd2d7d811fc99cff;hb=211d157271f527521d46875c1c220734f2fa1136;hp=0626e81aadd98bb8a90b6e897af815c110ef810e;hpb=81b488b2790e7bdeb2f43560b1d4a7d22c3dfdf5;p=shibboleth%2Fcpp-xmltooling.git diff --git a/xmltooling/base.h b/xmltooling/base.h index 0626e81..664a6a0 100644 --- a/xmltooling/base.h +++ b/xmltooling/base.h @@ -697,10 +697,13 @@ m_##proper = prepareForAssignment(m_##proper,proper); \ } \ void set##proper(int proper) { \ - char buf##proper[64]; \ - sprintf(buf##proper,"%d",proper); \ - auto_ptr_XMLCh wide##proper(buf##proper); \ - set##proper(wide##proper.get()); \ + try { \ + std::string buf(boost::lexical_cast(proper)); \ + xmltooling::auto_ptr_XMLCh widen(buf.c_str()); \ + set##proper(widen.get()); \ + } \ + catch (boost::bad_lexical_cast&) { \ + } \ } /** @@ -738,7 +741,7 @@ } \ void set##proper(const type* proper) { \ m_##proper = prepareForAssignment(m_##proper,proper); \ - XMLString::release(&m_##proper##Prefix); \ + xercesc::XMLString::release(&m_##proper##Prefix); \ m_##proper##Prefix = nullptr; \ } @@ -1019,7 +1022,7 @@ */ #define MARSHALL_QNAME_ATTRIB(proper,ucase,namespaceURI) \ if (m_##proper) { \ - auto_ptr_XMLCh qstr(m_##proper->toString().c_str()); \ + xmltooling::auto_ptr_XMLCh qstr(m_##proper->toString().c_str()); \ domElement->setAttributeNS(namespaceURI, ucase##_ATTRIB_NAME, qstr.get()); \ } @@ -1113,7 +1116,8 @@ */ #define PROC_QNAME_ATTRIB(proper,ucase,namespaceURI) \ if (xmltooling::XMLHelper::isNodeNamed(attribute, namespaceURI, ucase##_ATTRIB_NAME)) { \ - set##proper(XMLHelper::getAttributeValueAsQName(attribute)); \ + std::auto_ptr q(xmltooling::XMLHelper::getAttributeValueAsQName(attribute)); \ + set##proper(q.get()); \ return; \ } @@ -1249,10 +1253,13 @@ } \ XMLTOOLING_DOXYGEN(Sets proper.) \ void set##proper(int proper) { \ - char buf[64]; \ - sprintf(buf,"%d",proper); \ - xmltooling::auto_ptr_XMLCh widebuf(buf); \ - setTextContent(widebuf.get()); \ + try { \ + std::string buf(boost::lexical_cast(proper)); \ + xmltooling::auto_ptr_XMLCh widen(buf.c_str()); \ + setTextContent(widen.get()); \ + } \ + catch (boost::bad_lexical_cast&) { \ + } \ } \ XMLTOOLING_DOXYGEN(Sets or clears proper.) \ void set##proper(const XMLCh* proper) { \ @@ -1262,7 +1269,7 @@ /** * Implements cloning methods for an XMLObject specialization implementation class. * - * @param cname the name of the XMLObject specialization + * @param cname the name of the XMLObject specialization */ #define IMPL_XMLOBJECT_CLONE(cname) \ cname* clone##cname() const { \ @@ -1279,6 +1286,229 @@ } /** + * Implements cloning methods for an XMLObject specialization implementation class + * that must override a base class clone method. + * + * @param cname the name of the XMLObject specialization + * @param base name of base type. + */ +#define IMPL_XMLOBJECT_CLONE2(cname,base) \ + cname* clone##cname() const { \ + return dynamic_cast(clone()); \ + } \ + base* clone##base() const { \ + return dynamic_cast(clone()); \ + } \ + xmltooling::XMLObject* clone() const { \ + std::auto_ptr domClone(xmltooling::AbstractDOMCachingXMLObject::clone()); \ + cname##Impl* ret=dynamic_cast(domClone.get()); \ + if (ret) { \ + domClone.release(); \ + return ret; \ + } \ + return new cname##Impl(*this); \ + } + +/** + * Implements cloning methods for an XMLObject specialization implementation class that + * needs two stage duplication to avoid invoking virtual methods during construction. + * + * @param cname the name of the XMLObject specialization + */ +#define IMPL_XMLOBJECT_CLONE_EX(cname) \ + cname* clone##cname() const { \ + return dynamic_cast(clone()); \ + } \ + xmltooling::XMLObject* clone() const { \ + std::auto_ptr domClone(xmltooling::AbstractDOMCachingXMLObject::clone()); \ + cname##Impl* ret=dynamic_cast(domClone.get()); \ + if (ret) { \ + domClone.release(); \ + return ret; \ + } \ + std::auto_ptr ret2(new cname##Impl(*this)); \ + ret2->_clone(*this); \ + return ret2.release(); \ + } + +/** + * Implements cloning methods for an XMLObject specialization implementation class that + * needs two stage duplication to avoid invoking virtual methods during construction, + * and must override a base class clone method. + * + * @param cname the name of the XMLObject specialization + * @param base name of base type + */ +#define IMPL_XMLOBJECT_CLONE_EX2(cname,base) \ + cname* clone##cname() const { \ + return dynamic_cast(clone()); \ + } \ + base* clone##base() const { \ + return dynamic_cast(clone()); \ + } \ + xmltooling::XMLObject* clone() const { \ + std::auto_ptr domClone(xmltooling::AbstractDOMCachingXMLObject::clone()); \ + cname##Impl* ret=dynamic_cast(domClone.get()); \ + if (ret) { \ + domClone.release(); \ + return ret; \ + } \ + std::auto_ptr ret2(new cname##Impl(*this)); \ + ret2->_clone(*this); \ + return ret2.release(); \ + } + +/** + * Implements cloning of a child attribute, for use in copy constructor or + * deferred clone methods. + * + * proper the proper name of the attribute to clone + */ +#define IMPL_CLONE_ATTRIB(proper) \ + set##proper(src.get##proper()) + +/** + * Implements cloning of a child attribute in a foreign namespace, for use in copy constructor or + * deferred clone methods. + * + * proper the proper name of the attribute to clone + */ +#define IMPL_CLONE_FOREIGN_ATTRIB(proper) \ + set##proper(src.get##proper()); \ + if (src.m_##proper##Prefix) \ + m_##proper##Prefix = xercesc::XMLString::replicate(src.m_##proper##Prefix) + +/** + * Implements cloning of an integer child attribute, for use in copy constructor or + * deferred clone methods. + * + * proper the proper name of the attribute to clone + */ +#define IMPL_CLONE_INTEGER_ATTRIB(proper) \ + set##proper(src.m_##proper) + +/** + * Implements cloning of a boolean child attribute, for use in copy constructor or + * deferred clone methods. + * + * proper the proper name of the attribute to clone + */ +#define IMPL_CLONE_BOOLEAN_ATTRIB(proper) \ + proper(src.m_##proper) + +/** + * Implements cloning of a child object, for use in copy constructor or + * deferred clone methods. + * + * proper the proper name of the child object to clone + */ +#define IMPL_CLONE_XMLOBJECT_CHILD(proper) \ + if (src.get##proper()) \ + set##proper(src.get##proper()->clone()) + +/** + * Implements cloning of a typed child object, for use in copy constructor or + * deferred clone methods. + * + * proper the proper name of the child type to clone + */ +#define IMPL_CLONE_TYPED_CHILD(proper) \ + if (src.get##proper()) \ + set##proper(src.get##proper()->clone##proper()) + +/** + * Implements cloning of an untyped child collection, for use in copy constructor or + * deferred clone methods. + * + * proper the proper name of the child type to clone + */ +#define IMPL_CLONE_XMLOBJECT_CHILDREN(proper) \ + static void (VectorOf(XMLObject)::* XMLObject_push_back)(XMLObject* const&) = &VectorOf(XMLObject)::push_back; \ + VectorOf(XMLObject) c##proper = get##proper##s(); \ + std::for_each( \ + src.m_##proper##s.begin(), src.m_##proper##s.end(), \ + boost::lambda::if_(boost::lambda::_1 != ((XMLObject*)nullptr)) \ + [boost::lambda::bind(XMLObject_push_back, boost::ref(c##proper), boost::lambda::bind(&XMLObject::clone, boost::lambda::_1))] \ + ) + +/** + * Implements cloning of a child collection, for use in copy constructor or + * deferred clone methods. + * + * proper the proper name of the child type to clone + */ +#define IMPL_CLONE_TYPED_CHILDREN(proper) \ + static void (VectorOf(proper)::* proper##_push_back)(proper* const&) = &VectorOf(proper)::push_back; \ + VectorOf(proper) c##proper = get##proper##s(); \ + std::for_each( \ + src.m_##proper##s.begin(), src.m_##proper##s.end(), \ + boost::lambda::if_(boost::lambda::_1 != ((proper*)nullptr)) \ + [boost::lambda::bind(proper##_push_back, boost::ref(c##proper), boost::lambda::bind(&proper::clone##proper, boost::lambda::_1))] \ + ) + +/** + * Implements cloning of a child collection in a foreign namespace, for use in copy constructor or + * deferred clone methods. + * + * proper the proper name of the child type to clone + * ns the namespace of the child type + */ +#define IMPL_CLONE_TYPED_FOREIGN_CHILDREN(proper,ns) \ + static void (VectorOf(ns::proper)::* proper##_push_back)(ns::proper* const&) = &VectorOf(ns::proper)::push_back; \ + VectorOf(ns::proper) c##proper = get##proper##s(); \ + std::for_each( \ + src.m_##proper##s.begin(), src.m_##proper##s.end(), \ + boost::lambda::if_(boost::lambda::_1 != ((ns::proper*)nullptr)) \ + [boost::lambda::bind(proper##_push_back, boost::ref(c##proper), boost::lambda::bind(&ns::proper::clone##proper, boost::lambda::_1))] \ + ) + +/** + * Opens an iteration loop over all of the children of an object. + */ +#define IMPL_CLONE_CHILDBAG_BEGIN \ + for (list::const_iterator _bagit = src.m_children.begin(); _bagit != src.m_children.end(); ++_bagit) { + +/** + * Closes an iteration loop over all of the children of an object. + */ +#define IMPL_CLONE_CHILDBAG_END } + +/** + * Implements cloning of a typed child in a bag iteration loop based on a cast check. + * + * @param proper the proper name of the child type to clone + */ +#define IMPL_CLONE_TYPED_CHILD_IN_BAG(proper) \ + proper* _##proper##cast = dynamic_cast(*_bagit); \ + if (_##proper##cast) { \ + get##proper##s().push_back(_##proper##cast->clone##proper()); \ + continue; \ + } + +/** + * Implements cloning of a typed child in a forign namespace in a bag iteration loop based on a cast check. + * + * @param proper the proper name of the child type to clone + * @param ns the namespace of the child type + */ +#define IMPL_CLONE_TYPED_FOREIGN_CHILD_IN_BAG(proper,ns) \ + ns::proper* _##proper##cast = dynamic_cast(*_bagit); \ + if (_##proper##cast) { \ + get##proper##s().push_back(_##proper##cast->clone##proper()); \ + continue; \ + } + +/** + * Implements cloning of an XMLObject child in a bag iteration loop. + * + * @param proper the proper name of the child to clone + */ +#define IMPL_CLONE_XMLOBJECT_CHILD_IN_BAG(proper) \ + if (*_bagit) { \ + get##proper##s().push_back((*_bagit)->clone()); \ + } + +/** * Declares an XMLObject specialization with a simple content model and type, * handling it as string data. *