[Libreoffice-commits] core.git: config_host/config_global.h.in configure.ac include/rtl include/sal oox/source

Stephan Bergmann sbergman at redhat.com
Fri Feb 6 09:42:28 PST 2015


 config_host/config_global.h.in |    1 
 configure.ac                   |   17 ++++++
 include/rtl/ustring.hxx        |   86 ++++++++++++++++++++++++++++++
 include/sal/types.h            |   10 +++
 oox/source/export/shapes.cxx   |  116 ++++++++++++++++++++---------------------
 5 files changed, 172 insertions(+), 58 deletions(-)

New commits:
commit f1359d1221b335c4856821948f89868f021135eb
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Fri Feb 6 18:24:46 2015 +0100

    Make OUStringLiteral more useful
    
    ...don't dare make it non-explicit, yet.
    
    Along the way, introduce SAL_CONSTEXPR.
    
    Change-Id: Ia3179d0d5e001fd7aa92237c97437e9b74366ee1

diff --git a/config_host/config_global.h.in b/config_host/config_global.h.in
index ee05142..a1b8ffa 100644
--- a/config_host/config_global.h.in
+++ b/config_host/config_global.h.in
@@ -16,6 +16,7 @@ Any change in this header will cause a rebuild of almost everything.
 #define HAVE_CXX11_OVERRIDE 0
 #define HAVE_CXX11_FINAL 0
 #define HAVE_CXX11_PERFECT_FORWARDING 0
+#define HAVE_CXX11_CONSTEXPR 0
 #define HAVE_GCC_BUILTIN_ATOMIC 0
 /* _Pragma */
 #define HAVE_GCC_PRAGMA_OPERATOR 0
diff --git a/configure.ac b/configure.ac
index 950c7c8..e1f2254 100644
--- a/configure.ac
+++ b/configure.ac
@@ -6189,6 +6189,23 @@ if test "$perfect_forwarding" = yes; then
     AC_DEFINE([HAVE_CXX11_PERFECT_FORWARDING])
 fi
 
+AC_MSG_CHECKING([whether $CXX supports C++11 constexpr])
+save_CXXFLAGS=$CXXFLAGS
+CXXFLAGS="$CXXFLAGS $CXXFLAGS_CXX11"
+AC_LANG_PUSH([C++])
+AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
+    struct S {
+        int n_;
+        constexpr S(int n): n_(n) {}
+    };
+    ]])], [cxx11_constexpr=yes], [cxx11_constexpr=no])
+AC_LANG_POP([C++])
+CXXFLAGS=$save_CXXFLAGS
+AC_MSG_RESULT([$cxx11_constexpr])
+if test "$cxx11_constexpr" = yes; then
+    AC_DEFINE([HAVE_CXX11_CONSTEXPR])
+fi
+
 HAVE_GCC_PRAGMA_OPERATOR=
 dnl _Pragma support (may require C++11)
 if test "$GCC" = "yes"; then
diff --git a/include/rtl/ustring.hxx b/include/rtl/ustring.hxx
index 78a6b60..ffc5d6f 100644
--- a/include/rtl/ustring.hxx
+++ b/include/rtl/ustring.hxx
@@ -67,7 +67,8 @@ This class is not part of public API and is meant to be used only in LibreOffice
 struct SAL_WARN_UNUSED OUStringLiteral
 {
     template< int N >
-    explicit OUStringLiteral( const char (&str)[ N ] ) : size( N - 1 ), data( str ) { assert( strlen( str ) == N - 1 ); }
+    explicit SAL_CONSTEXPR OUStringLiteral( const char (&str)[ N ] ) : size( N - 1 ), data( str )
+    { /* only C++14 constexpr: assert( strlen( str ) == N - 1 ); */ }
     int size;
     const char* data;
 };
@@ -1304,6 +1305,89 @@ public:
         return !string.equalsAsciiL( literal, libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1 );
     }
 
