[Libreoffice-commits] core.git: include/formula include/o3tl

Stephan Bergmann sbergman at redhat.com
Fri Jan 9 06:45:26 PST 2015


 include/formula/tokenarray.hxx   |    4 +
 include/o3tl/typed_flags_set.hxx |  112 ++++++++++++++++++---------------------
 include/o3tl/underlying_type.hxx |   32 +++++++++++
 3 files changed, 87 insertions(+), 61 deletions(-)

New commits:
commit a1ecce3ad7df6a82191c4956cec986dc50503dde
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Fri Jan 9 15:44:29 2015 +0100

    One more place to work around missing std::underlying_type for GCC 4.6
    
    Change-Id: I46225e30f6326e0af5a8ac3bebe9847f4dbe50d0

diff --git a/include/formula/tokenarray.hxx b/include/formula/tokenarray.hxx
index d9c02da..639f8fa 100644
--- a/include/formula/tokenarray.hxx
+++ b/include/formula/tokenarray.hxx
@@ -23,6 +23,8 @@
 #include <com/sun/star/sheet/FormulaToken.hpp>
 #include <formula/token.hxx>
 #include <formula/ExternalReferenceHelper.hxx>
+#include <o3tl/underlying_type.hxx>
+
 #include <limits.h>
 #include <type_traits>
 #include <unordered_set>
@@ -90,7 +92,7 @@ public:
     inline  bool    isRewriteNeeded( OpCode eOp ) const;
 };
 
