summaryrefslogtreecommitdiff
path: root/include/vcl/BinaryDataContainer.hxx
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/vcl/BinaryDataContainer.hxx
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/vcl/BinaryDataContainer.hxx')
-rw-r--r--include/vcl/BinaryDataContainer.hxx49
1 files changed, 49 insertions, 0 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: */