summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2020-12-21 21:47:39 +0900
committerTomaž Vajngerl <quikee@gmail.com>2020-12-28 10:51:41 +0100
commitbd51df8e4e267cdad369af402bb243cb3ed222f1 (patch)
tree2a254aaab40d43f3d0c483fdc54ea6dc2fa769e5 /include
parent4c6ee7ed3d97c3a36b071336a910159fae7820e3 (diff)
vcl: add BinaryDataContainer and change GfxLink to use it
Add a wrapper for shared_ptr<sal_uInt8> called BinaryDataContainer, which is used to easily manage the binary data - mainly for a better reuse, control and to prevent duplication. Change-Id: I68140ec379dba4a5ab1b624a334129bba2401998 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/108255 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'include')
-rw-r--r--include/vcl/BinaryDataContainer.hxx49
-rw-r--r--include/vcl/gfxlink.hxx14
2 files changed, 55 insertions, 8 deletions
diff --git a/include/vcl/BinaryDataContainer.hxx b/include/vcl/BinaryDataContainer.hxx
new file mode 100644
index 000000000000..5eb5f4486b9e
--- /dev/null
+++ b/include/vcl/BinaryDataContainer.hxx
@@ -0,0 +1,49 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ */
+
+#pragma once
+
+#include <vcl/dllapi.h>
+#include <vector>
+#include <memory>
+
+/** Container for the binary data, which responsiility is to manage the
+ * make it as simple as possible to manage the binary data. The binary
+ * data can be anything, but typically it is a in-memory data from
+ * files (i.e. files of graphic formats).
+ */
+class VCL_DLLPUBLIC BinaryDataContainer final
+{
+private:
+ // the binary data
+ std::shared_ptr<std::vector<sal_uInt8>> mpData;
+
+public:
+ explicit BinaryDataContainer();
+ explicit BinaryDataContainer(size_t nSize);
+ explicit BinaryDataContainer(const sal_uInt8* pData, size_t nSize);
+
+ explicit BinaryDataContainer(const BinaryDataContainer& rBinaryDataContainer) = default;
+ explicit BinaryDataContainer(BinaryDataContainer&& rBinaryDataContainer) = default;
+ BinaryDataContainer& operator=(const BinaryDataContainer& rBinaryDataContainer) = default;
+ BinaryDataContainer& operator=(BinaryDataContainer&& rBinaryDataContainer) = default;
+
+ size_t getSize() const { return mpData ? mpData->size() : 0; }
+ bool isEmpty() const { return mpData && mpData->empty(); }
+ const sal_uInt8* getData() const { return mpData ? mpData->data() : nullptr; }
+
+ size_t calculateHash() const;
+
+ auto cbegin() { return mpData->cbegin(); }
+
+ auto cend() { return mpData->cend(); }
+};
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/include/vcl/gfxlink.hxx b/include/vcl/gfxlink.hxx
index 72352f6902a1..85bb85cb53f2 100644
--- a/include/vcl/gfxlink.hxx
+++ b/include/vcl/gfxlink.hxx
@@ -23,6 +23,7 @@
#include <tools/gen.hxx>
#include <vcl/dllapi.h>
#include <vcl/mapmod.hxx>
+#include <vcl/BinaryDataContainer.hxx>
#include <memory>
class SvStream;
@@ -61,20 +62,17 @@ class VCL_DLLPUBLIC GfxLink
private:
GfxLinkType meType;
sal_uInt32 mnUserId;
- mutable std::shared_ptr<sal_uInt8> mpSwapInData;
+ BinaryDataContainer maDataContainer;
mutable size_t maHash;
- sal_uInt32 mnSwapInDataSize;
MapMode maPrefMapMode;
Size maPrefSize;
bool mbPrefMapModeValid;
bool mbPrefSizeValid;
- SAL_DLLPRIVATE std::shared_ptr<sal_uInt8> GetSwapInData() const;
public:
- GfxLink();
-
- // pBuff = The Graphic data. This class takes ownership of this
- GfxLink( std::unique_ptr<sal_uInt8[]> pBuf, sal_uInt32 nBufSize, GfxLinkType nType );
+ GfxLink();
+ explicit GfxLink(std::unique_ptr<sal_uInt8[]> pBuf, sal_uInt32 nBufSize, GfxLinkType nType);
+ explicit GfxLink(BinaryDataContainer const & rDataConainer, GfxLinkType nType);
bool operator==( const GfxLink& ) const;
@@ -85,7 +83,7 @@ public:
void SetUserId( sal_uInt32 nUserId ) { mnUserId = nUserId; }
sal_uInt32 GetUserId() const { return mnUserId; }
- sal_uInt32 GetDataSize() const { return mnSwapInDataSize;}
+ sal_uInt32 GetDataSize() const { return maDataContainer.getSize(); }
const sal_uInt8* GetData() const;
const Size& GetPrefSize() const { return maPrefSize;}