LibreOffice Module vcl (master)  1
BinaryDataContainer.hxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  */
10 
11 #pragma once
12 
13 #include <vcl/dllapi.h>
14 #include <vector>
15 #include <memory>
16 
23 {
24 private:
25  // the binary data
26  std::shared_ptr<std::vector<sal_uInt8>> mpData;
27 
28 public:
30  BinaryDataContainer(const sal_uInt8* pData, size_t nSize);
31  BinaryDataContainer(std::unique_ptr<std::vector<sal_uInt8>> rData);
32 
33  BinaryDataContainer(const BinaryDataContainer& rBinaryDataContainer)
34  : mpData(rBinaryDataContainer.mpData)
35  {
36  }
37 
38  BinaryDataContainer(BinaryDataContainer&& rBinaryDataContainer) noexcept
39  : mpData(std::move(rBinaryDataContainer.mpData))
40  {
41  }
42 
43  BinaryDataContainer& operator=(const BinaryDataContainer& rBinaryDataContainer)
44  {
45  mpData = rBinaryDataContainer.mpData;
46  return *this;
47  }
48 
49  BinaryDataContainer& operator=(BinaryDataContainer&& rBinaryDataContainer) noexcept
50  {
51  mpData = std::move(rBinaryDataContainer.mpData);
52  return *this;
53  }
54 
55  size_t getSize() const { return mpData ? mpData->size() : 0; }
56  bool isEmpty() const { return !mpData || mpData->empty(); }
57  const sal_uInt8* getData() const { return mpData ? mpData->data() : nullptr; }
58 
59  size_t calculateHash() const;
60 
61  auto cbegin() { return mpData->cbegin(); }
62 
63  auto cend() { return mpData->cend(); }
64 };
65 
66 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
#define VCL_DLLPUBLIC
Definition: dllapi.h:29
BinaryDataContainer(BinaryDataContainer &&rBinaryDataContainer) noexcept
BinaryDataContainer & operator=(const BinaryDataContainer &rBinaryDataContainer)
Container for the binary data, whose responsibility is to manage the make it as simple as possible to...
BinaryDataContainer(const BinaryDataContainer &rBinaryDataContainer)
const sal_uInt8 * getData() const
std::shared_ptr< std::vector< sal_uInt8 > > mpData
unsigned char sal_uInt8
BinaryDataContainer & operator=(BinaryDataContainer &&rBinaryDataContainer) noexcept