|
| 1 | +/* |
| 2 | + * Copyright 2021 Google LLC |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +#ifndef FIRESTORE_CORE_SRC_API_COMMON_H_ |
| 18 | +#define FIRESTORE_CORE_SRC_API_COMMON_H_ |
| 19 | + |
| 20 | +// This file is copied from |
| 21 | +// https://github.com/firebase/firebase-cpp-sdk/blob/58dbf86c8b767b90f8427275388f6309617650fa/app/src/include/firebase/internal/common.h |
| 22 | +// in order to support optional.h |
| 23 | + |
| 24 | +// Include a STL header file, othewise _STLPORT_VERSION won't be set. |
| 25 | +#include <utility> |
| 26 | + |
| 27 | +// Move operators use rvalue references, which are a C++11 extension. |
| 28 | +// Also, Visual Studio 2010 and later actually support move operators despite |
| 29 | +// reporting __cplusplus to be 199711L, so explicitly check for that. |
| 30 | +// Also, stlport doesn't implement std::move(). |
| 31 | +#if (__cplusplus >= 201103L || _MSC_VER >= 1600) && !defined(_STLPORT_VERSION) |
| 32 | +#define FIREBASE_USE_MOVE_OPERATORS |
| 33 | +#endif |
| 34 | + |
| 35 | +// stlport doesn't implement std::function. |
| 36 | +#if !defined(_STLPORT_VERSION) |
| 37 | +#define FIREBASE_USE_STD_FUNCTION |
| 38 | +#endif // !defined(_STLPORT_VERSION) |
| 39 | + |
| 40 | +// stlport doesn't implement std::aligned_storage. |
| 41 | +#if defined(_STLPORT_VERSION) |
| 42 | +#include <cstddef> |
| 43 | + |
| 44 | +namespace firebase { |
| 45 | +template <std::size_t Length, std::size_t Alignment> |
| 46 | +struct AlignedStorage { |
| 47 | + struct type { |
| 48 | + alignas(Alignment) unsigned char data[Length]; |
| 49 | + }; |
| 50 | +}; |
| 51 | +} // namespace firebase |
| 52 | +#define FIREBASE_ALIGNED_STORAGE ::firebase::AlignedStorage |
| 53 | +#else |
| 54 | +#include <type_traits> |
| 55 | +#define FIREBASE_ALIGNED_STORAGE std::aligned_storage |
| 56 | +#endif // defined(_STLPORT_VERSION) |
| 57 | + |
| 58 | +// Visual Studio 2013 does not support snprintf, so use streams instead. |
| 59 | +#if !(defined(_MSC_VER) && _MSC_VER <= 1800) |
| 60 | +#define FIREBASE_USE_SNPRINTF |
| 61 | +#endif // !(defined(_MSC_VER) && _MSC_VER <= 1800) |
| 62 | + |
| 63 | +#if !(defined(_MSC_VER) && _MSC_VER <= 1800) |
| 64 | +#define FIREBASE_USE_EXPLICIT_DEFAULT_METHODS |
| 65 | +#endif // !(defined(_MSC_VER) && _MSC_VER <= 1800) |
| 66 | + |
| 67 | +#if !defined(DOXYGEN) && !defined(SWIG) |
| 68 | +#if !defined(_WIN32) && !defined(__CYGWIN__) |
| 69 | +// Prevent GCC & Clang from stripping a symbol. |
| 70 | +#define FIREBASE_APP_KEEP_SYMBOL __attribute__((used)) |
| 71 | +#else |
| 72 | +// MSVC needs to reference a symbol directly in the application for it to be |
| 73 | +// kept in the final executable. In this case, the end user's application |
| 74 | +// must include the appropriate Firebase header (e.g firebase/analytics.h) to |
| 75 | +// initialize the module. |
| 76 | +#define FIREBASE_APP_KEEP_SYMBOL |
| 77 | +#endif // !defined(_WIN32) && !defined(__CYGWIN__) |
| 78 | + |
| 79 | +// Module initializer's name. |
| 80 | +// |
| 81 | +// This can be used to explicitly include a module initializer in an application |
| 82 | +// to prevent the object from being stripped by the linker. The symbol is |
| 83 | +// located in the "firebase" namespace so can be referenced using: |
| 84 | +// |
| 85 | +// ::firebase::FIREBASE_APP_REGISTER_CALLBACKS_REFERENCE_NAME(name) |
| 86 | +// |
| 87 | +// Where "name" is the module name, for example "analytics". |
| 88 | +#define FIREBASE_APP_REGISTER_CALLBACKS_INITIALIZER_NAME(module_name) \ |
| 89 | + g_##module_name##_initializer |
| 90 | + |
| 91 | +// Declare a module initializer variable as a global. |
| 92 | +#define FIREBASE_APP_REGISTER_CALLBACKS_INITIALIZER_VARIABLE(module_name) \ |
| 93 | + namespace firebase { \ |
| 94 | + extern void* FIREBASE_APP_REGISTER_CALLBACKS_INITIALIZER_NAME(module_name); \ |
| 95 | + } /* namespace firebase */ |
| 96 | + |
| 97 | +// Generates code which references a module initializer. |
| 98 | +// For example, FIREBASE_APP_REGISTER_REFERENCE(analytics) will register the |
| 99 | +// module initializer for the analytics module. |
| 100 | +#define FIREBASE_APP_REGISTER_CALLBACKS_REFERENCE(module_name) \ |
| 101 | + FIREBASE_APP_REGISTER_CALLBACKS_INITIALIZER_VARIABLE(module_name) \ |
| 102 | + namespace firebase { \ |
| 103 | + static void* module_name##_ref FIREBASE_APP_KEEP_SYMBOL = \ |
| 104 | + &FIREBASE_APP_REGISTER_CALLBACKS_INITIALIZER_NAME(module_name); \ |
| 105 | + } /* namespace firebase */ |
| 106 | +#endif // !defined(DOXYGEN) && !defined(SWIG) |
| 107 | + |
| 108 | +#if defined(SWIG) || defined(DOXYGEN) |
| 109 | +// SWIG needs to ignore the FIREBASE_DEPRECATED tag. |
| 110 | +#define FIREBASE_DEPRECATED |
| 111 | +#endif // defined(SWIG) || defined(DOXYGEN) |
| 112 | + |
| 113 | +#ifndef FIREBASE_DEPRECATED |
| 114 | +#ifdef __GNUC__ |
| 115 | +#define FIREBASE_DEPRECATED __attribute__((deprecated)) |
| 116 | +#elif defined(_MSC_VER) |
| 117 | +#define FIREBASE_DEPRECATED __declspec(deprecated) |
| 118 | +#else |
| 119 | +// We don't know how to mark functions as "deprecated" with this compiler. |
| 120 | +#define FIREBASE_DEPRECATED |
| 121 | +#endif |
| 122 | +#endif // FIREBASE_DEPRECATED |
| 123 | + |
| 124 | +// Calculates the number of elements in an array. |
| 125 | +#define FIREBASE_ARRAYSIZE(x) (sizeof(x) / sizeof((x)[0])) |
| 126 | + |
| 127 | +// Guaranteed compile time strlen. |
| 128 | +#define FIREBASE_STRLEN(s) (FIREBASE_ARRAYSIZE(s) - sizeof((s)[0])) |
| 129 | + |
| 130 | +#endif // FIRESTORE_CORE_SRC_API_COMMON_H_ |
0 commit comments