-typedef std::unordered_set<OpCode, std::hash<std::underlying_type<OpCode>::type> > unordered_opcode_set;
+typedef std::unordered_set<OpCode, std::hash<o3tl::underlying_type<OpCode>::type> > unordered_opcode_set;
 
 class FORMULA_DLLPUBLIC FormulaTokenArray
 {
diff --git a/include/o3tl/typed_flags_set.hxx b/include/o3tl/typed_flags_set.hxx
index 501a09a..001d3fe 100644
--- a/include/o3tl/typed_flags_set.hxx
+++ b/include/o3tl/typed_flags_set.hxx
@@ -23,19 +23,13 @@
 #include <sal/config.h>
 
 #include <cassert>
-#include <type_traits>
+
+#include <o3tl/underlying_type.hxx>
 
 namespace o3tl {
 
 template<typename T> struct typed_flags {};
 
-#if defined __GNUC__ && __GNUC__ == 4 && __GNUC_MINOR__ <= 7 && \
-    !defined __clang__
-#define O3TL_STD_UNDERLYING_TYPE_E signed int
-#else
-#define O3TL_STD_UNDERLYING_TYPE_E typename std::underlying_type<E>::type
-#endif
-
 /// Mark a (scoped) enumeration as a set of bit flags, with accompanying
 /// operations.
 ///
@@ -49,7 +43,7 @@ template<typename T> struct typed_flags {};
 ///
 /// \param E the enumeration type.
 /// \param M the all-bits-set value for the bit flags.
-template<typename E, O3TL_STD_UNDERLYING_TYPE_E M>
+template<typename E, typename underlying_type<E>::type M>
 struct is_typed_flags {
     static_assert(
         M >= 0, "is_typed_flags expects only non-negative bit values");
@@ -58,7 +52,7 @@ struct is_typed_flags {
 
     class Wrap {
     public:
-        explicit Wrap(O3TL_STD_UNDERLYING_TYPE_E value):
+        explicit Wrap(typename underlying_type<E>::type value):
             value_(value)
         { assert(value >= 0); }
 
@@ -67,7 +61,7 @@ struct is_typed_flags {
 #if !defined _MSC_VER || _MSC_VER > 1700
         explicit
 #endif
-        operator O3TL_STD_UNDERLYING_TYPE_E() { return value_; }
+        operator typename underlying_type<E>::type() { return value_; }
 
 #if !defined _MSC_VER || _MSC_VER > 1700
         explicit
@@ -75,20 +69,20 @@ struct is_typed_flags {
         operator bool() { return value_ != 0; }
 
     private:
-        O3TL_STD_UNDERLYING_TYPE_E value_;
+        typename underlying_type<E>::type value_;
     };
 
-    static O3TL_STD_UNDERLYING_TYPE_E const mask = M;
+    static typename underlying_type<E>::type const mask = M;
 };
 
 }
 
 template<typename E>
 inline typename o3tl::typed_flags<E>::Wrap operator ~(E rhs) {
-    assert(static_cast<O3TL_STD_UNDERLYING_TYPE_E>(rhs) >= 0);
+    assert(static_cast<typename o3tl::underlying_type<E>::type>(rhs) >= 0);
     return static_cast<typename o3tl::typed_flags<E>::Wrap>(
         o3tl::typed_flags<E>::mask
-        & ~static_cast<O3TL_STD_UNDERLYING_TYPE_E>(rhs));
+        & ~static_cast<typename o3tl::underlying_type<E>::type>(rhs));
 }
 
 template<typename E>
@@ -97,36 +91,36 @@ inline typename o3tl::typed_flags<E>::Wrap operator ~(
 {
     return static_cast<typename o3tl::typed_flags<E>::Wrap>(
         o3tl::typed_flags<E>::mask
-        & ~static_cast<O3TL_STD_UNDERLYING_TYPE_E>(rhs));
+        & ~static_cast<typename o3tl::underlying_type<E>::type>(rhs));
 }
 
 template<typename E>
 inline typename o3tl::typed_flags<E>::Wrap operator ^(E lhs, E rhs) {
-    assert(static_cast<O3TL_STD_UNDERLYING_TYPE_E>(lhs) >= 0);
-    assert(static_cast<O3TL_STD_UNDERLYING_TYPE_E>(rhs) >= 0);
+    assert(static_cast<typename o3tl::underlying_type<E>::type>(lhs) >= 0);
+    assert(static_cast<typename o3tl::underlying_type<E>::type>(rhs) >= 0);
     return static_cast<typename o3tl::typed_flags<E>::Wrap>(
-        static_cast<O3TL_STD_UNDERLYING_TYPE_E>(lhs)
-        ^ static_cast<O3TL_STD_UNDERLYING_TYPE_E>(rhs));
+        static_cast<typename o3tl::underlying_type<E>::type>(lhs)
+        ^ static_cast<typename o3tl::underlying_type<E>::type>(rhs));
 }
 
 template<typename E>
 inline typename o3tl::typed_flags<E>::Wrap operator ^(
     E lhs, typename o3tl::typed_flags<E>::Wrap rhs)
 {
-    assert(static_cast<O3TL_STD_UNDERLYING_TYPE_E>(lhs) >= 0);
+    assert(static_cast<typename o3tl::underlying_type<E>::type>(lhs) >= 0);
     return static_cast<typename o3tl::typed_flags<E>::Wrap>(
-        static_cast<O3TL_STD_UNDERLYING_TYPE_E>(lhs)
-        ^ static_cast<O3TL_STD_UNDERLYING_TYPE_E>(rhs));
+        static_cast<typename o3tl::underlying_type<E>::type>(lhs)
+        ^ static_cast<typename o3tl::underlying_type<E>::type>(rhs));
 }
 
 template<typename E>
 inline typename o3tl::typed_flags<E>::Wrap operator ^(
     typename o3tl::typed_flags<E>::Wrap lhs, E rhs)
 {
-    assert(static_cast<O3TL_STD_UNDERLYING_TYPE_E>(rhs) >= 0);
+    assert(static_cast<typename o3tl::underlying_type<E>::type>(rhs) >= 0);
     return static_cast<typename o3tl::typed_flags<E>::Wrap>(
-        static_cast<O3TL_STD_UNDERLYING_TYPE_E>(lhs)
-        ^ static_cast<O3TL_STD_UNDERLYING_TYPE_E>(rhs));
+        static_cast<typename o3tl::underlying_type<E>::type>(lhs)
+        ^ static_cast<typename o3tl::underlying_type<E>::type>(rhs));
 }
 
 template<typename E>
@@ -135,37 +129,37 @@ inline typename o3tl::typed_flags<E>::Wrap operator ^(
     typename o3tl::typed_flags<E>::Wrap rhs)
 {
     return static_cast<typename o3tl::typed_flags<E>::Wrap>(
-        static_cast<O3TL_STD_UNDERLYING_TYPE_E>(lhs)
-        ^ static_cast<O3TL_STD_UNDERLYING_TYPE_E>(rhs));
+        static_cast<typename o3tl::underlying_type<E>::type>(lhs)
+        ^ static_cast<typename o3tl::underlying_type<E>::type>(rhs));
 }
 
 template<typename E>
 inline typename o3tl::typed_flags<E>::Wrap operator &(E lhs, E rhs) {
-    assert(static_cast<O3TL_STD_UNDERLYING_TYPE_E>(lhs) >= 0);
-    assert(static_cast<O3TL_STD_UNDERLYING_TYPE_E>(rhs) >= 0);
+    assert(static_cast<typename o3tl::underlying_type<E>::type>(lhs) >= 0);
+    assert(static_cast<typename o3tl::underlying_type<E>::type>(rhs) >= 0);
     return static_cast<typename o3tl::typed_flags<E>::Wrap>(
-        static_cast<O3TL_STD_UNDERLYING_TYPE_E>(lhs)
-        & static_cast<O3TL_STD_UNDERLYING_TYPE_E>(rhs));
+        static_cast<typename o3tl::underlying_type<E>::type>(lhs)
+        & static_cast<typename o3tl::underlying_type<E>::type>(rhs));
 }
 
 template<typename E>
 inline typename o3tl::typed_flags<E>::Wrap operator &(
     E lhs, typename o3tl::typed_flags<E>::Wrap rhs)
 {
-    assert(static_cast<O3TL_STD_UNDERLYING_TYPE_E>(lhs) >= 0);
+    assert(static_cast<typename o3tl::underlying_type<E>::type>(lhs) >= 0);
     return static_cast<typename o3tl::typed_flags<E>::Wrap>(
-        static_cast<O3TL_STD_UNDERLYING_TYPE_E>(lhs)
-        & static_cast<O3TL_STD_UNDERLYING_TYPE_E>(rhs));
+        static_cast<typename o3tl::underlying_type<E>::type>(lhs)
+        & static_cast<typename o3tl::underlying_type<E>::type>(rhs));
 }
 
 template<typename E>
 inline typename o3tl::typed_flags<E>::Wrap operator &(
     typename o3tl::typed_flags<E>::Wrap lhs, E rhs)
 {
-    assert(static_cast<O3TL_STD_UNDERLYING_TYPE_E>(rhs) >= 0);
+    assert(static_cast<typename o3tl::underlying_type<E>::type>(rhs) >= 0);
     return static_cast<typename o3tl::typed_flags<E>::Wrap>(
-        static_cast<O3TL_STD_UNDERLYING_TYPE_E>(lhs)
-        & static_cast<O3TL_STD_UNDERLYING_TYPE_E>(rhs));
+        static_cast<typename o3tl::underlying_type<E>::type>(lhs)
+        & static_cast<typename o3tl::underlying_type<E>::type>(rhs));
 }
 
 template<typename E>
@@ -174,37 +168,37 @@ inline typename o3tl::typed_flags<E>::Wrap operator &(
     typename o3tl::typed_flags<E>::Wrap rhs)
 {
     return static_cast<typename o3tl::typed_flags<E>::Wrap>(
-        static_cast<O3TL_STD_UNDERLYING_TYPE_E>(lhs)
-        & static_cast<O3TL_STD_UNDERLYING_TYPE_E>(rhs));
+        static_cast<typename o3tl::underlying_type<E>::type>(lhs)
+        & static_cast<typename o3tl::underlying_type<E>::type>(rhs));
 }
 
 template<typename E>
 inline typename o3tl::typed_flags<E>::Wrap operator |(E lhs, E rhs) {
-    assert(static_cast<O3TL_STD_UNDERLYING_TYPE_E>(lhs) >= 0);
-    assert(static_cast<O3TL_STD_UNDERLYING_TYPE_E>(rhs) >= 0);
+    assert(static_cast<typename o3tl::underlying_type<E>::type>(lhs) >= 0);
+    assert(static_cast<typename o3tl::underlying_type<E>::type>(rhs) >= 0);
     return static_cast<typename o3tl::typed_flags<E>::Wrap>(
-        static_cast<O3TL_STD_UNDERLYING_TYPE_E>(lhs)
-        | static_cast<O3TL_STD_UNDERLYING_TYPE_E>(rhs));
+        static_cast<typename o3tl::underlying_type<E>::type>(lhs)
+        | static_cast<typename o3tl::underlying_type<E>::type>(rhs));
 }
 
 template<typename E>
 inline typename o3tl::typed_flags<E>::Wrap operator |(
     E lhs, typename o3tl::typed_flags<E>::Wrap rhs)
 {
-    assert(static_cast<O3TL_STD_UNDERLYING_TYPE_E>(lhs) >= 0);
+    assert(static_cast<typename o3tl::underlying_type<E>::type>(lhs) >= 0);
     return static_cast<typename o3tl::typed_flags<E>::Wrap>(
-        static_cast<O3TL_STD_UNDERLYING_TYPE_E>(lhs)
-        | static_cast<O3TL_STD_UNDERLYING_TYPE_E>(rhs));
+        static_cast<typename o3tl::underlying_type<E>::type>(lhs)
+        | static_cast<typename o3tl::underlying_type<E>::type>(rhs));
 }
 
 template<typename E>
 inline typename o3tl::typed_flags<E>::Wrap operator |(
     typename o3tl::typed_flags<E>::Wrap lhs, E rhs)
 {
-    assert(static_cast<O3TL_STD_UNDERLYING_TYPE_E>(rhs) >= 0);
+    assert(static_cast<typename o3tl::underlying_type<E>::type>(rhs) >= 0);
     return static_cast<typename o3tl::typed_flags<E>::Wrap>(
-        static_cast<O3TL_STD_UNDERLYING_TYPE_E>(lhs)
-        | static_cast<O3TL_STD_UNDERLYING_TYPE_E>(rhs));
+        static_cast<typename o3tl::underlying_type<E>::type>(lhs)
+        | static_cast<typename o3tl::underlying_type<E>::type>(rhs));
 }
 
 template<typename E>
@@ -213,14 +207,14 @@ inline typename o3tl::typed_flags<E>::Wrap operator |(
     typename o3tl::typed_flags<E>::Wrap rhs)
 {
     return static_cast<typename o3tl::typed_flags<E>::Wrap>(
-        static_cast<O3TL_STD_UNDERLYING_TYPE_E>(lhs)
-        | static_cast<O3TL_STD_UNDERLYING_TYPE_E>(rhs));
+        static_cast<typename o3tl::underlying_type<E>::type>(lhs)
+        | static_cast<typename o3tl::underlying_type<E>::type>(rhs));
 }
 
 template<typename E>
 inline typename o3tl::typed_flags<E>::Self operator &=(E & lhs, E rhs) {
-    assert(static_cast<O3TL_STD_UNDERLYING_TYPE_E>(lhs) >= 0);
-    assert(static_cast<O3TL_STD_UNDERLYING_TYPE_E>(rhs) >= 0);
+    assert(static_cast<typename o3tl::underlying_type<E>::type>(lhs) >= 0);
+    assert(static_cast<typename o3tl::underlying_type<E>::type>(rhs) >= 0);
     lhs = lhs & rhs;
     return lhs;
 }
@@ -229,15 +223,15 @@ template<typename E>
 inline typename o3tl::typed_flags<E>::Self operator &=(
     E & lhs, typename o3tl::typed_flags<E>::Wrap rhs)
 {
-    assert(static_cast<O3TL_STD_UNDERLYING_TYPE_E>(lhs) >= 0);
+    assert(static_cast<typename o3tl::underlying_type<E>::type>(lhs) >= 0);
     lhs = lhs & rhs;
     return lhs;
 }
 
 template<typename E>
 inline typename o3tl::typed_flags<E>::Self operator |=(E & lhs, E rhs) {
-    assert(static_cast<O3TL_STD_UNDERLYING_TYPE_E>(lhs) >= 0);
-    assert(static_cast<O3TL_STD_UNDERLYING_TYPE_E>(rhs) >= 0);
+    assert(static_cast<typename o3tl::underlying_type<E>::type>(lhs) >= 0);
+    assert(static_cast<typename o3tl::underlying_type<E>::type>(rhs) >= 0);
     lhs = lhs | rhs;
     return lhs;
 }
@@ -246,13 +240,11 @@ template<typename E>
 inline typename o3tl::typed_flags<E>::Self operator |=(
     E & lhs, typename o3tl::typed_flags<E>::Wrap rhs)
 {
-    assert(static_cast<O3TL_STD_UNDERLYING_TYPE_E>(lhs) >= 0);
+    assert(static_cast<typename o3tl::underlying_type<E>::type>(lhs) >= 0);
     lhs = lhs | rhs;
     return lhs;
 }
 
-#undef O3TL_STD_UNDERLYING_TYPE_E
-
 #endif /* INCLUDED_O3TL_TYPED_FLAGS_SET_HXX */
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/include/o3tl/underlying_type.hxx b/include/o3tl/underlying_type.hxx
new file mode 100644
index 0000000..3d8b625
--- /dev/null
+++ b/include/o3tl/underlying_type.hxx
@@ -0,0 +1,32 @@
+/* -*- 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_O3TL_UNDERLYING_TYPE_HXX
+#define INCLUDED_O3TL_UNDERLYING_TYPE_HXX
+
+#include <sal/config.h>
+
+#include <type_traits>
+
+namespace o3tl {
+
+template<typename T> struct underlying_type {
+#if defined __GNUC__ && __GNUC__ == 4 && __GNUC_MINOR__ <= 7 && \
+        !defined __clang__
+    typedef int type;
+#else
+    typedef typename std::underlying_type<T>::type type;
+#endif
+};
+
+}
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */


More information about the Libreoffice-commits mailing list