+#if defined LIBO_INTERNAL_ONLY
+    /// @cond INTERNAL
+
+    /* Comparison between OUString and OUStringLiteral.
+
+       @since LibreOffice 4.5
+    */
+
+    friend bool operator ==(OUString const & lhs, OUStringLiteral const & rhs) {
+        return lhs.equalsAsciiL(rhs.data, rhs.size);
+    }
+
+    friend bool operator !=(OUString const & lhs, OUStringLiteral const & rhs) {
+        return !lhs.equalsAsciiL(rhs.data, rhs.size);
+    }
+
+    friend bool operator <(OUString const & lhs, OUStringLiteral const & rhs) {
+        return
+            (rtl_ustr_ascii_compare_WithLength(
+                lhs.pData->buffer, lhs.pData->length, rhs.data))
+            < 0;
+    }
+
+    friend bool operator <=(OUString const & lhs, OUStringLiteral const & rhs) {
+        return
+            (rtl_ustr_ascii_compare_WithLength(
+                lhs.pData->buffer, lhs.pData->length, rhs.data))
+            <= 0;
+    }
+
+    friend bool operator >(OUString const & lhs, OUStringLiteral const & rhs) {
+        return
+            (rtl_ustr_ascii_compare_WithLength(
+                lhs.pData->buffer, lhs.pData->length, rhs.data))
+            > 0;
+    }
+
+    friend bool operator >=(OUString const & lhs, OUStringLiteral const & rhs) {
+        return
+            (rtl_ustr_ascii_compare_WithLength(
+                lhs.pData->buffer, lhs.pData->length, rhs.data))
+            >= 0;
+    }
+
+    friend bool operator ==(OUStringLiteral const & lhs, OUString const & rhs) {
+        return rhs.equalsAsciiL(lhs.data, lhs.size);
+    }
+
+    friend bool operator !=(OUStringLiteral const & lhs, OUString const & rhs) {
+        return !rhs.equalsAsciiL(lhs.data, lhs.size);
+    }
+
+    friend bool operator <(OUStringLiteral const & lhs, OUString const & rhs) {
+        return
+            (rtl_ustr_ascii_compare_WithLength(
+                rhs.pData->buffer, rhs.pData->length, lhs.data))
+            >= 0;
+    }
+
+    friend bool operator <=(OUStringLiteral const & lhs, OUString const & rhs) {
+        return
+            (rtl_ustr_ascii_compare_WithLength(
+                rhs.pData->buffer, rhs.pData->length, lhs.data))
+            > 0;
+    }
+
+    friend bool operator >(OUStringLiteral const & lhs, OUString const & rhs) {
+        return
+            (rtl_ustr_ascii_compare_WithLength(
+                rhs.pData->buffer, rhs.pData->length, lhs.data))
+            <= 0;
+    }
+
+    friend bool operator >=(OUStringLiteral const & lhs, OUString const & rhs) {
+        return
+            (rtl_ustr_ascii_compare_WithLength(
+                rhs.pData->buffer, rhs.pData->length, lhs.data))
+            < 0;
+    }
+
+    /// @endcond
+#endif
+
     /**
       Returns a hashcode for this string.
 
diff --git a/include/sal/types.h b/include/sal/types.h
index 3d75f67..8810695 100644
--- a/include/sal/types.h
+++ b/include/sal/types.h
@@ -427,6 +427,16 @@ namespace css = ::com::sun::star;
 #define SAL_FINAL
 #endif
 
+/** C++11 "constexpr" feature.
+
+    @since LibreOffice 4.5
+*/
+#if HAVE_CXX11_CONSTEXPR
+#define SAL_CONSTEXPR constexpr
+#else
+#define SAL_CONSTEXPR
+#endif
+
 #endif /* __cplusplus */
 
 #ifdef __cplusplus
diff --git a/oox/source/export/shapes.cxx b/oox/source/export/shapes.cxx
index 2d040c7..64a0e3f 100644
--- a/oox/source/export/shapes.cxx
+++ b/oox/source/export/shapes.cxx
@@ -25,6 +25,8 @@
 #include <oox/token/tokens.hxx>
 
 #include <cstdio>
+#include <initializer_list>
+
 #include <com/sun/star/awt/CharSet.hpp>
 #include <com/sun/star/awt/FontDescriptor.hpp>
 #include <com/sun/star/awt/FontSlant.hpp>
