[Libreoffice-commits] core.git: include/vcl vcl/source
Xisco Fauli
anistenis at gmail.com
Wed Apr 27 18:49:17 UTC 2016
include/vcl/hatch.hxx | 18 ++++------
vcl/source/gdi/hatch.cxx | 78 +++++++++++++----------------------------------
2 files changed, 30 insertions(+), 66 deletions(-)
New commits:
commit 80590c1162bd7b1e3230785168dc87e0ce069f8a
Author: Xisco Fauli <anistenis at gmail.com>
Date: Tue Apr 26 00:48:57 2016 +0200
tdf#62525 vcl: use cow_wrapper for Hatch
Change-Id: I520b2a6a8c309b3702208633ed86225f61b7368c
Reviewed-on: https://gerrit.libreoffice.org/24376
Tested-by: Jenkins <ci at libreoffice.org>
Reviewed-by: Thorsten Behrens <Thorsten.Behrens at CIB.de>
diff --git a/include/vcl/hatch.hxx b/include/vcl/hatch.hxx
index 0518b29..41b9b95 100644
--- a/include/vcl/hatch.hxx
+++ b/include/vcl/hatch.hxx
@@ -24,33 +24,26 @@
#include <vcl/dllapi.h>
#include <vcl/vclenum.hxx>
+#include <o3tl/cow_wrapper.hxx>
class SvStream;
struct ImplHatch
{
- sal_uInt32 mnRefCount;
Color maColor;
HatchStyle meStyle;
long mnDistance;
sal_uInt16 mnAngle;
- ImplHatch();
- ImplHatch( const ImplHatch& rImplHatch );
+ ImplHatch();
+ ImplHatch( const ImplHatch& rImplHatch );
- friend SvStream& ReadImplHatch( SvStream& rIStm, ImplHatch& rImplHatch );
- friend SvStream& WriteImplHatch( SvStream& rOStm, const ImplHatch& rImplHatch );
+ bool operator==( const ImplHatch& rImplHatch ) const;
};
-
class VCL_DLLPUBLIC Hatch
{
-private:
-
- ImplHatch* mpImplHatch;
- SAL_DLLPRIVATE void ImplMakeUnique();
-
public:
Hatch();
@@ -75,6 +68,9 @@ public:
friend VCL_DLLPUBLIC SvStream& ReadHatch( SvStream& rIStm, Hatch& rHatch );
friend VCL_DLLPUBLIC SvStream& WriteHatch( SvStream& rOStm, const Hatch& rHatch );
+
+private:
+ o3tl::cow_wrapper< ImplHatch > mpImplHatch;
};
#endif // INCLUDED_VCL_HATCH_HXX
diff --git a/vcl/source/gdi/hatch.cxx b/vcl/source/gdi/hatch.cxx
index a8df021..cc12e5d 100644
--- a/vcl/source/gdi/hatch.cxx
+++ b/vcl/source/gdi/hatch.cxx
@@ -23,7 +23,6 @@
#include <vcl/hatch.hxx>
ImplHatch::ImplHatch() :
- mnRefCount ( 1 ),
maColor ( COL_BLACK ),
meStyle ( HATCH_SINGLE ),
mnDistance ( 1 ),
@@ -32,7 +31,6 @@ ImplHatch::ImplHatch() :
}
ImplHatch::ImplHatch( const ImplHatch& rImplHatch ) :
- mnRefCount ( 1 ),
maColor ( rImplHatch.maColor ),
meStyle ( rImplHatch.meStyle ),
mnDistance ( rImplHatch.mnDistance ),
@@ -40,21 +38,27 @@ ImplHatch::ImplHatch( const ImplHatch& rImplHatch ) :
{
}
-Hatch::Hatch()
+bool ImplHatch::operator==( const ImplHatch& rImplHatch ) const
{
- mpImplHatch = new ImplHatch;
+ if( maColor == rImplHatch.maColor &&
+ meStyle == rImplHatch.meStyle &&
+ mnDistance == rImplHatch.mnDistance &&
+ mnAngle == rImplHatch.mnAngle)
+ return true;
+ return false;
}
-Hatch::Hatch( const Hatch& rHatch )
+Hatch::Hatch() : mpImplHatch()
+{
+}
+
+Hatch::Hatch( const Hatch& rHatch ) : mpImplHatch( rHatch.mpImplHatch )
{
- mpImplHatch = rHatch.mpImplHatch;
- mpImplHatch->mnRefCount++;
}
Hatch::Hatch( HatchStyle eStyle, const Color& rColor,
- long nDistance, sal_uInt16 nAngle10 )
+ long nDistance, sal_uInt16 nAngle10 ) : mpImplHatch()
{
- mpImplHatch = new ImplHatch;
mpImplHatch->maColor = rColor;
mpImplHatch->meStyle = eStyle;
mpImplHatch->mnDistance = nDistance;
@@ -63,94 +67,58 @@ Hatch::Hatch( HatchStyle eStyle, const Color& rColor,
Hatch::~Hatch()
{
- if( !( --mpImplHatch->mnRefCount ) )
- delete mpImplHatch;
}
Hatch& Hatch::operator=( const Hatch& rHatch )
{
-
- rHatch.mpImplHatch->mnRefCount++;
-
- if( !( --mpImplHatch->mnRefCount ) )
- delete mpImplHatch;
-
mpImplHatch = rHatch.mpImplHatch;
return *this;
}
bool Hatch::operator==( const Hatch& rHatch ) const
{
-
- return( mpImplHatch == rHatch.mpImplHatch ||
- ( mpImplHatch->maColor == rHatch.mpImplHatch->maColor &&
- mpImplHatch->meStyle == rHatch.mpImplHatch->meStyle &&
- mpImplHatch->mnDistance == rHatch.mpImplHatch->mnDistance &&
- mpImplHatch->mnAngle == rHatch.mpImplHatch->mnAngle ) );
+ return mpImplHatch == rHatch.mpImplHatch;
}
-void Hatch::ImplMakeUnique()
-{
- if( mpImplHatch->mnRefCount != 1 )
- {
- if( mpImplHatch->mnRefCount )
- mpImplHatch->mnRefCount--;
-
- mpImplHatch = new ImplHatch( *mpImplHatch );
- }
-}
void Hatch::SetColor( const Color& rColor )
{
- ImplMakeUnique();
mpImplHatch->maColor = rColor;
}
void Hatch::SetDistance( long nDistance )
{
- ImplMakeUnique();
mpImplHatch->mnDistance = nDistance;
}
void Hatch::SetAngle( sal_uInt16 nAngle10 )
{
- ImplMakeUnique();
mpImplHatch->mnAngle = nAngle10;
}
-SvStream& ReadImplHatch( SvStream& rIStm, ImplHatch& rImplHatch )
+SvStream& ReadHatch( SvStream& rIStm, Hatch& rHatch )
{
VersionCompat aCompat( rIStm, StreamMode::READ );
sal_uInt16 nTmp16;
sal_Int32 nTmp32(0);
- rIStm.ReadUInt16( nTmp16 ); rImplHatch.meStyle = (HatchStyle) nTmp16;
- ReadColor( rIStm, rImplHatch.maColor ).ReadInt32( nTmp32 ).ReadUInt16( rImplHatch.mnAngle );
- rImplHatch.mnDistance = nTmp32;
+ rIStm.ReadUInt16( nTmp16 ); rHatch.mpImplHatch->meStyle = (HatchStyle) nTmp16;
+ ReadColor( rIStm, rHatch.mpImplHatch->maColor ).ReadInt32( nTmp32 ).ReadUInt16(
+ rHatch.mpImplHatch->mnAngle );
+ rHatch.mpImplHatch->mnDistance = nTmp32;
return rIStm;
}
-SvStream& WriteImplHatch( SvStream& rOStm, const ImplHatch& rImplHatch )
+SvStream& WriteHatch( SvStream& rOStm, const Hatch& rHatch )
{
VersionCompat aCompat( rOStm, StreamMode::WRITE, 1 );
- rOStm.WriteUInt16( rImplHatch.meStyle );
- WriteColor( rOStm, rImplHatch.maColor );
- rOStm.WriteInt32( rImplHatch.mnDistance ).WriteUInt16( rImplHatch.mnAngle );
+ rOStm.WriteUInt16( rHatch.mpImplHatch->meStyle );
+ WriteColor( rOStm, rHatch.mpImplHatch->maColor );
+ rOStm.WriteInt32( rHatch.mpImplHatch->mnDistance ).WriteUInt16( rHatch.mpImplHatch->mnAngle );
return rOStm;
}
-SvStream& ReadHatch( SvStream& rIStm, Hatch& rHatch )
-{
- rHatch.ImplMakeUnique();
- return ReadImplHatch( rIStm, *rHatch.mpImplHatch );
-}
-
-SvStream& WriteHatch( SvStream& rOStm, const Hatch& rHatch )
-{
- return WriteImplHatch( rOStm, *rHatch.mpImplHatch );
-}
-
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
More information about the Libreoffice-commits
mailing list