X-Git-Url: http://www.project-moonshot.org/gitweb/?a=blobdiff_plain;f=xmltooling%2Fbase.h;h=4e8009138e78ba038b16a7dc7d266b2b80a20d97;hb=988adfb35c4e29a54c15a7a73a52c48a6b5bed6f;hp=d1f1e07c5358516ac3302b7c0fe7067ad32a284c;hpb=2cae93ec49dcd10e18beebd1a6accf832272c2c1;p=shibboleth%2Fcpp-xmltooling.git diff --git a/xmltooling/base.h b/xmltooling/base.h index d1f1e07..4e80091 100644 --- a/xmltooling/base.h +++ b/xmltooling/base.h @@ -697,10 +697,12 @@ m_##proper = prepareForAssignment(m_##proper,proper); \ } \ void set##proper(int proper) { \ - char buf##proper[64]; \ - std::sprintf(buf##proper,"%d",proper); \ - xmltooling::auto_ptr_XMLCh wide##proper(buf##proper); \ - set##proper(wide##proper.get()); \ + try { \ + xmltooling::xstring buf = boost::lexical_cast(proper); \ + set##proper(buf.c_str()); \ + } \ + catch (boost::bad_lexical_cast&) { \ + } \ } /** @@ -1250,10 +1252,12 @@ } \ XMLTOOLING_DOXYGEN(Sets proper.) \ void set##proper(int proper) { \ - char buf[64]; \ - std::sprintf(buf,"%d",proper); \ - xmltooling::auto_ptr_XMLCh widebuf(buf); \ - setTextContent(widebuf.get()); \ + try { \ + xmltooling::xstring buf = boost::lexical_cast(proper); \ + setTextContent(buf.c_str()); \ + } \ + catch (boost::bad_lexical_cast&) { \ + } \ } \ XMLTOOLING_DOXYGEN(Sets or clears proper.) \ void set##proper(const XMLCh* proper) { \ @@ -1263,7 +1267,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 { \ @@ -1280,6 +1284,79 @@ } /** + * 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(); \ + } + +/** * Declares an XMLObject specialization with a simple content model and type, * handling it as string data. *