summaryrefslogtreecommitdiff
path: root/sw/inc/nodeoffset.hxx
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2021-10-19 09:08:35 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2021-10-21 15:25:56 +0200
commit5f9ffc31cd1b5433c354c7d39ce1d80fa0e57fc8 (patch)
tree8736f233563535eb3aa5fa019bb92a9970970428 /sw/inc/nodeoffset.hxx
parent81debfba86b1d67d1c2e0ecd9c10ca35c3e7de5e (diff)
introduce SwNodeOffset strong typedef
for indexing into node children. Replaces various usage of sal_uLong, tools::Long, sal_uInt32 with an underlying type of sal_Int32. Also add a NODE_OFFSET_MAX constant to replace usage of ULONG_MAX Change-Id: I2f466922e1ebc19029bb2883d2b29aa4c0614170 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/123892 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sw/inc/nodeoffset.hxx')
-rw-r--r--sw/inc/nodeoffset.hxx39
1 files changed, 39 insertions, 0 deletions
diff --git a/sw/inc/nodeoffset.hxx b/sw/inc/nodeoffset.hxx
new file mode 100644
index 000000000000..0911fdb67b23
--- /dev/null
+++ b/sw/inc/nodeoffset.hxx
@@ -0,0 +1,39 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
+/*
+ * 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 <sal/config.h>
+#include "swdllapi.h"
+#include <o3tl/strong_int.hxx>
+#include <iostream>
+
+typedef o3tl::strong_int<sal_Int32, struct Tag_SwNodeOffset> SwNodeOffset;
+
+/* Just to make it easier to write arithmetic with these types */
+template <typename T>
+typename std::enable_if<std::is_signed<T>::value, SwNodeOffset>::type operator+(SwNodeOffset a, T n)
+{
+ return a + SwNodeOffset(n);
+}
+
+/* Just to make it easier to write arithmetic with these types */
+template <typename T>
+typename std::enable_if<std::is_signed<T>::value, SwNodeOffset>::type operator-(SwNodeOffset a, T n)
+{
+ return a - SwNodeOffset(n);
+}
+
+inline SwNodeOffset abs(const SwNodeOffset& a) { return a > SwNodeOffset(0) ? a : -a; }
+inline SwNodeOffset min(const SwNodeOffset& a, const SwNodeOffset& b) { return a > b ? a : b; }
+
+constexpr SwNodeOffset NODE_OFFSET_MAX(SAL_MAX_INT32);
+
+SW_DLLPUBLIC std::ostream& operator<<(std::ostream& s, const SwNodeOffset& index);
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */