You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by GitBox <gi...@apache.org> on 2022/09/16 17:11:43 UTC

[GitHub] [ignite-3] isapego commented on a diff in pull request #1090: IGNITE-17701 Add common C++ utilities

isapego commented on code in PR #1090:
URL: https://github.com/apache/ignite-3/pull/1090#discussion_r973208265


##########
modules/platforms/cpp/common/Bytes.h:
##########
@@ -0,0 +1,406 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include "Config.h"
+
+#include <cstddef>
+#include <cstdint>
+#include <cstring>
+#include <type_traits>
+
+#if defined(__cpp_lib_endian) && __cpp_lib_endian >= 201907L
+# define IGNITE_STD_ENDIAN 1
+#endif
+#if defined(__cpp_lib_byteswap) && __cpp_lib_byteswap >= 202110L
+# define IGNITE_STD_BYTESWAP 1
+#endif
+
+#if IGNITE_STD_ENDIAN || IGNITE_STD_BYTESWAP
+# include <bit>
+#endif
+
+#if !IGNITE_STD_ENDIAN
+# if defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
+#  define IGNITE_NATIVE_BYTE_ORDER BIG
+# elif defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
+#  define IGNITE_NATIVE_BYTE_ORDER LITTLE
+# elif defined(_WIN32)
+#  define IGNITE_NATIVE_BYTE_ORDER LITTLE
+# else
+#  error "Unknown endianess"
+# endif
+#endif
+
+#if !IGNITE_STD_BYTESWAP
+# if defined(_MSC_VER)
+#  include <cstdlib>
+#  define IGNITE_BYTESWAP_16(x) _byteswap_ushort(x)
+#  define IGNITE_BYTESWAP_32(x) _byteswap_ulong(x)
+#  define IGNITE_BYTESWAP_64(x) _byteswap_uint64(x)
+#  define IGNITE_BYTESWAP_SPECIFIER
+# elif defined(__GNUC__) || defined(__clang__)
+// Some rather old gcc and clang versions do not provide the required builtin functions. But we already
+// require C++17 support and we can safely assume that if a compiler is modern enough for this standard
+// it is also modern enough for these builtins.
+#  define IGNITE_BYTESWAP_16(x) __builtin_bswap16(x)
+#  define IGNITE_BYTESWAP_32(x) __builtin_bswap32(x)
+#  define IGNITE_BYTESWAP_64(x) __builtin_bswap64(x)
+# else
+#  define IGNITE_BYTESWAP_16(x) ignite::bytes::swap16(x)
+#  define IGNITE_BYTESWAP_32(x) ignite::bytes::swap32(x)
+#  define IGNITE_BYTESWAP_64(x) ignite::bytes::swap64(x)
+# endif
+#endif
+
+#ifndef IGNITE_BYTESWAP_SPECIFIER
+# define IGNITE_BYTESWAP_SPECIFIER constexpr
+#endif
+
+namespace ignite {
+
+/**
+ * Byte order enum.
+ */
+enum class Endian {
+#if IGNITE_STD_ENDIAN
+    LITTLE = std::endian::little,
+    BIG = std::endian::big,
+    NATIVE = std::endian::native,

Review Comment:
   `std::endian` is C++20 feature



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org