File indexing completed on 2025-01-31 10:12:24
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021 #ifndef GOOGLE_PROTOBUF_REFLECTION_MODE_H__
0022 #define GOOGLE_PROTOBUF_REFLECTION_MODE_H__
0023
0024 #include <cstddef>
0025
0026
0027 #include "google/protobuf/port_def.inc"
0028
0029 namespace google {
0030 namespace protobuf {
0031 namespace internal {
0032
0033
0034
0035
0036
0037
0038 enum class ReflectionMode {
0039 kDefault,
0040 kDebugString,
0041 kDiagnostics,
0042 };
0043
0044
0045
0046
0047
0048
0049 ReflectionMode GetReflectionMode();
0050
0051
0052 class PROTOBUF_EXPORT ScopedReflectionMode final {
0053 public:
0054
0055
0056
0057
0058 explicit ScopedReflectionMode(ReflectionMode mode);
0059
0060
0061 ~ScopedReflectionMode();
0062
0063
0064
0065 static ReflectionMode current_reflection_mode();
0066
0067
0068
0069 ScopedReflectionMode(const ScopedReflectionMode&) = delete;
0070 ScopedReflectionMode& operator=(const ScopedReflectionMode&) = delete;
0071
0072 private:
0073 #if !defined(PROTOBUF_NO_THREADLOCAL)
0074 const ReflectionMode previous_mode_;
0075 #if defined(PROTOBUF_USE_DLLS) && defined(_WIN32)
0076
0077
0078 static ReflectionMode& reflection_mode();
0079 #else
0080 PROTOBUF_CONSTINIT static PROTOBUF_THREAD_LOCAL ReflectionMode
0081 reflection_mode_;
0082 #endif
0083 #endif
0084 };
0085
0086 #if !defined(PROTOBUF_NO_THREADLOCAL)
0087
0088 #if defined(PROTOBUF_USE_DLLS) && defined(_WIN32)
0089
0090 inline ScopedReflectionMode::ScopedReflectionMode(ReflectionMode mode)
0091 : previous_mode_(reflection_mode()) {
0092 if (mode > reflection_mode()) {
0093 reflection_mode() = mode;
0094 }
0095 }
0096
0097 inline ScopedReflectionMode::~ScopedReflectionMode() {
0098 reflection_mode() = previous_mode_;
0099 }
0100
0101 inline ReflectionMode ScopedReflectionMode::current_reflection_mode() {
0102 return reflection_mode();
0103 }
0104
0105 #else
0106
0107 inline ScopedReflectionMode::ScopedReflectionMode(ReflectionMode mode)
0108 : previous_mode_(reflection_mode_) {
0109 if (mode > reflection_mode_) {
0110 reflection_mode_ = mode;
0111 }
0112 }
0113
0114 inline ScopedReflectionMode::~ScopedReflectionMode() {
0115 reflection_mode_ = previous_mode_;
0116 }
0117
0118 inline ReflectionMode ScopedReflectionMode::current_reflection_mode() {
0119 return reflection_mode_;
0120 }
0121
0122 #endif
0123
0124 #else
0125
0126 inline ScopedReflectionMode::ScopedReflectionMode(ReflectionMode mode) {}
0127 inline ScopedReflectionMode::~ScopedReflectionMode() {}
0128 inline ReflectionMode ScopedReflectionMode::current_reflection_mode() {
0129 return ReflectionMode::kDefault;
0130 }
0131
0132 #endif
0133
0134 inline ReflectionMode GetReflectionMode() {
0135 return ScopedReflectionMode::current_reflection_mode();
0136 }
0137
0138 }
0139 }
0140 }
0141
0142 #include "google/protobuf/port_undef.inc"
0143
0144 #endif