summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorMark Page <aptitude@btconnect.com>2016-05-31 12:26:28 +0100
committerNoel Grandin <noelgrandin@gmail.com>2016-06-08 11:05:30 +0000
commitf595e70cfee85a423f592190c607231cb00e3180 (patch)
tree40a57d2fa1222496081f39d5a3a05d3ccdaf7d72 /include
parent5164ac456f3cb51949fe3bec293660fab74d26de (diff)
Simplify GfxLink using smart pointers
Uses std::shared_ptr for sharing graphic data Changed constructor to std::unique_ptr<sal_uInt8[]> to ensure the delete[] operator is called when GfxLink internals takes ownership of the data Change-Id: I4edd4634df8d6ba4d94953260c1a7ac560ccf04a Reviewed-on: https://gerrit.libreoffice.org/25402 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Noel Grandin <noelgrandin@gmail.com>
Diffstat (limited to 'include')
-rw-r--r--include/vcl/gfxlink.hxx100
1 files changed, 31 insertions, 69 deletions
diff --git a/include/vcl/gfxlink.hxx b/include/vcl/gfxlink.hxx
index 864d1d6863a6..0fc6e0c26293 100644
--- a/include/vcl/gfxlink.hxx
+++ b/include/vcl/gfxlink.hxx
@@ -25,56 +25,10 @@
#include <tools/solar.h>
#include <vcl/dllapi.h>
#include <vcl/mapmod.hxx>
+#include <memory>
class SvStream;
-
-struct ImpBuffer
-{
- sal_uLong mnRefCount;
- sal_uInt8* mpBuffer;
-
- ImpBuffer( sal_uInt8* pBuf ) { mnRefCount = 1UL; mpBuffer = pBuf; }
-
- ~ImpBuffer() { delete[] mpBuffer; }
-};
-
-
-struct ImpSwap
-{
- OUString maURL;
- sal_uLong mnDataSize;
- sal_uLong mnRefCount;
-
- ImpSwap( sal_uInt8* pData, sal_uLong nDataSize );
- ~ImpSwap();
-
- sal_uInt8* GetData() const;
-
- bool IsSwapped() const { return maURL.getLength() > 0; }
-
- void WriteTo( SvStream& rOStm ) const;
-};
-
-
-struct ImpGfxLink
-{
- MapMode maPrefMapMode;
- Size maPrefSize;
- bool mbPrefMapModeValid;
- bool mbPrefSizeValid;
-
- ImpGfxLink() :
- maPrefMapMode(),
- maPrefSize(),
- mbPrefMapModeValid( false ),
- mbPrefSizeValid( false )
- {}
-};
-
-//#endif // __PRIVATE
-
-
enum class GfxLinkType
{
NONE = 0,
@@ -88,56 +42,64 @@ enum class GfxLinkType
NativePct = 8, // Don't forget to update the following defines
NativeSvg = 9, // Don't forget to update the following defines
NativeMov = 10, // Don't forget to update the following defines
- // #i15508# added BMP type support
NativeBmp = 11 // Don't forget to update the following defines
};
#define GFX_LINK_FIRST_NATIVE_ID GfxLinkType::NativeGif
#define GFX_LINK_LAST_NATIVE_ID GfxLinkType::NativeBmp
-
-struct ImpBuffer;
-struct ImpSwap;
-struct ImpGfxLink;
class Graphic;
class VCL_DLLPUBLIC GfxLink
{
private:
- GfxLinkType meType;
- ImpBuffer* mpBuf;
- ImpSwap* mpSwap;
- sal_uInt32 mnBufSize;
- sal_uInt32 mnUserId;
- ImpGfxLink* mpImpData;
+ struct SwapOutData
+ {
+ SwapOutData(const OUString &aURL);
+ ~SwapOutData();
- SAL_DLLPRIVATE void ImplCopy( const GfxLink& rGfxLink );
+ OUString maURL; // File is removed in the destructor
+ };
+
+ GfxLinkType meType = GfxLinkType::NONE;
+ sal_uInt32 mnUserId = 0;
+
+ std::shared_ptr<sal_uInt8> mpSwapInData;
+ std::shared_ptr<SwapOutData> mpSwapOutData;
+
+ sal_uInt32 mnSwapInDataSize = 0;
+ MapMode maPrefMapMode;
+ Size maPrefSize;
+ bool mbPrefMapModeValid = false;
+ bool mbPrefSizeValid = false;
+
+ SAL_DLLPRIVATE std::shared_ptr<sal_uInt8> GetSwapInData() const;
public:
GfxLink();
- GfxLink( const GfxLink& );
- GfxLink( sal_uInt8* pBuf, sal_uInt32 nBufSize, GfxLinkType nType );
+
+ // pBuff = The Graphic data. This class takes ownership of this
+ GfxLink( std::unique_ptr<sal_uInt8[]> pBuf, sal_uInt32 nBufSize, GfxLinkType nType );
~GfxLink();
- GfxLink& operator=( const GfxLink& );
- bool IsEqual( const GfxLink& ) const;
+ bool IsEqual( const GfxLink& ) const;
GfxLinkType GetType() const { return meType;}
void SetUserId( sal_uInt32 nUserId ) { mnUserId = nUserId; }
sal_uInt32 GetUserId() const { return mnUserId; }
- sal_uInt32 GetDataSize() const { return mnBufSize;}
+ sal_uInt32 GetDataSize() const { return mnSwapInDataSize;}
const sal_uInt8* GetData() const;
- const Size& GetPrefSize() const { return mpImpData->maPrefSize;}
+ const Size& GetPrefSize() const { return maPrefSize;}
void SetPrefSize( const Size& rPrefSize );
- bool IsPrefSizeValid() { return mpImpData->mbPrefSizeValid;}
+ bool IsPrefSizeValid() { return mbPrefSizeValid;}
- const MapMode& GetPrefMapMode() const { return mpImpData->maPrefMapMode;}
+ const MapMode& GetPrefMapMode() const { return maPrefMapMode;}
void SetPrefMapMode( const MapMode& rPrefMapMode );
- bool IsPrefMapModeValid() { return mpImpData->mbPrefMapModeValid;}
+ bool IsPrefMapModeValid() { return mbPrefMapModeValid;}
bool IsNative() const;
@@ -147,7 +109,7 @@ public:
void SwapOut();
void SwapIn();
- bool IsSwappedOut() const { return( mpSwap != nullptr ); }
+ bool IsSwappedOut() const { return( bool(mpSwapOutData) ); }
public: