diff options
author | David Tardon <dtardon@redhat.com> | 2016-09-09 11:08:31 +0200 |
---|---|---|
committer | David Tardon <dtardon@redhat.com> | 2016-09-09 12:14:04 +0200 |
commit | df19c3c8006174e452cea455328ebb25e81a444b (patch) | |
tree | cfa90a7d15dd14be301caedc53e78ef954b9138b /xmloff | |
parent | 22547c51cf9484b0d7e1a7ed317fe5f70aaab694 (diff) |
reduce the insanity level of the codebase a bit
Change-Id: I4e0ee3cb87dd8f2bf8e35909e1b93d311c17a8c6
Diffstat (limited to 'xmloff')
-rw-r--r-- | xmloff/inc/xexptran.hxx | 11 | ||||
-rw-r--r-- | xmloff/source/draw/xexptran.cxx | 135 |
2 files changed, 32 insertions, 114 deletions
diff --git a/xmloff/inc/xexptran.hxx b/xmloff/inc/xexptran.hxx index 230fd5b5a722..184158d906b6 100644 --- a/xmloff/inc/xexptran.hxx +++ b/xmloff/inc/xexptran.hxx @@ -28,6 +28,7 @@ #include <com/sun/star/drawing/HomogenMatrix.hpp> #include <tools/mapunit.hxx> +#include <memory> #include <vector> struct ImpSdXMLExpTransObj2DBase; @@ -45,14 +46,15 @@ namespace basegfx class SdXMLImExTransform2D { - std::vector< ImpSdXMLExpTransObj2DBase* > maList; + // NOTE: This uses shared_ptr, because with unique_ptr the code + // fails to compile because of incomplete type. + std::vector< std::shared_ptr< ImpSdXMLExpTransObj2DBase > > maList; OUString msString; void EmptyList(); public: SdXMLImExTransform2D() {} - ~SdXMLImExTransform2D() { EmptyList(); } void AddRotate(double fNew); void AddTranslate(const ::basegfx::B2DTuple& rNew); @@ -66,7 +68,9 @@ public: class SdXMLImExTransform3D { - std::vector< ImpSdXMLExpTransObj3DBase* > maList; + // NOTE: This uses shared_ptr, because with unique_ptr the code + // fails to compile because of incomplete type. + std::vector< std::shared_ptr< ImpSdXMLExpTransObj3DBase > > maList; OUString msString; void EmptyList(); @@ -74,7 +78,6 @@ class SdXMLImExTransform3D public: SdXMLImExTransform3D() {} SdXMLImExTransform3D(const OUString& rNew, const SvXMLUnitConverter& rConv); - ~SdXMLImExTransform3D() { EmptyList(); } void AddMatrix(const ::basegfx::B3DHomMatrix& rNew); diff --git a/xmloff/source/draw/xexptran.cxx b/xmloff/source/draw/xexptran.cxx index 7c4debc31f50..f87f33d54714 100644 --- a/xmloff/source/draw/xexptran.cxx +++ b/xmloff/source/draw/xexptran.cxx @@ -18,6 +18,7 @@ */ #include "xexptran.hxx" +#include <o3tl/make_unique.hxx> #include <rtl/ustrbuf.hxx> #include <sax/tools/converter.hxx> #include <xmloff/xmluconv.hxx> @@ -35,6 +36,8 @@ using namespace ::com::sun::star; +using o3tl::make_unique; + // parsing help functions for simple chars void Imp_SkipSpaces(const OUString& rStr, sal_Int32& rPos, const sal_Int32 nLen) { @@ -170,6 +173,7 @@ struct ImpSdXMLExpTransObj2DBase sal_uInt16 mnType; explicit ImpSdXMLExpTransObj2DBase(sal_uInt16 nType) : mnType(nType) {} + virtual ~ImpSdXMLExpTransObj2DBase() {} }; // possible object types for 2D @@ -224,51 +228,6 @@ struct ImpSdXMLExpTransObj2DMatrix : public ImpSdXMLExpTransObj2DBase void SdXMLImExTransform2D::EmptyList() { - const sal_uInt32 nCount = maList.size(); - for(sal_uInt32 a(0L); a < nCount; a++) - { - ImpSdXMLExpTransObj2DBase* pObj = maList[a]; - - switch(pObj->mnType) - { - case IMP_SDXMLEXP_TRANSOBJ2D_ROTATE : - { - delete static_cast<ImpSdXMLExpTransObj2DRotate*>(pObj); - break; - } - case IMP_SDXMLEXP_TRANSOBJ2D_SCALE : - { - delete static_cast<ImpSdXMLExpTransObj2DScale*>(pObj); - break; - } - case IMP_SDXMLEXP_TRANSOBJ2D_TRANSLATE : - { - delete static_cast<ImpSdXMLExpTransObj2DTranslate*>(pObj); - break; - } - case IMP_SDXMLEXP_TRANSOBJ2D_SKEWX : - { - delete static_cast<ImpSdXMLExpTransObj2DSkewX*>(pObj); - break; - } - case IMP_SDXMLEXP_TRANSOBJ2D_SKEWY : - { - delete static_cast<ImpSdXMLExpTransObj2DSkewY*>(pObj); - break; - } - case IMP_SDXMLEXP_TRANSOBJ2D_MATRIX : - { - delete static_cast<ImpSdXMLExpTransObj2DMatrix*>(pObj); - break; - } - default : - { - OSL_FAIL("SdXMLImExTransform2D: impossible entry!"); - break; - } - } - } - maList.clear(); } @@ -277,19 +236,19 @@ void SdXMLImExTransform2D::EmptyList() void SdXMLImExTransform2D::AddRotate(double fNew) { if(fNew != 0.0) - maList.push_back(new ImpSdXMLExpTransObj2DRotate(fNew)); + maList.push_back(make_unique<ImpSdXMLExpTransObj2DRotate>(fNew)); } void SdXMLImExTransform2D::AddTranslate(const ::basegfx::B2DTuple& rNew) { if(!rNew.equalZero()) - maList.push_back(new ImpSdXMLExpTransObj2DTranslate(rNew)); + maList.push_back(make_unique<ImpSdXMLExpTransObj2DTranslate>(rNew)); } void SdXMLImExTransform2D::AddSkewX(double fNew) { if(fNew != 0.0) - maList.push_back(new ImpSdXMLExpTransObj2DSkewX(fNew)); + maList.push_back(make_unique<ImpSdXMLExpTransObj2DSkewX>(fNew)); } // gen string for export @@ -302,7 +261,7 @@ const OUString& SdXMLImExTransform2D::GetExportString(const SvXMLUnitConverter& const sal_uInt32 nCount = maList.size(); for(sal_uInt32 a(0L); a < nCount; a++) { - ImpSdXMLExpTransObj2DBase* pObj = maList[a]; + ImpSdXMLExpTransObj2DBase* pObj = maList[a].get(); switch(pObj->mnType) { case IMP_SDXMLEXP_TRANSOBJ2D_ROTATE : @@ -429,7 +388,7 @@ void SdXMLImExTransform2D::SetString(const OUString& rNew, const SvXMLUnitConver Imp_SkipSpacesAndOpeningBraces(aStr, nPos, nLen); fValue = Imp_GetDoubleChar(aStr, nPos, nLen, rConv, fValue); if(fValue != 0.0) - maList.push_back(new ImpSdXMLExpTransObj2DRotate(fValue)); + maList.push_back(make_unique<ImpSdXMLExpTransObj2DRotate>(fValue)); Imp_SkipSpacesAndClosingBraces(aStr, nPos, nLen); } @@ -443,7 +402,7 @@ void SdXMLImExTransform2D::SetString(const OUString& rNew, const SvXMLUnitConver aValue.setY(Imp_GetDoubleChar(aStr, nPos, nLen, rConv, aValue.getY())); if(aValue.getX() != 1.0 || aValue.getY() != 1.0) - maList.push_back(new ImpSdXMLExpTransObj2DScale(aValue)); + maList.push_back(make_unique<ImpSdXMLExpTransObj2DScale>(aValue)); Imp_SkipSpacesAndClosingBraces(aStr, nPos, nLen); } @@ -457,7 +416,7 @@ void SdXMLImExTransform2D::SetString(const OUString& rNew, const SvXMLUnitConver aValue.setY(Imp_GetDoubleChar(aStr, nPos, nLen, rConv, aValue.getY(), true)); if(!aValue.equalZero()) - maList.push_back(new ImpSdXMLExpTransObj2DTranslate(aValue)); + maList.push_back(make_unique<ImpSdXMLExpTransObj2DTranslate>(aValue)); Imp_SkipSpacesAndClosingBraces(aStr, nPos, nLen); } @@ -468,7 +427,7 @@ void SdXMLImExTransform2D::SetString(const OUString& rNew, const SvXMLUnitConver Imp_SkipSpacesAndOpeningBraces(aStr, nPos, nLen); fValue = Imp_GetDoubleChar(aStr, nPos, nLen, rConv, fValue); if(fValue != 0.0) - maList.push_back(new ImpSdXMLExpTransObj2DSkewX(fValue)); + maList.push_back(make_unique<ImpSdXMLExpTransObj2DSkewX>(fValue)); Imp_SkipSpacesAndClosingBraces(aStr, nPos, nLen); } @@ -479,7 +438,7 @@ void SdXMLImExTransform2D::SetString(const OUString& rNew, const SvXMLUnitConver Imp_SkipSpacesAndOpeningBraces(aStr, nPos, nLen); fValue = Imp_GetDoubleChar(aStr, nPos, nLen, rConv, fValue); if(fValue != 0.0) - maList.push_back(new ImpSdXMLExpTransObj2DSkewY(fValue)); + maList.push_back(make_unique<ImpSdXMLExpTransObj2DSkewY>(fValue)); Imp_SkipSpacesAndClosingBraces(aStr, nPos, nLen); } @@ -515,7 +474,7 @@ void SdXMLImExTransform2D::SetString(const OUString& rNew, const SvXMLUnitConver Imp_SkipSpacesAndCommas(aStr, nPos, nLen); if(!aValue.isIdentity()) - maList.push_back(new ImpSdXMLExpTransObj2DMatrix(aValue)); + maList.push_back(make_unique<ImpSdXMLExpTransObj2DMatrix>(aValue)); Imp_SkipSpacesAndClosingBraces(aStr, nPos, nLen); } @@ -535,7 +494,7 @@ void SdXMLImExTransform2D::GetFullTransform(::basegfx::B2DHomMatrix& rFullTrans) const sal_uInt32 nCount = maList.size(); for(sal_uInt32 a(0L); a < nCount; a++) { - ImpSdXMLExpTransObj2DBase* pObj = maList[a]; + ImpSdXMLExpTransObj2DBase* pObj = maList[a].get(); switch(pObj->mnType) { case IMP_SDXMLEXP_TRANSOBJ2D_ROTATE : @@ -592,6 +551,7 @@ struct ImpSdXMLExpTransObj3DBase sal_uInt16 mnType; explicit ImpSdXMLExpTransObj3DBase(sal_uInt16 nType) : mnType(nType) {} + virtual ~ImpSdXMLExpTransObj3DBase() {} }; // possible object types for 3D @@ -646,51 +606,6 @@ struct ImpSdXMLExpTransObj3DMatrix : public ImpSdXMLExpTransObj3DBase void SdXMLImExTransform3D::EmptyList() { - const sal_uInt32 nCount = maList.size(); - for(sal_uInt32 a(0L); a < nCount; a++) - { - ImpSdXMLExpTransObj3DBase* pObj = maList[a]; - - switch(pObj->mnType) - { - case IMP_SDXMLEXP_TRANSOBJ3D_ROTATE_X : - { - delete static_cast<ImpSdXMLExpTransObj3DRotateX*>(pObj); - break; - } - case IMP_SDXMLEXP_TRANSOBJ3D_ROTATE_Y : - { - delete static_cast<ImpSdXMLExpTransObj3DRotateY*>(pObj); - break; - } - case IMP_SDXMLEXP_TRANSOBJ3D_ROTATE_Z : - { - delete static_cast<ImpSdXMLExpTransObj3DRotateZ*>(pObj); - break; - } - case IMP_SDXMLEXP_TRANSOBJ3D_SCALE : - { - delete static_cast<ImpSdXMLExpTransObj3DScale*>(pObj); - break; - } - case IMP_SDXMLEXP_TRANSOBJ3D_TRANSLATE : - { - delete static_cast<ImpSdXMLExpTransObj3DTranslate*>(pObj); - break; - } - case IMP_SDXMLEXP_TRANSOBJ3D_MATRIX : - { - delete static_cast<ImpSdXMLExpTransObj3DMatrix*>(pObj); - break; - } - default : - { - OSL_FAIL("SdXMLImExTransform3D: impossible entry!"); - break; - } - } - } - maList.clear(); } @@ -699,7 +614,7 @@ void SdXMLImExTransform3D::EmptyList() void SdXMLImExTransform3D::AddMatrix(const ::basegfx::B3DHomMatrix& rNew) { if(!rNew.isIdentity()) - maList.push_back(new ImpSdXMLExpTransObj3DMatrix(rNew)); + maList.push_back(make_unique<ImpSdXMLExpTransObj3DMatrix>(rNew)); } void SdXMLImExTransform3D::AddHomogenMatrix(const drawing::HomogenMatrix& xHomMat) @@ -732,7 +647,7 @@ const OUString& SdXMLImExTransform3D::GetExportString(const SvXMLUnitConverter& const sal_uInt32 nCount = maList.size(); for(sal_uInt32 a(0L); a < nCount; a++) { - ImpSdXMLExpTransObj3DBase* pObj = maList[a]; + ImpSdXMLExpTransObj3DBase* pObj = maList[a].get(); switch(pObj->mnType) { case IMP_SDXMLEXP_TRANSOBJ3D_ROTATE_X : @@ -894,7 +809,7 @@ void SdXMLImExTransform3D::SetString(const OUString& rNew, const SvXMLUnitConver Imp_SkipSpacesAndOpeningBraces(aStr, nPos, nLen); fValue = Imp_GetDoubleChar(aStr, nPos, nLen, rConv, fValue); if(fValue != 0.0) - maList.push_back(new ImpSdXMLExpTransObj3DRotateX(basegfx::deg2rad(fValue))); + maList.push_back(make_unique<ImpSdXMLExpTransObj3DRotateX>(basegfx::deg2rad(fValue))); Imp_SkipSpacesAndClosingBraces(aStr, nPos, nLen); } @@ -906,7 +821,7 @@ void SdXMLImExTransform3D::SetString(const OUString& rNew, const SvXMLUnitConver Imp_SkipSpacesAndOpeningBraces(aStr, nPos, nLen); fValue = Imp_GetDoubleChar(aStr, nPos, nLen, rConv, fValue); if(fValue != 0.0) - maList.push_back(new ImpSdXMLExpTransObj3DRotateY(basegfx::deg2rad(fValue))); + maList.push_back(make_unique<ImpSdXMLExpTransObj3DRotateY>(basegfx::deg2rad(fValue))); Imp_SkipSpacesAndClosingBraces(aStr, nPos, nLen); } @@ -918,7 +833,7 @@ void SdXMLImExTransform3D::SetString(const OUString& rNew, const SvXMLUnitConver Imp_SkipSpacesAndOpeningBraces(aStr, nPos, nLen); fValue = Imp_GetDoubleChar(aStr, nPos, nLen, rConv, fValue); if(fValue != 0.0) - maList.push_back(new ImpSdXMLExpTransObj3DRotateZ(basegfx::deg2rad(fValue))); + maList.push_back(make_unique<ImpSdXMLExpTransObj3DRotateZ>(basegfx::deg2rad(fValue))); Imp_SkipSpacesAndClosingBraces(aStr, nPos, nLen); } @@ -935,7 +850,7 @@ void SdXMLImExTransform3D::SetString(const OUString& rNew, const SvXMLUnitConver aValue.setZ(Imp_GetDoubleChar(aStr, nPos, nLen, rConv, aValue.getZ())); if(1.0 != aValue.getX() || 1.0 != aValue.getY() || 1.0 != aValue.getZ()) - maList.push_back(new ImpSdXMLExpTransObj3DScale(aValue)); + maList.push_back(make_unique<ImpSdXMLExpTransObj3DScale>(aValue)); Imp_SkipSpacesAndClosingBraces(aStr, nPos, nLen); } @@ -952,7 +867,7 @@ void SdXMLImExTransform3D::SetString(const OUString& rNew, const SvXMLUnitConver aValue.setZ(Imp_GetDoubleChar(aStr, nPos, nLen, rConv, aValue.getZ(), true)); if(!aValue.equalZero()) - maList.push_back(new ImpSdXMLExpTransObj3DTranslate(aValue)); + maList.push_back(make_unique<ImpSdXMLExpTransObj3DTranslate>(aValue)); Imp_SkipSpacesAndClosingBraces(aStr, nPos, nLen); } @@ -1012,7 +927,7 @@ void SdXMLImExTransform3D::SetString(const OUString& rNew, const SvXMLUnitConver Imp_SkipSpacesAndCommas(aStr, nPos, nLen); if(!aValue.isIdentity()) - maList.push_back(new ImpSdXMLExpTransObj3DMatrix(aValue)); + maList.push_back(make_unique<ImpSdXMLExpTransObj3DMatrix>(aValue)); Imp_SkipSpacesAndClosingBraces(aStr, nPos, nLen); } @@ -1065,7 +980,7 @@ void SdXMLImExTransform3D::GetFullTransform(::basegfx::B3DHomMatrix& rFullTrans) const sal_uInt32 nCount = maList.size(); for(sal_uInt32 a(0L); a < nCount; a++) { - ImpSdXMLExpTransObj3DBase* pObj = maList[a]; + ImpSdXMLExpTransObj3DBase* pObj = maList[a].get(); switch(pObj->mnType) { case IMP_SDXMLEXP_TRANSOBJ3D_ROTATE_X : |