@@ -281,60 +283,60 @@ ShapeExport& ShapeExport::WriteGroupShape(uno::Reference<drawing::XShape> xShape
 
 static bool lcl_IsOnBlacklist(OUString& rShapeType)
 {
-    static const std::vector<OUString> vBlacklist = {
-            "ring",
-            "can",
-            "cube",
-            "paper",
-            "frame",
-            "smiley",
-            "sun",
-            "flower",
-            "forbidden",
-            "bracket-pair",
-            "brace-pair",
-            "col-60da8460",
-            "col-502ad400",
-            "quad-bevel",
-            "cloud-callout",
-            "line-callout-1",
-            "line-callout-2",
-            "line-callout-3",
-            "paper",
-            "vertical-scroll",
-            "horizontal-scroll",
-            "mso-spt34",
-            "mso-spt75",
-            "mso-spt164",
-            "mso-spt180",
-            "flowchart-process",
-            "flowchart-alternate-process",
-            "flowchart-decision",
-            "flowchart-data",
-            "flowchart-predefined-process",
-            "flowchart-internal-storage",
-            "flowchart-document",
-            "flowchart-multidocument",
-            "flowchart-terminator",
-            "flowchart-preparation",
-            "flowchart-manual-input",
-            "flowchart-manual-operation",
-            "flowchart-connector",
-            "flowchart-off-page-connector",
-            "flowchart-card",
-            "flowchart-punched-tape",
-            "flowchart-summing-junction",
-            "flowchart-or",
-            "flowchart-collate",
-            "flowchart-sort",
-            "flowchart-extract",
-            "flowchart-merge",
-            "flowchart-stored-data",
-            "flowchart-delay",
-            "flowchart-sequential-access",
-            "flowchart-magnetic-disk",
-            "flowchart-direct-access-storage",
-            "flowchart-display"
+    static const std::initializer_list<OUStringLiteral> vBlacklist = {
+        OUStringLiteral("ring"),
+        OUStringLiteral("can"),
+        OUStringLiteral("cube"),
+        OUStringLiteral("paper"),
+        OUStringLiteral("frame"),
+        OUStringLiteral("smiley"),
+        OUStringLiteral("sun"),
+        OUStringLiteral("flower"),
+        OUStringLiteral("forbidden"),
+        OUStringLiteral("bracket-pair"),
+        OUStringLiteral("brace-pair"),
+        OUStringLiteral("col-60da8460"),
+        OUStringLiteral("col-502ad400"),
+        OUStringLiteral("quad-bevel"),
+        OUStringLiteral("cloud-callout"),
+        OUStringLiteral("line-callout-1"),
+        OUStringLiteral("line-callout-2"),
+        OUStringLiteral("line-callout-3"),
+        OUStringLiteral("paper"),
+        OUStringLiteral("vertical-scroll"),
+        OUStringLiteral("horizontal-scroll"),
+        OUStringLiteral("mso-spt34"),
+        OUStringLiteral("mso-spt75"),
+        OUStringLiteral("mso-spt164"),
+        OUStringLiteral("mso-spt180"),
+        OUStringLiteral("flowchart-process"),
+        OUStringLiteral("flowchart-alternate-process"),
+        OUStringLiteral("flowchart-decision"),
+        OUStringLiteral("flowchart-data"),
+        OUStringLiteral("flowchart-predefined-process"),
+        OUStringLiteral("flowchart-internal-storage"),
+        OUStringLiteral("flowchart-document"),
+        OUStringLiteral("flowchart-multidocument"),
+        OUStringLiteral("flowchart-terminator"),
+        OUStringLiteral("flowchart-preparation"),
+        OUStringLiteral("flowchart-manual-input"),
+        OUStringLiteral("flowchart-manual-operation"),
+        OUStringLiteral("flowchart-connector"),
+        OUStringLiteral("flowchart-off-page-connector"),
+        OUStringLiteral("flowchart-card"),
+        OUStringLiteral("flowchart-punched-tape"),
+        OUStringLiteral("flowchart-summing-junction"),
+        OUStringLiteral("flowchart-or"),
+        OUStringLiteral("flowchart-collate"),
+        OUStringLiteral("flowchart-sort"),
+        OUStringLiteral("flowchart-extract"),
+        OUStringLiteral("flowchart-merge"),
+        OUStringLiteral("flowchart-stored-data"),
+        OUStringLiteral("flowchart-delay"),
+        OUStringLiteral("flowchart-sequential-access"),
+        OUStringLiteral("flowchart-magnetic-disk"),
+        OUStringLiteral("flowchart-direct-access-storage"),
+        OUStringLiteral("flowchart-display")
     };
 
     return std::find(vBlacklist.begin(), vBlacklist.end(), rShapeType) != vBlacklist.end();
@@ -342,9 +344,9 @@ static bool lcl_IsOnBlacklist(OUString& rShapeType)
 
 static bool lcl_IsOnWhitelist(OUString& rShapeType)
 {
-    static const std::vector<OUString> vWhitelist = {
-            "heart",
-            "puzzle"
+    static const std::initializer_list<OUStringLiteral> vWhitelist = {
+        OUStringLiteral("heart"),
+        OUStringLiteral("puzzle")
     };
 
     return std::find(vWhitelist.begin(), vWhitelist.end(), rShapeType) != vWhitelist.end();


More information about the Libreoffice-commits mailing list