summaryrefslogtreecommitdiffstats
path: root/sc/inc/stlalgorithm.hxx
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 16:51:28 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 16:51:28 +0000
commit940b4d1848e8c70ab7642901a68594e8016caffc (patch)
treeeb72f344ee6c3d9b80a7ecc079ea79e9fba8676d /sc/inc/stlalgorithm.hxx
parentInitial commit. (diff)
downloadlibreoffice-940b4d1848e8c70ab7642901a68594e8016caffc.tar.xz
libreoffice-940b4d1848e8c70ab7642901a68594e8016caffc.zip
Adding upstream version 1:7.0.4.upstream/1%7.0.4upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'sc/inc/stlalgorithm.hxx')
-rw-r--r--sc/inc/stlalgorithm.hxx79
1 files changed, 79 insertions, 0 deletions
diff --git a/sc/inc/stlalgorithm.hxx b/sc/inc/stlalgorithm.hxx
new file mode 100644
index 000000000..14c73f579
--- /dev/null
+++ b/sc/inc/stlalgorithm.hxx
@@ -0,0 +1,79 @@
+/* -*- 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/.
+ */
+
+#ifndef INCLUDED_SC_INC_STLALGORITHM_HXX
+#define INCLUDED_SC_INC_STLALGORITHM_HXX
+
+#include <limits>
+
+#include <rtl/alloc.h>
+
+namespace sc {
+
+/**
+ * Custom allocator for STL container to ensure that the base address of
+ * allocated storage is aligned to a specified boundary.
+ */
+template<typename T, size_t Alignment>
+class AlignedAllocator
+{
+public:
+ typedef T value_type;
+ typedef size_t size_type;
+ typedef std::ptrdiff_t difference_type;
+
+ typedef T* pointer;
+ typedef const T* const_pointer;
+ typedef T* void_pointer;
+
+ typedef T& reference;
+ typedef const T& const_reference;
+
+ template<typename Type2>
+ struct rebind
+ {
+ typedef AlignedAllocator<Type2,Alignment> other;
+ };
+
+ AlignedAllocator() {}
+
+ template<typename Type2>
+ AlignedAllocator(const AlignedAllocator<Type2,Alignment>&) {}
+
+ static void construct(T* p, const value_type& val) { new(p) value_type(val); }
+ static void destroy(T* p)
+ {
+ p->~value_type();
+ (void)p; // avoid bogus MSVC '12 "unreferenced formal parameter" warning
+ }
+
+ static size_type max_size()
+ {
+ return std::numeric_limits<size_type>::max() / sizeof(value_type);
+ }
+
+ bool operator== (const AlignedAllocator&) const { return true; }
+ bool operator!= (const AlignedAllocator&) const { return false; }
+
+ static pointer allocate(size_type n)
+ {
+ return static_cast<pointer>(rtl_allocateAlignedMemory(Alignment, n*sizeof(value_type)));
+ }
+
+ static void deallocate(pointer p, size_type)
+ {
+ rtl_freeAlignedMemory(p);
+ }
+};
+
+}
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */