Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/absl/strings/internal/has_absl_stringify.h +55 -0
- miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/absl/strings/internal/memutil.h +148 -0
- miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/absl/strings/internal/ostringstream.h +114 -0
- miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/absl/strings/internal/resize_uninitialized.h +119 -0
- miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/absl/strings/internal/stl_type_traits.h +248 -0
- miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/absl/strings/internal/str_format/arg.h +623 -0
- miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/absl/strings/internal/str_format/bind.h +249 -0
- miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/absl/strings/internal/str_format/checker.h +100 -0
- miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/absl/strings/internal/str_format/constexpr_parser.h +351 -0
- miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/absl/strings/internal/str_format/extension.h +450 -0
- miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/absl/strings/internal/str_format/float_conversion.h +37 -0
- miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/absl/strings/internal/str_format/output.h +97 -0
- miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/absl/strings/internal/str_format/parser.h +268 -0
- miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/absl/strings/internal/str_join_internal.h +317 -0
- miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/absl/strings/internal/str_split_internal.h +431 -0
- miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/absl/strings/internal/string_constant.h +72 -0
- miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/absl/strings/internal/stringify_sink.h +57 -0
- miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/absl/strings/internal/utf8.h +50 -0
- miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/absl/synchronization/barrier.h +79 -0
- miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/absl/synchronization/blocking_counter.h +101 -0
- miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/absl/synchronization/internal/create_thread_identity.h +56 -0
- miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/absl/synchronization/internal/futex.h +157 -0
- miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/absl/synchronization/internal/graphcycles.h +141 -0
- miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/absl/synchronization/internal/kernel_timeout.h +170 -0
- miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/absl/synchronization/internal/per_thread_sem.h +110 -0
- miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/absl/synchronization/internal/waiter.h +161 -0
- miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/absl/synchronization/mutex.h +1129 -0
- miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/absl/synchronization/notification.h +123 -0
- miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/absl/time/civil_time.h +563 -0
- miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/absl/time/clock.h +74 -0
- miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/absl/time/internal/cctz/include/cctz/civil_time.h +332 -0
- miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/absl/time/internal/cctz/include/cctz/civil_time_detail.h +632 -0
- miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/absl/time/internal/cctz/include/cctz/time_zone.h +459 -0
- miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/absl/time/internal/cctz/include/cctz/zone_info_source.h +102 -0
- miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/absl/time/internal/cctz/src/time_zone_fixed.h +52 -0
- miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/absl/time/internal/cctz/src/time_zone_if.h +77 -0
- miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/absl/time/internal/cctz/src/time_zone_impl.h +93 -0
- miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/absl/time/internal/cctz/src/time_zone_info.h +137 -0
- miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/absl/time/internal/cctz/src/time_zone_libc.h +55 -0
- miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/absl/time/internal/cctz/src/time_zone_posix.h +132 -0
- miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/absl/time/internal/cctz/src/tzfile.h +122 -0
- miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/absl/time/internal/get_current_time_chrono.inc +31 -0
- miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/absl/time/internal/get_current_time_posix.inc +24 -0
- miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/absl/time/time.h +1715 -0
- miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/absl/types/bad_optional_access.h +78 -0
- miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/absl/types/bad_variant_access.h +82 -0
- miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/absl/types/compare.h +599 -0
- miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/absl/types/internal/optional.h +404 -0
- miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/absl/types/internal/span.h +139 -0
- miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/absl/types/internal/variant.h +1634 -0
miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/absl/strings/internal/has_absl_stringify.h
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2022 The Abseil Authors
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// https://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
|
| 15 |
+
#ifndef ABSL_STRINGS_INTERNAL_HAS_ABSL_STRINGIFY_H_
|
| 16 |
+
#define ABSL_STRINGS_INTERNAL_HAS_ABSL_STRINGIFY_H_
|
| 17 |
+
#include <string>
|
| 18 |
+
#include <type_traits>
|
| 19 |
+
#include <utility>
|
| 20 |
+
|
| 21 |
+
#include "absl/strings/string_view.h"
|
| 22 |
+
|
| 23 |
+
namespace absl {
|
| 24 |
+
ABSL_NAMESPACE_BEGIN
|
| 25 |
+
|
| 26 |
+
namespace strings_internal {
|
| 27 |
+
|
| 28 |
+
// This is an empty class not intended to be used. It exists so that
|
| 29 |
+
// `HasAbslStringify` can reference a universal class rather than needing to be
|
| 30 |
+
// copied for each new sink.
|
| 31 |
+
class UnimplementedSink {
|
| 32 |
+
public:
|
| 33 |
+
void Append(size_t count, char ch);
|
| 34 |
+
|
| 35 |
+
void Append(string_view v);
|
| 36 |
+
|
| 37 |
+
// Support `absl::Format(&sink, format, args...)`.
|
| 38 |
+
friend void AbslFormatFlush(UnimplementedSink* sink, absl::string_view v);
|
| 39 |
+
};
|
| 40 |
+
|
| 41 |
+
template <typename T, typename = void>
|
| 42 |
+
struct HasAbslStringify : std::false_type {};
|
| 43 |
+
|
| 44 |
+
template <typename T>
|
| 45 |
+
struct HasAbslStringify<
|
| 46 |
+
T, std::enable_if_t<std::is_void<decltype(AbslStringify(
|
| 47 |
+
std::declval<strings_internal::UnimplementedSink&>(),
|
| 48 |
+
std::declval<const T&>()))>::value>> : std::true_type {};
|
| 49 |
+
|
| 50 |
+
} // namespace strings_internal
|
| 51 |
+
|
| 52 |
+
ABSL_NAMESPACE_END
|
| 53 |
+
} // namespace absl
|
| 54 |
+
|
| 55 |
+
#endif // ABSL_STRINGS_INTERNAL_HAS_ABSL_STRINGIFY_H_
|
miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/absl/strings/internal/memutil.h
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//
|
| 2 |
+
// Copyright 2017 The Abseil Authors.
|
| 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 |
+
// https://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 |
+
// These routines provide mem versions of standard C string routines,
|
| 18 |
+
// such as strpbrk. They function exactly the same as the str versions,
|
| 19 |
+
// so if you wonder what they are, replace the word "mem" by
|
| 20 |
+
// "str" and check out the man page. I could return void*, as the
|
| 21 |
+
// strutil.h mem*() routines tend to do, but I return char* instead
|
| 22 |
+
// since this is by far the most common way these functions are called.
|
| 23 |
+
//
|
| 24 |
+
// The difference between the mem and str versions is the mem version
|
| 25 |
+
// takes a pointer and a length, rather than a '\0'-terminated string.
|
| 26 |
+
// The memcase* routines defined here assume the locale is "C"
|
| 27 |
+
// (they use absl::ascii_tolower instead of tolower).
|
| 28 |
+
//
|
| 29 |
+
// These routines are based on the BSD library.
|
| 30 |
+
//
|
| 31 |
+
// Here's a list of routines from string.h, and their mem analogues.
|
| 32 |
+
// Functions in lowercase are defined in string.h; those in UPPERCASE
|
| 33 |
+
// are defined here:
|
| 34 |
+
//
|
| 35 |
+
// strlen --
|
| 36 |
+
// strcat strncat MEMCAT
|
| 37 |
+
// strcpy strncpy memcpy
|
| 38 |
+
// -- memccpy (very cool function, btw)
|
| 39 |
+
// -- memmove
|
| 40 |
+
// -- memset
|
| 41 |
+
// strcmp strncmp memcmp
|
| 42 |
+
// strcasecmp strncasecmp MEMCASECMP
|
| 43 |
+
// strchr memchr
|
| 44 |
+
// strcoll --
|
| 45 |
+
// strxfrm --
|
| 46 |
+
// strdup strndup MEMDUP
|
| 47 |
+
// strrchr MEMRCHR
|
| 48 |
+
// strspn MEMSPN
|
| 49 |
+
// strcspn MEMCSPN
|
| 50 |
+
// strpbrk MEMPBRK
|
| 51 |
+
// strstr MEMSTR MEMMEM
|
| 52 |
+
// (g)strcasestr MEMCASESTR MEMCASEMEM
|
| 53 |
+
// strtok --
|
| 54 |
+
// strprefix MEMPREFIX (strprefix is from strutil.h)
|
| 55 |
+
// strcaseprefix MEMCASEPREFIX (strcaseprefix is from strutil.h)
|
| 56 |
+
// strsuffix MEMSUFFIX (strsuffix is from strutil.h)
|
| 57 |
+
// strcasesuffix MEMCASESUFFIX (strcasesuffix is from strutil.h)
|
| 58 |
+
// -- MEMIS
|
| 59 |
+
// -- MEMCASEIS
|
| 60 |
+
// strcount MEMCOUNT (strcount is from strutil.h)
|
| 61 |
+
|
| 62 |
+
#ifndef ABSL_STRINGS_INTERNAL_MEMUTIL_H_
|
| 63 |
+
#define ABSL_STRINGS_INTERNAL_MEMUTIL_H_
|
| 64 |
+
|
| 65 |
+
#include <cstddef>
|
| 66 |
+
#include <cstring>
|
| 67 |
+
|
| 68 |
+
#include "absl/base/port.h" // disable some warnings on Windows
|
| 69 |
+
#include "absl/strings/ascii.h" // for absl::ascii_tolower
|
| 70 |
+
|
| 71 |
+
namespace absl {
|
| 72 |
+
ABSL_NAMESPACE_BEGIN
|
| 73 |
+
namespace strings_internal {
|
| 74 |
+
|
| 75 |
+
inline char* memcat(char* dest, size_t destlen, const char* src,
|
| 76 |
+
size_t srclen) {
|
| 77 |
+
return reinterpret_cast<char*>(memcpy(dest + destlen, src, srclen));
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
int memcasecmp(const char* s1, const char* s2, size_t len);
|
| 81 |
+
char* memdup(const char* s, size_t slen);
|
| 82 |
+
char* memrchr(const char* s, int c, size_t slen);
|
| 83 |
+
size_t memspn(const char* s, size_t slen, const char* accept);
|
| 84 |
+
size_t memcspn(const char* s, size_t slen, const char* reject);
|
| 85 |
+
char* mempbrk(const char* s, size_t slen, const char* accept);
|
| 86 |
+
|
| 87 |
+
// This is for internal use only. Don't call this directly
|
| 88 |
+
template <bool case_sensitive>
|
| 89 |
+
const char* int_memmatch(const char* haystack, size_t haylen,
|
| 90 |
+
const char* needle, size_t neelen) {
|
| 91 |
+
if (0 == neelen) {
|
| 92 |
+
return haystack; // even if haylen is 0
|
| 93 |
+
}
|
| 94 |
+
const char* hayend = haystack + haylen;
|
| 95 |
+
const char* needlestart = needle;
|
| 96 |
+
const char* needleend = needlestart + neelen;
|
| 97 |
+
|
| 98 |
+
for (; haystack < hayend; ++haystack) {
|
| 99 |
+
char hay = case_sensitive
|
| 100 |
+
? *haystack
|
| 101 |
+
: absl::ascii_tolower(static_cast<unsigned char>(*haystack));
|
| 102 |
+
char nee = case_sensitive
|
| 103 |
+
? *needle
|
| 104 |
+
: absl::ascii_tolower(static_cast<unsigned char>(*needle));
|
| 105 |
+
if (hay == nee) {
|
| 106 |
+
if (++needle == needleend) {
|
| 107 |
+
return haystack + 1 - neelen;
|
| 108 |
+
}
|
| 109 |
+
} else if (needle != needlestart) {
|
| 110 |
+
// must back up haystack in case a prefix matched (find "aab" in "aaab")
|
| 111 |
+
haystack -= needle - needlestart; // for loop will advance one more
|
| 112 |
+
needle = needlestart;
|
| 113 |
+
}
|
| 114 |
+
}
|
| 115 |
+
return nullptr;
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
// These are the guys you can call directly
|
| 119 |
+
inline const char* memstr(const char* phaystack, size_t haylen,
|
| 120 |
+
const char* pneedle) {
|
| 121 |
+
return int_memmatch<true>(phaystack, haylen, pneedle, strlen(pneedle));
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
inline const char* memcasestr(const char* phaystack, size_t haylen,
|
| 125 |
+
const char* pneedle) {
|
| 126 |
+
return int_memmatch<false>(phaystack, haylen, pneedle, strlen(pneedle));
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
inline const char* memmem(const char* phaystack, size_t haylen,
|
| 130 |
+
const char* pneedle, size_t needlelen) {
|
| 131 |
+
return int_memmatch<true>(phaystack, haylen, pneedle, needlelen);
|
| 132 |
+
}
|
| 133 |
+
|
| 134 |
+
inline const char* memcasemem(const char* phaystack, size_t haylen,
|
| 135 |
+
const char* pneedle, size_t needlelen) {
|
| 136 |
+
return int_memmatch<false>(phaystack, haylen, pneedle, needlelen);
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
+
// This is significantly faster for case-sensitive matches with very
|
| 140 |
+
// few possible matches. See unit test for benchmarks.
|
| 141 |
+
const char* memmatch(const char* phaystack, size_t haylen, const char* pneedle,
|
| 142 |
+
size_t neelen);
|
| 143 |
+
|
| 144 |
+
} // namespace strings_internal
|
| 145 |
+
ABSL_NAMESPACE_END
|
| 146 |
+
} // namespace absl
|
| 147 |
+
|
| 148 |
+
#endif // ABSL_STRINGS_INTERNAL_MEMUTIL_H_
|
miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/absl/strings/internal/ostringstream.h
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2017 The Abseil Authors.
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// https://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
|
| 15 |
+
#ifndef ABSL_STRINGS_INTERNAL_OSTRINGSTREAM_H_
|
| 16 |
+
#define ABSL_STRINGS_INTERNAL_OSTRINGSTREAM_H_
|
| 17 |
+
|
| 18 |
+
#include <cassert>
|
| 19 |
+
#include <ios>
|
| 20 |
+
#include <ostream>
|
| 21 |
+
#include <streambuf>
|
| 22 |
+
#include <string>
|
| 23 |
+
#include <utility>
|
| 24 |
+
|
| 25 |
+
#include "absl/base/config.h"
|
| 26 |
+
|
| 27 |
+
namespace absl {
|
| 28 |
+
ABSL_NAMESPACE_BEGIN
|
| 29 |
+
namespace strings_internal {
|
| 30 |
+
|
| 31 |
+
// The same as std::ostringstream but appends to a user-specified std::string,
|
| 32 |
+
// and is faster. It is ~70% faster to create, ~50% faster to write to, and
|
| 33 |
+
// completely free to extract the result std::string.
|
| 34 |
+
//
|
| 35 |
+
// std::string s;
|
| 36 |
+
// OStringStream strm(&s);
|
| 37 |
+
// strm << 42 << ' ' << 3.14; // appends to `s`
|
| 38 |
+
//
|
| 39 |
+
// The stream object doesn't have to be named. Starting from C++11 operator<<
|
| 40 |
+
// works with rvalues of std::ostream.
|
| 41 |
+
//
|
| 42 |
+
// std::string s;
|
| 43 |
+
// OStringStream(&s) << 42 << ' ' << 3.14; // appends to `s`
|
| 44 |
+
//
|
| 45 |
+
// OStringStream is faster to create than std::ostringstream but it's still
|
| 46 |
+
// relatively slow. Avoid creating multiple streams where a single stream will
|
| 47 |
+
// do.
|
| 48 |
+
//
|
| 49 |
+
// Creates unnecessary instances of OStringStream: slow.
|
| 50 |
+
//
|
| 51 |
+
// std::string s;
|
| 52 |
+
// OStringStream(&s) << 42;
|
| 53 |
+
// OStringStream(&s) << ' ';
|
| 54 |
+
// OStringStream(&s) << 3.14;
|
| 55 |
+
//
|
| 56 |
+
// Creates a single instance of OStringStream and reuses it: fast.
|
| 57 |
+
//
|
| 58 |
+
// std::string s;
|
| 59 |
+
// OStringStream strm(&s);
|
| 60 |
+
// strm << 42;
|
| 61 |
+
// strm << ' ';
|
| 62 |
+
// strm << 3.14;
|
| 63 |
+
//
|
| 64 |
+
// Note: flush() has no effect. No reason to call it.
|
| 65 |
+
class OStringStream final : public std::ostream {
|
| 66 |
+
public:
|
| 67 |
+
// The argument can be null, in which case you'll need to call str(p) with a
|
| 68 |
+
// non-null argument before you can write to the stream.
|
| 69 |
+
//
|
| 70 |
+
// The destructor of OStringStream doesn't use the std::string. It's OK to
|
| 71 |
+
// destroy the std::string before the stream.
|
| 72 |
+
explicit OStringStream(std::string* str)
|
| 73 |
+
: std::ostream(&buf_), buf_(str) {}
|
| 74 |
+
OStringStream(OStringStream&& that)
|
| 75 |
+
: std::ostream(std::move(static_cast<std::ostream&>(that))),
|
| 76 |
+
buf_(that.buf_) {
|
| 77 |
+
rdbuf(&buf_);
|
| 78 |
+
}
|
| 79 |
+
OStringStream& operator=(OStringStream&& that) {
|
| 80 |
+
std::ostream::operator=(std::move(static_cast<std::ostream&>(that)));
|
| 81 |
+
buf_ = that.buf_;
|
| 82 |
+
rdbuf(&buf_);
|
| 83 |
+
return *this;
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
std::string* str() { return buf_.str(); }
|
| 87 |
+
const std::string* str() const { return buf_.str(); }
|
| 88 |
+
void str(std::string* str) { buf_.str(str); }
|
| 89 |
+
|
| 90 |
+
private:
|
| 91 |
+
class Streambuf final : public std::streambuf {
|
| 92 |
+
public:
|
| 93 |
+
explicit Streambuf(std::string* str) : str_(str) {}
|
| 94 |
+
Streambuf(const Streambuf&) = default;
|
| 95 |
+
Streambuf& operator=(const Streambuf&) = default;
|
| 96 |
+
|
| 97 |
+
std::string* str() { return str_; }
|
| 98 |
+
const std::string* str() const { return str_; }
|
| 99 |
+
void str(std::string* str) { str_ = str; }
|
| 100 |
+
|
| 101 |
+
protected:
|
| 102 |
+
int_type overflow(int c) override;
|
| 103 |
+
std::streamsize xsputn(const char* s, std::streamsize n) override;
|
| 104 |
+
|
| 105 |
+
private:
|
| 106 |
+
std::string* str_;
|
| 107 |
+
} buf_;
|
| 108 |
+
};
|
| 109 |
+
|
| 110 |
+
} // namespace strings_internal
|
| 111 |
+
ABSL_NAMESPACE_END
|
| 112 |
+
} // namespace absl
|
| 113 |
+
|
| 114 |
+
#endif // ABSL_STRINGS_INTERNAL_OSTRINGSTREAM_H_
|
miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/absl/strings/internal/resize_uninitialized.h
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//
|
| 2 |
+
// Copyright 2017 The Abseil Authors.
|
| 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 |
+
// https://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 ABSL_STRINGS_INTERNAL_RESIZE_UNINITIALIZED_H_
|
| 18 |
+
#define ABSL_STRINGS_INTERNAL_RESIZE_UNINITIALIZED_H_
|
| 19 |
+
|
| 20 |
+
#include <algorithm>
|
| 21 |
+
#include <string>
|
| 22 |
+
#include <type_traits>
|
| 23 |
+
#include <utility>
|
| 24 |
+
|
| 25 |
+
#include "absl/base/port.h"
|
| 26 |
+
#include "absl/meta/type_traits.h" // for void_t
|
| 27 |
+
|
| 28 |
+
namespace absl {
|
| 29 |
+
ABSL_NAMESPACE_BEGIN
|
| 30 |
+
namespace strings_internal {
|
| 31 |
+
|
| 32 |
+
// In this type trait, we look for a __resize_default_init member function, and
|
| 33 |
+
// we use it if available, otherwise, we use resize. We provide HasMember to
|
| 34 |
+
// indicate whether __resize_default_init is present.
|
| 35 |
+
template <typename string_type, typename = void>
|
| 36 |
+
struct ResizeUninitializedTraits {
|
| 37 |
+
using HasMember = std::false_type;
|
| 38 |
+
static void Resize(string_type* s, size_t new_size) { s->resize(new_size); }
|
| 39 |
+
};
|
| 40 |
+
|
| 41 |
+
// __resize_default_init is provided by libc++ >= 8.0
|
| 42 |
+
template <typename string_type>
|
| 43 |
+
struct ResizeUninitializedTraits<
|
| 44 |
+
string_type, absl::void_t<decltype(std::declval<string_type&>()
|
| 45 |
+
.__resize_default_init(237))> > {
|
| 46 |
+
using HasMember = std::true_type;
|
| 47 |
+
static void Resize(string_type* s, size_t new_size) {
|
| 48 |
+
s->__resize_default_init(new_size);
|
| 49 |
+
}
|
| 50 |
+
};
|
| 51 |
+
|
| 52 |
+
// Returns true if the std::string implementation supports a resize where
|
| 53 |
+
// the new characters added to the std::string are left untouched.
|
| 54 |
+
//
|
| 55 |
+
// (A better name might be "STLStringSupportsUninitializedResize", alluding to
|
| 56 |
+
// the previous function.)
|
| 57 |
+
template <typename string_type>
|
| 58 |
+
inline constexpr bool STLStringSupportsNontrashingResize(string_type*) {
|
| 59 |
+
return ResizeUninitializedTraits<string_type>::HasMember::value;
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
// Like str->resize(new_size), except any new characters added to "*str" as a
|
| 63 |
+
// result of resizing may be left uninitialized, rather than being filled with
|
| 64 |
+
// '0' bytes. Typically used when code is then going to overwrite the backing
|
| 65 |
+
// store of the std::string with known data.
|
| 66 |
+
template <typename string_type, typename = void>
|
| 67 |
+
inline void STLStringResizeUninitialized(string_type* s, size_t new_size) {
|
| 68 |
+
ResizeUninitializedTraits<string_type>::Resize(s, new_size);
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
// Used to ensure exponential growth so that the amortized complexity of
|
| 72 |
+
// increasing the string size by a small amount is O(1), in contrast to
|
| 73 |
+
// O(str->size()) in the case of precise growth.
|
| 74 |
+
template <typename string_type>
|
| 75 |
+
void STLStringReserveAmortized(string_type* s, size_t new_size) {
|
| 76 |
+
const size_t cap = s->capacity();
|
| 77 |
+
if (new_size > cap) {
|
| 78 |
+
// Make sure to always grow by at least a factor of 2x.
|
| 79 |
+
s->reserve((std::max)(new_size, 2 * cap));
|
| 80 |
+
}
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
// In this type trait, we look for an __append_default_init member function, and
|
| 84 |
+
// we use it if available, otherwise, we use append.
|
| 85 |
+
template <typename string_type, typename = void>
|
| 86 |
+
struct AppendUninitializedTraits {
|
| 87 |
+
static void Append(string_type* s, size_t n) {
|
| 88 |
+
s->append(n, typename string_type::value_type());
|
| 89 |
+
}
|
| 90 |
+
};
|
| 91 |
+
|
| 92 |
+
template <typename string_type>
|
| 93 |
+
struct AppendUninitializedTraits<
|
| 94 |
+
string_type, absl::void_t<decltype(std::declval<string_type&>()
|
| 95 |
+
.__append_default_init(237))> > {
|
| 96 |
+
static void Append(string_type* s, size_t n) {
|
| 97 |
+
s->__append_default_init(n);
|
| 98 |
+
}
|
| 99 |
+
};
|
| 100 |
+
|
| 101 |
+
// Like STLStringResizeUninitialized(str, new_size), except guaranteed to use
|
| 102 |
+
// exponential growth so that the amortized complexity of increasing the string
|
| 103 |
+
// size by a small amount is O(1), in contrast to O(str->size()) in the case of
|
| 104 |
+
// precise growth.
|
| 105 |
+
template <typename string_type>
|
| 106 |
+
void STLStringResizeUninitializedAmortized(string_type* s, size_t new_size) {
|
| 107 |
+
const size_t size = s->size();
|
| 108 |
+
if (new_size > size) {
|
| 109 |
+
AppendUninitializedTraits<string_type>::Append(s, new_size - size);
|
| 110 |
+
} else {
|
| 111 |
+
s->erase(new_size);
|
| 112 |
+
}
|
| 113 |
+
}
|
| 114 |
+
|
| 115 |
+
} // namespace strings_internal
|
| 116 |
+
ABSL_NAMESPACE_END
|
| 117 |
+
} // namespace absl
|
| 118 |
+
|
| 119 |
+
#endif // ABSL_STRINGS_INTERNAL_RESIZE_UNINITIALIZED_H_
|
miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/absl/strings/internal/stl_type_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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2017 The Abseil Authors.
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// https://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
//
|
| 15 |
+
|
| 16 |
+
// Thie file provides the IsStrictlyBaseOfAndConvertibleToSTLContainer type
|
| 17 |
+
// trait metafunction to assist in working with the _GLIBCXX_DEBUG debug
|
| 18 |
+
// wrappers of STL containers.
|
| 19 |
+
//
|
| 20 |
+
// DO NOT INCLUDE THIS FILE DIRECTLY. Use this file by including
|
| 21 |
+
// absl/strings/str_split.h.
|
| 22 |
+
//
|
| 23 |
+
// IWYU pragma: private, include "absl/strings/str_split.h"
|
| 24 |
+
|
| 25 |
+
#ifndef ABSL_STRINGS_INTERNAL_STL_TYPE_TRAITS_H_
|
| 26 |
+
#define ABSL_STRINGS_INTERNAL_STL_TYPE_TRAITS_H_
|
| 27 |
+
|
| 28 |
+
#include <array>
|
| 29 |
+
#include <bitset>
|
| 30 |
+
#include <deque>
|
| 31 |
+
#include <forward_list>
|
| 32 |
+
#include <list>
|
| 33 |
+
#include <map>
|
| 34 |
+
#include <set>
|
| 35 |
+
#include <type_traits>
|
| 36 |
+
#include <unordered_map>
|
| 37 |
+
#include <unordered_set>
|
| 38 |
+
#include <vector>
|
| 39 |
+
|
| 40 |
+
#include "absl/meta/type_traits.h"
|
| 41 |
+
|
| 42 |
+
namespace absl {
|
| 43 |
+
ABSL_NAMESPACE_BEGIN
|
| 44 |
+
namespace strings_internal {
|
| 45 |
+
|
| 46 |
+
template <typename C, template <typename...> class T>
|
| 47 |
+
struct IsSpecializationImpl : std::false_type {};
|
| 48 |
+
template <template <typename...> class T, typename... Args>
|
| 49 |
+
struct IsSpecializationImpl<T<Args...>, T> : std::true_type {};
|
| 50 |
+
template <typename C, template <typename...> class T>
|
| 51 |
+
using IsSpecialization = IsSpecializationImpl<absl::decay_t<C>, T>;
|
| 52 |
+
|
| 53 |
+
template <typename C>
|
| 54 |
+
struct IsArrayImpl : std::false_type {};
|
| 55 |
+
template <template <typename, size_t> class A, typename T, size_t N>
|
| 56 |
+
struct IsArrayImpl<A<T, N>> : std::is_same<A<T, N>, std::array<T, N>> {};
|
| 57 |
+
template <typename C>
|
| 58 |
+
using IsArray = IsArrayImpl<absl::decay_t<C>>;
|
| 59 |
+
|
| 60 |
+
template <typename C>
|
| 61 |
+
struct IsBitsetImpl : std::false_type {};
|
| 62 |
+
template <template <size_t> class B, size_t N>
|
| 63 |
+
struct IsBitsetImpl<B<N>> : std::is_same<B<N>, std::bitset<N>> {};
|
| 64 |
+
template <typename C>
|
| 65 |
+
using IsBitset = IsBitsetImpl<absl::decay_t<C>>;
|
| 66 |
+
|
| 67 |
+
template <typename C>
|
| 68 |
+
struct IsSTLContainer
|
| 69 |
+
: absl::disjunction<
|
| 70 |
+
IsArray<C>, IsBitset<C>, IsSpecialization<C, std::deque>,
|
| 71 |
+
IsSpecialization<C, std::forward_list>,
|
| 72 |
+
IsSpecialization<C, std::list>, IsSpecialization<C, std::map>,
|
| 73 |
+
IsSpecialization<C, std::multimap>, IsSpecialization<C, std::set>,
|
| 74 |
+
IsSpecialization<C, std::multiset>,
|
| 75 |
+
IsSpecialization<C, std::unordered_map>,
|
| 76 |
+
IsSpecialization<C, std::unordered_multimap>,
|
| 77 |
+
IsSpecialization<C, std::unordered_set>,
|
| 78 |
+
IsSpecialization<C, std::unordered_multiset>,
|
| 79 |
+
IsSpecialization<C, std::vector>> {};
|
| 80 |
+
|
| 81 |
+
template <typename C, template <typename...> class T, typename = void>
|
| 82 |
+
struct IsBaseOfSpecializationImpl : std::false_type {};
|
| 83 |
+
// IsBaseOfSpecializationImpl needs multiple partial specializations to SFINAE
|
| 84 |
+
// on the existence of container dependent types and plug them into the STL
|
| 85 |
+
// template.
|
| 86 |
+
template <typename C, template <typename, typename> class T>
|
| 87 |
+
struct IsBaseOfSpecializationImpl<
|
| 88 |
+
C, T, absl::void_t<typename C::value_type, typename C::allocator_type>>
|
| 89 |
+
: std::is_base_of<C,
|
| 90 |
+
T<typename C::value_type, typename C::allocator_type>> {};
|
| 91 |
+
template <typename C, template <typename, typename, typename> class T>
|
| 92 |
+
struct IsBaseOfSpecializationImpl<
|
| 93 |
+
C, T,
|
| 94 |
+
absl::void_t<typename C::key_type, typename C::key_compare,
|
| 95 |
+
typename C::allocator_type>>
|
| 96 |
+
: std::is_base_of<C, T<typename C::key_type, typename C::key_compare,
|
| 97 |
+
typename C::allocator_type>> {};
|
| 98 |
+
template <typename C, template <typename, typename, typename, typename> class T>
|
| 99 |
+
struct IsBaseOfSpecializationImpl<
|
| 100 |
+
C, T,
|
| 101 |
+
absl::void_t<typename C::key_type, typename C::mapped_type,
|
| 102 |
+
typename C::key_compare, typename C::allocator_type>>
|
| 103 |
+
: std::is_base_of<C,
|
| 104 |
+
T<typename C::key_type, typename C::mapped_type,
|
| 105 |
+
typename C::key_compare, typename C::allocator_type>> {
|
| 106 |
+
};
|
| 107 |
+
template <typename C, template <typename, typename, typename, typename> class T>
|
| 108 |
+
struct IsBaseOfSpecializationImpl<
|
| 109 |
+
C, T,
|
| 110 |
+
absl::void_t<typename C::key_type, typename C::hasher,
|
| 111 |
+
typename C::key_equal, typename C::allocator_type>>
|
| 112 |
+
: std::is_base_of<C, T<typename C::key_type, typename C::hasher,
|
| 113 |
+
typename C::key_equal, typename C::allocator_type>> {
|
| 114 |
+
};
|
| 115 |
+
template <typename C,
|
| 116 |
+
template <typename, typename, typename, typename, typename> class T>
|
| 117 |
+
struct IsBaseOfSpecializationImpl<
|
| 118 |
+
C, T,
|
| 119 |
+
absl::void_t<typename C::key_type, typename C::mapped_type,
|
| 120 |
+
typename C::hasher, typename C::key_equal,
|
| 121 |
+
typename C::allocator_type>>
|
| 122 |
+
: std::is_base_of<C, T<typename C::key_type, typename C::mapped_type,
|
| 123 |
+
typename C::hasher, typename C::key_equal,
|
| 124 |
+
typename C::allocator_type>> {};
|
| 125 |
+
template <typename C, template <typename...> class T>
|
| 126 |
+
using IsBaseOfSpecialization = IsBaseOfSpecializationImpl<absl::decay_t<C>, T>;
|
| 127 |
+
|
| 128 |
+
template <typename C>
|
| 129 |
+
struct IsBaseOfArrayImpl : std::false_type {};
|
| 130 |
+
template <template <typename, size_t> class A, typename T, size_t N>
|
| 131 |
+
struct IsBaseOfArrayImpl<A<T, N>> : std::is_base_of<A<T, N>, std::array<T, N>> {
|
| 132 |
+
};
|
| 133 |
+
template <typename C>
|
| 134 |
+
using IsBaseOfArray = IsBaseOfArrayImpl<absl::decay_t<C>>;
|
| 135 |
+
|
| 136 |
+
template <typename C>
|
| 137 |
+
struct IsBaseOfBitsetImpl : std::false_type {};
|
| 138 |
+
template <template <size_t> class B, size_t N>
|
| 139 |
+
struct IsBaseOfBitsetImpl<B<N>> : std::is_base_of<B<N>, std::bitset<N>> {};
|
| 140 |
+
template <typename C>
|
| 141 |
+
using IsBaseOfBitset = IsBaseOfBitsetImpl<absl::decay_t<C>>;
|
| 142 |
+
|
| 143 |
+
template <typename C>
|
| 144 |
+
struct IsBaseOfSTLContainer
|
| 145 |
+
: absl::disjunction<IsBaseOfArray<C>, IsBaseOfBitset<C>,
|
| 146 |
+
IsBaseOfSpecialization<C, std::deque>,
|
| 147 |
+
IsBaseOfSpecialization<C, std::forward_list>,
|
| 148 |
+
IsBaseOfSpecialization<C, std::list>,
|
| 149 |
+
IsBaseOfSpecialization<C, std::map>,
|
| 150 |
+
IsBaseOfSpecialization<C, std::multimap>,
|
| 151 |
+
IsBaseOfSpecialization<C, std::set>,
|
| 152 |
+
IsBaseOfSpecialization<C, std::multiset>,
|
| 153 |
+
IsBaseOfSpecialization<C, std::unordered_map>,
|
| 154 |
+
IsBaseOfSpecialization<C, std::unordered_multimap>,
|
| 155 |
+
IsBaseOfSpecialization<C, std::unordered_set>,
|
| 156 |
+
IsBaseOfSpecialization<C, std::unordered_multiset>,
|
| 157 |
+
IsBaseOfSpecialization<C, std::vector>> {};
|
| 158 |
+
|
| 159 |
+
template <typename C, template <typename...> class T, typename = void>
|
| 160 |
+
struct IsConvertibleToSpecializationImpl : std::false_type {};
|
| 161 |
+
// IsConvertibleToSpecializationImpl needs multiple partial specializations to
|
| 162 |
+
// SFINAE on the existence of container dependent types and plug them into the
|
| 163 |
+
// STL template.
|
| 164 |
+
template <typename C, template <typename, typename> class T>
|
| 165 |
+
struct IsConvertibleToSpecializationImpl<
|
| 166 |
+
C, T, absl::void_t<typename C::value_type, typename C::allocator_type>>
|
| 167 |
+
: std::is_convertible<
|
| 168 |
+
C, T<typename C::value_type, typename C::allocator_type>> {};
|
| 169 |
+
template <typename C, template <typename, typename, typename> class T>
|
| 170 |
+
struct IsConvertibleToSpecializationImpl<
|
| 171 |
+
C, T,
|
| 172 |
+
absl::void_t<typename C::key_type, typename C::key_compare,
|
| 173 |
+
typename C::allocator_type>>
|
| 174 |
+
: std::is_convertible<C, T<typename C::key_type, typename C::key_compare,
|
| 175 |
+
typename C::allocator_type>> {};
|
| 176 |
+
template <typename C, template <typename, typename, typename, typename> class T>
|
| 177 |
+
struct IsConvertibleToSpecializationImpl<
|
| 178 |
+
C, T,
|
| 179 |
+
absl::void_t<typename C::key_type, typename C::mapped_type,
|
| 180 |
+
typename C::key_compare, typename C::allocator_type>>
|
| 181 |
+
: std::is_convertible<
|
| 182 |
+
C, T<typename C::key_type, typename C::mapped_type,
|
| 183 |
+
typename C::key_compare, typename C::allocator_type>> {};
|
| 184 |
+
template <typename C, template <typename, typename, typename, typename> class T>
|
| 185 |
+
struct IsConvertibleToSpecializationImpl<
|
| 186 |
+
C, T,
|
| 187 |
+
absl::void_t<typename C::key_type, typename C::hasher,
|
| 188 |
+
typename C::key_equal, typename C::allocator_type>>
|
| 189 |
+
: std::is_convertible<
|
| 190 |
+
C, T<typename C::key_type, typename C::hasher, typename C::key_equal,
|
| 191 |
+
typename C::allocator_type>> {};
|
| 192 |
+
template <typename C,
|
| 193 |
+
template <typename, typename, typename, typename, typename> class T>
|
| 194 |
+
struct IsConvertibleToSpecializationImpl<
|
| 195 |
+
C, T,
|
| 196 |
+
absl::void_t<typename C::key_type, typename C::mapped_type,
|
| 197 |
+
typename C::hasher, typename C::key_equal,
|
| 198 |
+
typename C::allocator_type>>
|
| 199 |
+
: std::is_convertible<C, T<typename C::key_type, typename C::mapped_type,
|
| 200 |
+
typename C::hasher, typename C::key_equal,
|
| 201 |
+
typename C::allocator_type>> {};
|
| 202 |
+
template <typename C, template <typename...> class T>
|
| 203 |
+
using IsConvertibleToSpecialization =
|
| 204 |
+
IsConvertibleToSpecializationImpl<absl::decay_t<C>, T>;
|
| 205 |
+
|
| 206 |
+
template <typename C>
|
| 207 |
+
struct IsConvertibleToArrayImpl : std::false_type {};
|
| 208 |
+
template <template <typename, size_t> class A, typename T, size_t N>
|
| 209 |
+
struct IsConvertibleToArrayImpl<A<T, N>>
|
| 210 |
+
: std::is_convertible<A<T, N>, std::array<T, N>> {};
|
| 211 |
+
template <typename C>
|
| 212 |
+
using IsConvertibleToArray = IsConvertibleToArrayImpl<absl::decay_t<C>>;
|
| 213 |
+
|
| 214 |
+
template <typename C>
|
| 215 |
+
struct IsConvertibleToBitsetImpl : std::false_type {};
|
| 216 |
+
template <template <size_t> class B, size_t N>
|
| 217 |
+
struct IsConvertibleToBitsetImpl<B<N>>
|
| 218 |
+
: std::is_convertible<B<N>, std::bitset<N>> {};
|
| 219 |
+
template <typename C>
|
| 220 |
+
using IsConvertibleToBitset = IsConvertibleToBitsetImpl<absl::decay_t<C>>;
|
| 221 |
+
|
| 222 |
+
template <typename C>
|
| 223 |
+
struct IsConvertibleToSTLContainer
|
| 224 |
+
: absl::disjunction<
|
| 225 |
+
IsConvertibleToArray<C>, IsConvertibleToBitset<C>,
|
| 226 |
+
IsConvertibleToSpecialization<C, std::deque>,
|
| 227 |
+
IsConvertibleToSpecialization<C, std::forward_list>,
|
| 228 |
+
IsConvertibleToSpecialization<C, std::list>,
|
| 229 |
+
IsConvertibleToSpecialization<C, std::map>,
|
| 230 |
+
IsConvertibleToSpecialization<C, std::multimap>,
|
| 231 |
+
IsConvertibleToSpecialization<C, std::set>,
|
| 232 |
+
IsConvertibleToSpecialization<C, std::multiset>,
|
| 233 |
+
IsConvertibleToSpecialization<C, std::unordered_map>,
|
| 234 |
+
IsConvertibleToSpecialization<C, std::unordered_multimap>,
|
| 235 |
+
IsConvertibleToSpecialization<C, std::unordered_set>,
|
| 236 |
+
IsConvertibleToSpecialization<C, std::unordered_multiset>,
|
| 237 |
+
IsConvertibleToSpecialization<C, std::vector>> {};
|
| 238 |
+
|
| 239 |
+
template <typename C>
|
| 240 |
+
struct IsStrictlyBaseOfAndConvertibleToSTLContainer
|
| 241 |
+
: absl::conjunction<absl::negation<IsSTLContainer<C>>,
|
| 242 |
+
IsBaseOfSTLContainer<C>,
|
| 243 |
+
IsConvertibleToSTLContainer<C>> {};
|
| 244 |
+
|
| 245 |
+
} // namespace strings_internal
|
| 246 |
+
ABSL_NAMESPACE_END
|
| 247 |
+
} // namespace absl
|
| 248 |
+
#endif // ABSL_STRINGS_INTERNAL_STL_TYPE_TRAITS_H_
|
miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/absl/strings/internal/str_format/arg.h
ADDED
|
@@ -0,0 +1,623 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
| 1 |
+
// Copyright 2020 The Abseil Authors.
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// https://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
|
| 15 |
+
#ifndef ABSL_STRINGS_INTERNAL_STR_FORMAT_ARG_H_
|
| 16 |
+
#define ABSL_STRINGS_INTERNAL_STR_FORMAT_ARG_H_
|
| 17 |
+
|
| 18 |
+
#include <string.h>
|
| 19 |
+
#include <wchar.h>
|
| 20 |
+
|
| 21 |
+
#include <algorithm>
|
| 22 |
+
#include <cstdio>
|
| 23 |
+
#include <iomanip>
|
| 24 |
+
#include <limits>
|
| 25 |
+
#include <memory>
|
| 26 |
+
#include <sstream>
|
| 27 |
+
#include <string>
|
| 28 |
+
#include <type_traits>
|
| 29 |
+
#include <utility>
|
| 30 |
+
|
| 31 |
+
#include "absl/base/port.h"
|
| 32 |
+
#include "absl/meta/type_traits.h"
|
| 33 |
+
#include "absl/numeric/int128.h"
|
| 34 |
+
#include "absl/strings/internal/has_absl_stringify.h"
|
| 35 |
+
#include "absl/strings/internal/str_format/extension.h"
|
| 36 |
+
#include "absl/strings/string_view.h"
|
| 37 |
+
|
| 38 |
+
namespace absl {
|
| 39 |
+
ABSL_NAMESPACE_BEGIN
|
| 40 |
+
|
| 41 |
+
class Cord;
|
| 42 |
+
class FormatCountCapture;
|
| 43 |
+
class FormatSink;
|
| 44 |
+
|
| 45 |
+
template <absl::FormatConversionCharSet C>
|
| 46 |
+
struct FormatConvertResult;
|
| 47 |
+
class FormatConversionSpec;
|
| 48 |
+
|
| 49 |
+
namespace str_format_internal {
|
| 50 |
+
|
| 51 |
+
template <FormatConversionCharSet C>
|
| 52 |
+
struct ArgConvertResult {
|
| 53 |
+
bool value;
|
| 54 |
+
};
|
| 55 |
+
|
| 56 |
+
using IntegralConvertResult = ArgConvertResult<FormatConversionCharSetUnion(
|
| 57 |
+
FormatConversionCharSetInternal::c,
|
| 58 |
+
FormatConversionCharSetInternal::kNumeric,
|
| 59 |
+
FormatConversionCharSetInternal::kStar,
|
| 60 |
+
FormatConversionCharSetInternal::v)>;
|
| 61 |
+
using FloatingConvertResult = ArgConvertResult<FormatConversionCharSetUnion(
|
| 62 |
+
FormatConversionCharSetInternal::kFloating,
|
| 63 |
+
FormatConversionCharSetInternal::v)>;
|
| 64 |
+
using CharConvertResult = ArgConvertResult<FormatConversionCharSetUnion(
|
| 65 |
+
FormatConversionCharSetInternal::c,
|
| 66 |
+
FormatConversionCharSetInternal::kNumeric,
|
| 67 |
+
FormatConversionCharSetInternal::kStar)>;
|
| 68 |
+
|
| 69 |
+
template <typename T, typename = void>
|
| 70 |
+
struct HasUserDefinedConvert : std::false_type {};
|
| 71 |
+
|
| 72 |
+
template <typename T>
|
| 73 |
+
struct HasUserDefinedConvert<T, void_t<decltype(AbslFormatConvert(
|
| 74 |
+
std::declval<const T&>(),
|
| 75 |
+
std::declval<const FormatConversionSpec&>(),
|
| 76 |
+
std::declval<FormatSink*>()))>>
|
| 77 |
+
: std::true_type {};
|
| 78 |
+
|
| 79 |
+
// These declarations prevent ADL lookup from continuing in absl namespaces,
|
| 80 |
+
// we are deliberately using these as ADL hooks and want them to consider
|
| 81 |
+
// non-absl namespaces only.
|
| 82 |
+
void AbslFormatConvert();
|
| 83 |
+
void AbslStringify();
|
| 84 |
+
|
| 85 |
+
template <typename T>
|
| 86 |
+
bool ConvertIntArg(T v, FormatConversionSpecImpl conv, FormatSinkImpl* sink);
|
| 87 |
+
|
| 88 |
+
// Forward declarations of internal `ConvertIntArg` function template
|
| 89 |
+
// instantiations are here to avoid including the template body in the headers
|
| 90 |
+
// and instantiating it in large numbers of translation units. Explicit
|
| 91 |
+
// instantiations can be found in "absl/strings/internal/str_format/arg.cc"
|
| 92 |
+
extern template bool ConvertIntArg<char>(char v, FormatConversionSpecImpl conv,
|
| 93 |
+
FormatSinkImpl* sink);
|
| 94 |
+
extern template bool ConvertIntArg<signed char>(signed char v,
|
| 95 |
+
FormatConversionSpecImpl conv,
|
| 96 |
+
FormatSinkImpl* sink);
|
| 97 |
+
extern template bool ConvertIntArg<unsigned char>(unsigned char v,
|
| 98 |
+
FormatConversionSpecImpl conv,
|
| 99 |
+
FormatSinkImpl* sink);
|
| 100 |
+
extern template bool ConvertIntArg<short>(short v, // NOLINT
|
| 101 |
+
FormatConversionSpecImpl conv,
|
| 102 |
+
FormatSinkImpl* sink);
|
| 103 |
+
extern template bool ConvertIntArg<unsigned short>( // NOLINT
|
| 104 |
+
unsigned short v, FormatConversionSpecImpl conv, // NOLINT
|
| 105 |
+
FormatSinkImpl* sink);
|
| 106 |
+
extern template bool ConvertIntArg<int>(int v, FormatConversionSpecImpl conv,
|
| 107 |
+
FormatSinkImpl* sink);
|
| 108 |
+
extern template bool ConvertIntArg<unsigned int>(unsigned int v,
|
| 109 |
+
FormatConversionSpecImpl conv,
|
| 110 |
+
FormatSinkImpl* sink);
|
| 111 |
+
extern template bool ConvertIntArg<long>( // NOLINT
|
| 112 |
+
long v, FormatConversionSpecImpl conv, FormatSinkImpl* sink); // NOLINT
|
| 113 |
+
extern template bool ConvertIntArg<unsigned long>(unsigned long v, // NOLINT
|
| 114 |
+
FormatConversionSpecImpl conv,
|
| 115 |
+
FormatSinkImpl* sink);
|
| 116 |
+
extern template bool ConvertIntArg<long long>(long long v, // NOLINT
|
| 117 |
+
FormatConversionSpecImpl conv,
|
| 118 |
+
FormatSinkImpl* sink);
|
| 119 |
+
extern template bool ConvertIntArg<unsigned long long>( // NOLINT
|
| 120 |
+
unsigned long long v, FormatConversionSpecImpl conv, // NOLINT
|
| 121 |
+
FormatSinkImpl* sink);
|
| 122 |
+
|
| 123 |
+
template <typename T>
|
| 124 |
+
auto FormatConvertImpl(const T& v, FormatConversionSpecImpl conv,
|
| 125 |
+
FormatSinkImpl* sink)
|
| 126 |
+
-> decltype(AbslFormatConvert(v,
|
| 127 |
+
std::declval<const FormatConversionSpec&>(),
|
| 128 |
+
std::declval<FormatSink*>())) {
|
| 129 |
+
using FormatConversionSpecT =
|
| 130 |
+
absl::enable_if_t<sizeof(const T& (*)()) != 0, FormatConversionSpec>;
|
| 131 |
+
using FormatSinkT =
|
| 132 |
+
absl::enable_if_t<sizeof(const T& (*)()) != 0, FormatSink>;
|
| 133 |
+
auto fcs = conv.Wrap<FormatConversionSpecT>();
|
| 134 |
+
auto fs = sink->Wrap<FormatSinkT>();
|
| 135 |
+
return AbslFormatConvert(v, fcs, &fs);
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
template <typename T>
|
| 139 |
+
auto FormatConvertImpl(const T& v, FormatConversionSpecImpl conv,
|
| 140 |
+
FormatSinkImpl* sink)
|
| 141 |
+
-> std::enable_if_t<std::is_enum<T>::value &&
|
| 142 |
+
std::is_void<decltype(AbslStringify(
|
| 143 |
+
std::declval<FormatSink&>(), v))>::value,
|
| 144 |
+
IntegralConvertResult> {
|
| 145 |
+
if (conv.conversion_char() == FormatConversionCharInternal::v) {
|
| 146 |
+
using FormatSinkT =
|
| 147 |
+
absl::enable_if_t<sizeof(const T& (*)()) != 0, FormatSink>;
|
| 148 |
+
auto fs = sink->Wrap<FormatSinkT>();
|
| 149 |
+
AbslStringify(fs, v);
|
| 150 |
+
return {true};
|
| 151 |
+
} else {
|
| 152 |
+
return {ConvertIntArg(
|
| 153 |
+
static_cast<typename std::underlying_type<T>::type>(v), conv, sink)};
|
| 154 |
+
}
|
| 155 |
+
}
|
| 156 |
+
|
| 157 |
+
template <typename T>
|
| 158 |
+
auto FormatConvertImpl(const T& v, FormatConversionSpecImpl,
|
| 159 |
+
FormatSinkImpl* sink)
|
| 160 |
+
-> std::enable_if_t<!std::is_enum<T>::value &&
|
| 161 |
+
std::is_void<decltype(AbslStringify(
|
| 162 |
+
std::declval<FormatSink&>(), v))>::value,
|
| 163 |
+
ArgConvertResult<FormatConversionCharSetInternal::v>> {
|
| 164 |
+
using FormatSinkT =
|
| 165 |
+
absl::enable_if_t<sizeof(const T& (*)()) != 0, FormatSink>;
|
| 166 |
+
auto fs = sink->Wrap<FormatSinkT>();
|
| 167 |
+
AbslStringify(fs, v);
|
| 168 |
+
return {true};
|
| 169 |
+
}
|
| 170 |
+
|
| 171 |
+
template <typename T>
|
| 172 |
+
class StreamedWrapper;
|
| 173 |
+
|
| 174 |
+
// If 'v' can be converted (in the printf sense) according to 'conv',
|
| 175 |
+
// then convert it, appending to `sink` and return `true`.
|
| 176 |
+
// Otherwise fail and return `false`.
|
| 177 |
+
|
| 178 |
+
// AbslFormatConvert(v, conv, sink) is intended to be found by ADL on 'v'
|
| 179 |
+
// as an extension mechanism. These FormatConvertImpl functions are the default
|
| 180 |
+
// implementations.
|
| 181 |
+
// The ADL search is augmented via the 'Sink*' parameter, which also
|
| 182 |
+
// serves as a disambiguator to reject possible unintended 'AbslFormatConvert'
|
| 183 |
+
// functions in the namespaces associated with 'v'.
|
| 184 |
+
|
| 185 |
+
// Raw pointers.
|
| 186 |
+
struct VoidPtr {
|
| 187 |
+
VoidPtr() = default;
|
| 188 |
+
template <typename T,
|
| 189 |
+
decltype(reinterpret_cast<uintptr_t>(std::declval<T*>())) = 0>
|
| 190 |
+
VoidPtr(T* ptr) // NOLINT
|
| 191 |
+
: value(ptr ? reinterpret_cast<uintptr_t>(ptr) : 0) {}
|
| 192 |
+
uintptr_t value;
|
| 193 |
+
};
|
| 194 |
+
|
| 195 |
+
template <FormatConversionCharSet C>
|
| 196 |
+
constexpr FormatConversionCharSet ExtractCharSet(FormatConvertResult<C>) {
|
| 197 |
+
return C;
|
| 198 |
+
}
|
| 199 |
+
|
| 200 |
+
template <FormatConversionCharSet C>
|
| 201 |
+
constexpr FormatConversionCharSet ExtractCharSet(ArgConvertResult<C>) {
|
| 202 |
+
return C;
|
| 203 |
+
}
|
| 204 |
+
|
| 205 |
+
using StringConvertResult = ArgConvertResult<FormatConversionCharSetUnion(
|
| 206 |
+
FormatConversionCharSetInternal::s, FormatConversionCharSetInternal::v)>;
|
| 207 |
+
ArgConvertResult<FormatConversionCharSetInternal::p> FormatConvertImpl(
|
| 208 |
+
VoidPtr v, FormatConversionSpecImpl conv, FormatSinkImpl* sink);
|
| 209 |
+
|
| 210 |
+
// Strings.
|
| 211 |
+
StringConvertResult FormatConvertImpl(const std::string& v,
|
| 212 |
+
FormatConversionSpecImpl conv,
|
| 213 |
+
FormatSinkImpl* sink);
|
| 214 |
+
StringConvertResult FormatConvertImpl(string_view v,
|
| 215 |
+
FormatConversionSpecImpl conv,
|
| 216 |
+
FormatSinkImpl* sink);
|
| 217 |
+
#if defined(ABSL_HAVE_STD_STRING_VIEW) && !defined(ABSL_USES_STD_STRING_VIEW)
|
| 218 |
+
inline StringConvertResult FormatConvertImpl(std::string_view v,
|
| 219 |
+
FormatConversionSpecImpl conv,
|
| 220 |
+
FormatSinkImpl* sink) {
|
| 221 |
+
return FormatConvertImpl(absl::string_view(v.data(), v.size()), conv, sink);
|
| 222 |
+
}
|
| 223 |
+
#endif // ABSL_HAVE_STD_STRING_VIEW && !ABSL_USES_STD_STRING_VIEW
|
| 224 |
+
|
| 225 |
+
ArgConvertResult<FormatConversionCharSetUnion(
|
| 226 |
+
FormatConversionCharSetInternal::s, FormatConversionCharSetInternal::p)>
|
| 227 |
+
FormatConvertImpl(const char* v, const FormatConversionSpecImpl conv,
|
| 228 |
+
FormatSinkImpl* sink);
|
| 229 |
+
|
| 230 |
+
template <class AbslCord, typename std::enable_if<std::is_same<
|
| 231 |
+
AbslCord, absl::Cord>::value>::type* = nullptr>
|
| 232 |
+
StringConvertResult FormatConvertImpl(const AbslCord& value,
|
| 233 |
+
FormatConversionSpecImpl conv,
|
| 234 |
+
FormatSinkImpl* sink) {
|
| 235 |
+
bool is_left = conv.has_left_flag();
|
| 236 |
+
size_t space_remaining = 0;
|
| 237 |
+
|
| 238 |
+
int width = conv.width();
|
| 239 |
+
if (width >= 0) space_remaining = static_cast<size_t>(width);
|
| 240 |
+
|
| 241 |
+
size_t to_write = value.size();
|
| 242 |
+
|
| 243 |
+
int precision = conv.precision();
|
| 244 |
+
if (precision >= 0)
|
| 245 |
+
to_write = (std::min)(to_write, static_cast<size_t>(precision));
|
| 246 |
+
|
| 247 |
+
space_remaining = Excess(to_write, space_remaining);
|
| 248 |
+
|
| 249 |
+
if (space_remaining > 0 && !is_left) sink->Append(space_remaining, ' ');
|
| 250 |
+
|
| 251 |
+
for (string_view piece : value.Chunks()) {
|
| 252 |
+
if (piece.size() > to_write) {
|
| 253 |
+
piece.remove_suffix(piece.size() - to_write);
|
| 254 |
+
to_write = 0;
|
| 255 |
+
} else {
|
| 256 |
+
to_write -= piece.size();
|
| 257 |
+
}
|
| 258 |
+
sink->Append(piece);
|
| 259 |
+
if (to_write == 0) {
|
| 260 |
+
break;
|
| 261 |
+
}
|
| 262 |
+
}
|
| 263 |
+
|
| 264 |
+
if (space_remaining > 0 && is_left) sink->Append(space_remaining, ' ');
|
| 265 |
+
return {true};
|
| 266 |
+
}
|
| 267 |
+
|
| 268 |
+
bool ConvertBoolArg(bool v, FormatSinkImpl* sink);
|
| 269 |
+
|
| 270 |
+
// Floats.
|
| 271 |
+
FloatingConvertResult FormatConvertImpl(float v, FormatConversionSpecImpl conv,
|
| 272 |
+
FormatSinkImpl* sink);
|
| 273 |
+
FloatingConvertResult FormatConvertImpl(double v, FormatConversionSpecImpl conv,
|
| 274 |
+
FormatSinkImpl* sink);
|
| 275 |
+
FloatingConvertResult FormatConvertImpl(long double v,
|
| 276 |
+
FormatConversionSpecImpl conv,
|
| 277 |
+
FormatSinkImpl* sink);
|
| 278 |
+
|
| 279 |
+
// Chars.
|
| 280 |
+
CharConvertResult FormatConvertImpl(char v, FormatConversionSpecImpl conv,
|
| 281 |
+
FormatSinkImpl* sink);
|
| 282 |
+
CharConvertResult FormatConvertImpl(signed char v,
|
| 283 |
+
FormatConversionSpecImpl conv,
|
| 284 |
+
FormatSinkImpl* sink);
|
| 285 |
+
CharConvertResult FormatConvertImpl(unsigned char v,
|
| 286 |
+
FormatConversionSpecImpl conv,
|
| 287 |
+
FormatSinkImpl* sink);
|
| 288 |
+
|
| 289 |
+
// Ints.
|
| 290 |
+
IntegralConvertResult FormatConvertImpl(short v, // NOLINT
|
| 291 |
+
FormatConversionSpecImpl conv,
|
| 292 |
+
FormatSinkImpl* sink);
|
| 293 |
+
IntegralConvertResult FormatConvertImpl(unsigned short v, // NOLINT
|
| 294 |
+
FormatConversionSpecImpl conv,
|
| 295 |
+
FormatSinkImpl* sink);
|
| 296 |
+
IntegralConvertResult FormatConvertImpl(int v, FormatConversionSpecImpl conv,
|
| 297 |
+
FormatSinkImpl* sink);
|
| 298 |
+
IntegralConvertResult FormatConvertImpl(unsigned v,
|
| 299 |
+
FormatConversionSpecImpl conv,
|
| 300 |
+
FormatSinkImpl* sink);
|
| 301 |
+
IntegralConvertResult FormatConvertImpl(long v, // NOLINT
|
| 302 |
+
FormatConversionSpecImpl conv,
|
| 303 |
+
FormatSinkImpl* sink);
|
| 304 |
+
IntegralConvertResult FormatConvertImpl(unsigned long v, // NOLINT
|
| 305 |
+
FormatConversionSpecImpl conv,
|
| 306 |
+
FormatSinkImpl* sink);
|
| 307 |
+
IntegralConvertResult FormatConvertImpl(long long v, // NOLINT
|
| 308 |
+
FormatConversionSpecImpl conv,
|
| 309 |
+
FormatSinkImpl* sink);
|
| 310 |
+
IntegralConvertResult FormatConvertImpl(unsigned long long v, // NOLINT
|
| 311 |
+
FormatConversionSpecImpl conv,
|
| 312 |
+
FormatSinkImpl* sink);
|
| 313 |
+
IntegralConvertResult FormatConvertImpl(int128 v, FormatConversionSpecImpl conv,
|
| 314 |
+
FormatSinkImpl* sink);
|
| 315 |
+
IntegralConvertResult FormatConvertImpl(uint128 v,
|
| 316 |
+
FormatConversionSpecImpl conv,
|
| 317 |
+
FormatSinkImpl* sink);
|
| 318 |
+
|
| 319 |
+
// This function needs to be a template due to ambiguity regarding type
|
| 320 |
+
// conversions.
|
| 321 |
+
template <typename T, enable_if_t<std::is_same<T, bool>::value, int> = 0>
|
| 322 |
+
IntegralConvertResult FormatConvertImpl(T v, FormatConversionSpecImpl conv,
|
| 323 |
+
FormatSinkImpl* sink) {
|
| 324 |
+
if (conv.conversion_char() == FormatConversionCharInternal::v) {
|
| 325 |
+
return {ConvertBoolArg(v, sink)};
|
| 326 |
+
}
|
| 327 |
+
|
| 328 |
+
return FormatConvertImpl(static_cast<int>(v), conv, sink);
|
| 329 |
+
}
|
| 330 |
+
|
| 331 |
+
// We provide this function to help the checker, but it is never defined.
|
| 332 |
+
// FormatArgImpl will use the underlying Convert functions instead.
|
| 333 |
+
template <typename T>
|
| 334 |
+
typename std::enable_if<std::is_enum<T>::value &&
|
| 335 |
+
!HasUserDefinedConvert<T>::value &&
|
| 336 |
+
!strings_internal::HasAbslStringify<T>::value,
|
| 337 |
+
IntegralConvertResult>::type
|
| 338 |
+
FormatConvertImpl(T v, FormatConversionSpecImpl conv, FormatSinkImpl* sink);
|
| 339 |
+
|
| 340 |
+
template <typename T>
|
| 341 |
+
StringConvertResult FormatConvertImpl(const StreamedWrapper<T>& v,
|
| 342 |
+
FormatConversionSpecImpl conv,
|
| 343 |
+
FormatSinkImpl* out) {
|
| 344 |
+
std::ostringstream oss;
|
| 345 |
+
oss << v.v_;
|
| 346 |
+
if (!oss) return {false};
|
| 347 |
+
return str_format_internal::FormatConvertImpl(oss.str(), conv, out);
|
| 348 |
+
}
|
| 349 |
+
|
| 350 |
+
// Use templates and dependent types to delay evaluation of the function
|
| 351 |
+
// until after FormatCountCapture is fully defined.
|
| 352 |
+
struct FormatCountCaptureHelper {
|
| 353 |
+
template <class T = int>
|
| 354 |
+
static ArgConvertResult<FormatConversionCharSetInternal::n> ConvertHelper(
|
| 355 |
+
const FormatCountCapture& v, FormatConversionSpecImpl conv,
|
| 356 |
+
FormatSinkImpl* sink) {
|
| 357 |
+
const absl::enable_if_t<sizeof(T) != 0, FormatCountCapture>& v2 = v;
|
| 358 |
+
|
| 359 |
+
if (conv.conversion_char() !=
|
| 360 |
+
str_format_internal::FormatConversionCharInternal::n) {
|
| 361 |
+
return {false};
|
| 362 |
+
}
|
| 363 |
+
*v2.p_ = static_cast<int>(sink->size());
|
| 364 |
+
return {true};
|
| 365 |
+
}
|
| 366 |
+
};
|
| 367 |
+
|
| 368 |
+
template <class T = int>
|
| 369 |
+
ArgConvertResult<FormatConversionCharSetInternal::n> FormatConvertImpl(
|
| 370 |
+
const FormatCountCapture& v, FormatConversionSpecImpl conv,
|
| 371 |
+
FormatSinkImpl* sink) {
|
| 372 |
+
return FormatCountCaptureHelper::ConvertHelper(v, conv, sink);
|
| 373 |
+
}
|
| 374 |
+
|
| 375 |
+
// Helper friend struct to hide implementation details from the public API of
|
| 376 |
+
// FormatArgImpl.
|
| 377 |
+
struct FormatArgImplFriend {
|
| 378 |
+
template <typename Arg>
|
| 379 |
+
static bool ToInt(Arg arg, int* out) {
|
| 380 |
+
// A value initialized FormatConversionSpecImpl has a `none` conv, which
|
| 381 |
+
// tells the dispatcher to run the `int` conversion.
|
| 382 |
+
return arg.dispatcher_(arg.data_, {}, out);
|
| 383 |
+
}
|
| 384 |
+
|
| 385 |
+
template <typename Arg>
|
| 386 |
+
static bool Convert(Arg arg, FormatConversionSpecImpl conv,
|
| 387 |
+
FormatSinkImpl* out) {
|
| 388 |
+
return arg.dispatcher_(arg.data_, conv, out);
|
| 389 |
+
}
|
| 390 |
+
|
| 391 |
+
template <typename Arg>
|
| 392 |
+
static typename Arg::Dispatcher GetVTablePtrForTest(Arg arg) {
|
| 393 |
+
return arg.dispatcher_;
|
| 394 |
+
}
|
| 395 |
+
};
|
| 396 |
+
|
| 397 |
+
template <typename Arg>
|
| 398 |
+
constexpr FormatConversionCharSet ArgumentToConv() {
|
| 399 |
+
using ConvResult = decltype(str_format_internal::FormatConvertImpl(
|
| 400 |
+
std::declval<const Arg&>(),
|
| 401 |
+
std::declval<const FormatConversionSpecImpl&>(),
|
| 402 |
+
std::declval<FormatSinkImpl*>()));
|
| 403 |
+
return absl::str_format_internal::ExtractCharSet(ConvResult{});
|
| 404 |
+
}
|
| 405 |
+
|
| 406 |
+
// A type-erased handle to a format argument.
|
| 407 |
+
class FormatArgImpl {
|
| 408 |
+
private:
|
| 409 |
+
enum { kInlinedSpace = 8 };
|
| 410 |
+
|
| 411 |
+
using VoidPtr = str_format_internal::VoidPtr;
|
| 412 |
+
|
| 413 |
+
union Data {
|
| 414 |
+
const void* ptr;
|
| 415 |
+
const volatile void* volatile_ptr;
|
| 416 |
+
char buf[kInlinedSpace];
|
| 417 |
+
};
|
| 418 |
+
|
| 419 |
+
using Dispatcher = bool (*)(Data, FormatConversionSpecImpl, void* out);
|
| 420 |
+
|
| 421 |
+
template <typename T>
|
| 422 |
+
struct store_by_value
|
| 423 |
+
: std::integral_constant<bool, (sizeof(T) <= kInlinedSpace) &&
|
| 424 |
+
(std::is_integral<T>::value ||
|
| 425 |
+
std::is_floating_point<T>::value ||
|
| 426 |
+
std::is_pointer<T>::value ||
|
| 427 |
+
std::is_same<VoidPtr, T>::value)> {};
|
| 428 |
+
|
| 429 |
+
enum StoragePolicy { ByPointer, ByVolatilePointer, ByValue };
|
| 430 |
+
template <typename T>
|
| 431 |
+
struct storage_policy
|
| 432 |
+
: std::integral_constant<StoragePolicy,
|
| 433 |
+
(std::is_volatile<T>::value
|
| 434 |
+
? ByVolatilePointer
|
| 435 |
+
: (store_by_value<T>::value ? ByValue
|
| 436 |
+
: ByPointer))> {
|
| 437 |
+
};
|
| 438 |
+
|
| 439 |
+
// To reduce the number of vtables we will decay values before hand.
|
| 440 |
+
// Anything with a user-defined Convert will get its own vtable.
|
| 441 |
+
// For everything else:
|
| 442 |
+
// - Decay char* and char arrays into `const char*`
|
| 443 |
+
// - Decay any other pointer to `const void*`
|
| 444 |
+
// - Decay all enums to their underlying type.
|
| 445 |
+
// - Decay function pointers to void*.
|
| 446 |
+
template <typename T, typename = void>
|
| 447 |
+
struct DecayType {
|
| 448 |
+
static constexpr bool kHasUserDefined =
|
| 449 |
+
str_format_internal::HasUserDefinedConvert<T>::value ||
|
| 450 |
+
strings_internal::HasAbslStringify<T>::value;
|
| 451 |
+
using type = typename std::conditional<
|
| 452 |
+
!kHasUserDefined && std::is_convertible<T, const char*>::value,
|
| 453 |
+
const char*,
|
| 454 |
+
typename std::conditional<!kHasUserDefined &&
|
| 455 |
+
std::is_convertible<T, VoidPtr>::value,
|
| 456 |
+
VoidPtr, const T&>::type>::type;
|
| 457 |
+
};
|
| 458 |
+
template <typename T>
|
| 459 |
+
struct DecayType<T,
|
| 460 |
+
typename std::enable_if<
|
| 461 |
+
!str_format_internal::HasUserDefinedConvert<T>::value &&
|
| 462 |
+
!strings_internal::HasAbslStringify<T>::value &&
|
| 463 |
+
std::is_enum<T>::value>::type> {
|
| 464 |
+
using type = typename std::underlying_type<T>::type;
|
| 465 |
+
};
|
| 466 |
+
|
| 467 |
+
public:
|
| 468 |
+
template <typename T>
|
| 469 |
+
explicit FormatArgImpl(const T& value) {
|
| 470 |
+
using D = typename DecayType<T>::type;
|
| 471 |
+
static_assert(
|
| 472 |
+
std::is_same<D, const T&>::value || storage_policy<D>::value == ByValue,
|
| 473 |
+
"Decayed types must be stored by value");
|
| 474 |
+
Init(static_cast<D>(value));
|
| 475 |
+
}
|
| 476 |
+
|
| 477 |
+
private:
|
| 478 |
+
friend struct str_format_internal::FormatArgImplFriend;
|
| 479 |
+
template <typename T, StoragePolicy = storage_policy<T>::value>
|
| 480 |
+
struct Manager;
|
| 481 |
+
|
| 482 |
+
template <typename T>
|
| 483 |
+
struct Manager<T, ByPointer> {
|
| 484 |
+
static Data SetValue(const T& value) {
|
| 485 |
+
Data data;
|
| 486 |
+
data.ptr = std::addressof(value);
|
| 487 |
+
return data;
|
| 488 |
+
}
|
| 489 |
+
|
| 490 |
+
static const T& Value(Data arg) { return *static_cast<const T*>(arg.ptr); }
|
| 491 |
+
};
|
| 492 |
+
|
| 493 |
+
template <typename T>
|
| 494 |
+
struct Manager<T, ByVolatilePointer> {
|
| 495 |
+
static Data SetValue(const T& value) {
|
| 496 |
+
Data data;
|
| 497 |
+
data.volatile_ptr = &value;
|
| 498 |
+
return data;
|
| 499 |
+
}
|
| 500 |
+
|
| 501 |
+
static const T& Value(Data arg) {
|
| 502 |
+
return *static_cast<const T*>(arg.volatile_ptr);
|
| 503 |
+
}
|
| 504 |
+
};
|
| 505 |
+
|
| 506 |
+
template <typename T>
|
| 507 |
+
struct Manager<T, ByValue> {
|
| 508 |
+
static Data SetValue(const T& value) {
|
| 509 |
+
Data data;
|
| 510 |
+
memcpy(data.buf, &value, sizeof(value));
|
| 511 |
+
return data;
|
| 512 |
+
}
|
| 513 |
+
|
| 514 |
+
static T Value(Data arg) {
|
| 515 |
+
T value;
|
| 516 |
+
memcpy(&value, arg.buf, sizeof(T));
|
| 517 |
+
return value;
|
| 518 |
+
}
|
| 519 |
+
};
|
| 520 |
+
|
| 521 |
+
template <typename T>
|
| 522 |
+
void Init(const T& value) {
|
| 523 |
+
data_ = Manager<T>::SetValue(value);
|
| 524 |
+
dispatcher_ = &Dispatch<T>;
|
| 525 |
+
}
|
| 526 |
+
|
| 527 |
+
template <typename T>
|
| 528 |
+
static int ToIntVal(const T& val) {
|
| 529 |
+
using CommonType = typename std::conditional<std::is_signed<T>::value,
|
| 530 |
+
int64_t, uint64_t>::type;
|
| 531 |
+
if (static_cast<CommonType>(val) >
|
| 532 |
+
static_cast<CommonType>((std::numeric_limits<int>::max)())) {
|
| 533 |
+
return (std::numeric_limits<int>::max)();
|
| 534 |
+
} else if (std::is_signed<T>::value &&
|
| 535 |
+
static_cast<CommonType>(val) <
|
| 536 |
+
static_cast<CommonType>((std::numeric_limits<int>::min)())) {
|
| 537 |
+
return (std::numeric_limits<int>::min)();
|
| 538 |
+
}
|
| 539 |
+
return static_cast<int>(val);
|
| 540 |
+
}
|
| 541 |
+
|
| 542 |
+
template <typename T>
|
| 543 |
+
static bool ToInt(Data arg, int* out, std::true_type /* is_integral */,
|
| 544 |
+
std::false_type) {
|
| 545 |
+
*out = ToIntVal(Manager<T>::Value(arg));
|
| 546 |
+
return true;
|
| 547 |
+
}
|
| 548 |
+
|
| 549 |
+
template <typename T>
|
| 550 |
+
static bool ToInt(Data arg, int* out, std::false_type,
|
| 551 |
+
std::true_type /* is_enum */) {
|
| 552 |
+
*out = ToIntVal(static_cast<typename std::underlying_type<T>::type>(
|
| 553 |
+
Manager<T>::Value(arg)));
|
| 554 |
+
return true;
|
| 555 |
+
}
|
| 556 |
+
|
| 557 |
+
template <typename T>
|
| 558 |
+
static bool ToInt(Data, int*, std::false_type, std::false_type) {
|
| 559 |
+
return false;
|
| 560 |
+
}
|
| 561 |
+
|
| 562 |
+
template <typename T>
|
| 563 |
+
static bool Dispatch(Data arg, FormatConversionSpecImpl spec, void* out) {
|
| 564 |
+
// A `none` conv indicates that we want the `int` conversion.
|
| 565 |
+
if (ABSL_PREDICT_FALSE(spec.conversion_char() ==
|
| 566 |
+
FormatConversionCharInternal::kNone)) {
|
| 567 |
+
return ToInt<T>(arg, static_cast<int*>(out), std::is_integral<T>(),
|
| 568 |
+
std::is_enum<T>());
|
| 569 |
+
}
|
| 570 |
+
if (ABSL_PREDICT_FALSE(!Contains(ArgumentToConv<T>(),
|
| 571 |
+
spec.conversion_char()))) {
|
| 572 |
+
return false;
|
| 573 |
+
}
|
| 574 |
+
return str_format_internal::FormatConvertImpl(
|
| 575 |
+
Manager<T>::Value(arg), spec,
|
| 576 |
+
static_cast<FormatSinkImpl*>(out))
|
| 577 |
+
.value;
|
| 578 |
+
}
|
| 579 |
+
|
| 580 |
+
Data data_;
|
| 581 |
+
Dispatcher dispatcher_;
|
| 582 |
+
};
|
| 583 |
+
|
| 584 |
+
#define ABSL_INTERNAL_FORMAT_DISPATCH_INSTANTIATE_(T, E) \
|
| 585 |
+
E template bool FormatArgImpl::Dispatch<T>(Data, FormatConversionSpecImpl, \
|
| 586 |
+
void*)
|
| 587 |
+
|
| 588 |
+
#define ABSL_INTERNAL_FORMAT_DISPATCH_OVERLOADS_EXPAND_(...) \
|
| 589 |
+
ABSL_INTERNAL_FORMAT_DISPATCH_INSTANTIATE_(str_format_internal::VoidPtr, \
|
| 590 |
+
__VA_ARGS__); \
|
| 591 |
+
ABSL_INTERNAL_FORMAT_DISPATCH_INSTANTIATE_(bool, __VA_ARGS__); \
|
| 592 |
+
ABSL_INTERNAL_FORMAT_DISPATCH_INSTANTIATE_(char, __VA_ARGS__); \
|
| 593 |
+
ABSL_INTERNAL_FORMAT_DISPATCH_INSTANTIATE_(signed char, __VA_ARGS__); \
|
| 594 |
+
ABSL_INTERNAL_FORMAT_DISPATCH_INSTANTIATE_(unsigned char, __VA_ARGS__); \
|
| 595 |
+
ABSL_INTERNAL_FORMAT_DISPATCH_INSTANTIATE_(short, __VA_ARGS__); /* NOLINT */ \
|
| 596 |
+
ABSL_INTERNAL_FORMAT_DISPATCH_INSTANTIATE_(unsigned short, /* NOLINT */ \
|
| 597 |
+
__VA_ARGS__); \
|
| 598 |
+
ABSL_INTERNAL_FORMAT_DISPATCH_INSTANTIATE_(int, __VA_ARGS__); \
|
| 599 |
+
ABSL_INTERNAL_FORMAT_DISPATCH_INSTANTIATE_(unsigned int, __VA_ARGS__); \
|
| 600 |
+
ABSL_INTERNAL_FORMAT_DISPATCH_INSTANTIATE_(long, __VA_ARGS__); /* NOLINT */ \
|
| 601 |
+
ABSL_INTERNAL_FORMAT_DISPATCH_INSTANTIATE_(unsigned long, /* NOLINT */ \
|
| 602 |
+
__VA_ARGS__); \
|
| 603 |
+
ABSL_INTERNAL_FORMAT_DISPATCH_INSTANTIATE_(long long, /* NOLINT */ \
|
| 604 |
+
__VA_ARGS__); \
|
| 605 |
+
ABSL_INTERNAL_FORMAT_DISPATCH_INSTANTIATE_(unsigned long long, /* NOLINT */ \
|
| 606 |
+
__VA_ARGS__); \
|
| 607 |
+
ABSL_INTERNAL_FORMAT_DISPATCH_INSTANTIATE_(int128, __VA_ARGS__); \
|
| 608 |
+
ABSL_INTERNAL_FORMAT_DISPATCH_INSTANTIATE_(uint128, __VA_ARGS__); \
|
| 609 |
+
ABSL_INTERNAL_FORMAT_DISPATCH_INSTANTIATE_(float, __VA_ARGS__); \
|
| 610 |
+
ABSL_INTERNAL_FORMAT_DISPATCH_INSTANTIATE_(double, __VA_ARGS__); \
|
| 611 |
+
ABSL_INTERNAL_FORMAT_DISPATCH_INSTANTIATE_(long double, __VA_ARGS__); \
|
| 612 |
+
ABSL_INTERNAL_FORMAT_DISPATCH_INSTANTIATE_(const char*, __VA_ARGS__); \
|
| 613 |
+
ABSL_INTERNAL_FORMAT_DISPATCH_INSTANTIATE_(std::string, __VA_ARGS__); \
|
| 614 |
+
ABSL_INTERNAL_FORMAT_DISPATCH_INSTANTIATE_(string_view, __VA_ARGS__)
|
| 615 |
+
|
| 616 |
+
ABSL_INTERNAL_FORMAT_DISPATCH_OVERLOADS_EXPAND_(extern);
|
| 617 |
+
|
| 618 |
+
|
| 619 |
+
} // namespace str_format_internal
|
| 620 |
+
ABSL_NAMESPACE_END
|
| 621 |
+
} // namespace absl
|
| 622 |
+
|
| 623 |
+
#endif // ABSL_STRINGS_INTERNAL_STR_FORMAT_ARG_H_
|
miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/absl/strings/internal/str_format/bind.h
ADDED
|
@@ -0,0 +1,249 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2020 The Abseil Authors.
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// https://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
|
| 15 |
+
#ifndef ABSL_STRINGS_INTERNAL_STR_FORMAT_BIND_H_
|
| 16 |
+
#define ABSL_STRINGS_INTERNAL_STR_FORMAT_BIND_H_
|
| 17 |
+
|
| 18 |
+
#include <array>
|
| 19 |
+
#include <cstdio>
|
| 20 |
+
#include <sstream>
|
| 21 |
+
#include <string>
|
| 22 |
+
|
| 23 |
+
#include "absl/base/port.h"
|
| 24 |
+
#include "absl/strings/internal/str_format/arg.h"
|
| 25 |
+
#include "absl/strings/internal/str_format/checker.h"
|
| 26 |
+
#include "absl/strings/internal/str_format/parser.h"
|
| 27 |
+
#include "absl/types/span.h"
|
| 28 |
+
#include "absl/utility/utility.h"
|
| 29 |
+
|
| 30 |
+
namespace absl {
|
| 31 |
+
ABSL_NAMESPACE_BEGIN
|
| 32 |
+
|
| 33 |
+
class UntypedFormatSpec;
|
| 34 |
+
|
| 35 |
+
namespace str_format_internal {
|
| 36 |
+
|
| 37 |
+
class BoundConversion : public FormatConversionSpecImpl {
|
| 38 |
+
public:
|
| 39 |
+
const FormatArgImpl* arg() const { return arg_; }
|
| 40 |
+
void set_arg(const FormatArgImpl* a) { arg_ = a; }
|
| 41 |
+
|
| 42 |
+
private:
|
| 43 |
+
const FormatArgImpl* arg_;
|
| 44 |
+
};
|
| 45 |
+
|
| 46 |
+
// This is the type-erased class that the implementation uses.
|
| 47 |
+
class UntypedFormatSpecImpl {
|
| 48 |
+
public:
|
| 49 |
+
UntypedFormatSpecImpl() = delete;
|
| 50 |
+
|
| 51 |
+
explicit UntypedFormatSpecImpl(string_view s)
|
| 52 |
+
: data_(s.data()), size_(s.size()) {}
|
| 53 |
+
explicit UntypedFormatSpecImpl(
|
| 54 |
+
const str_format_internal::ParsedFormatBase* pc)
|
| 55 |
+
: data_(pc), size_(~size_t{}) {}
|
| 56 |
+
|
| 57 |
+
bool has_parsed_conversion() const { return size_ == ~size_t{}; }
|
| 58 |
+
|
| 59 |
+
string_view str() const {
|
| 60 |
+
assert(!has_parsed_conversion());
|
| 61 |
+
return string_view(static_cast<const char*>(data_), size_);
|
| 62 |
+
}
|
| 63 |
+
const str_format_internal::ParsedFormatBase* parsed_conversion() const {
|
| 64 |
+
assert(has_parsed_conversion());
|
| 65 |
+
return static_cast<const str_format_internal::ParsedFormatBase*>(data_);
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
template <typename T>
|
| 69 |
+
static const UntypedFormatSpecImpl& Extract(const T& s) {
|
| 70 |
+
return s.spec_;
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
private:
|
| 74 |
+
const void* data_;
|
| 75 |
+
size_t size_;
|
| 76 |
+
};
|
| 77 |
+
|
| 78 |
+
template <typename T, FormatConversionCharSet...>
|
| 79 |
+
struct MakeDependent {
|
| 80 |
+
using type = T;
|
| 81 |
+
};
|
| 82 |
+
|
| 83 |
+
// Implicitly convertible from `const char*`, `string_view`, and the
|
| 84 |
+
// `ExtendedParsedFormat` type. This abstraction allows all format functions to
|
| 85 |
+
// operate on any without providing too many overloads.
|
| 86 |
+
template <FormatConversionCharSet... Args>
|
| 87 |
+
class FormatSpecTemplate
|
| 88 |
+
: public MakeDependent<UntypedFormatSpec, Args...>::type {
|
| 89 |
+
using Base = typename MakeDependent<UntypedFormatSpec, Args...>::type;
|
| 90 |
+
|
| 91 |
+
template <bool res>
|
| 92 |
+
struct ErrorMaker {
|
| 93 |
+
constexpr bool operator()(int) const { return res; }
|
| 94 |
+
};
|
| 95 |
+
|
| 96 |
+
template <int i, int j>
|
| 97 |
+
static constexpr bool CheckArity(ErrorMaker<true> SpecifierCount = {},
|
| 98 |
+
ErrorMaker<i == j> ParametersPassed = {}) {
|
| 99 |
+
static_assert(SpecifierCount(i) == ParametersPassed(j),
|
| 100 |
+
"Number of arguments passed must match the number of "
|
| 101 |
+
"conversion specifiers.");
|
| 102 |
+
return true;
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
template <FormatConversionCharSet specified, FormatConversionCharSet passed,
|
| 106 |
+
int arg>
|
| 107 |
+
static constexpr bool CheckMatch(
|
| 108 |
+
ErrorMaker<Contains(specified, passed)> MismatchedArgumentNumber = {}) {
|
| 109 |
+
static_assert(MismatchedArgumentNumber(arg),
|
| 110 |
+
"Passed argument must match specified format.");
|
| 111 |
+
return true;
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
template <FormatConversionCharSet... C, size_t... I>
|
| 115 |
+
static bool CheckMatches(absl::index_sequence<I...>) {
|
| 116 |
+
bool res[] = {true, CheckMatch<Args, C, I + 1>()...};
|
| 117 |
+
(void)res;
|
| 118 |
+
return true;
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
public:
|
| 122 |
+
#ifdef ABSL_INTERNAL_ENABLE_FORMAT_CHECKER
|
| 123 |
+
|
| 124 |
+
// Honeypot overload for when the string is not constexpr.
|
| 125 |
+
// We use the 'unavailable' attribute to give a better compiler error than
|
| 126 |
+
// just 'method is deleted'.
|
| 127 |
+
FormatSpecTemplate(...) // NOLINT
|
| 128 |
+
__attribute__((unavailable("Format string is not constexpr.")));
|
| 129 |
+
|
| 130 |
+
// Honeypot overload for when the format is constexpr and invalid.
|
| 131 |
+
// We use the 'unavailable' attribute to give a better compiler error than
|
| 132 |
+
// just 'method is deleted'.
|
| 133 |
+
// To avoid checking the format twice, we just check that the format is
|
| 134 |
+
// constexpr. If it is valid, then the overload below will kick in.
|
| 135 |
+
// We add the template here to make this overload have lower priority.
|
| 136 |
+
template <typename = void>
|
| 137 |
+
FormatSpecTemplate(const char* s) // NOLINT
|
| 138 |
+
__attribute__((
|
| 139 |
+
enable_if(str_format_internal::EnsureConstexpr(s), "constexpr trap"),
|
| 140 |
+
unavailable(
|
| 141 |
+
"Format specified does not match the arguments passed.")));
|
| 142 |
+
|
| 143 |
+
template <typename T = void>
|
| 144 |
+
FormatSpecTemplate(string_view s) // NOLINT
|
| 145 |
+
__attribute__((enable_if(str_format_internal::EnsureConstexpr(s),
|
| 146 |
+
"constexpr trap")))
|
| 147 |
+
: Base("to avoid noise in the compiler error") {
|
| 148 |
+
static_assert(sizeof(T*) == 0,
|
| 149 |
+
"Format specified does not match the arguments passed.");
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
// Good format overload.
|
| 153 |
+
FormatSpecTemplate(const char* s) // NOLINT
|
| 154 |
+
__attribute__((enable_if(ValidFormatImpl<Args...>(s), "bad format trap")))
|
| 155 |
+
: Base(s) {}
|
| 156 |
+
|
| 157 |
+
FormatSpecTemplate(string_view s) // NOLINT
|
| 158 |
+
__attribute__((enable_if(ValidFormatImpl<Args...>(s), "bad format trap")))
|
| 159 |
+
: Base(s) {}
|
| 160 |
+
|
| 161 |
+
#else // ABSL_INTERNAL_ENABLE_FORMAT_CHECKER
|
| 162 |
+
|
| 163 |
+
FormatSpecTemplate(const char* s) : Base(s) {} // NOLINT
|
| 164 |
+
FormatSpecTemplate(string_view s) : Base(s) {} // NOLINT
|
| 165 |
+
|
| 166 |
+
#endif // ABSL_INTERNAL_ENABLE_FORMAT_CHECKER
|
| 167 |
+
|
| 168 |
+
template <FormatConversionCharSet... C>
|
| 169 |
+
FormatSpecTemplate(const ExtendedParsedFormat<C...>& pc) // NOLINT
|
| 170 |
+
: Base(&pc) {
|
| 171 |
+
CheckArity<sizeof...(C), sizeof...(Args)>();
|
| 172 |
+
CheckMatches<C...>(absl::make_index_sequence<sizeof...(C)>{});
|
| 173 |
+
}
|
| 174 |
+
};
|
| 175 |
+
|
| 176 |
+
class Streamable {
|
| 177 |
+
public:
|
| 178 |
+
Streamable(const UntypedFormatSpecImpl& format,
|
| 179 |
+
absl::Span<const FormatArgImpl> args)
|
| 180 |
+
: format_(format) {
|
| 181 |
+
if (args.size() <= ABSL_ARRAYSIZE(few_args_)) {
|
| 182 |
+
for (size_t i = 0; i < args.size(); ++i) {
|
| 183 |
+
few_args_[i] = args[i];
|
| 184 |
+
}
|
| 185 |
+
args_ = absl::MakeSpan(few_args_, args.size());
|
| 186 |
+
} else {
|
| 187 |
+
many_args_.assign(args.begin(), args.end());
|
| 188 |
+
args_ = many_args_;
|
| 189 |
+
}
|
| 190 |
+
}
|
| 191 |
+
|
| 192 |
+
std::ostream& Print(std::ostream& os) const;
|
| 193 |
+
|
| 194 |
+
friend std::ostream& operator<<(std::ostream& os, const Streamable& l) {
|
| 195 |
+
return l.Print(os);
|
| 196 |
+
}
|
| 197 |
+
|
| 198 |
+
private:
|
| 199 |
+
const UntypedFormatSpecImpl& format_;
|
| 200 |
+
absl::Span<const FormatArgImpl> args_;
|
| 201 |
+
// if args_.size() is 4 or less:
|
| 202 |
+
FormatArgImpl few_args_[4] = {FormatArgImpl(0), FormatArgImpl(0),
|
| 203 |
+
FormatArgImpl(0), FormatArgImpl(0)};
|
| 204 |
+
// if args_.size() is more than 4:
|
| 205 |
+
std::vector<FormatArgImpl> many_args_;
|
| 206 |
+
};
|
| 207 |
+
|
| 208 |
+
// for testing
|
| 209 |
+
std::string Summarize(UntypedFormatSpecImpl format,
|
| 210 |
+
absl::Span<const FormatArgImpl> args);
|
| 211 |
+
bool BindWithPack(const UnboundConversion* props,
|
| 212 |
+
absl::Span<const FormatArgImpl> pack, BoundConversion* bound);
|
| 213 |
+
|
| 214 |
+
bool FormatUntyped(FormatRawSinkImpl raw_sink,
|
| 215 |
+
UntypedFormatSpecImpl format,
|
| 216 |
+
absl::Span<const FormatArgImpl> args);
|
| 217 |
+
|
| 218 |
+
std::string& AppendPack(std::string* out, UntypedFormatSpecImpl format,
|
| 219 |
+
absl::Span<const FormatArgImpl> args);
|
| 220 |
+
|
| 221 |
+
std::string FormatPack(const UntypedFormatSpecImpl format,
|
| 222 |
+
absl::Span<const FormatArgImpl> args);
|
| 223 |
+
|
| 224 |
+
int FprintF(std::FILE* output, UntypedFormatSpecImpl format,
|
| 225 |
+
absl::Span<const FormatArgImpl> args);
|
| 226 |
+
int SnprintF(char* output, size_t size, UntypedFormatSpecImpl format,
|
| 227 |
+
absl::Span<const FormatArgImpl> args);
|
| 228 |
+
|
| 229 |
+
// Returned by Streamed(v). Converts via '%s' to the std::string created
|
| 230 |
+
// by std::ostream << v.
|
| 231 |
+
template <typename T>
|
| 232 |
+
class StreamedWrapper {
|
| 233 |
+
public:
|
| 234 |
+
explicit StreamedWrapper(const T& v) : v_(v) { }
|
| 235 |
+
|
| 236 |
+
private:
|
| 237 |
+
template <typename S>
|
| 238 |
+
friend ArgConvertResult<FormatConversionCharSetUnion(
|
| 239 |
+
FormatConversionCharSetInternal::s, FormatConversionCharSetInternal::v)>
|
| 240 |
+
FormatConvertImpl(const StreamedWrapper<S>& v, FormatConversionSpecImpl conv,
|
| 241 |
+
FormatSinkImpl* out);
|
| 242 |
+
const T& v_;
|
| 243 |
+
};
|
| 244 |
+
|
| 245 |
+
} // namespace str_format_internal
|
| 246 |
+
ABSL_NAMESPACE_END
|
| 247 |
+
} // namespace absl
|
| 248 |
+
|
| 249 |
+
#endif // ABSL_STRINGS_INTERNAL_STR_FORMAT_BIND_H_
|
miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/absl/strings/internal/str_format/checker.h
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2020 The Abseil Authors.
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// https://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
|
| 15 |
+
#ifndef ABSL_STRINGS_INTERNAL_STR_FORMAT_CHECKER_H_
|
| 16 |
+
#define ABSL_STRINGS_INTERNAL_STR_FORMAT_CHECKER_H_
|
| 17 |
+
|
| 18 |
+
#include <algorithm>
|
| 19 |
+
|
| 20 |
+
#include "absl/base/attributes.h"
|
| 21 |
+
#include "absl/strings/internal/str_format/arg.h"
|
| 22 |
+
#include "absl/strings/internal/str_format/constexpr_parser.h"
|
| 23 |
+
#include "absl/strings/internal/str_format/extension.h"
|
| 24 |
+
|
| 25 |
+
// Compile time check support for entry points.
|
| 26 |
+
|
| 27 |
+
#ifndef ABSL_INTERNAL_ENABLE_FORMAT_CHECKER
|
| 28 |
+
// We disable format checker under vscode intellisense compilation.
|
| 29 |
+
// See https://github.com/microsoft/vscode-cpptools/issues/3683 for
|
| 30 |
+
// more details.
|
| 31 |
+
#if ABSL_HAVE_ATTRIBUTE(enable_if) && !defined(__native_client__) && \
|
| 32 |
+
!defined(__INTELLISENSE__)
|
| 33 |
+
#define ABSL_INTERNAL_ENABLE_FORMAT_CHECKER 1
|
| 34 |
+
#endif // ABSL_HAVE_ATTRIBUTE(enable_if) && !defined(__native_client__) &&
|
| 35 |
+
// !defined(__INTELLISENSE__)
|
| 36 |
+
#endif // ABSL_INTERNAL_ENABLE_FORMAT_CHECKER
|
| 37 |
+
|
| 38 |
+
namespace absl {
|
| 39 |
+
ABSL_NAMESPACE_BEGIN
|
| 40 |
+
namespace str_format_internal {
|
| 41 |
+
|
| 42 |
+
#ifdef ABSL_INTERNAL_ENABLE_FORMAT_CHECKER
|
| 43 |
+
|
| 44 |
+
template <FormatConversionCharSet... C>
|
| 45 |
+
constexpr bool ValidFormatImpl(string_view format) {
|
| 46 |
+
int next_arg = 0;
|
| 47 |
+
const char* p = format.data();
|
| 48 |
+
const char* const end = p + format.size();
|
| 49 |
+
constexpr FormatConversionCharSet
|
| 50 |
+
kAllowedConvs[(std::max)(sizeof...(C), size_t{1})] = {C...};
|
| 51 |
+
bool used[(std::max)(sizeof...(C), size_t{1})]{};
|
| 52 |
+
constexpr int kNumArgs = sizeof...(C);
|
| 53 |
+
while (p != end) {
|
| 54 |
+
while (p != end && *p != '%') ++p;
|
| 55 |
+
if (p == end) {
|
| 56 |
+
break;
|
| 57 |
+
}
|
| 58 |
+
if (p + 1 >= end) return false;
|
| 59 |
+
if (p[1] == '%') {
|
| 60 |
+
// %%
|
| 61 |
+
p += 2;
|
| 62 |
+
continue;
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
UnboundConversion conv(absl::kConstInit);
|
| 66 |
+
p = ConsumeUnboundConversion(p + 1, end, &conv, &next_arg);
|
| 67 |
+
if (p == nullptr) return false;
|
| 68 |
+
if (conv.arg_position <= 0 || conv.arg_position > kNumArgs) {
|
| 69 |
+
return false;
|
| 70 |
+
}
|
| 71 |
+
if (!Contains(kAllowedConvs[conv.arg_position - 1], conv.conv)) {
|
| 72 |
+
return false;
|
| 73 |
+
}
|
| 74 |
+
used[conv.arg_position - 1] = true;
|
| 75 |
+
for (auto extra : {conv.width, conv.precision}) {
|
| 76 |
+
if (extra.is_from_arg()) {
|
| 77 |
+
int pos = extra.get_from_arg();
|
| 78 |
+
if (pos <= 0 || pos > kNumArgs) return false;
|
| 79 |
+
used[pos - 1] = true;
|
| 80 |
+
if (!Contains(kAllowedConvs[pos - 1], '*')) {
|
| 81 |
+
return false;
|
| 82 |
+
}
|
| 83 |
+
}
|
| 84 |
+
}
|
| 85 |
+
}
|
| 86 |
+
if (sizeof...(C) != 0) {
|
| 87 |
+
for (bool b : used) {
|
| 88 |
+
if (!b) return false;
|
| 89 |
+
}
|
| 90 |
+
}
|
| 91 |
+
return true;
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
#endif // ABSL_INTERNAL_ENABLE_FORMAT_CHECKER
|
| 95 |
+
|
| 96 |
+
} // namespace str_format_internal
|
| 97 |
+
ABSL_NAMESPACE_END
|
| 98 |
+
} // namespace absl
|
| 99 |
+
|
| 100 |
+
#endif // ABSL_STRINGS_INTERNAL_STR_FORMAT_CHECKER_H_
|
miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/absl/strings/internal/str_format/constexpr_parser.h
ADDED
|
@@ -0,0 +1,351 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2022 The Abseil Authors
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// https://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
|
| 15 |
+
#ifndef ABSL_STRINGS_INTERNAL_STR_FORMAT_CONSTEXPR_PARSER_H_
|
| 16 |
+
#define ABSL_STRINGS_INTERNAL_STR_FORMAT_CONSTEXPR_PARSER_H_
|
| 17 |
+
|
| 18 |
+
#include <cassert>
|
| 19 |
+
#include <cstdint>
|
| 20 |
+
#include <limits>
|
| 21 |
+
|
| 22 |
+
#include "absl/base/const_init.h"
|
| 23 |
+
#include "absl/strings/internal/str_format/extension.h"
|
| 24 |
+
|
| 25 |
+
namespace absl {
|
| 26 |
+
ABSL_NAMESPACE_BEGIN
|
| 27 |
+
namespace str_format_internal {
|
| 28 |
+
|
| 29 |
+
enum class LengthMod : std::uint8_t { h, hh, l, ll, L, j, z, t, q, none };
|
| 30 |
+
|
| 31 |
+
// The analyzed properties of a single specified conversion.
|
| 32 |
+
struct UnboundConversion {
|
| 33 |
+
// This is a user defined default constructor on purpose to skip the
|
| 34 |
+
// initialization of parts of the object that are not necessary.
|
| 35 |
+
UnboundConversion() {} // NOLINT
|
| 36 |
+
|
| 37 |
+
// This constructor is provided for the static checker. We don't want to do
|
| 38 |
+
// the unnecessary initialization in the normal case.
|
| 39 |
+
explicit constexpr UnboundConversion(absl::ConstInitType)
|
| 40 |
+
: arg_position{}, width{}, precision{} {}
|
| 41 |
+
|
| 42 |
+
class InputValue {
|
| 43 |
+
public:
|
| 44 |
+
constexpr void set_value(int value) {
|
| 45 |
+
assert(value >= 0);
|
| 46 |
+
value_ = value;
|
| 47 |
+
}
|
| 48 |
+
constexpr int value() const { return value_; }
|
| 49 |
+
|
| 50 |
+
// Marks the value as "from arg". aka the '*' format.
|
| 51 |
+
// Requires `value >= 1`.
|
| 52 |
+
// When set, is_from_arg() return true and get_from_arg() returns the
|
| 53 |
+
// original value.
|
| 54 |
+
// `value()`'s return value is unspecified in this state.
|
| 55 |
+
constexpr void set_from_arg(int value) {
|
| 56 |
+
assert(value > 0);
|
| 57 |
+
value_ = -value - 1;
|
| 58 |
+
}
|
| 59 |
+
constexpr bool is_from_arg() const { return value_ < -1; }
|
| 60 |
+
constexpr int get_from_arg() const {
|
| 61 |
+
assert(is_from_arg());
|
| 62 |
+
return -value_ - 1;
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
private:
|
| 66 |
+
int value_ = -1;
|
| 67 |
+
};
|
| 68 |
+
|
| 69 |
+
// No need to initialize. It will always be set in the parser.
|
| 70 |
+
int arg_position;
|
| 71 |
+
|
| 72 |
+
InputValue width;
|
| 73 |
+
InputValue precision;
|
| 74 |
+
|
| 75 |
+
Flags flags = Flags::kBasic;
|
| 76 |
+
LengthMod length_mod = LengthMod::none;
|
| 77 |
+
FormatConversionChar conv = FormatConversionCharInternal::kNone;
|
| 78 |
+
};
|
| 79 |
+
|
| 80 |
+
// Helper tag class for the table below.
|
| 81 |
+
// It allows fast `char -> ConversionChar/LengthMod/Flags` checking and
|
| 82 |
+
// conversions.
|
| 83 |
+
class ConvTag {
|
| 84 |
+
public:
|
| 85 |
+
constexpr ConvTag(FormatConversionChar conversion_char) // NOLINT
|
| 86 |
+
: tag_(static_cast<uint8_t>(conversion_char)) {}
|
| 87 |
+
constexpr ConvTag(LengthMod length_mod) // NOLINT
|
| 88 |
+
: tag_(0x80 | static_cast<uint8_t>(length_mod)) {}
|
| 89 |
+
constexpr ConvTag(Flags flags) // NOLINT
|
| 90 |
+
: tag_(0xc0 | static_cast<uint8_t>(flags)) {}
|
| 91 |
+
constexpr ConvTag() : tag_(0xFF) {}
|
| 92 |
+
|
| 93 |
+
constexpr bool is_conv() const { return (tag_ & 0x80) == 0; }
|
| 94 |
+
constexpr bool is_length() const { return (tag_ & 0xC0) == 0x80; }
|
| 95 |
+
constexpr bool is_flags() const { return (tag_ & 0xE0) == 0xC0; }
|
| 96 |
+
|
| 97 |
+
constexpr FormatConversionChar as_conv() const {
|
| 98 |
+
assert(is_conv());
|
| 99 |
+
assert(!is_length());
|
| 100 |
+
assert(!is_flags());
|
| 101 |
+
return static_cast<FormatConversionChar>(tag_);
|
| 102 |
+
}
|
| 103 |
+
constexpr LengthMod as_length() const {
|
| 104 |
+
assert(!is_conv());
|
| 105 |
+
assert(is_length());
|
| 106 |
+
assert(!is_flags());
|
| 107 |
+
return static_cast<LengthMod>(tag_ & 0x3F);
|
| 108 |
+
}
|
| 109 |
+
constexpr Flags as_flags() const {
|
| 110 |
+
assert(!is_conv());
|
| 111 |
+
assert(!is_length());
|
| 112 |
+
assert(is_flags());
|
| 113 |
+
return static_cast<Flags>(tag_ & 0x1F);
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
private:
|
| 117 |
+
uint8_t tag_;
|
| 118 |
+
};
|
| 119 |
+
|
| 120 |
+
struct ConvTagHolder {
|
| 121 |
+
using CC = FormatConversionCharInternal;
|
| 122 |
+
using LM = LengthMod;
|
| 123 |
+
|
| 124 |
+
// Abbreviations to fit in the table below.
|
| 125 |
+
static constexpr auto kFSign = Flags::kSignCol;
|
| 126 |
+
static constexpr auto kFAlt = Flags::kAlt;
|
| 127 |
+
static constexpr auto kFPos = Flags::kShowPos;
|
| 128 |
+
static constexpr auto kFLeft = Flags::kLeft;
|
| 129 |
+
static constexpr auto kFZero = Flags::kZero;
|
| 130 |
+
|
| 131 |
+
static constexpr ConvTag value[256] = {
|
| 132 |
+
{}, {}, {}, {}, {}, {}, {}, {}, // 00-07
|
| 133 |
+
{}, {}, {}, {}, {}, {}, {}, {}, // 08-0f
|
| 134 |
+
{}, {}, {}, {}, {}, {}, {}, {}, // 10-17
|
| 135 |
+
{}, {}, {}, {}, {}, {}, {}, {}, // 18-1f
|
| 136 |
+
kFSign, {}, {}, kFAlt, {}, {}, {}, {}, // !"#$%&'
|
| 137 |
+
{}, {}, {}, kFPos, {}, kFLeft, {}, {}, // ()*+,-./
|
| 138 |
+
kFZero, {}, {}, {}, {}, {}, {}, {}, // 01234567
|
| 139 |
+
{}, {}, {}, {}, {}, {}, {}, {}, // 89:;<=>?
|
| 140 |
+
{}, CC::A, {}, {}, {}, CC::E, CC::F, CC::G, // @ABCDEFG
|
| 141 |
+
{}, {}, {}, {}, LM::L, {}, {}, {}, // HIJKLMNO
|
| 142 |
+
{}, {}, {}, {}, {}, {}, {}, {}, // PQRSTUVW
|
| 143 |
+
CC::X, {}, {}, {}, {}, {}, {}, {}, // XYZ[\]^_
|
| 144 |
+
{}, CC::a, {}, CC::c, CC::d, CC::e, CC::f, CC::g, // `abcdefg
|
| 145 |
+
LM::h, CC::i, LM::j, {}, LM::l, {}, CC::n, CC::o, // hijklmno
|
| 146 |
+
CC::p, LM::q, {}, CC::s, LM::t, CC::u, CC::v, {}, // pqrstuvw
|
| 147 |
+
CC::x, {}, LM::z, {}, {}, {}, {}, {}, // xyz{|}!
|
| 148 |
+
{}, {}, {}, {}, {}, {}, {}, {}, // 80-87
|
| 149 |
+
{}, {}, {}, {}, {}, {}, {}, {}, // 88-8f
|
| 150 |
+
{}, {}, {}, {}, {}, {}, {}, {}, // 90-97
|
| 151 |
+
{}, {}, {}, {}, {}, {}, {}, {}, // 98-9f
|
| 152 |
+
{}, {}, {}, {}, {}, {}, {}, {}, // a0-a7
|
| 153 |
+
{}, {}, {}, {}, {}, {}, {}, {}, // a8-af
|
| 154 |
+
{}, {}, {}, {}, {}, {}, {}, {}, // b0-b7
|
| 155 |
+
{}, {}, {}, {}, {}, {}, {}, {}, // b8-bf
|
| 156 |
+
{}, {}, {}, {}, {}, {}, {}, {}, // c0-c7
|
| 157 |
+
{}, {}, {}, {}, {}, {}, {}, {}, // c8-cf
|
| 158 |
+
{}, {}, {}, {}, {}, {}, {}, {}, // d0-d7
|
| 159 |
+
{}, {}, {}, {}, {}, {}, {}, {}, // d8-df
|
| 160 |
+
{}, {}, {}, {}, {}, {}, {}, {}, // e0-e7
|
| 161 |
+
{}, {}, {}, {}, {}, {}, {}, {}, // e8-ef
|
| 162 |
+
{}, {}, {}, {}, {}, {}, {}, {}, // f0-f7
|
| 163 |
+
{}, {}, {}, {}, {}, {}, {}, {}, // f8-ff
|
| 164 |
+
};
|
| 165 |
+
};
|
| 166 |
+
|
| 167 |
+
// Keep a single table for all the conversion chars and length modifiers.
|
| 168 |
+
constexpr ConvTag GetTagForChar(char c) {
|
| 169 |
+
return ConvTagHolder::value[static_cast<unsigned char>(c)];
|
| 170 |
+
}
|
| 171 |
+
|
| 172 |
+
constexpr bool CheckFastPathSetting(const UnboundConversion& conv) {
|
| 173 |
+
bool width_precision_needed =
|
| 174 |
+
conv.width.value() >= 0 || conv.precision.value() >= 0;
|
| 175 |
+
if (width_precision_needed && conv.flags == Flags::kBasic) {
|
| 176 |
+
#if defined(__clang__)
|
| 177 |
+
// Some compilers complain about this in constexpr even when not executed,
|
| 178 |
+
// so only enable the error dump in clang.
|
| 179 |
+
fprintf(stderr,
|
| 180 |
+
"basic=%d left=%d show_pos=%d sign_col=%d alt=%d zero=%d "
|
| 181 |
+
"width=%d precision=%d\n",
|
| 182 |
+
conv.flags == Flags::kBasic ? 1 : 0,
|
| 183 |
+
FlagsContains(conv.flags, Flags::kLeft) ? 1 : 0,
|
| 184 |
+
FlagsContains(conv.flags, Flags::kShowPos) ? 1 : 0,
|
| 185 |
+
FlagsContains(conv.flags, Flags::kSignCol) ? 1 : 0,
|
| 186 |
+
FlagsContains(conv.flags, Flags::kAlt) ? 1 : 0,
|
| 187 |
+
FlagsContains(conv.flags, Flags::kZero) ? 1 : 0, conv.width.value(),
|
| 188 |
+
conv.precision.value());
|
| 189 |
+
#endif // defined(__clang__)
|
| 190 |
+
return false;
|
| 191 |
+
}
|
| 192 |
+
return true;
|
| 193 |
+
}
|
| 194 |
+
|
| 195 |
+
constexpr int ParseDigits(char& c, const char*& pos, const char* const end) {
|
| 196 |
+
int digits = c - '0';
|
| 197 |
+
// We do not want to overflow `digits` so we consume at most digits10
|
| 198 |
+
// digits. If there are more digits the parsing will fail later on when the
|
| 199 |
+
// digit doesn't match the expected characters.
|
| 200 |
+
int num_digits = std::numeric_limits<int>::digits10;
|
| 201 |
+
for (;;) {
|
| 202 |
+
if (ABSL_PREDICT_FALSE(pos == end)) break;
|
| 203 |
+
c = *pos++;
|
| 204 |
+
if ('0' > c || c > '9') break;
|
| 205 |
+
--num_digits;
|
| 206 |
+
if (ABSL_PREDICT_FALSE(!num_digits)) break;
|
| 207 |
+
digits = 10 * digits + c - '0';
|
| 208 |
+
}
|
| 209 |
+
return digits;
|
| 210 |
+
}
|
| 211 |
+
|
| 212 |
+
template <bool is_positional>
|
| 213 |
+
constexpr const char* ConsumeConversion(const char* pos, const char* const end,
|
| 214 |
+
UnboundConversion* conv,
|
| 215 |
+
int* next_arg) {
|
| 216 |
+
const char* const original_pos = pos;
|
| 217 |
+
char c = 0;
|
| 218 |
+
// Read the next char into `c` and update `pos`. Returns false if there are
|
| 219 |
+
// no more chars to read.
|
| 220 |
+
#define ABSL_FORMAT_PARSER_INTERNAL_GET_CHAR() \
|
| 221 |
+
do { \
|
| 222 |
+
if (ABSL_PREDICT_FALSE(pos == end)) return nullptr; \
|
| 223 |
+
c = *pos++; \
|
| 224 |
+
} while (0)
|
| 225 |
+
|
| 226 |
+
if (is_positional) {
|
| 227 |
+
ABSL_FORMAT_PARSER_INTERNAL_GET_CHAR();
|
| 228 |
+
if (ABSL_PREDICT_FALSE(c < '1' || c > '9')) return nullptr;
|
| 229 |
+
conv->arg_position = ParseDigits(c, pos, end);
|
| 230 |
+
assert(conv->arg_position > 0);
|
| 231 |
+
if (ABSL_PREDICT_FALSE(c != '$')) return nullptr;
|
| 232 |
+
}
|
| 233 |
+
|
| 234 |
+
ABSL_FORMAT_PARSER_INTERNAL_GET_CHAR();
|
| 235 |
+
|
| 236 |
+
// We should start with the basic flag on.
|
| 237 |
+
assert(conv->flags == Flags::kBasic);
|
| 238 |
+
|
| 239 |
+
// Any non alpha character makes this conversion not basic.
|
| 240 |
+
// This includes flags (-+ #0), width (1-9, *) or precision (.).
|
| 241 |
+
// All conversion characters and length modifiers are alpha characters.
|
| 242 |
+
if (c < 'A') {
|
| 243 |
+
while (c <= '0') {
|
| 244 |
+
auto tag = GetTagForChar(c);
|
| 245 |
+
if (tag.is_flags()) {
|
| 246 |
+
conv->flags = conv->flags | tag.as_flags();
|
| 247 |
+
ABSL_FORMAT_PARSER_INTERNAL_GET_CHAR();
|
| 248 |
+
} else {
|
| 249 |
+
break;
|
| 250 |
+
}
|
| 251 |
+
}
|
| 252 |
+
|
| 253 |
+
if (c <= '9') {
|
| 254 |
+
if (c >= '0') {
|
| 255 |
+
int maybe_width = ParseDigits(c, pos, end);
|
| 256 |
+
if (!is_positional && c == '$') {
|
| 257 |
+
if (ABSL_PREDICT_FALSE(*next_arg != 0)) return nullptr;
|
| 258 |
+
// Positional conversion.
|
| 259 |
+
*next_arg = -1;
|
| 260 |
+
return ConsumeConversion<true>(original_pos, end, conv, next_arg);
|
| 261 |
+
}
|
| 262 |
+
conv->flags = conv->flags | Flags::kNonBasic;
|
| 263 |
+
conv->width.set_value(maybe_width);
|
| 264 |
+
} else if (c == '*') {
|
| 265 |
+
conv->flags = conv->flags | Flags::kNonBasic;
|
| 266 |
+
ABSL_FORMAT_PARSER_INTERNAL_GET_CHAR();
|
| 267 |
+
if (is_positional) {
|
| 268 |
+
if (ABSL_PREDICT_FALSE(c < '1' || c > '9')) return nullptr;
|
| 269 |
+
conv->width.set_from_arg(ParseDigits(c, pos, end));
|
| 270 |
+
if (ABSL_PREDICT_FALSE(c != '$')) return nullptr;
|
| 271 |
+
ABSL_FORMAT_PARSER_INTERNAL_GET_CHAR();
|
| 272 |
+
} else {
|
| 273 |
+
conv->width.set_from_arg(++*next_arg);
|
| 274 |
+
}
|
| 275 |
+
}
|
| 276 |
+
}
|
| 277 |
+
|
| 278 |
+
if (c == '.') {
|
| 279 |
+
conv->flags = conv->flags | Flags::kNonBasic;
|
| 280 |
+
ABSL_FORMAT_PARSER_INTERNAL_GET_CHAR();
|
| 281 |
+
if ('0' <= c && c <= '9') {
|
| 282 |
+
conv->precision.set_value(ParseDigits(c, pos, end));
|
| 283 |
+
} else if (c == '*') {
|
| 284 |
+
ABSL_FORMAT_PARSER_INTERNAL_GET_CHAR();
|
| 285 |
+
if (is_positional) {
|
| 286 |
+
if (ABSL_PREDICT_FALSE(c < '1' || c > '9')) return nullptr;
|
| 287 |
+
conv->precision.set_from_arg(ParseDigits(c, pos, end));
|
| 288 |
+
if (c != '$') return nullptr;
|
| 289 |
+
ABSL_FORMAT_PARSER_INTERNAL_GET_CHAR();
|
| 290 |
+
} else {
|
| 291 |
+
conv->precision.set_from_arg(++*next_arg);
|
| 292 |
+
}
|
| 293 |
+
} else {
|
| 294 |
+
conv->precision.set_value(0);
|
| 295 |
+
}
|
| 296 |
+
}
|
| 297 |
+
}
|
| 298 |
+
|
| 299 |
+
auto tag = GetTagForChar(c);
|
| 300 |
+
|
| 301 |
+
if (ABSL_PREDICT_FALSE(c == 'v' && conv->flags != Flags::kBasic)) {
|
| 302 |
+
return nullptr;
|
| 303 |
+
}
|
| 304 |
+
|
| 305 |
+
if (ABSL_PREDICT_FALSE(!tag.is_conv())) {
|
| 306 |
+
if (ABSL_PREDICT_FALSE(!tag.is_length())) return nullptr;
|
| 307 |
+
|
| 308 |
+
// It is a length modifier.
|
| 309 |
+
using str_format_internal::LengthMod;
|
| 310 |
+
LengthMod length_mod = tag.as_length();
|
| 311 |
+
ABSL_FORMAT_PARSER_INTERNAL_GET_CHAR();
|
| 312 |
+
if (c == 'h' && length_mod == LengthMod::h) {
|
| 313 |
+
conv->length_mod = LengthMod::hh;
|
| 314 |
+
ABSL_FORMAT_PARSER_INTERNAL_GET_CHAR();
|
| 315 |
+
} else if (c == 'l' && length_mod == LengthMod::l) {
|
| 316 |
+
conv->length_mod = LengthMod::ll;
|
| 317 |
+
ABSL_FORMAT_PARSER_INTERNAL_GET_CHAR();
|
| 318 |
+
} else {
|
| 319 |
+
conv->length_mod = length_mod;
|
| 320 |
+
}
|
| 321 |
+
tag = GetTagForChar(c);
|
| 322 |
+
|
| 323 |
+
if (ABSL_PREDICT_FALSE(c == 'v')) return nullptr;
|
| 324 |
+
if (ABSL_PREDICT_FALSE(!tag.is_conv())) return nullptr;
|
| 325 |
+
}
|
| 326 |
+
|
| 327 |
+
assert(CheckFastPathSetting(*conv));
|
| 328 |
+
(void)(&CheckFastPathSetting);
|
| 329 |
+
|
| 330 |
+
conv->conv = tag.as_conv();
|
| 331 |
+
if (!is_positional) conv->arg_position = ++*next_arg;
|
| 332 |
+
return pos;
|
| 333 |
+
}
|
| 334 |
+
|
| 335 |
+
// Consume conversion spec prefix (not including '%') of [p, end) if valid.
|
| 336 |
+
// Examples of valid specs would be e.g.: "s", "d", "-12.6f".
|
| 337 |
+
// If valid, it returns the first character following the conversion spec,
|
| 338 |
+
// and the spec part is broken down and returned in 'conv'.
|
| 339 |
+
// If invalid, returns nullptr.
|
| 340 |
+
constexpr const char* ConsumeUnboundConversion(const char* p, const char* end,
|
| 341 |
+
UnboundConversion* conv,
|
| 342 |
+
int* next_arg) {
|
| 343 |
+
if (*next_arg < 0) return ConsumeConversion<true>(p, end, conv, next_arg);
|
| 344 |
+
return ConsumeConversion<false>(p, end, conv, next_arg);
|
| 345 |
+
}
|
| 346 |
+
|
| 347 |
+
} // namespace str_format_internal
|
| 348 |
+
ABSL_NAMESPACE_END
|
| 349 |
+
} // namespace absl
|
| 350 |
+
|
| 351 |
+
#endif // ABSL_STRINGS_INTERNAL_STR_FORMAT_CONSTEXPR_PARSER_H_
|
miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/absl/strings/internal/str_format/extension.h
ADDED
|
@@ -0,0 +1,450 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//
|
| 2 |
+
// Copyright 2017 The Abseil Authors.
|
| 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 |
+
// https://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 |
+
#ifndef ABSL_STRINGS_INTERNAL_STR_FORMAT_EXTENSION_H_
|
| 17 |
+
#define ABSL_STRINGS_INTERNAL_STR_FORMAT_EXTENSION_H_
|
| 18 |
+
|
| 19 |
+
#include <limits.h>
|
| 20 |
+
|
| 21 |
+
#include <cstddef>
|
| 22 |
+
#include <cstdint>
|
| 23 |
+
#include <cstring>
|
| 24 |
+
#include <ostream>
|
| 25 |
+
|
| 26 |
+
#include "absl/base/config.h"
|
| 27 |
+
#include "absl/base/port.h"
|
| 28 |
+
#include "absl/meta/type_traits.h"
|
| 29 |
+
#include "absl/strings/internal/str_format/output.h"
|
| 30 |
+
#include "absl/strings/string_view.h"
|
| 31 |
+
|
| 32 |
+
namespace absl {
|
| 33 |
+
ABSL_NAMESPACE_BEGIN
|
| 34 |
+
|
| 35 |
+
enum class FormatConversionChar : uint8_t;
|
| 36 |
+
enum class FormatConversionCharSet : uint64_t;
|
| 37 |
+
|
| 38 |
+
namespace str_format_internal {
|
| 39 |
+
|
| 40 |
+
class FormatRawSinkImpl {
|
| 41 |
+
public:
|
| 42 |
+
// Implicitly convert from any type that provides the hook function as
|
| 43 |
+
// described above.
|
| 44 |
+
template <typename T, decltype(str_format_internal::InvokeFlush(
|
| 45 |
+
std::declval<T*>(), string_view()))* = nullptr>
|
| 46 |
+
FormatRawSinkImpl(T* raw) // NOLINT
|
| 47 |
+
: sink_(raw), write_(&FormatRawSinkImpl::Flush<T>) {}
|
| 48 |
+
|
| 49 |
+
void Write(string_view s) { write_(sink_, s); }
|
| 50 |
+
|
| 51 |
+
template <typename T>
|
| 52 |
+
static FormatRawSinkImpl Extract(T s) {
|
| 53 |
+
return s.sink_;
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
private:
|
| 57 |
+
template <typename T>
|
| 58 |
+
static void Flush(void* r, string_view s) {
|
| 59 |
+
str_format_internal::InvokeFlush(static_cast<T*>(r), s);
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
void* sink_;
|
| 63 |
+
void (*write_)(void*, string_view);
|
| 64 |
+
};
|
| 65 |
+
|
| 66 |
+
// An abstraction to which conversions write their string data.
|
| 67 |
+
class FormatSinkImpl {
|
| 68 |
+
public:
|
| 69 |
+
explicit FormatSinkImpl(FormatRawSinkImpl raw) : raw_(raw) {}
|
| 70 |
+
|
| 71 |
+
~FormatSinkImpl() { Flush(); }
|
| 72 |
+
|
| 73 |
+
void Flush() {
|
| 74 |
+
raw_.Write(string_view(buf_, static_cast<size_t>(pos_ - buf_)));
|
| 75 |
+
pos_ = buf_;
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
void Append(size_t n, char c) {
|
| 79 |
+
if (n == 0) return;
|
| 80 |
+
size_ += n;
|
| 81 |
+
auto raw_append = [&](size_t count) {
|
| 82 |
+
memset(pos_, c, count);
|
| 83 |
+
pos_ += count;
|
| 84 |
+
};
|
| 85 |
+
while (n > Avail()) {
|
| 86 |
+
n -= Avail();
|
| 87 |
+
if (Avail() > 0) {
|
| 88 |
+
raw_append(Avail());
|
| 89 |
+
}
|
| 90 |
+
Flush();
|
| 91 |
+
}
|
| 92 |
+
raw_append(n);
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
void Append(string_view v) {
|
| 96 |
+
size_t n = v.size();
|
| 97 |
+
if (n == 0) return;
|
| 98 |
+
size_ += n;
|
| 99 |
+
if (n >= Avail()) {
|
| 100 |
+
Flush();
|
| 101 |
+
raw_.Write(v);
|
| 102 |
+
return;
|
| 103 |
+
}
|
| 104 |
+
memcpy(pos_, v.data(), n);
|
| 105 |
+
pos_ += n;
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
size_t size() const { return size_; }
|
| 109 |
+
|
| 110 |
+
// Put 'v' to 'sink' with specified width, precision, and left flag.
|
| 111 |
+
bool PutPaddedString(string_view v, int width, int precision, bool left);
|
| 112 |
+
|
| 113 |
+
template <typename T>
|
| 114 |
+
T Wrap() {
|
| 115 |
+
return T(this);
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
template <typename T>
|
| 119 |
+
static FormatSinkImpl* Extract(T* s) {
|
| 120 |
+
return s->sink_;
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
private:
|
| 124 |
+
size_t Avail() const {
|
| 125 |
+
return static_cast<size_t>(buf_ + sizeof(buf_) - pos_);
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
FormatRawSinkImpl raw_;
|
| 129 |
+
size_t size_ = 0;
|
| 130 |
+
char* pos_ = buf_;
|
| 131 |
+
char buf_[1024];
|
| 132 |
+
};
|
| 133 |
+
|
| 134 |
+
enum class Flags : uint8_t {
|
| 135 |
+
kBasic = 0,
|
| 136 |
+
kLeft = 1 << 0,
|
| 137 |
+
kShowPos = 1 << 1,
|
| 138 |
+
kSignCol = 1 << 2,
|
| 139 |
+
kAlt = 1 << 3,
|
| 140 |
+
kZero = 1 << 4,
|
| 141 |
+
// This is not a real flag. It just exists to turn off kBasic when no other
|
| 142 |
+
// flags are set. This is for when width/precision are specified.
|
| 143 |
+
kNonBasic = 1 << 5,
|
| 144 |
+
};
|
| 145 |
+
|
| 146 |
+
constexpr Flags operator|(Flags a, Flags b) {
|
| 147 |
+
return static_cast<Flags>(static_cast<uint8_t>(a) | static_cast<uint8_t>(b));
|
| 148 |
+
}
|
| 149 |
+
|
| 150 |
+
constexpr bool FlagsContains(Flags haystack, Flags needle) {
|
| 151 |
+
return (static_cast<uint8_t>(haystack) & static_cast<uint8_t>(needle)) ==
|
| 152 |
+
static_cast<uint8_t>(needle);
|
| 153 |
+
}
|
| 154 |
+
|
| 155 |
+
std::string FlagsToString(Flags v);
|
| 156 |
+
|
| 157 |
+
inline std::ostream& operator<<(std::ostream& os, Flags v) {
|
| 158 |
+
return os << FlagsToString(v);
|
| 159 |
+
}
|
| 160 |
+
|
| 161 |
+
// clang-format off
|
| 162 |
+
#define ABSL_INTERNAL_CONVERSION_CHARS_EXPAND_(X_VAL, X_SEP) \
|
| 163 |
+
/* text */ \
|
| 164 |
+
X_VAL(c) X_SEP X_VAL(s) X_SEP \
|
| 165 |
+
/* ints */ \
|
| 166 |
+
X_VAL(d) X_SEP X_VAL(i) X_SEP X_VAL(o) X_SEP \
|
| 167 |
+
X_VAL(u) X_SEP X_VAL(x) X_SEP X_VAL(X) X_SEP \
|
| 168 |
+
/* floats */ \
|
| 169 |
+
X_VAL(f) X_SEP X_VAL(F) X_SEP X_VAL(e) X_SEP X_VAL(E) X_SEP \
|
| 170 |
+
X_VAL(g) X_SEP X_VAL(G) X_SEP X_VAL(a) X_SEP X_VAL(A) X_SEP \
|
| 171 |
+
/* misc */ \
|
| 172 |
+
X_VAL(n) X_SEP X_VAL(p) X_SEP X_VAL(v)
|
| 173 |
+
// clang-format on
|
| 174 |
+
|
| 175 |
+
// This type should not be referenced, it exists only to provide labels
|
| 176 |
+
// internally that match the values declared in FormatConversionChar in
|
| 177 |
+
// str_format.h. This is meant to allow internal libraries to use the same
|
| 178 |
+
// declared interface type as the public interface
|
| 179 |
+
// (absl::StrFormatConversionChar) while keeping the definition in a public
|
| 180 |
+
// header.
|
| 181 |
+
// Internal libraries should use the form
|
| 182 |
+
// `FormatConversionCharInternal::c`, `FormatConversionCharInternal::kNone` for
|
| 183 |
+
// comparisons. Use in switch statements is not recommended due to a bug in how
|
| 184 |
+
// gcc 4.9 -Wswitch handles declared but undefined enums.
|
| 185 |
+
struct FormatConversionCharInternal {
|
| 186 |
+
FormatConversionCharInternal() = delete;
|
| 187 |
+
|
| 188 |
+
private:
|
| 189 |
+
// clang-format off
|
| 190 |
+
enum class Enum : uint8_t {
|
| 191 |
+
c, s, // text
|
| 192 |
+
d, i, o, u, x, X, // int
|
| 193 |
+
f, F, e, E, g, G, a, A, // float
|
| 194 |
+
n, p, v, // misc
|
| 195 |
+
kNone
|
| 196 |
+
};
|
| 197 |
+
// clang-format on
|
| 198 |
+
public:
|
| 199 |
+
#define ABSL_INTERNAL_X_VAL(id) \
|
| 200 |
+
static constexpr FormatConversionChar id = \
|
| 201 |
+
static_cast<FormatConversionChar>(Enum::id);
|
| 202 |
+
ABSL_INTERNAL_CONVERSION_CHARS_EXPAND_(ABSL_INTERNAL_X_VAL, )
|
| 203 |
+
#undef ABSL_INTERNAL_X_VAL
|
| 204 |
+
static constexpr FormatConversionChar kNone =
|
| 205 |
+
static_cast<FormatConversionChar>(Enum::kNone);
|
| 206 |
+
};
|
| 207 |
+
// clang-format on
|
| 208 |
+
|
| 209 |
+
inline FormatConversionChar FormatConversionCharFromChar(char c) {
|
| 210 |
+
switch (c) {
|
| 211 |
+
#define ABSL_INTERNAL_X_VAL(id) \
|
| 212 |
+
case #id[0]: \
|
| 213 |
+
return FormatConversionCharInternal::id;
|
| 214 |
+
ABSL_INTERNAL_CONVERSION_CHARS_EXPAND_(ABSL_INTERNAL_X_VAL, )
|
| 215 |
+
#undef ABSL_INTERNAL_X_VAL
|
| 216 |
+
}
|
| 217 |
+
return FormatConversionCharInternal::kNone;
|
| 218 |
+
}
|
| 219 |
+
|
| 220 |
+
inline bool FormatConversionCharIsUpper(FormatConversionChar c) {
|
| 221 |
+
if (c == FormatConversionCharInternal::X ||
|
| 222 |
+
c == FormatConversionCharInternal::F ||
|
| 223 |
+
c == FormatConversionCharInternal::E ||
|
| 224 |
+
c == FormatConversionCharInternal::G ||
|
| 225 |
+
c == FormatConversionCharInternal::A) {
|
| 226 |
+
return true;
|
| 227 |
+
} else {
|
| 228 |
+
return false;
|
| 229 |
+
}
|
| 230 |
+
}
|
| 231 |
+
|
| 232 |
+
inline bool FormatConversionCharIsFloat(FormatConversionChar c) {
|
| 233 |
+
if (c == FormatConversionCharInternal::a ||
|
| 234 |
+
c == FormatConversionCharInternal::e ||
|
| 235 |
+
c == FormatConversionCharInternal::f ||
|
| 236 |
+
c == FormatConversionCharInternal::g ||
|
| 237 |
+
c == FormatConversionCharInternal::A ||
|
| 238 |
+
c == FormatConversionCharInternal::E ||
|
| 239 |
+
c == FormatConversionCharInternal::F ||
|
| 240 |
+
c == FormatConversionCharInternal::G) {
|
| 241 |
+
return true;
|
| 242 |
+
} else {
|
| 243 |
+
return false;
|
| 244 |
+
}
|
| 245 |
+
}
|
| 246 |
+
|
| 247 |
+
inline char FormatConversionCharToChar(FormatConversionChar c) {
|
| 248 |
+
if (c == FormatConversionCharInternal::kNone) {
|
| 249 |
+
return '\0';
|
| 250 |
+
|
| 251 |
+
#define ABSL_INTERNAL_X_VAL(e) \
|
| 252 |
+
} else if (c == FormatConversionCharInternal::e) { \
|
| 253 |
+
return #e[0];
|
| 254 |
+
#define ABSL_INTERNAL_X_SEP
|
| 255 |
+
ABSL_INTERNAL_CONVERSION_CHARS_EXPAND_(ABSL_INTERNAL_X_VAL,
|
| 256 |
+
ABSL_INTERNAL_X_SEP)
|
| 257 |
+
} else {
|
| 258 |
+
return '\0';
|
| 259 |
+
}
|
| 260 |
+
|
| 261 |
+
#undef ABSL_INTERNAL_X_VAL
|
| 262 |
+
#undef ABSL_INTERNAL_X_SEP
|
| 263 |
+
}
|
| 264 |
+
|
| 265 |
+
// The associated char.
|
| 266 |
+
inline std::ostream& operator<<(std::ostream& os, FormatConversionChar v) {
|
| 267 |
+
char c = FormatConversionCharToChar(v);
|
| 268 |
+
if (!c) c = '?';
|
| 269 |
+
return os << c;
|
| 270 |
+
}
|
| 271 |
+
|
| 272 |
+
struct FormatConversionSpecImplFriend;
|
| 273 |
+
|
| 274 |
+
class FormatConversionSpecImpl {
|
| 275 |
+
public:
|
| 276 |
+
// Width and precison are not specified, no flags are set.
|
| 277 |
+
bool is_basic() const { return flags_ == Flags::kBasic; }
|
| 278 |
+
bool has_left_flag() const { return FlagsContains(flags_, Flags::kLeft); }
|
| 279 |
+
bool has_show_pos_flag() const {
|
| 280 |
+
return FlagsContains(flags_, Flags::kShowPos);
|
| 281 |
+
}
|
| 282 |
+
bool has_sign_col_flag() const {
|
| 283 |
+
return FlagsContains(flags_, Flags::kSignCol);
|
| 284 |
+
}
|
| 285 |
+
bool has_alt_flag() const { return FlagsContains(flags_, Flags::kAlt); }
|
| 286 |
+
bool has_zero_flag() const { return FlagsContains(flags_, Flags::kZero); }
|
| 287 |
+
|
| 288 |
+
FormatConversionChar conversion_char() const {
|
| 289 |
+
// Keep this field first in the struct . It generates better code when
|
| 290 |
+
// accessing it when ConversionSpec is passed by value in registers.
|
| 291 |
+
static_assert(offsetof(FormatConversionSpecImpl, conv_) == 0, "");
|
| 292 |
+
return conv_;
|
| 293 |
+
}
|
| 294 |
+
|
| 295 |
+
void set_conversion_char(FormatConversionChar c) { conv_ = c; }
|
| 296 |
+
|
| 297 |
+
// Returns the specified width. If width is unspecfied, it returns a negative
|
| 298 |
+
// value.
|
| 299 |
+
int width() const { return width_; }
|
| 300 |
+
// Returns the specified precision. If precision is unspecfied, it returns a
|
| 301 |
+
// negative value.
|
| 302 |
+
int precision() const { return precision_; }
|
| 303 |
+
|
| 304 |
+
template <typename T>
|
| 305 |
+
T Wrap() {
|
| 306 |
+
return T(*this);
|
| 307 |
+
}
|
| 308 |
+
|
| 309 |
+
private:
|
| 310 |
+
friend struct str_format_internal::FormatConversionSpecImplFriend;
|
| 311 |
+
FormatConversionChar conv_ = FormatConversionCharInternal::kNone;
|
| 312 |
+
Flags flags_;
|
| 313 |
+
int width_;
|
| 314 |
+
int precision_;
|
| 315 |
+
};
|
| 316 |
+
|
| 317 |
+
struct FormatConversionSpecImplFriend final {
|
| 318 |
+
static void SetFlags(Flags f, FormatConversionSpecImpl* conv) {
|
| 319 |
+
conv->flags_ = f;
|
| 320 |
+
}
|
| 321 |
+
static void SetConversionChar(FormatConversionChar c,
|
| 322 |
+
FormatConversionSpecImpl* conv) {
|
| 323 |
+
conv->conv_ = c;
|
| 324 |
+
}
|
| 325 |
+
static void SetWidth(int w, FormatConversionSpecImpl* conv) {
|
| 326 |
+
conv->width_ = w;
|
| 327 |
+
}
|
| 328 |
+
static void SetPrecision(int p, FormatConversionSpecImpl* conv) {
|
| 329 |
+
conv->precision_ = p;
|
| 330 |
+
}
|
| 331 |
+
static std::string FlagsToString(const FormatConversionSpecImpl& spec) {
|
| 332 |
+
return str_format_internal::FlagsToString(spec.flags_);
|
| 333 |
+
}
|
| 334 |
+
};
|
| 335 |
+
|
| 336 |
+
// Type safe OR operator.
|
| 337 |
+
// We need this for two reasons:
|
| 338 |
+
// 1. operator| on enums makes them decay to integers and the result is an
|
| 339 |
+
// integer. We need the result to stay as an enum.
|
| 340 |
+
// 2. We use "enum class" which would not work even if we accepted the decay.
|
| 341 |
+
constexpr FormatConversionCharSet FormatConversionCharSetUnion(
|
| 342 |
+
FormatConversionCharSet a) {
|
| 343 |
+
return a;
|
| 344 |
+
}
|
| 345 |
+
|
| 346 |
+
template <typename... CharSet>
|
| 347 |
+
constexpr FormatConversionCharSet FormatConversionCharSetUnion(
|
| 348 |
+
FormatConversionCharSet a, CharSet... rest) {
|
| 349 |
+
return static_cast<FormatConversionCharSet>(
|
| 350 |
+
static_cast<uint64_t>(a) |
|
| 351 |
+
static_cast<uint64_t>(FormatConversionCharSetUnion(rest...)));
|
| 352 |
+
}
|
| 353 |
+
|
| 354 |
+
constexpr uint64_t FormatConversionCharToConvInt(FormatConversionChar c) {
|
| 355 |
+
return uint64_t{1} << (1 + static_cast<uint8_t>(c));
|
| 356 |
+
}
|
| 357 |
+
|
| 358 |
+
constexpr uint64_t FormatConversionCharToConvInt(char conv) {
|
| 359 |
+
return
|
| 360 |
+
#define ABSL_INTERNAL_CHAR_SET_CASE(c) \
|
| 361 |
+
conv == #c[0] \
|
| 362 |
+
? FormatConversionCharToConvInt(FormatConversionCharInternal::c) \
|
| 363 |
+
:
|
| 364 |
+
ABSL_INTERNAL_CONVERSION_CHARS_EXPAND_(ABSL_INTERNAL_CHAR_SET_CASE, )
|
| 365 |
+
#undef ABSL_INTERNAL_CHAR_SET_CASE
|
| 366 |
+
conv == '*'
|
| 367 |
+
? 1
|
| 368 |
+
: 0;
|
| 369 |
+
}
|
| 370 |
+
|
| 371 |
+
constexpr FormatConversionCharSet FormatConversionCharToConvValue(char conv) {
|
| 372 |
+
return static_cast<FormatConversionCharSet>(
|
| 373 |
+
FormatConversionCharToConvInt(conv));
|
| 374 |
+
}
|
| 375 |
+
|
| 376 |
+
struct FormatConversionCharSetInternal {
|
| 377 |
+
#define ABSL_INTERNAL_CHAR_SET_CASE(c) \
|
| 378 |
+
static constexpr FormatConversionCharSet c = \
|
| 379 |
+
FormatConversionCharToConvValue(#c[0]);
|
| 380 |
+
ABSL_INTERNAL_CONVERSION_CHARS_EXPAND_(ABSL_INTERNAL_CHAR_SET_CASE, )
|
| 381 |
+
#undef ABSL_INTERNAL_CHAR_SET_CASE
|
| 382 |
+
|
| 383 |
+
// Used for width/precision '*' specification.
|
| 384 |
+
static constexpr FormatConversionCharSet kStar =
|
| 385 |
+
FormatConversionCharToConvValue('*');
|
| 386 |
+
|
| 387 |
+
static constexpr FormatConversionCharSet kIntegral =
|
| 388 |
+
FormatConversionCharSetUnion(d, i, u, o, x, X);
|
| 389 |
+
static constexpr FormatConversionCharSet kFloating =
|
| 390 |
+
FormatConversionCharSetUnion(a, e, f, g, A, E, F, G);
|
| 391 |
+
static constexpr FormatConversionCharSet kNumeric =
|
| 392 |
+
FormatConversionCharSetUnion(kIntegral, kFloating);
|
| 393 |
+
static constexpr FormatConversionCharSet kPointer = p;
|
| 394 |
+
};
|
| 395 |
+
|
| 396 |
+
// Type safe OR operator.
|
| 397 |
+
// We need this for two reasons:
|
| 398 |
+
// 1. operator| on enums makes them decay to integers and the result is an
|
| 399 |
+
// integer. We need the result to stay as an enum.
|
| 400 |
+
// 2. We use "enum class" which would not work even if we accepted the decay.
|
| 401 |
+
constexpr FormatConversionCharSet operator|(FormatConversionCharSet a,
|
| 402 |
+
FormatConversionCharSet b) {
|
| 403 |
+
return FormatConversionCharSetUnion(a, b);
|
| 404 |
+
}
|
| 405 |
+
|
| 406 |
+
// Overloaded conversion functions to support absl::ParsedFormat.
|
| 407 |
+
// Get a conversion with a single character in it.
|
| 408 |
+
constexpr FormatConversionCharSet ToFormatConversionCharSet(char c) {
|
| 409 |
+
return static_cast<FormatConversionCharSet>(
|
| 410 |
+
FormatConversionCharToConvValue(c));
|
| 411 |
+
}
|
| 412 |
+
|
| 413 |
+
// Get a conversion with a single character in it.
|
| 414 |
+
constexpr FormatConversionCharSet ToFormatConversionCharSet(
|
| 415 |
+
FormatConversionCharSet c) {
|
| 416 |
+
return c;
|
| 417 |
+
}
|
| 418 |
+
|
| 419 |
+
template <typename T>
|
| 420 |
+
void ToFormatConversionCharSet(T) = delete;
|
| 421 |
+
|
| 422 |
+
// Checks whether `c` exists in `set`.
|
| 423 |
+
constexpr bool Contains(FormatConversionCharSet set, char c) {
|
| 424 |
+
return (static_cast<uint64_t>(set) &
|
| 425 |
+
static_cast<uint64_t>(FormatConversionCharToConvValue(c))) != 0;
|
| 426 |
+
}
|
| 427 |
+
|
| 428 |
+
// Checks whether all the characters in `c` are contained in `set`
|
| 429 |
+
constexpr bool Contains(FormatConversionCharSet set,
|
| 430 |
+
FormatConversionCharSet c) {
|
| 431 |
+
return (static_cast<uint64_t>(set) & static_cast<uint64_t>(c)) ==
|
| 432 |
+
static_cast<uint64_t>(c);
|
| 433 |
+
}
|
| 434 |
+
|
| 435 |
+
// Checks whether all the characters in `c` are contained in `set`
|
| 436 |
+
constexpr bool Contains(FormatConversionCharSet set, FormatConversionChar c) {
|
| 437 |
+
return (static_cast<uint64_t>(set) & FormatConversionCharToConvInt(c)) != 0;
|
| 438 |
+
}
|
| 439 |
+
|
| 440 |
+
// Return capacity - used, clipped to a minimum of 0.
|
| 441 |
+
inline size_t Excess(size_t used, size_t capacity) {
|
| 442 |
+
return used < capacity ? capacity - used : 0;
|
| 443 |
+
}
|
| 444 |
+
|
| 445 |
+
} // namespace str_format_internal
|
| 446 |
+
|
| 447 |
+
ABSL_NAMESPACE_END
|
| 448 |
+
} // namespace absl
|
| 449 |
+
|
| 450 |
+
#endif // ABSL_STRINGS_INTERNAL_STR_FORMAT_EXTENSION_H_
|
miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/absl/strings/internal/str_format/float_conversion.h
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2020 The Abseil Authors.
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// https://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
|
| 15 |
+
#ifndef ABSL_STRINGS_INTERNAL_STR_FORMAT_FLOAT_CONVERSION_H_
|
| 16 |
+
#define ABSL_STRINGS_INTERNAL_STR_FORMAT_FLOAT_CONVERSION_H_
|
| 17 |
+
|
| 18 |
+
#include "absl/strings/internal/str_format/extension.h"
|
| 19 |
+
|
| 20 |
+
namespace absl {
|
| 21 |
+
ABSL_NAMESPACE_BEGIN
|
| 22 |
+
namespace str_format_internal {
|
| 23 |
+
|
| 24 |
+
bool ConvertFloatImpl(float v, const FormatConversionSpecImpl &conv,
|
| 25 |
+
FormatSinkImpl *sink);
|
| 26 |
+
|
| 27 |
+
bool ConvertFloatImpl(double v, const FormatConversionSpecImpl &conv,
|
| 28 |
+
FormatSinkImpl *sink);
|
| 29 |
+
|
| 30 |
+
bool ConvertFloatImpl(long double v, const FormatConversionSpecImpl &conv,
|
| 31 |
+
FormatSinkImpl *sink);
|
| 32 |
+
|
| 33 |
+
} // namespace str_format_internal
|
| 34 |
+
ABSL_NAMESPACE_END
|
| 35 |
+
} // namespace absl
|
| 36 |
+
|
| 37 |
+
#endif // ABSL_STRINGS_INTERNAL_STR_FORMAT_FLOAT_CONVERSION_H_
|
miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/absl/strings/internal/str_format/output.h
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2017 The Abseil Authors.
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// https://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
//
|
| 15 |
+
// Output extension hooks for the Format library.
|
| 16 |
+
// `internal::InvokeFlush` calls the appropriate flush function for the
|
| 17 |
+
// specified output argument.
|
| 18 |
+
// `BufferRawSink` is a simple output sink for a char buffer. Used by SnprintF.
|
| 19 |
+
// `FILERawSink` is a std::FILE* based sink. Used by PrintF and FprintF.
|
| 20 |
+
|
| 21 |
+
#ifndef ABSL_STRINGS_INTERNAL_STR_FORMAT_OUTPUT_H_
|
| 22 |
+
#define ABSL_STRINGS_INTERNAL_STR_FORMAT_OUTPUT_H_
|
| 23 |
+
|
| 24 |
+
#include <cstdio>
|
| 25 |
+
#include <ios>
|
| 26 |
+
#include <ostream>
|
| 27 |
+
#include <string>
|
| 28 |
+
|
| 29 |
+
#include "absl/base/port.h"
|
| 30 |
+
#include "absl/strings/string_view.h"
|
| 31 |
+
|
| 32 |
+
namespace absl {
|
| 33 |
+
ABSL_NAMESPACE_BEGIN
|
| 34 |
+
namespace str_format_internal {
|
| 35 |
+
|
| 36 |
+
// RawSink implementation that writes into a char* buffer.
|
| 37 |
+
// It will not overflow the buffer, but will keep the total count of chars
|
| 38 |
+
// that would have been written.
|
| 39 |
+
class BufferRawSink {
|
| 40 |
+
public:
|
| 41 |
+
BufferRawSink(char* buffer, size_t size) : buffer_(buffer), size_(size) {}
|
| 42 |
+
|
| 43 |
+
size_t total_written() const { return total_written_; }
|
| 44 |
+
void Write(string_view v);
|
| 45 |
+
|
| 46 |
+
private:
|
| 47 |
+
char* buffer_;
|
| 48 |
+
size_t size_;
|
| 49 |
+
size_t total_written_ = 0;
|
| 50 |
+
};
|
| 51 |
+
|
| 52 |
+
// RawSink implementation that writes into a FILE*.
|
| 53 |
+
// It keeps track of the total number of bytes written and any error encountered
|
| 54 |
+
// during the writes.
|
| 55 |
+
class FILERawSink {
|
| 56 |
+
public:
|
| 57 |
+
explicit FILERawSink(std::FILE* output) : output_(output) {}
|
| 58 |
+
|
| 59 |
+
void Write(string_view v);
|
| 60 |
+
|
| 61 |
+
size_t count() const { return count_; }
|
| 62 |
+
int error() const { return error_; }
|
| 63 |
+
|
| 64 |
+
private:
|
| 65 |
+
std::FILE* output_;
|
| 66 |
+
int error_ = 0;
|
| 67 |
+
size_t count_ = 0;
|
| 68 |
+
};
|
| 69 |
+
|
| 70 |
+
// Provide RawSink integration with common types from the STL.
|
| 71 |
+
inline void AbslFormatFlush(std::string* out, string_view s) {
|
| 72 |
+
out->append(s.data(), s.size());
|
| 73 |
+
}
|
| 74 |
+
inline void AbslFormatFlush(std::ostream* out, string_view s) {
|
| 75 |
+
out->write(s.data(), static_cast<std::streamsize>(s.size()));
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
inline void AbslFormatFlush(FILERawSink* sink, string_view v) {
|
| 79 |
+
sink->Write(v);
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
inline void AbslFormatFlush(BufferRawSink* sink, string_view v) {
|
| 83 |
+
sink->Write(v);
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
// This is a SFINAE to get a better compiler error message when the type
|
| 87 |
+
// is not supported.
|
| 88 |
+
template <typename T>
|
| 89 |
+
auto InvokeFlush(T* out, string_view s) -> decltype(AbslFormatFlush(out, s)) {
|
| 90 |
+
AbslFormatFlush(out, s);
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
} // namespace str_format_internal
|
| 94 |
+
ABSL_NAMESPACE_END
|
| 95 |
+
} // namespace absl
|
| 96 |
+
|
| 97 |
+
#endif // ABSL_STRINGS_INTERNAL_STR_FORMAT_OUTPUT_H_
|
miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/absl/strings/internal/str_format/parser.h
ADDED
|
@@ -0,0 +1,268 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2020 The Abseil Authors.
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// https://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
|
| 15 |
+
#ifndef ABSL_STRINGS_INTERNAL_STR_FORMAT_PARSER_H_
|
| 16 |
+
#define ABSL_STRINGS_INTERNAL_STR_FORMAT_PARSER_H_
|
| 17 |
+
|
| 18 |
+
#include <limits.h>
|
| 19 |
+
#include <stddef.h>
|
| 20 |
+
#include <stdlib.h>
|
| 21 |
+
|
| 22 |
+
#include <cassert>
|
| 23 |
+
#include <cstdint>
|
| 24 |
+
#include <initializer_list>
|
| 25 |
+
#include <iosfwd>
|
| 26 |
+
#include <iterator>
|
| 27 |
+
#include <memory>
|
| 28 |
+
#include <string>
|
| 29 |
+
#include <vector>
|
| 30 |
+
|
| 31 |
+
#include "absl/strings/internal/str_format/checker.h"
|
| 32 |
+
#include "absl/strings/internal/str_format/constexpr_parser.h"
|
| 33 |
+
#include "absl/strings/internal/str_format/extension.h"
|
| 34 |
+
|
| 35 |
+
namespace absl {
|
| 36 |
+
ABSL_NAMESPACE_BEGIN
|
| 37 |
+
namespace str_format_internal {
|
| 38 |
+
|
| 39 |
+
std::string LengthModToString(LengthMod v);
|
| 40 |
+
|
| 41 |
+
const char* ConsumeUnboundConversionNoInline(const char* p, const char* end,
|
| 42 |
+
UnboundConversion* conv,
|
| 43 |
+
int* next_arg);
|
| 44 |
+
|
| 45 |
+
// Parse the format string provided in 'src' and pass the identified items into
|
| 46 |
+
// 'consumer'.
|
| 47 |
+
// Text runs will be passed by calling
|
| 48 |
+
// Consumer::Append(string_view);
|
| 49 |
+
// ConversionItems will be passed by calling
|
| 50 |
+
// Consumer::ConvertOne(UnboundConversion, string_view);
|
| 51 |
+
// In the case of ConvertOne, the string_view that is passed is the
|
| 52 |
+
// portion of the format string corresponding to the conversion, not including
|
| 53 |
+
// the leading %. On success, it returns true. On failure, it stops and returns
|
| 54 |
+
// false.
|
| 55 |
+
template <typename Consumer>
|
| 56 |
+
bool ParseFormatString(string_view src, Consumer consumer) {
|
| 57 |
+
int next_arg = 0;
|
| 58 |
+
const char* p = src.data();
|
| 59 |
+
const char* const end = p + src.size();
|
| 60 |
+
while (p != end) {
|
| 61 |
+
const char* percent =
|
| 62 |
+
static_cast<const char*>(memchr(p, '%', static_cast<size_t>(end - p)));
|
| 63 |
+
if (!percent) {
|
| 64 |
+
// We found the last substring.
|
| 65 |
+
return consumer.Append(string_view(p, static_cast<size_t>(end - p)));
|
| 66 |
+
}
|
| 67 |
+
// We found a percent, so push the text run then process the percent.
|
| 68 |
+
if (ABSL_PREDICT_FALSE(!consumer.Append(
|
| 69 |
+
string_view(p, static_cast<size_t>(percent - p))))) {
|
| 70 |
+
return false;
|
| 71 |
+
}
|
| 72 |
+
if (ABSL_PREDICT_FALSE(percent + 1 >= end)) return false;
|
| 73 |
+
|
| 74 |
+
auto tag = GetTagForChar(percent[1]);
|
| 75 |
+
if (tag.is_conv()) {
|
| 76 |
+
if (ABSL_PREDICT_FALSE(next_arg < 0)) {
|
| 77 |
+
// This indicates an error in the format string.
|
| 78 |
+
// The only way to get `next_arg < 0` here is to have a positional
|
| 79 |
+
// argument first which sets next_arg to -1 and then a non-positional
|
| 80 |
+
// argument.
|
| 81 |
+
return false;
|
| 82 |
+
}
|
| 83 |
+
p = percent + 2;
|
| 84 |
+
|
| 85 |
+
// Keep this case separate from the one below.
|
| 86 |
+
// ConvertOne is more efficient when the compiler can see that the `basic`
|
| 87 |
+
// flag is set.
|
| 88 |
+
UnboundConversion conv;
|
| 89 |
+
conv.conv = tag.as_conv();
|
| 90 |
+
conv.arg_position = ++next_arg;
|
| 91 |
+
if (ABSL_PREDICT_FALSE(
|
| 92 |
+
!consumer.ConvertOne(conv, string_view(percent + 1, 1)))) {
|
| 93 |
+
return false;
|
| 94 |
+
}
|
| 95 |
+
} else if (percent[1] != '%') {
|
| 96 |
+
UnboundConversion conv;
|
| 97 |
+
p = ConsumeUnboundConversionNoInline(percent + 1, end, &conv, &next_arg);
|
| 98 |
+
if (ABSL_PREDICT_FALSE(p == nullptr)) return false;
|
| 99 |
+
if (ABSL_PREDICT_FALSE(!consumer.ConvertOne(
|
| 100 |
+
conv, string_view(percent + 1,
|
| 101 |
+
static_cast<size_t>(p - (percent + 1)))))) {
|
| 102 |
+
return false;
|
| 103 |
+
}
|
| 104 |
+
} else {
|
| 105 |
+
if (ABSL_PREDICT_FALSE(!consumer.Append("%"))) return false;
|
| 106 |
+
p = percent + 2;
|
| 107 |
+
continue;
|
| 108 |
+
}
|
| 109 |
+
}
|
| 110 |
+
return true;
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
// Always returns true, or fails to compile in a constexpr context if s does not
|
| 114 |
+
// point to a constexpr char array.
|
| 115 |
+
constexpr bool EnsureConstexpr(string_view s) {
|
| 116 |
+
return s.empty() || s[0] == s[0];
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
class ParsedFormatBase {
|
| 120 |
+
public:
|
| 121 |
+
explicit ParsedFormatBase(
|
| 122 |
+
string_view format, bool allow_ignored,
|
| 123 |
+
std::initializer_list<FormatConversionCharSet> convs);
|
| 124 |
+
|
| 125 |
+
ParsedFormatBase(const ParsedFormatBase& other) { *this = other; }
|
| 126 |
+
|
| 127 |
+
ParsedFormatBase(ParsedFormatBase&& other) { *this = std::move(other); }
|
| 128 |
+
|
| 129 |
+
ParsedFormatBase& operator=(const ParsedFormatBase& other) {
|
| 130 |
+
if (this == &other) return *this;
|
| 131 |
+
has_error_ = other.has_error_;
|
| 132 |
+
items_ = other.items_;
|
| 133 |
+
size_t text_size = items_.empty() ? 0 : items_.back().text_end;
|
| 134 |
+
data_.reset(new char[text_size]);
|
| 135 |
+
memcpy(data_.get(), other.data_.get(), text_size);
|
| 136 |
+
return *this;
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
+
ParsedFormatBase& operator=(ParsedFormatBase&& other) {
|
| 140 |
+
if (this == &other) return *this;
|
| 141 |
+
has_error_ = other.has_error_;
|
| 142 |
+
data_ = std::move(other.data_);
|
| 143 |
+
items_ = std::move(other.items_);
|
| 144 |
+
// Reset the vector to make sure the invariants hold.
|
| 145 |
+
other.items_.clear();
|
| 146 |
+
return *this;
|
| 147 |
+
}
|
| 148 |
+
|
| 149 |
+
template <typename Consumer>
|
| 150 |
+
bool ProcessFormat(Consumer consumer) const {
|
| 151 |
+
const char* const base = data_.get();
|
| 152 |
+
string_view text(base, 0);
|
| 153 |
+
for (const auto& item : items_) {
|
| 154 |
+
const char* const end = text.data() + text.size();
|
| 155 |
+
text =
|
| 156 |
+
string_view(end, static_cast<size_t>((base + item.text_end) - end));
|
| 157 |
+
if (item.is_conversion) {
|
| 158 |
+
if (!consumer.ConvertOne(item.conv, text)) return false;
|
| 159 |
+
} else {
|
| 160 |
+
if (!consumer.Append(text)) return false;
|
| 161 |
+
}
|
| 162 |
+
}
|
| 163 |
+
return !has_error_;
|
| 164 |
+
}
|
| 165 |
+
|
| 166 |
+
bool has_error() const { return has_error_; }
|
| 167 |
+
|
| 168 |
+
private:
|
| 169 |
+
// Returns whether the conversions match and if !allow_ignored it verifies
|
| 170 |
+
// that all conversions are used by the format.
|
| 171 |
+
bool MatchesConversions(
|
| 172 |
+
bool allow_ignored,
|
| 173 |
+
std::initializer_list<FormatConversionCharSet> convs) const;
|
| 174 |
+
|
| 175 |
+
struct ParsedFormatConsumer;
|
| 176 |
+
|
| 177 |
+
struct ConversionItem {
|
| 178 |
+
bool is_conversion;
|
| 179 |
+
// Points to the past-the-end location of this element in the data_ array.
|
| 180 |
+
size_t text_end;
|
| 181 |
+
UnboundConversion conv;
|
| 182 |
+
};
|
| 183 |
+
|
| 184 |
+
bool has_error_;
|
| 185 |
+
std::unique_ptr<char[]> data_;
|
| 186 |
+
std::vector<ConversionItem> items_;
|
| 187 |
+
};
|
| 188 |
+
|
| 189 |
+
|
| 190 |
+
// A value type representing a preparsed format. These can be created, copied
|
| 191 |
+
// around, and reused to speed up formatting loops.
|
| 192 |
+
// The user must specify through the template arguments the conversion
|
| 193 |
+
// characters used in the format. This will be checked at compile time.
|
| 194 |
+
//
|
| 195 |
+
// This class uses Conv enum values to specify each argument.
|
| 196 |
+
// This allows for more flexibility as you can specify multiple possible
|
| 197 |
+
// conversion characters for each argument.
|
| 198 |
+
// ParsedFormat<char...> is a simplified alias for when the user only
|
| 199 |
+
// needs to specify a single conversion character for each argument.
|
| 200 |
+
//
|
| 201 |
+
// Example:
|
| 202 |
+
// // Extended format supports multiple characters per argument:
|
| 203 |
+
// using MyFormat = ExtendedParsedFormat<Conv::d | Conv::x>;
|
| 204 |
+
// MyFormat GetFormat(bool use_hex) {
|
| 205 |
+
// if (use_hex) return MyFormat("foo %x bar");
|
| 206 |
+
// return MyFormat("foo %d bar");
|
| 207 |
+
// }
|
| 208 |
+
// // 'format' can be used with any value that supports 'd' and 'x',
|
| 209 |
+
// // like `int`.
|
| 210 |
+
// auto format = GetFormat(use_hex);
|
| 211 |
+
// value = StringF(format, i);
|
| 212 |
+
//
|
| 213 |
+
// This class also supports runtime format checking with the ::New() and
|
| 214 |
+
// ::NewAllowIgnored() factory functions.
|
| 215 |
+
// This is the only API that allows the user to pass a runtime specified format
|
| 216 |
+
// string. These factory functions will return NULL if the format does not match
|
| 217 |
+
// the conversions requested by the user.
|
| 218 |
+
template <FormatConversionCharSet... C>
|
| 219 |
+
class ExtendedParsedFormat : public str_format_internal::ParsedFormatBase {
|
| 220 |
+
public:
|
| 221 |
+
explicit ExtendedParsedFormat(string_view format)
|
| 222 |
+
#ifdef ABSL_INTERNAL_ENABLE_FORMAT_CHECKER
|
| 223 |
+
__attribute__((
|
| 224 |
+
enable_if(str_format_internal::EnsureConstexpr(format),
|
| 225 |
+
"Format string is not constexpr."),
|
| 226 |
+
enable_if(str_format_internal::ValidFormatImpl<C...>(format),
|
| 227 |
+
"Format specified does not match the template arguments.")))
|
| 228 |
+
#endif // ABSL_INTERNAL_ENABLE_FORMAT_CHECKER
|
| 229 |
+
: ExtendedParsedFormat(format, false) {
|
| 230 |
+
}
|
| 231 |
+
|
| 232 |
+
// ExtendedParsedFormat factory function.
|
| 233 |
+
// The user still has to specify the conversion characters, but they will not
|
| 234 |
+
// be checked at compile time. Instead, it will be checked at runtime.
|
| 235 |
+
// This delays the checking to runtime, but allows the user to pass
|
| 236 |
+
// dynamically sourced formats.
|
| 237 |
+
// It returns NULL if the format does not match the conversion characters.
|
| 238 |
+
// The user is responsible for checking the return value before using it.
|
| 239 |
+
//
|
| 240 |
+
// The 'New' variant will check that all the specified arguments are being
|
| 241 |
+
// consumed by the format and return NULL if any argument is being ignored.
|
| 242 |
+
// The 'NewAllowIgnored' variant will not verify this and will allow formats
|
| 243 |
+
// that ignore arguments.
|
| 244 |
+
static std::unique_ptr<ExtendedParsedFormat> New(string_view format) {
|
| 245 |
+
return New(format, false);
|
| 246 |
+
}
|
| 247 |
+
static std::unique_ptr<ExtendedParsedFormat> NewAllowIgnored(
|
| 248 |
+
string_view format) {
|
| 249 |
+
return New(format, true);
|
| 250 |
+
}
|
| 251 |
+
|
| 252 |
+
private:
|
| 253 |
+
static std::unique_ptr<ExtendedParsedFormat> New(string_view format,
|
| 254 |
+
bool allow_ignored) {
|
| 255 |
+
std::unique_ptr<ExtendedParsedFormat> conv(
|
| 256 |
+
new ExtendedParsedFormat(format, allow_ignored));
|
| 257 |
+
if (conv->has_error()) return nullptr;
|
| 258 |
+
return conv;
|
| 259 |
+
}
|
| 260 |
+
|
| 261 |
+
ExtendedParsedFormat(string_view s, bool allow_ignored)
|
| 262 |
+
: ParsedFormatBase(s, allow_ignored, {C...}) {}
|
| 263 |
+
};
|
| 264 |
+
} // namespace str_format_internal
|
| 265 |
+
ABSL_NAMESPACE_END
|
| 266 |
+
} // namespace absl
|
| 267 |
+
|
| 268 |
+
#endif // ABSL_STRINGS_INTERNAL_STR_FORMAT_PARSER_H_
|
miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/absl/strings/internal/str_join_internal.h
ADDED
|
@@ -0,0 +1,317 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//
|
| 2 |
+
// Copyright 2017 The Abseil Authors.
|
| 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 |
+
// https://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 |
+
// This file declares INTERNAL parts of the Join API that are inlined/templated
|
| 18 |
+
// or otherwise need to be available at compile time. The main abstractions
|
| 19 |
+
// defined in this file are:
|
| 20 |
+
//
|
| 21 |
+
// - A handful of default Formatters
|
| 22 |
+
// - JoinAlgorithm() overloads
|
| 23 |
+
// - JoinRange() overloads
|
| 24 |
+
// - JoinTuple()
|
| 25 |
+
//
|
| 26 |
+
// DO NOT INCLUDE THIS FILE DIRECTLY. Use this file by including
|
| 27 |
+
// absl/strings/str_join.h
|
| 28 |
+
//
|
| 29 |
+
// IWYU pragma: private, include "absl/strings/str_join.h"
|
| 30 |
+
|
| 31 |
+
#ifndef ABSL_STRINGS_INTERNAL_STR_JOIN_INTERNAL_H_
|
| 32 |
+
#define ABSL_STRINGS_INTERNAL_STR_JOIN_INTERNAL_H_
|
| 33 |
+
|
| 34 |
+
#include <cstring>
|
| 35 |
+
#include <iterator>
|
| 36 |
+
#include <memory>
|
| 37 |
+
#include <string>
|
| 38 |
+
#include <type_traits>
|
| 39 |
+
#include <utility>
|
| 40 |
+
|
| 41 |
+
#include "absl/strings/internal/ostringstream.h"
|
| 42 |
+
#include "absl/strings/internal/resize_uninitialized.h"
|
| 43 |
+
#include "absl/strings/str_cat.h"
|
| 44 |
+
|
| 45 |
+
namespace absl {
|
| 46 |
+
ABSL_NAMESPACE_BEGIN
|
| 47 |
+
namespace strings_internal {
|
| 48 |
+
|
| 49 |
+
//
|
| 50 |
+
// Formatter objects
|
| 51 |
+
//
|
| 52 |
+
// The following are implementation classes for standard Formatter objects. The
|
| 53 |
+
// factory functions that users will call to create and use these formatters are
|
| 54 |
+
// defined and documented in strings/join.h.
|
| 55 |
+
//
|
| 56 |
+
|
| 57 |
+
// The default formatter. Converts alpha-numeric types to strings.
|
| 58 |
+
struct AlphaNumFormatterImpl {
|
| 59 |
+
// This template is needed in order to support passing in a dereferenced
|
| 60 |
+
// vector<bool>::iterator
|
| 61 |
+
template <typename T>
|
| 62 |
+
void operator()(std::string* out, const T& t) const {
|
| 63 |
+
StrAppend(out, AlphaNum(t));
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
void operator()(std::string* out, const AlphaNum& t) const {
|
| 67 |
+
StrAppend(out, t);
|
| 68 |
+
}
|
| 69 |
+
};
|
| 70 |
+
|
| 71 |
+
// A type that's used to overload the JoinAlgorithm() function (defined below)
|
| 72 |
+
// for ranges that do not require additional formatting (e.g., a range of
|
| 73 |
+
// strings).
|
| 74 |
+
|
| 75 |
+
struct NoFormatter : public AlphaNumFormatterImpl {};
|
| 76 |
+
|
| 77 |
+
// Formats types to strings using the << operator.
|
| 78 |
+
class StreamFormatterImpl {
|
| 79 |
+
public:
|
| 80 |
+
// The method isn't const because it mutates state. Making it const will
|
| 81 |
+
// render StreamFormatterImpl thread-hostile.
|
| 82 |
+
template <typename T>
|
| 83 |
+
void operator()(std::string* out, const T& t) {
|
| 84 |
+
// The stream is created lazily to avoid paying the relatively high cost
|
| 85 |
+
// of its construction when joining an empty range.
|
| 86 |
+
if (strm_) {
|
| 87 |
+
strm_->clear(); // clear the bad, fail and eof bits in case they were set
|
| 88 |
+
strm_->str(out);
|
| 89 |
+
} else {
|
| 90 |
+
strm_.reset(new strings_internal::OStringStream(out));
|
| 91 |
+
}
|
| 92 |
+
*strm_ << t;
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
private:
|
| 96 |
+
std::unique_ptr<strings_internal::OStringStream> strm_;
|
| 97 |
+
};
|
| 98 |
+
|
| 99 |
+
// Formats a std::pair<>. The 'first' member is formatted using f1_ and the
|
| 100 |
+
// 'second' member is formatted using f2_. sep_ is the separator.
|
| 101 |
+
template <typename F1, typename F2>
|
| 102 |
+
class PairFormatterImpl {
|
| 103 |
+
public:
|
| 104 |
+
PairFormatterImpl(F1 f1, absl::string_view sep, F2 f2)
|
| 105 |
+
: f1_(std::move(f1)), sep_(sep), f2_(std::move(f2)) {}
|
| 106 |
+
|
| 107 |
+
template <typename T>
|
| 108 |
+
void operator()(std::string* out, const T& p) {
|
| 109 |
+
f1_(out, p.first);
|
| 110 |
+
out->append(sep_);
|
| 111 |
+
f2_(out, p.second);
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
template <typename T>
|
| 115 |
+
void operator()(std::string* out, const T& p) const {
|
| 116 |
+
f1_(out, p.first);
|
| 117 |
+
out->append(sep_);
|
| 118 |
+
f2_(out, p.second);
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
private:
|
| 122 |
+
F1 f1_;
|
| 123 |
+
std::string sep_;
|
| 124 |
+
F2 f2_;
|
| 125 |
+
};
|
| 126 |
+
|
| 127 |
+
// Wraps another formatter and dereferences the argument to operator() then
|
| 128 |
+
// passes the dereferenced argument to the wrapped formatter. This can be
|
| 129 |
+
// useful, for example, to join a std::vector<int*>.
|
| 130 |
+
template <typename Formatter>
|
| 131 |
+
class DereferenceFormatterImpl {
|
| 132 |
+
public:
|
| 133 |
+
DereferenceFormatterImpl() : f_() {}
|
| 134 |
+
explicit DereferenceFormatterImpl(Formatter&& f)
|
| 135 |
+
: f_(std::forward<Formatter>(f)) {}
|
| 136 |
+
|
| 137 |
+
template <typename T>
|
| 138 |
+
void operator()(std::string* out, const T& t) {
|
| 139 |
+
f_(out, *t);
|
| 140 |
+
}
|
| 141 |
+
|
| 142 |
+
template <typename T>
|
| 143 |
+
void operator()(std::string* out, const T& t) const {
|
| 144 |
+
f_(out, *t);
|
| 145 |
+
}
|
| 146 |
+
|
| 147 |
+
private:
|
| 148 |
+
Formatter f_;
|
| 149 |
+
};
|
| 150 |
+
|
| 151 |
+
// DefaultFormatter<T> is a traits class that selects a default Formatter to use
|
| 152 |
+
// for the given type T. The ::Type member names the Formatter to use. This is
|
| 153 |
+
// used by the strings::Join() functions that do NOT take a Formatter argument,
|
| 154 |
+
// in which case a default Formatter must be chosen.
|
| 155 |
+
//
|
| 156 |
+
// AlphaNumFormatterImpl is the default in the base template, followed by
|
| 157 |
+
// specializations for other types.
|
| 158 |
+
template <typename ValueType>
|
| 159 |
+
struct DefaultFormatter {
|
| 160 |
+
typedef AlphaNumFormatterImpl Type;
|
| 161 |
+
};
|
| 162 |
+
template <>
|
| 163 |
+
struct DefaultFormatter<const char*> {
|
| 164 |
+
typedef AlphaNumFormatterImpl Type;
|
| 165 |
+
};
|
| 166 |
+
template <>
|
| 167 |
+
struct DefaultFormatter<char*> {
|
| 168 |
+
typedef AlphaNumFormatterImpl Type;
|
| 169 |
+
};
|
| 170 |
+
template <>
|
| 171 |
+
struct DefaultFormatter<std::string> {
|
| 172 |
+
typedef NoFormatter Type;
|
| 173 |
+
};
|
| 174 |
+
template <>
|
| 175 |
+
struct DefaultFormatter<absl::string_view> {
|
| 176 |
+
typedef NoFormatter Type;
|
| 177 |
+
};
|
| 178 |
+
template <typename ValueType>
|
| 179 |
+
struct DefaultFormatter<ValueType*> {
|
| 180 |
+
typedef DereferenceFormatterImpl<typename DefaultFormatter<ValueType>::Type>
|
| 181 |
+
Type;
|
| 182 |
+
};
|
| 183 |
+
|
| 184 |
+
template <typename ValueType>
|
| 185 |
+
struct DefaultFormatter<std::unique_ptr<ValueType>>
|
| 186 |
+
: public DefaultFormatter<ValueType*> {};
|
| 187 |
+
|
| 188 |
+
//
|
| 189 |
+
// JoinAlgorithm() functions
|
| 190 |
+
//
|
| 191 |
+
|
| 192 |
+
// The main joining algorithm. This simply joins the elements in the given
|
| 193 |
+
// iterator range, each separated by the given separator, into an output string,
|
| 194 |
+
// and formats each element using the provided Formatter object.
|
| 195 |
+
template <typename Iterator, typename Formatter>
|
| 196 |
+
std::string JoinAlgorithm(Iterator start, Iterator end, absl::string_view s,
|
| 197 |
+
Formatter&& f) {
|
| 198 |
+
std::string result;
|
| 199 |
+
absl::string_view sep("");
|
| 200 |
+
for (Iterator it = start; it != end; ++it) {
|
| 201 |
+
result.append(sep.data(), sep.size());
|
| 202 |
+
f(&result, *it);
|
| 203 |
+
sep = s;
|
| 204 |
+
}
|
| 205 |
+
return result;
|
| 206 |
+
}
|
| 207 |
+
|
| 208 |
+
// A joining algorithm that's optimized for a forward iterator range of
|
| 209 |
+
// string-like objects that do not need any additional formatting. This is to
|
| 210 |
+
// optimize the common case of joining, say, a std::vector<string> or a
|
| 211 |
+
// std::vector<absl::string_view>.
|
| 212 |
+
//
|
| 213 |
+
// This is an overload of the previous JoinAlgorithm() function. Here the
|
| 214 |
+
// Formatter argument is of type NoFormatter. Since NoFormatter is an internal
|
| 215 |
+
// type, this overload is only invoked when strings::Join() is called with a
|
| 216 |
+
// range of string-like objects (e.g., std::string, absl::string_view), and an
|
| 217 |
+
// explicit Formatter argument was NOT specified.
|
| 218 |
+
//
|
| 219 |
+
// The optimization is that the needed space will be reserved in the output
|
| 220 |
+
// string to avoid the need to resize while appending. To do this, the iterator
|
| 221 |
+
// range will be traversed twice: once to calculate the total needed size, and
|
| 222 |
+
// then again to copy the elements and delimiters to the output string.
|
| 223 |
+
template <typename Iterator,
|
| 224 |
+
typename = typename std::enable_if<std::is_convertible<
|
| 225 |
+
typename std::iterator_traits<Iterator>::iterator_category,
|
| 226 |
+
std::forward_iterator_tag>::value>::type>
|
| 227 |
+
std::string JoinAlgorithm(Iterator start, Iterator end, absl::string_view s,
|
| 228 |
+
NoFormatter) {
|
| 229 |
+
std::string result;
|
| 230 |
+
if (start != end) {
|
| 231 |
+
// Sums size
|
| 232 |
+
auto&& start_value = *start;
|
| 233 |
+
size_t result_size = start_value.size();
|
| 234 |
+
for (Iterator it = start; ++it != end;) {
|
| 235 |
+
result_size += s.size();
|
| 236 |
+
result_size += (*it).size();
|
| 237 |
+
}
|
| 238 |
+
|
| 239 |
+
if (result_size > 0) {
|
| 240 |
+
STLStringResizeUninitialized(&result, result_size);
|
| 241 |
+
|
| 242 |
+
// Joins strings
|
| 243 |
+
char* result_buf = &*result.begin();
|
| 244 |
+
|
| 245 |
+
memcpy(result_buf, start_value.data(), start_value.size());
|
| 246 |
+
result_buf += start_value.size();
|
| 247 |
+
for (Iterator it = start; ++it != end;) {
|
| 248 |
+
memcpy(result_buf, s.data(), s.size());
|
| 249 |
+
result_buf += s.size();
|
| 250 |
+
auto&& value = *it;
|
| 251 |
+
memcpy(result_buf, value.data(), value.size());
|
| 252 |
+
result_buf += value.size();
|
| 253 |
+
}
|
| 254 |
+
}
|
| 255 |
+
}
|
| 256 |
+
|
| 257 |
+
return result;
|
| 258 |
+
}
|
| 259 |
+
|
| 260 |
+
// JoinTupleLoop implements a loop over the elements of a std::tuple, which
|
| 261 |
+
// are heterogeneous. The primary template matches the tuple interior case. It
|
| 262 |
+
// continues the iteration after appending a separator (for nonzero indices)
|
| 263 |
+
// and formatting an element of the tuple. The specialization for the I=N case
|
| 264 |
+
// matches the end-of-tuple, and terminates the iteration.
|
| 265 |
+
template <size_t I, size_t N>
|
| 266 |
+
struct JoinTupleLoop {
|
| 267 |
+
template <typename Tup, typename Formatter>
|
| 268 |
+
void operator()(std::string* out, const Tup& tup, absl::string_view sep,
|
| 269 |
+
Formatter&& fmt) {
|
| 270 |
+
if (I > 0) out->append(sep.data(), sep.size());
|
| 271 |
+
fmt(out, std::get<I>(tup));
|
| 272 |
+
JoinTupleLoop<I + 1, N>()(out, tup, sep, fmt);
|
| 273 |
+
}
|
| 274 |
+
};
|
| 275 |
+
template <size_t N>
|
| 276 |
+
struct JoinTupleLoop<N, N> {
|
| 277 |
+
template <typename Tup, typename Formatter>
|
| 278 |
+
void operator()(std::string*, const Tup&, absl::string_view, Formatter&&) {}
|
| 279 |
+
};
|
| 280 |
+
|
| 281 |
+
template <typename... T, typename Formatter>
|
| 282 |
+
std::string JoinAlgorithm(const std::tuple<T...>& tup, absl::string_view sep,
|
| 283 |
+
Formatter&& fmt) {
|
| 284 |
+
std::string result;
|
| 285 |
+
JoinTupleLoop<0, sizeof...(T)>()(&result, tup, sep, fmt);
|
| 286 |
+
return result;
|
| 287 |
+
}
|
| 288 |
+
|
| 289 |
+
template <typename Iterator>
|
| 290 |
+
std::string JoinRange(Iterator first, Iterator last,
|
| 291 |
+
absl::string_view separator) {
|
| 292 |
+
// No formatter was explicitly given, so a default must be chosen.
|
| 293 |
+
typedef typename std::iterator_traits<Iterator>::value_type ValueType;
|
| 294 |
+
typedef typename DefaultFormatter<ValueType>::Type Formatter;
|
| 295 |
+
return JoinAlgorithm(first, last, separator, Formatter());
|
| 296 |
+
}
|
| 297 |
+
|
| 298 |
+
template <typename Range, typename Formatter>
|
| 299 |
+
std::string JoinRange(const Range& range, absl::string_view separator,
|
| 300 |
+
Formatter&& fmt) {
|
| 301 |
+
using std::begin;
|
| 302 |
+
using std::end;
|
| 303 |
+
return JoinAlgorithm(begin(range), end(range), separator, fmt);
|
| 304 |
+
}
|
| 305 |
+
|
| 306 |
+
template <typename Range>
|
| 307 |
+
std::string JoinRange(const Range& range, absl::string_view separator) {
|
| 308 |
+
using std::begin;
|
| 309 |
+
using std::end;
|
| 310 |
+
return JoinRange(begin(range), end(range), separator);
|
| 311 |
+
}
|
| 312 |
+
|
| 313 |
+
} // namespace strings_internal
|
| 314 |
+
ABSL_NAMESPACE_END
|
| 315 |
+
} // namespace absl
|
| 316 |
+
|
| 317 |
+
#endif // ABSL_STRINGS_INTERNAL_STR_JOIN_INTERNAL_H_
|
miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/absl/strings/internal/str_split_internal.h
ADDED
|
@@ -0,0 +1,431 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2017 The Abseil Authors.
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// https://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
//
|
| 15 |
+
|
| 16 |
+
// This file declares INTERNAL parts of the Split API that are inline/templated
|
| 17 |
+
// or otherwise need to be available at compile time. The main abstractions
|
| 18 |
+
// defined in here are
|
| 19 |
+
//
|
| 20 |
+
// - ConvertibleToStringView
|
| 21 |
+
// - SplitIterator<>
|
| 22 |
+
// - Splitter<>
|
| 23 |
+
//
|
| 24 |
+
// DO NOT INCLUDE THIS FILE DIRECTLY. Use this file by including
|
| 25 |
+
// absl/strings/str_split.h.
|
| 26 |
+
//
|
| 27 |
+
// IWYU pragma: private, include "absl/strings/str_split.h"
|
| 28 |
+
|
| 29 |
+
#ifndef ABSL_STRINGS_INTERNAL_STR_SPLIT_INTERNAL_H_
|
| 30 |
+
#define ABSL_STRINGS_INTERNAL_STR_SPLIT_INTERNAL_H_
|
| 31 |
+
|
| 32 |
+
#include <array>
|
| 33 |
+
#include <initializer_list>
|
| 34 |
+
#include <iterator>
|
| 35 |
+
#include <tuple>
|
| 36 |
+
#include <type_traits>
|
| 37 |
+
#include <utility>
|
| 38 |
+
#include <vector>
|
| 39 |
+
|
| 40 |
+
#include "absl/base/macros.h"
|
| 41 |
+
#include "absl/base/port.h"
|
| 42 |
+
#include "absl/meta/type_traits.h"
|
| 43 |
+
#include "absl/strings/string_view.h"
|
| 44 |
+
|
| 45 |
+
#ifdef _GLIBCXX_DEBUG
|
| 46 |
+
#include "absl/strings/internal/stl_type_traits.h"
|
| 47 |
+
#endif // _GLIBCXX_DEBUG
|
| 48 |
+
|
| 49 |
+
namespace absl {
|
| 50 |
+
ABSL_NAMESPACE_BEGIN
|
| 51 |
+
namespace strings_internal {
|
| 52 |
+
|
| 53 |
+
// This class is implicitly constructible from everything that absl::string_view
|
| 54 |
+
// is implicitly constructible from, except for rvalue strings. This means it
|
| 55 |
+
// can be used as a function parameter in places where passing a temporary
|
| 56 |
+
// string might cause memory lifetime issues.
|
| 57 |
+
class ConvertibleToStringView {
|
| 58 |
+
public:
|
| 59 |
+
ConvertibleToStringView(const char* s) // NOLINT(runtime/explicit)
|
| 60 |
+
: value_(s) {}
|
| 61 |
+
ConvertibleToStringView(char* s) : value_(s) {} // NOLINT(runtime/explicit)
|
| 62 |
+
ConvertibleToStringView(absl::string_view s) // NOLINT(runtime/explicit)
|
| 63 |
+
: value_(s) {}
|
| 64 |
+
ConvertibleToStringView(const std::string& s) // NOLINT(runtime/explicit)
|
| 65 |
+
: value_(s) {}
|
| 66 |
+
|
| 67 |
+
// Disable conversion from rvalue strings.
|
| 68 |
+
ConvertibleToStringView(std::string&& s) = delete;
|
| 69 |
+
ConvertibleToStringView(const std::string&& s) = delete;
|
| 70 |
+
|
| 71 |
+
absl::string_view value() const { return value_; }
|
| 72 |
+
|
| 73 |
+
private:
|
| 74 |
+
absl::string_view value_;
|
| 75 |
+
};
|
| 76 |
+
|
| 77 |
+
// An iterator that enumerates the parts of a string from a Splitter. The text
|
| 78 |
+
// to be split, the Delimiter, and the Predicate are all taken from the given
|
| 79 |
+
// Splitter object. Iterators may only be compared if they refer to the same
|
| 80 |
+
// Splitter instance.
|
| 81 |
+
//
|
| 82 |
+
// This class is NOT part of the public splitting API.
|
| 83 |
+
template <typename Splitter>
|
| 84 |
+
class SplitIterator {
|
| 85 |
+
public:
|
| 86 |
+
using iterator_category = std::input_iterator_tag;
|
| 87 |
+
using value_type = absl::string_view;
|
| 88 |
+
using difference_type = ptrdiff_t;
|
| 89 |
+
using pointer = const value_type*;
|
| 90 |
+
using reference = const value_type&;
|
| 91 |
+
|
| 92 |
+
enum State { kInitState, kLastState, kEndState };
|
| 93 |
+
SplitIterator(State state, const Splitter* splitter)
|
| 94 |
+
: pos_(0),
|
| 95 |
+
state_(state),
|
| 96 |
+
splitter_(splitter),
|
| 97 |
+
delimiter_(splitter->delimiter()),
|
| 98 |
+
predicate_(splitter->predicate()) {
|
| 99 |
+
// Hack to maintain backward compatibility. This one block makes it so an
|
| 100 |
+
// empty absl::string_view whose .data() happens to be nullptr behaves
|
| 101 |
+
// *differently* from an otherwise empty absl::string_view whose .data() is
|
| 102 |
+
// not nullptr. This is an undesirable difference in general, but this
|
| 103 |
+
// behavior is maintained to avoid breaking existing code that happens to
|
| 104 |
+
// depend on this old behavior/bug. Perhaps it will be fixed one day. The
|
| 105 |
+
// difference in behavior is as follows:
|
| 106 |
+
// Split(absl::string_view(""), '-'); // {""}
|
| 107 |
+
// Split(absl::string_view(), '-'); // {}
|
| 108 |
+
if (splitter_->text().data() == nullptr) {
|
| 109 |
+
state_ = kEndState;
|
| 110 |
+
pos_ = splitter_->text().size();
|
| 111 |
+
return;
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
if (state_ == kEndState) {
|
| 115 |
+
pos_ = splitter_->text().size();
|
| 116 |
+
} else {
|
| 117 |
+
++(*this);
|
| 118 |
+
}
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
bool at_end() const { return state_ == kEndState; }
|
| 122 |
+
|
| 123 |
+
reference operator*() const { return curr_; }
|
| 124 |
+
pointer operator->() const { return &curr_; }
|
| 125 |
+
|
| 126 |
+
SplitIterator& operator++() {
|
| 127 |
+
do {
|
| 128 |
+
if (state_ == kLastState) {
|
| 129 |
+
state_ = kEndState;
|
| 130 |
+
return *this;
|
| 131 |
+
}
|
| 132 |
+
const absl::string_view text = splitter_->text();
|
| 133 |
+
const absl::string_view d = delimiter_.Find(text, pos_);
|
| 134 |
+
if (d.data() == text.data() + text.size()) state_ = kLastState;
|
| 135 |
+
curr_ = text.substr(pos_,
|
| 136 |
+
static_cast<size_t>(d.data() - (text.data() + pos_)));
|
| 137 |
+
pos_ += curr_.size() + d.size();
|
| 138 |
+
} while (!predicate_(curr_));
|
| 139 |
+
return *this;
|
| 140 |
+
}
|
| 141 |
+
|
| 142 |
+
SplitIterator operator++(int) {
|
| 143 |
+
SplitIterator old(*this);
|
| 144 |
+
++(*this);
|
| 145 |
+
return old;
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
friend bool operator==(const SplitIterator& a, const SplitIterator& b) {
|
| 149 |
+
return a.state_ == b.state_ && a.pos_ == b.pos_;
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
friend bool operator!=(const SplitIterator& a, const SplitIterator& b) {
|
| 153 |
+
return !(a == b);
|
| 154 |
+
}
|
| 155 |
+
|
| 156 |
+
private:
|
| 157 |
+
size_t pos_;
|
| 158 |
+
State state_;
|
| 159 |
+
absl::string_view curr_;
|
| 160 |
+
const Splitter* splitter_;
|
| 161 |
+
typename Splitter::DelimiterType delimiter_;
|
| 162 |
+
typename Splitter::PredicateType predicate_;
|
| 163 |
+
};
|
| 164 |
+
|
| 165 |
+
// HasMappedType<T>::value is true iff there exists a type T::mapped_type.
|
| 166 |
+
template <typename T, typename = void>
|
| 167 |
+
struct HasMappedType : std::false_type {};
|
| 168 |
+
template <typename T>
|
| 169 |
+
struct HasMappedType<T, absl::void_t<typename T::mapped_type>>
|
| 170 |
+
: std::true_type {};
|
| 171 |
+
|
| 172 |
+
// HasValueType<T>::value is true iff there exists a type T::value_type.
|
| 173 |
+
template <typename T, typename = void>
|
| 174 |
+
struct HasValueType : std::false_type {};
|
| 175 |
+
template <typename T>
|
| 176 |
+
struct HasValueType<T, absl::void_t<typename T::value_type>> : std::true_type {
|
| 177 |
+
};
|
| 178 |
+
|
| 179 |
+
// HasConstIterator<T>::value is true iff there exists a type T::const_iterator.
|
| 180 |
+
template <typename T, typename = void>
|
| 181 |
+
struct HasConstIterator : std::false_type {};
|
| 182 |
+
template <typename T>
|
| 183 |
+
struct HasConstIterator<T, absl::void_t<typename T::const_iterator>>
|
| 184 |
+
: std::true_type {};
|
| 185 |
+
|
| 186 |
+
// HasEmplace<T>::value is true iff there exists a method T::emplace().
|
| 187 |
+
template <typename T, typename = void>
|
| 188 |
+
struct HasEmplace : std::false_type {};
|
| 189 |
+
template <typename T>
|
| 190 |
+
struct HasEmplace<T, absl::void_t<decltype(std::declval<T>().emplace())>>
|
| 191 |
+
: std::true_type {};
|
| 192 |
+
|
| 193 |
+
// IsInitializerList<T>::value is true iff T is an std::initializer_list. More
|
| 194 |
+
// details below in Splitter<> where this is used.
|
| 195 |
+
std::false_type IsInitializerListDispatch(...); // default: No
|
| 196 |
+
template <typename T>
|
| 197 |
+
std::true_type IsInitializerListDispatch(std::initializer_list<T>*);
|
| 198 |
+
template <typename T>
|
| 199 |
+
struct IsInitializerList
|
| 200 |
+
: decltype(IsInitializerListDispatch(static_cast<T*>(nullptr))) {};
|
| 201 |
+
|
| 202 |
+
// A SplitterIsConvertibleTo<C>::type alias exists iff the specified condition
|
| 203 |
+
// is true for type 'C'.
|
| 204 |
+
//
|
| 205 |
+
// Restricts conversion to container-like types (by testing for the presence of
|
| 206 |
+
// a const_iterator member type) and also to disable conversion to an
|
| 207 |
+
// std::initializer_list (which also has a const_iterator). Otherwise, code
|
| 208 |
+
// compiled in C++11 will get an error due to ambiguous conversion paths (in
|
| 209 |
+
// C++11 std::vector<T>::operator= is overloaded to take either a std::vector<T>
|
| 210 |
+
// or an std::initializer_list<T>).
|
| 211 |
+
|
| 212 |
+
template <typename C, bool has_value_type, bool has_mapped_type>
|
| 213 |
+
struct SplitterIsConvertibleToImpl : std::false_type {};
|
| 214 |
+
|
| 215 |
+
template <typename C>
|
| 216 |
+
struct SplitterIsConvertibleToImpl<C, true, false>
|
| 217 |
+
: std::is_constructible<typename C::value_type, absl::string_view> {};
|
| 218 |
+
|
| 219 |
+
template <typename C>
|
| 220 |
+
struct SplitterIsConvertibleToImpl<C, true, true>
|
| 221 |
+
: absl::conjunction<
|
| 222 |
+
std::is_constructible<typename C::key_type, absl::string_view>,
|
| 223 |
+
std::is_constructible<typename C::mapped_type, absl::string_view>> {};
|
| 224 |
+
|
| 225 |
+
template <typename C>
|
| 226 |
+
struct SplitterIsConvertibleTo
|
| 227 |
+
: SplitterIsConvertibleToImpl<
|
| 228 |
+
C,
|
| 229 |
+
#ifdef _GLIBCXX_DEBUG
|
| 230 |
+
!IsStrictlyBaseOfAndConvertibleToSTLContainer<C>::value &&
|
| 231 |
+
#endif // _GLIBCXX_DEBUG
|
| 232 |
+
!IsInitializerList<
|
| 233 |
+
typename std::remove_reference<C>::type>::value &&
|
| 234 |
+
HasValueType<C>::value && HasConstIterator<C>::value,
|
| 235 |
+
HasMappedType<C>::value> {
|
| 236 |
+
};
|
| 237 |
+
|
| 238 |
+
// This class implements the range that is returned by absl::StrSplit(). This
|
| 239 |
+
// class has templated conversion operators that allow it to be implicitly
|
| 240 |
+
// converted to a variety of types that the caller may have specified on the
|
| 241 |
+
// left-hand side of an assignment.
|
| 242 |
+
//
|
| 243 |
+
// The main interface for interacting with this class is through its implicit
|
| 244 |
+
// conversion operators. However, this class may also be used like a container
|
| 245 |
+
// in that it has .begin() and .end() member functions. It may also be used
|
| 246 |
+
// within a range-for loop.
|
| 247 |
+
//
|
| 248 |
+
// Output containers can be collections of any type that is constructible from
|
| 249 |
+
// an absl::string_view.
|
| 250 |
+
//
|
| 251 |
+
// An Predicate functor may be supplied. This predicate will be used to filter
|
| 252 |
+
// the split strings: only strings for which the predicate returns true will be
|
| 253 |
+
// kept. A Predicate object is any unary functor that takes an absl::string_view
|
| 254 |
+
// and returns bool.
|
| 255 |
+
//
|
| 256 |
+
// The StringType parameter can be either string_view or string, depending on
|
| 257 |
+
// whether the Splitter refers to a string stored elsewhere, or if the string
|
| 258 |
+
// resides inside the Splitter itself.
|
| 259 |
+
template <typename Delimiter, typename Predicate, typename StringType>
|
| 260 |
+
class Splitter {
|
| 261 |
+
public:
|
| 262 |
+
using DelimiterType = Delimiter;
|
| 263 |
+
using PredicateType = Predicate;
|
| 264 |
+
using const_iterator = strings_internal::SplitIterator<Splitter>;
|
| 265 |
+
using value_type = typename std::iterator_traits<const_iterator>::value_type;
|
| 266 |
+
|
| 267 |
+
Splitter(StringType input_text, Delimiter d, Predicate p)
|
| 268 |
+
: text_(std::move(input_text)),
|
| 269 |
+
delimiter_(std::move(d)),
|
| 270 |
+
predicate_(std::move(p)) {}
|
| 271 |
+
|
| 272 |
+
absl::string_view text() const { return text_; }
|
| 273 |
+
const Delimiter& delimiter() const { return delimiter_; }
|
| 274 |
+
const Predicate& predicate() const { return predicate_; }
|
| 275 |
+
|
| 276 |
+
// Range functions that iterate the split substrings as absl::string_view
|
| 277 |
+
// objects. These methods enable a Splitter to be used in a range-based for
|
| 278 |
+
// loop.
|
| 279 |
+
const_iterator begin() const { return {const_iterator::kInitState, this}; }
|
| 280 |
+
const_iterator end() const { return {const_iterator::kEndState, this}; }
|
| 281 |
+
|
| 282 |
+
// An implicit conversion operator that is restricted to only those containers
|
| 283 |
+
// that the splitter is convertible to.
|
| 284 |
+
template <typename Container,
|
| 285 |
+
typename = typename std::enable_if<
|
| 286 |
+
SplitterIsConvertibleTo<Container>::value>::type>
|
| 287 |
+
operator Container() const { // NOLINT(runtime/explicit)
|
| 288 |
+
return ConvertToContainer<Container, typename Container::value_type,
|
| 289 |
+
HasMappedType<Container>::value>()(*this);
|
| 290 |
+
}
|
| 291 |
+
|
| 292 |
+
// Returns a pair with its .first and .second members set to the first two
|
| 293 |
+
// strings returned by the begin() iterator. Either/both of .first and .second
|
| 294 |
+
// will be constructed with empty strings if the iterator doesn't have a
|
| 295 |
+
// corresponding value.
|
| 296 |
+
template <typename First, typename Second>
|
| 297 |
+
operator std::pair<First, Second>() const { // NOLINT(runtime/explicit)
|
| 298 |
+
absl::string_view first, second;
|
| 299 |
+
auto it = begin();
|
| 300 |
+
if (it != end()) {
|
| 301 |
+
first = *it;
|
| 302 |
+
if (++it != end()) {
|
| 303 |
+
second = *it;
|
| 304 |
+
}
|
| 305 |
+
}
|
| 306 |
+
return {First(first), Second(second)};
|
| 307 |
+
}
|
| 308 |
+
|
| 309 |
+
private:
|
| 310 |
+
// ConvertToContainer is a functor converting a Splitter to the requested
|
| 311 |
+
// Container of ValueType. It is specialized below to optimize splitting to
|
| 312 |
+
// certain combinations of Container and ValueType.
|
| 313 |
+
//
|
| 314 |
+
// This base template handles the generic case of storing the split results in
|
| 315 |
+
// the requested non-map-like container and converting the split substrings to
|
| 316 |
+
// the requested type.
|
| 317 |
+
template <typename Container, typename ValueType, bool is_map = false>
|
| 318 |
+
struct ConvertToContainer {
|
| 319 |
+
Container operator()(const Splitter& splitter) const {
|
| 320 |
+
Container c;
|
| 321 |
+
auto it = std::inserter(c, c.end());
|
| 322 |
+
for (const auto& sp : splitter) {
|
| 323 |
+
*it++ = ValueType(sp);
|
| 324 |
+
}
|
| 325 |
+
return c;
|
| 326 |
+
}
|
| 327 |
+
};
|
| 328 |
+
|
| 329 |
+
// Partial specialization for a std::vector<absl::string_view>.
|
| 330 |
+
//
|
| 331 |
+
// Optimized for the common case of splitting to a
|
| 332 |
+
// std::vector<absl::string_view>. In this case we first split the results to
|
| 333 |
+
// a small array of absl::string_view on the stack, to reduce reallocations.
|
| 334 |
+
template <typename A>
|
| 335 |
+
struct ConvertToContainer<std::vector<absl::string_view, A>,
|
| 336 |
+
absl::string_view, false> {
|
| 337 |
+
std::vector<absl::string_view, A> operator()(
|
| 338 |
+
const Splitter& splitter) const {
|
| 339 |
+
struct raw_view {
|
| 340 |
+
const char* data;
|
| 341 |
+
size_t size;
|
| 342 |
+
operator absl::string_view() const { // NOLINT(runtime/explicit)
|
| 343 |
+
return {data, size};
|
| 344 |
+
}
|
| 345 |
+
};
|
| 346 |
+
std::vector<absl::string_view, A> v;
|
| 347 |
+
std::array<raw_view, 16> ar;
|
| 348 |
+
for (auto it = splitter.begin(); !it.at_end();) {
|
| 349 |
+
size_t index = 0;
|
| 350 |
+
do {
|
| 351 |
+
ar[index].data = it->data();
|
| 352 |
+
ar[index].size = it->size();
|
| 353 |
+
++it;
|
| 354 |
+
} while (++index != ar.size() && !it.at_end());
|
| 355 |
+
v.insert(v.end(), ar.begin(), ar.begin() + index);
|
| 356 |
+
}
|
| 357 |
+
return v;
|
| 358 |
+
}
|
| 359 |
+
};
|
| 360 |
+
|
| 361 |
+
// Partial specialization for a std::vector<std::string>.
|
| 362 |
+
//
|
| 363 |
+
// Optimized for the common case of splitting to a std::vector<std::string>.
|
| 364 |
+
// In this case we first split the results to a std::vector<absl::string_view>
|
| 365 |
+
// so the returned std::vector<std::string> can have space reserved to avoid
|
| 366 |
+
// std::string moves.
|
| 367 |
+
template <typename A>
|
| 368 |
+
struct ConvertToContainer<std::vector<std::string, A>, std::string, false> {
|
| 369 |
+
std::vector<std::string, A> operator()(const Splitter& splitter) const {
|
| 370 |
+
const std::vector<absl::string_view> v = splitter;
|
| 371 |
+
return std::vector<std::string, A>(v.begin(), v.end());
|
| 372 |
+
}
|
| 373 |
+
};
|
| 374 |
+
|
| 375 |
+
// Partial specialization for containers of pairs (e.g., maps).
|
| 376 |
+
//
|
| 377 |
+
// The algorithm is to insert a new pair into the map for each even-numbered
|
| 378 |
+
// item, with the even-numbered item as the key with a default-constructed
|
| 379 |
+
// value. Each odd-numbered item will then be assigned to the last pair's
|
| 380 |
+
// value.
|
| 381 |
+
template <typename Container, typename First, typename Second>
|
| 382 |
+
struct ConvertToContainer<Container, std::pair<const First, Second>, true> {
|
| 383 |
+
using iterator = typename Container::iterator;
|
| 384 |
+
|
| 385 |
+
Container operator()(const Splitter& splitter) const {
|
| 386 |
+
Container m;
|
| 387 |
+
iterator it;
|
| 388 |
+
bool insert = true;
|
| 389 |
+
for (const absl::string_view sv : splitter) {
|
| 390 |
+
if (insert) {
|
| 391 |
+
it = InsertOrEmplace(&m, sv);
|
| 392 |
+
} else {
|
| 393 |
+
it->second = Second(sv);
|
| 394 |
+
}
|
| 395 |
+
insert = !insert;
|
| 396 |
+
}
|
| 397 |
+
return m;
|
| 398 |
+
}
|
| 399 |
+
|
| 400 |
+
// Inserts the key and an empty value into the map, returning an iterator to
|
| 401 |
+
// the inserted item. We use emplace() if available, otherwise insert().
|
| 402 |
+
template <typename M>
|
| 403 |
+
static absl::enable_if_t<HasEmplace<M>::value, iterator> InsertOrEmplace(
|
| 404 |
+
M* m, absl::string_view key) {
|
| 405 |
+
// Use piecewise_construct to support old versions of gcc in which pair
|
| 406 |
+
// constructor can't otherwise construct string from string_view.
|
| 407 |
+
return ToIter(m->emplace(std::piecewise_construct, std::make_tuple(key),
|
| 408 |
+
std::tuple<>()));
|
| 409 |
+
}
|
| 410 |
+
template <typename M>
|
| 411 |
+
static absl::enable_if_t<!HasEmplace<M>::value, iterator> InsertOrEmplace(
|
| 412 |
+
M* m, absl::string_view key) {
|
| 413 |
+
return ToIter(m->insert(std::make_pair(First(key), Second(""))));
|
| 414 |
+
}
|
| 415 |
+
|
| 416 |
+
static iterator ToIter(std::pair<iterator, bool> pair) {
|
| 417 |
+
return pair.first;
|
| 418 |
+
}
|
| 419 |
+
static iterator ToIter(iterator iter) { return iter; }
|
| 420 |
+
};
|
| 421 |
+
|
| 422 |
+
StringType text_;
|
| 423 |
+
Delimiter delimiter_;
|
| 424 |
+
Predicate predicate_;
|
| 425 |
+
};
|
| 426 |
+
|
| 427 |
+
} // namespace strings_internal
|
| 428 |
+
ABSL_NAMESPACE_END
|
| 429 |
+
} // namespace absl
|
| 430 |
+
|
| 431 |
+
#endif // ABSL_STRINGS_INTERNAL_STR_SPLIT_INTERNAL_H_
|
miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/absl/strings/internal/string_constant.h
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2020 The Abseil Authors.
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// https://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
|
| 15 |
+
#ifndef ABSL_STRINGS_INTERNAL_STRING_CONSTANT_H_
|
| 16 |
+
#define ABSL_STRINGS_INTERNAL_STRING_CONSTANT_H_
|
| 17 |
+
|
| 18 |
+
#include "absl/meta/type_traits.h"
|
| 19 |
+
#include "absl/strings/string_view.h"
|
| 20 |
+
|
| 21 |
+
namespace absl {
|
| 22 |
+
ABSL_NAMESPACE_BEGIN
|
| 23 |
+
namespace strings_internal {
|
| 24 |
+
|
| 25 |
+
// StringConstant<T> represents a compile time string constant.
|
| 26 |
+
// It can be accessed via its `absl::string_view value` static member.
|
| 27 |
+
// It is guaranteed that the `string_view` returned has constant `.data()`,
|
| 28 |
+
// constant `.size()` and constant `value[i]` for all `0 <= i < .size()`
|
| 29 |
+
//
|
| 30 |
+
// The `T` is an opaque type. It is guaranteed that different string constants
|
| 31 |
+
// will have different values of `T`. This allows users to associate the string
|
| 32 |
+
// constant with other static state at compile time.
|
| 33 |
+
//
|
| 34 |
+
// Instances should be made using the `MakeStringConstant()` factory function
|
| 35 |
+
// below.
|
| 36 |
+
template <typename T>
|
| 37 |
+
struct StringConstant {
|
| 38 |
+
private:
|
| 39 |
+
static constexpr bool TryConstexprEval(absl::string_view view) {
|
| 40 |
+
return view.empty() || 2 * view[0] != 1;
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
public:
|
| 44 |
+
static constexpr absl::string_view value = T{}();
|
| 45 |
+
constexpr absl::string_view operator()() const { return value; }
|
| 46 |
+
|
| 47 |
+
// Check to be sure `view` points to constant data.
|
| 48 |
+
// Otherwise, it can't be constant evaluated.
|
| 49 |
+
static_assert(TryConstexprEval(value),
|
| 50 |
+
"The input string_view must point to constant data.");
|
| 51 |
+
};
|
| 52 |
+
|
| 53 |
+
#ifdef ABSL_INTERNAL_NEED_REDUNDANT_CONSTEXPR_DECL
|
| 54 |
+
template <typename T>
|
| 55 |
+
constexpr absl::string_view StringConstant<T>::value;
|
| 56 |
+
#endif
|
| 57 |
+
|
| 58 |
+
// Factory function for `StringConstant` instances.
|
| 59 |
+
// It supports callables that have a constexpr default constructor and a
|
| 60 |
+
// constexpr operator().
|
| 61 |
+
// It must return an `absl::string_view` or `const char*` pointing to constant
|
| 62 |
+
// data. This is validated at compile time.
|
| 63 |
+
template <typename T>
|
| 64 |
+
constexpr StringConstant<T> MakeStringConstant(T) {
|
| 65 |
+
return {};
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
} // namespace strings_internal
|
| 69 |
+
ABSL_NAMESPACE_END
|
| 70 |
+
} // namespace absl
|
| 71 |
+
|
| 72 |
+
#endif // ABSL_STRINGS_INTERNAL_STRING_CONSTANT_H_
|
miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/absl/strings/internal/stringify_sink.h
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2022 The Abseil Authors
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// https://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
|
| 15 |
+
#ifndef ABSL_STRINGS_INTERNAL_STRINGIFY_SINK_H_
|
| 16 |
+
#define ABSL_STRINGS_INTERNAL_STRINGIFY_SINK_H_
|
| 17 |
+
|
| 18 |
+
#include <string>
|
| 19 |
+
#include <type_traits>
|
| 20 |
+
#include <utility>
|
| 21 |
+
|
| 22 |
+
#include "absl/strings/string_view.h"
|
| 23 |
+
|
| 24 |
+
namespace absl {
|
| 25 |
+
ABSL_NAMESPACE_BEGIN
|
| 26 |
+
|
| 27 |
+
namespace strings_internal {
|
| 28 |
+
class StringifySink {
|
| 29 |
+
public:
|
| 30 |
+
void Append(size_t count, char ch);
|
| 31 |
+
|
| 32 |
+
void Append(string_view v);
|
| 33 |
+
|
| 34 |
+
// Support `absl::Format(&sink, format, args...)`.
|
| 35 |
+
friend void AbslFormatFlush(StringifySink* sink, absl::string_view v) {
|
| 36 |
+
sink->Append(v);
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
private:
|
| 40 |
+
template <typename T>
|
| 41 |
+
friend string_view ExtractStringification(StringifySink& sink, const T& v);
|
| 42 |
+
|
| 43 |
+
std::string buffer_;
|
| 44 |
+
};
|
| 45 |
+
|
| 46 |
+
template <typename T>
|
| 47 |
+
string_view ExtractStringification(StringifySink& sink, const T& v) {
|
| 48 |
+
AbslStringify(sink, v);
|
| 49 |
+
return sink.buffer_;
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
} // namespace strings_internal
|
| 53 |
+
|
| 54 |
+
ABSL_NAMESPACE_END
|
| 55 |
+
} // namespace absl
|
| 56 |
+
|
| 57 |
+
#endif // ABSL_STRINGS_INTERNAL_STRINGIFY_SINK_H_
|
miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/absl/strings/internal/utf8.h
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2017 The Abseil Authors.
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// https://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
//
|
| 15 |
+
// UTF8 utilities, implemented to reduce dependencies.
|
| 16 |
+
|
| 17 |
+
#ifndef ABSL_STRINGS_INTERNAL_UTF8_H_
|
| 18 |
+
#define ABSL_STRINGS_INTERNAL_UTF8_H_
|
| 19 |
+
|
| 20 |
+
#include <cstddef>
|
| 21 |
+
#include <cstdint>
|
| 22 |
+
|
| 23 |
+
#include "absl/base/config.h"
|
| 24 |
+
|
| 25 |
+
namespace absl {
|
| 26 |
+
ABSL_NAMESPACE_BEGIN
|
| 27 |
+
namespace strings_internal {
|
| 28 |
+
|
| 29 |
+
// For Unicode code points 0 through 0x10FFFF, EncodeUTF8Char writes
|
| 30 |
+
// out the UTF-8 encoding into buffer, and returns the number of chars
|
| 31 |
+
// it wrote.
|
| 32 |
+
//
|
| 33 |
+
// As described in https://tools.ietf.org/html/rfc3629#section-3 , the encodings
|
| 34 |
+
// are:
|
| 35 |
+
// 00 - 7F : 0xxxxxxx
|
| 36 |
+
// 80 - 7FF : 110xxxxx 10xxxxxx
|
| 37 |
+
// 800 - FFFF : 1110xxxx 10xxxxxx 10xxxxxx
|
| 38 |
+
// 10000 - 10FFFF : 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
|
| 39 |
+
//
|
| 40 |
+
// Values greater than 0x10FFFF are not supported and may or may not write
|
| 41 |
+
// characters into buffer, however never will more than kMaxEncodedUTF8Size
|
| 42 |
+
// bytes be written, regardless of the value of utf8_char.
|
| 43 |
+
enum { kMaxEncodedUTF8Size = 4 };
|
| 44 |
+
size_t EncodeUTF8Char(char *buffer, char32_t utf8_char);
|
| 45 |
+
|
| 46 |
+
} // namespace strings_internal
|
| 47 |
+
ABSL_NAMESPACE_END
|
| 48 |
+
} // namespace absl
|
| 49 |
+
|
| 50 |
+
#endif // ABSL_STRINGS_INTERNAL_UTF8_H_
|
miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/absl/synchronization/barrier.h
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2017 The Abseil Authors.
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// https://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
//
|
| 15 |
+
// -----------------------------------------------------------------------------
|
| 16 |
+
// barrier.h
|
| 17 |
+
// -----------------------------------------------------------------------------
|
| 18 |
+
|
| 19 |
+
#ifndef ABSL_SYNCHRONIZATION_BARRIER_H_
|
| 20 |
+
#define ABSL_SYNCHRONIZATION_BARRIER_H_
|
| 21 |
+
|
| 22 |
+
#include "absl/base/thread_annotations.h"
|
| 23 |
+
#include "absl/synchronization/mutex.h"
|
| 24 |
+
|
| 25 |
+
namespace absl {
|
| 26 |
+
ABSL_NAMESPACE_BEGIN
|
| 27 |
+
|
| 28 |
+
// Barrier
|
| 29 |
+
//
|
| 30 |
+
// This class creates a barrier which blocks threads until a prespecified
|
| 31 |
+
// threshold of threads (`num_threads`) utilizes the barrier. A thread utilizes
|
| 32 |
+
// the `Barrier` by calling `Block()` on the barrier, which will block that
|
| 33 |
+
// thread; no call to `Block()` will return until `num_threads` threads have
|
| 34 |
+
// called it.
|
| 35 |
+
//
|
| 36 |
+
// Exactly one call to `Block()` will return `true`, which is then responsible
|
| 37 |
+
// for destroying the barrier; because stack allocation will cause the barrier
|
| 38 |
+
// to be deleted when it is out of scope, barriers should not be stack
|
| 39 |
+
// allocated.
|
| 40 |
+
//
|
| 41 |
+
// Example:
|
| 42 |
+
//
|
| 43 |
+
// // Main thread creates a `Barrier`:
|
| 44 |
+
// barrier = new Barrier(num_threads);
|
| 45 |
+
//
|
| 46 |
+
// // Each participating thread could then call:
|
| 47 |
+
// if (barrier->Block()) delete barrier; // Exactly one call to `Block()`
|
| 48 |
+
// // returns `true`; that call
|
| 49 |
+
// // deletes the barrier.
|
| 50 |
+
class Barrier {
|
| 51 |
+
public:
|
| 52 |
+
// `num_threads` is the number of threads that will participate in the barrier
|
| 53 |
+
explicit Barrier(int num_threads)
|
| 54 |
+
: num_to_block_(num_threads), num_to_exit_(num_threads) {}
|
| 55 |
+
|
| 56 |
+
Barrier(const Barrier&) = delete;
|
| 57 |
+
Barrier& operator=(const Barrier&) = delete;
|
| 58 |
+
|
| 59 |
+
// Barrier::Block()
|
| 60 |
+
//
|
| 61 |
+
// Blocks the current thread, and returns only when the `num_threads`
|
| 62 |
+
// threshold of threads utilizing this barrier has been reached. `Block()`
|
| 63 |
+
// returns `true` for precisely one caller, which may then destroy the
|
| 64 |
+
// barrier.
|
| 65 |
+
//
|
| 66 |
+
// Memory ordering: For any threads X and Y, any action taken by X
|
| 67 |
+
// before X calls `Block()` will be visible to Y after Y returns from
|
| 68 |
+
// `Block()`.
|
| 69 |
+
bool Block();
|
| 70 |
+
|
| 71 |
+
private:
|
| 72 |
+
Mutex lock_;
|
| 73 |
+
int num_to_block_ ABSL_GUARDED_BY(lock_);
|
| 74 |
+
int num_to_exit_ ABSL_GUARDED_BY(lock_);
|
| 75 |
+
};
|
| 76 |
+
|
| 77 |
+
ABSL_NAMESPACE_END
|
| 78 |
+
} // namespace absl
|
| 79 |
+
#endif // ABSL_SYNCHRONIZATION_BARRIER_H_
|
miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/absl/synchronization/blocking_counter.h
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//
|
| 2 |
+
// Copyright 2017 The Abseil Authors.
|
| 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 |
+
// https://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 |
+
// blocking_counter.h
|
| 18 |
+
// -----------------------------------------------------------------------------
|
| 19 |
+
|
| 20 |
+
#ifndef ABSL_SYNCHRONIZATION_BLOCKING_COUNTER_H_
|
| 21 |
+
#define ABSL_SYNCHRONIZATION_BLOCKING_COUNTER_H_
|
| 22 |
+
|
| 23 |
+
#include <atomic>
|
| 24 |
+
|
| 25 |
+
#include "absl/base/thread_annotations.h"
|
| 26 |
+
#include "absl/synchronization/mutex.h"
|
| 27 |
+
|
| 28 |
+
namespace absl {
|
| 29 |
+
ABSL_NAMESPACE_BEGIN
|
| 30 |
+
|
| 31 |
+
// BlockingCounter
|
| 32 |
+
//
|
| 33 |
+
// This class allows a thread to block for a pre-specified number of actions.
|
| 34 |
+
// `BlockingCounter` maintains a single non-negative abstract integer "count"
|
| 35 |
+
// with an initial value `initial_count`. A thread can then call `Wait()` on
|
| 36 |
+
// this blocking counter to block until the specified number of events occur;
|
| 37 |
+
// worker threads then call 'DecrementCount()` on the counter upon completion of
|
| 38 |
+
// their work. Once the counter's internal "count" reaches zero, the blocked
|
| 39 |
+
// thread unblocks.
|
| 40 |
+
//
|
| 41 |
+
// A `BlockingCounter` requires the following:
|
| 42 |
+
// - its `initial_count` is non-negative.
|
| 43 |
+
// - the number of calls to `DecrementCount()` on it is at most
|
| 44 |
+
// `initial_count`.
|
| 45 |
+
// - `Wait()` is called at most once on it.
|
| 46 |
+
//
|
| 47 |
+
// Given the above requirements, a `BlockingCounter` provides the following
|
| 48 |
+
// guarantees:
|
| 49 |
+
// - Once its internal "count" reaches zero, no legal action on the object
|
| 50 |
+
// can further change the value of "count".
|
| 51 |
+
// - When `Wait()` returns, it is legal to destroy the `BlockingCounter`.
|
| 52 |
+
// - When `Wait()` returns, the number of calls to `DecrementCount()` on
|
| 53 |
+
// this blocking counter exactly equals `initial_count`.
|
| 54 |
+
//
|
| 55 |
+
// Example:
|
| 56 |
+
// BlockingCounter bcount(N); // there are N items of work
|
| 57 |
+
// ... Allow worker threads to start.
|
| 58 |
+
// ... On completing each work item, workers do:
|
| 59 |
+
// ... bcount.DecrementCount(); // an item of work has been completed
|
| 60 |
+
//
|
| 61 |
+
// bcount.Wait(); // wait for all work to be complete
|
| 62 |
+
//
|
| 63 |
+
class BlockingCounter {
|
| 64 |
+
public:
|
| 65 |
+
explicit BlockingCounter(int initial_count);
|
| 66 |
+
|
| 67 |
+
BlockingCounter(const BlockingCounter&) = delete;
|
| 68 |
+
BlockingCounter& operator=(const BlockingCounter&) = delete;
|
| 69 |
+
|
| 70 |
+
// BlockingCounter::DecrementCount()
|
| 71 |
+
//
|
| 72 |
+
// Decrements the counter's "count" by one, and return "count == 0". This
|
| 73 |
+
// function requires that "count != 0" when it is called.
|
| 74 |
+
//
|
| 75 |
+
// Memory ordering: For any threads X and Y, any action taken by X
|
| 76 |
+
// before it calls `DecrementCount()` is visible to thread Y after
|
| 77 |
+
// Y's call to `DecrementCount()`, provided Y's call returns `true`.
|
| 78 |
+
bool DecrementCount();
|
| 79 |
+
|
| 80 |
+
// BlockingCounter::Wait()
|
| 81 |
+
//
|
| 82 |
+
// Blocks until the counter reaches zero. This function may be called at most
|
| 83 |
+
// once. On return, `DecrementCount()` will have been called "initial_count"
|
| 84 |
+
// times and the blocking counter may be destroyed.
|
| 85 |
+
//
|
| 86 |
+
// Memory ordering: For any threads X and Y, any action taken by X
|
| 87 |
+
// before X calls `DecrementCount()` is visible to Y after Y returns
|
| 88 |
+
// from `Wait()`.
|
| 89 |
+
void Wait();
|
| 90 |
+
|
| 91 |
+
private:
|
| 92 |
+
Mutex lock_;
|
| 93 |
+
std::atomic<int> count_;
|
| 94 |
+
int num_waiting_ ABSL_GUARDED_BY(lock_);
|
| 95 |
+
bool done_ ABSL_GUARDED_BY(lock_);
|
| 96 |
+
};
|
| 97 |
+
|
| 98 |
+
ABSL_NAMESPACE_END
|
| 99 |
+
} // namespace absl
|
| 100 |
+
|
| 101 |
+
#endif // ABSL_SYNCHRONIZATION_BLOCKING_COUNTER_H_
|
miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/absl/synchronization/internal/create_thread_identity.h
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright 2017 The Abseil Authors.
|
| 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 |
+
* https://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 |
+
// Interface for getting the current ThreadIdentity, creating one if necessary.
|
| 18 |
+
// See thread_identity.h.
|
| 19 |
+
//
|
| 20 |
+
// This file is separate from thread_identity.h because creating a new
|
| 21 |
+
// ThreadIdentity requires slightly higher level libraries (per_thread_sem
|
| 22 |
+
// and low_level_alloc) than accessing an existing one. This separation allows
|
| 23 |
+
// us to have a smaller //absl/base:base.
|
| 24 |
+
|
| 25 |
+
#ifndef ABSL_SYNCHRONIZATION_INTERNAL_CREATE_THREAD_IDENTITY_H_
|
| 26 |
+
#define ABSL_SYNCHRONIZATION_INTERNAL_CREATE_THREAD_IDENTITY_H_
|
| 27 |
+
|
| 28 |
+
#include "absl/base/internal/thread_identity.h"
|
| 29 |
+
#include "absl/base/port.h"
|
| 30 |
+
|
| 31 |
+
namespace absl {
|
| 32 |
+
ABSL_NAMESPACE_BEGIN
|
| 33 |
+
namespace synchronization_internal {
|
| 34 |
+
|
| 35 |
+
// Allocates and attaches a ThreadIdentity object for the calling thread.
|
| 36 |
+
// For private use only.
|
| 37 |
+
base_internal::ThreadIdentity* CreateThreadIdentity();
|
| 38 |
+
|
| 39 |
+
// Returns the ThreadIdentity object representing the calling thread; guaranteed
|
| 40 |
+
// to be unique for its lifetime. The returned object will remain valid for the
|
| 41 |
+
// program's lifetime; although it may be re-assigned to a subsequent thread.
|
| 42 |
+
// If one does not exist for the calling thread, allocate it now.
|
| 43 |
+
inline base_internal::ThreadIdentity* GetOrCreateCurrentThreadIdentity() {
|
| 44 |
+
base_internal::ThreadIdentity* identity =
|
| 45 |
+
base_internal::CurrentThreadIdentityIfPresent();
|
| 46 |
+
if (ABSL_PREDICT_FALSE(identity == nullptr)) {
|
| 47 |
+
return CreateThreadIdentity();
|
| 48 |
+
}
|
| 49 |
+
return identity;
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
} // namespace synchronization_internal
|
| 53 |
+
ABSL_NAMESPACE_END
|
| 54 |
+
} // namespace absl
|
| 55 |
+
|
| 56 |
+
#endif // ABSL_SYNCHRONIZATION_INTERNAL_CREATE_THREAD_IDENTITY_H_
|
miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/absl/synchronization/internal/futex.h
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2020 The Abseil Authors.
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// https://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
#ifndef ABSL_SYNCHRONIZATION_INTERNAL_FUTEX_H_
|
| 15 |
+
#define ABSL_SYNCHRONIZATION_INTERNAL_FUTEX_H_
|
| 16 |
+
|
| 17 |
+
#include "absl/base/config.h"
|
| 18 |
+
|
| 19 |
+
#ifdef _WIN32
|
| 20 |
+
#include <windows.h>
|
| 21 |
+
#else
|
| 22 |
+
#include <sys/time.h>
|
| 23 |
+
#include <unistd.h>
|
| 24 |
+
#endif
|
| 25 |
+
|
| 26 |
+
#ifdef __linux__
|
| 27 |
+
#include <linux/futex.h>
|
| 28 |
+
#include <sys/syscall.h>
|
| 29 |
+
#endif
|
| 30 |
+
|
| 31 |
+
#include <errno.h>
|
| 32 |
+
#include <stdio.h>
|
| 33 |
+
#include <time.h>
|
| 34 |
+
|
| 35 |
+
#include <atomic>
|
| 36 |
+
#include <cstdint>
|
| 37 |
+
|
| 38 |
+
#include "absl/base/optimization.h"
|
| 39 |
+
#include "absl/synchronization/internal/kernel_timeout.h"
|
| 40 |
+
|
| 41 |
+
#ifdef ABSL_INTERNAL_HAVE_FUTEX
|
| 42 |
+
#error ABSL_INTERNAL_HAVE_FUTEX may not be set on the command line
|
| 43 |
+
#elif defined(__BIONIC__)
|
| 44 |
+
// Bionic supports all the futex operations we need even when some of the futex
|
| 45 |
+
// definitions are missing.
|
| 46 |
+
#define ABSL_INTERNAL_HAVE_FUTEX
|
| 47 |
+
#elif defined(__linux__) && defined(FUTEX_CLOCK_REALTIME)
|
| 48 |
+
// FUTEX_CLOCK_REALTIME requires Linux >= 2.6.28.
|
| 49 |
+
#define ABSL_INTERNAL_HAVE_FUTEX
|
| 50 |
+
#endif
|
| 51 |
+
|
| 52 |
+
#ifdef ABSL_INTERNAL_HAVE_FUTEX
|
| 53 |
+
|
| 54 |
+
namespace absl {
|
| 55 |
+
ABSL_NAMESPACE_BEGIN
|
| 56 |
+
namespace synchronization_internal {
|
| 57 |
+
|
| 58 |
+
// Some Android headers are missing these definitions even though they
|
| 59 |
+
// support these futex operations.
|
| 60 |
+
#ifdef __BIONIC__
|
| 61 |
+
#ifndef SYS_futex
|
| 62 |
+
#define SYS_futex __NR_futex
|
| 63 |
+
#endif
|
| 64 |
+
#ifndef FUTEX_WAIT_BITSET
|
| 65 |
+
#define FUTEX_WAIT_BITSET 9
|
| 66 |
+
#endif
|
| 67 |
+
#ifndef FUTEX_PRIVATE_FLAG
|
| 68 |
+
#define FUTEX_PRIVATE_FLAG 128
|
| 69 |
+
#endif
|
| 70 |
+
#ifndef FUTEX_CLOCK_REALTIME
|
| 71 |
+
#define FUTEX_CLOCK_REALTIME 256
|
| 72 |
+
#endif
|
| 73 |
+
#ifndef FUTEX_BITSET_MATCH_ANY
|
| 74 |
+
#define FUTEX_BITSET_MATCH_ANY 0xFFFFFFFF
|
| 75 |
+
#endif
|
| 76 |
+
#endif
|
| 77 |
+
|
| 78 |
+
#if defined(__NR_futex_time64) && !defined(SYS_futex_time64)
|
| 79 |
+
#define SYS_futex_time64 __NR_futex_time64
|
| 80 |
+
#endif
|
| 81 |
+
|
| 82 |
+
#if defined(SYS_futex_time64) && !defined(SYS_futex)
|
| 83 |
+
#define SYS_futex SYS_futex_time64
|
| 84 |
+
#endif
|
| 85 |
+
|
| 86 |
+
class FutexImpl {
|
| 87 |
+
public:
|
| 88 |
+
static int WaitUntil(std::atomic<int32_t> *v, int32_t val,
|
| 89 |
+
KernelTimeout t) {
|
| 90 |
+
long err = 0; // NOLINT(runtime/int)
|
| 91 |
+
if (t.has_timeout()) {
|
| 92 |
+
// https://locklessinc.com/articles/futex_cheat_sheet/
|
| 93 |
+
// Unlike FUTEX_WAIT, FUTEX_WAIT_BITSET uses absolute time.
|
| 94 |
+
struct timespec abs_timeout = t.MakeAbsTimespec();
|
| 95 |
+
// Atomically check that the futex value is still 0, and if it
|
| 96 |
+
// is, sleep until abs_timeout or until woken by FUTEX_WAKE.
|
| 97 |
+
err = syscall(
|
| 98 |
+
SYS_futex, reinterpret_cast<int32_t *>(v),
|
| 99 |
+
FUTEX_WAIT_BITSET | FUTEX_PRIVATE_FLAG | FUTEX_CLOCK_REALTIME, val,
|
| 100 |
+
&abs_timeout, nullptr, FUTEX_BITSET_MATCH_ANY);
|
| 101 |
+
} else {
|
| 102 |
+
// Atomically check that the futex value is still 0, and if it
|
| 103 |
+
// is, sleep until woken by FUTEX_WAKE.
|
| 104 |
+
err = syscall(SYS_futex, reinterpret_cast<int32_t *>(v),
|
| 105 |
+
FUTEX_WAIT | FUTEX_PRIVATE_FLAG, val, nullptr);
|
| 106 |
+
}
|
| 107 |
+
if (ABSL_PREDICT_FALSE(err != 0)) {
|
| 108 |
+
return -errno;
|
| 109 |
+
}
|
| 110 |
+
return 0;
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
static int WaitBitsetAbsoluteTimeout(std::atomic<int32_t> *v, int32_t val,
|
| 114 |
+
int32_t bits,
|
| 115 |
+
const struct timespec *abstime) {
|
| 116 |
+
// NOLINTNEXTLINE(runtime/int)
|
| 117 |
+
long err = syscall(SYS_futex, reinterpret_cast<int32_t*>(v),
|
| 118 |
+
FUTEX_WAIT_BITSET | FUTEX_PRIVATE_FLAG, val, abstime,
|
| 119 |
+
nullptr, bits);
|
| 120 |
+
if (ABSL_PREDICT_FALSE(err != 0)) {
|
| 121 |
+
return -errno;
|
| 122 |
+
}
|
| 123 |
+
return 0;
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
static int Wake(std::atomic<int32_t> *v, int32_t count) {
|
| 127 |
+
// NOLINTNEXTLINE(runtime/int)
|
| 128 |
+
long err = syscall(SYS_futex, reinterpret_cast<int32_t*>(v),
|
| 129 |
+
FUTEX_WAKE | FUTEX_PRIVATE_FLAG, count);
|
| 130 |
+
if (ABSL_PREDICT_FALSE(err < 0)) {
|
| 131 |
+
return -errno;
|
| 132 |
+
}
|
| 133 |
+
return 0;
|
| 134 |
+
}
|
| 135 |
+
|
| 136 |
+
// FUTEX_WAKE_BITSET
|
| 137 |
+
static int WakeBitset(std::atomic<int32_t> *v, int32_t count, int32_t bits) {
|
| 138 |
+
// NOLINTNEXTLINE(runtime/int)
|
| 139 |
+
long err = syscall(SYS_futex, reinterpret_cast<int32_t*>(v),
|
| 140 |
+
FUTEX_WAKE_BITSET | FUTEX_PRIVATE_FLAG, count, nullptr,
|
| 141 |
+
nullptr, bits);
|
| 142 |
+
if (ABSL_PREDICT_FALSE(err < 0)) {
|
| 143 |
+
return -errno;
|
| 144 |
+
}
|
| 145 |
+
return 0;
|
| 146 |
+
}
|
| 147 |
+
};
|
| 148 |
+
|
| 149 |
+
class Futex : public FutexImpl {};
|
| 150 |
+
|
| 151 |
+
} // namespace synchronization_internal
|
| 152 |
+
ABSL_NAMESPACE_END
|
| 153 |
+
} // namespace absl
|
| 154 |
+
|
| 155 |
+
#endif // ABSL_INTERNAL_HAVE_FUTEX
|
| 156 |
+
|
| 157 |
+
#endif // ABSL_SYNCHRONIZATION_INTERNAL_FUTEX_H_
|
miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/absl/synchronization/internal/graphcycles.h
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2017 The Abseil Authors.
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// https://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
//
|
| 15 |
+
|
| 16 |
+
#ifndef ABSL_SYNCHRONIZATION_INTERNAL_GRAPHCYCLES_H_
|
| 17 |
+
#define ABSL_SYNCHRONIZATION_INTERNAL_GRAPHCYCLES_H_
|
| 18 |
+
|
| 19 |
+
// GraphCycles detects the introduction of a cycle into a directed
|
| 20 |
+
// graph that is being built up incrementally.
|
| 21 |
+
//
|
| 22 |
+
// Nodes are identified by small integers. It is not possible to
|
| 23 |
+
// record multiple edges with the same (source, destination) pair;
|
| 24 |
+
// requests to add an edge where one already exists are silently
|
| 25 |
+
// ignored.
|
| 26 |
+
//
|
| 27 |
+
// It is also not possible to introduce a cycle; an attempt to insert
|
| 28 |
+
// an edge that would introduce a cycle fails and returns false.
|
| 29 |
+
//
|
| 30 |
+
// GraphCycles uses no internal locking; calls into it should be
|
| 31 |
+
// serialized externally.
|
| 32 |
+
|
| 33 |
+
// Performance considerations:
|
| 34 |
+
// Works well on sparse graphs, poorly on dense graphs.
|
| 35 |
+
// Extra information is maintained incrementally to detect cycles quickly.
|
| 36 |
+
// InsertEdge() is very fast when the edge already exists, and reasonably fast
|
| 37 |
+
// otherwise.
|
| 38 |
+
// FindPath() is linear in the size of the graph.
|
| 39 |
+
// The current implementation uses O(|V|+|E|) space.
|
| 40 |
+
|
| 41 |
+
#include <cstdint>
|
| 42 |
+
|
| 43 |
+
#include "absl/base/config.h"
|
| 44 |
+
|
| 45 |
+
namespace absl {
|
| 46 |
+
ABSL_NAMESPACE_BEGIN
|
| 47 |
+
namespace synchronization_internal {
|
| 48 |
+
|
| 49 |
+
// Opaque identifier for a graph node.
|
| 50 |
+
struct GraphId {
|
| 51 |
+
uint64_t handle;
|
| 52 |
+
|
| 53 |
+
bool operator==(const GraphId& x) const { return handle == x.handle; }
|
| 54 |
+
bool operator!=(const GraphId& x) const { return handle != x.handle; }
|
| 55 |
+
};
|
| 56 |
+
|
| 57 |
+
// Return an invalid graph id that will never be assigned by GraphCycles.
|
| 58 |
+
inline GraphId InvalidGraphId() {
|
| 59 |
+
return GraphId{0};
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
class GraphCycles {
|
| 63 |
+
public:
|
| 64 |
+
GraphCycles();
|
| 65 |
+
~GraphCycles();
|
| 66 |
+
|
| 67 |
+
// Return the id to use for ptr, assigning one if necessary.
|
| 68 |
+
// Subsequent calls with the same ptr value will return the same id
|
| 69 |
+
// until Remove().
|
| 70 |
+
GraphId GetId(void* ptr);
|
| 71 |
+
|
| 72 |
+
// Remove "ptr" from the graph. Its corresponding node and all
|
| 73 |
+
// edges to and from it are removed.
|
| 74 |
+
void RemoveNode(void* ptr);
|
| 75 |
+
|
| 76 |
+
// Return the pointer associated with id, or nullptr if id is not
|
| 77 |
+
// currently in the graph.
|
| 78 |
+
void* Ptr(GraphId id);
|
| 79 |
+
|
| 80 |
+
// Attempt to insert an edge from source_node to dest_node. If the
|
| 81 |
+
// edge would introduce a cycle, return false without making any
|
| 82 |
+
// changes. Otherwise add the edge and return true.
|
| 83 |
+
bool InsertEdge(GraphId source_node, GraphId dest_node);
|
| 84 |
+
|
| 85 |
+
// Remove any edge that exists from source_node to dest_node.
|
| 86 |
+
void RemoveEdge(GraphId source_node, GraphId dest_node);
|
| 87 |
+
|
| 88 |
+
// Return whether node exists in the graph.
|
| 89 |
+
bool HasNode(GraphId node);
|
| 90 |
+
|
| 91 |
+
// Return whether there is an edge directly from source_node to dest_node.
|
| 92 |
+
bool HasEdge(GraphId source_node, GraphId dest_node) const;
|
| 93 |
+
|
| 94 |
+
// Return whether dest_node is reachable from source_node
|
| 95 |
+
// by following edges.
|
| 96 |
+
bool IsReachable(GraphId source_node, GraphId dest_node) const;
|
| 97 |
+
|
| 98 |
+
// Find a path from "source" to "dest". If such a path exists,
|
| 99 |
+
// place the nodes on the path in the array path[], and return
|
| 100 |
+
// the number of nodes on the path. If the path is longer than
|
| 101 |
+
// max_path_len nodes, only the first max_path_len nodes are placed
|
| 102 |
+
// in path[]. The client should compare the return value with
|
| 103 |
+
// max_path_len" to see when this occurs. If no path exists, return
|
| 104 |
+
// 0. Any valid path stored in path[] will start with "source" and
|
| 105 |
+
// end with "dest". There is no guarantee that the path is the
|
| 106 |
+
// shortest, but no node will appear twice in the path, except the
|
| 107 |
+
// source and destination node if they are identical; therefore, the
|
| 108 |
+
// return value is at most one greater than the number of nodes in
|
| 109 |
+
// the graph.
|
| 110 |
+
int FindPath(GraphId source, GraphId dest, int max_path_len,
|
| 111 |
+
GraphId path[]) const;
|
| 112 |
+
|
| 113 |
+
// Update the stack trace recorded for id with the current stack
|
| 114 |
+
// trace if the last time it was updated had a smaller priority
|
| 115 |
+
// than the priority passed on this call.
|
| 116 |
+
//
|
| 117 |
+
// *get_stack_trace is called to get the stack trace.
|
| 118 |
+
void UpdateStackTrace(GraphId id, int priority,
|
| 119 |
+
int (*get_stack_trace)(void**, int));
|
| 120 |
+
|
| 121 |
+
// Set *ptr to the beginning of the array that holds the recorded
|
| 122 |
+
// stack trace for id and return the depth of the stack trace.
|
| 123 |
+
int GetStackTrace(GraphId id, void*** ptr);
|
| 124 |
+
|
| 125 |
+
// Check internal invariants. Crashes on failure, returns true on success.
|
| 126 |
+
// Expensive: should only be called from graphcycles_test.cc.
|
| 127 |
+
bool CheckInvariants() const;
|
| 128 |
+
|
| 129 |
+
// ----------------------------------------------------
|
| 130 |
+
struct Rep;
|
| 131 |
+
private:
|
| 132 |
+
Rep *rep_; // opaque representation
|
| 133 |
+
GraphCycles(const GraphCycles&) = delete;
|
| 134 |
+
GraphCycles& operator=(const GraphCycles&) = delete;
|
| 135 |
+
};
|
| 136 |
+
|
| 137 |
+
} // namespace synchronization_internal
|
| 138 |
+
ABSL_NAMESPACE_END
|
| 139 |
+
} // namespace absl
|
| 140 |
+
|
| 141 |
+
#endif
|
miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/absl/synchronization/internal/kernel_timeout.h
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2017 The Abseil Authors.
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// https://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
//
|
| 15 |
+
|
| 16 |
+
// An optional absolute timeout, with nanosecond granularity,
|
| 17 |
+
// compatible with absl::Time. Suitable for in-register
|
| 18 |
+
// parameter-passing (e.g. syscalls.)
|
| 19 |
+
// Constructible from a absl::Time (for a timeout to be respected) or {}
|
| 20 |
+
// (for "no timeout".)
|
| 21 |
+
// This is a private low-level API for use by a handful of low-level
|
| 22 |
+
// components. Higher-level components should build APIs based on
|
| 23 |
+
// absl::Time and absl::Duration.
|
| 24 |
+
|
| 25 |
+
#ifndef ABSL_SYNCHRONIZATION_INTERNAL_KERNEL_TIMEOUT_H_
|
| 26 |
+
#define ABSL_SYNCHRONIZATION_INTERNAL_KERNEL_TIMEOUT_H_
|
| 27 |
+
|
| 28 |
+
#include <time.h>
|
| 29 |
+
|
| 30 |
+
#include <algorithm>
|
| 31 |
+
#include <cstdint>
|
| 32 |
+
#include <limits>
|
| 33 |
+
|
| 34 |
+
#include "absl/base/internal/raw_logging.h"
|
| 35 |
+
#include "absl/time/clock.h"
|
| 36 |
+
#include "absl/time/time.h"
|
| 37 |
+
|
| 38 |
+
namespace absl {
|
| 39 |
+
ABSL_NAMESPACE_BEGIN
|
| 40 |
+
namespace synchronization_internal {
|
| 41 |
+
|
| 42 |
+
class Waiter;
|
| 43 |
+
|
| 44 |
+
class KernelTimeout {
|
| 45 |
+
public:
|
| 46 |
+
// A timeout that should expire at <t>. Any value, in the full
|
| 47 |
+
// InfinitePast() to InfiniteFuture() range, is valid here and will be
|
| 48 |
+
// respected.
|
| 49 |
+
explicit KernelTimeout(absl::Time t) : ns_(MakeNs(t)) {}
|
| 50 |
+
// No timeout.
|
| 51 |
+
KernelTimeout() : ns_(0) {}
|
| 52 |
+
|
| 53 |
+
// A more explicit factory for those who prefer it. Equivalent to {}.
|
| 54 |
+
static KernelTimeout Never() { return {}; }
|
| 55 |
+
|
| 56 |
+
// We explicitly do not support other custom formats: timespec, int64_t nanos.
|
| 57 |
+
// Unify on this and absl::Time, please.
|
| 58 |
+
|
| 59 |
+
bool has_timeout() const { return ns_ != 0; }
|
| 60 |
+
|
| 61 |
+
// Convert to parameter for sem_timedwait/futex/similar. Only for approved
|
| 62 |
+
// users. Do not call if !has_timeout.
|
| 63 |
+
struct timespec MakeAbsTimespec() const;
|
| 64 |
+
|
| 65 |
+
// Convert to unix epoch nanos. Do not call if !has_timeout.
|
| 66 |
+
int64_t MakeAbsNanos() const;
|
| 67 |
+
|
| 68 |
+
private:
|
| 69 |
+
// internal rep, not user visible: ns after unix epoch.
|
| 70 |
+
// zero = no timeout.
|
| 71 |
+
// Negative we treat as an unlikely (and certainly expired!) but valid
|
| 72 |
+
// timeout.
|
| 73 |
+
int64_t ns_;
|
| 74 |
+
|
| 75 |
+
static int64_t MakeNs(absl::Time t) {
|
| 76 |
+
// optimization--InfiniteFuture is common "no timeout" value
|
| 77 |
+
// and cheaper to compare than convert.
|
| 78 |
+
if (t == absl::InfiniteFuture()) return 0;
|
| 79 |
+
int64_t x = ToUnixNanos(t);
|
| 80 |
+
|
| 81 |
+
// A timeout that lands exactly on the epoch (x=0) needs to be respected,
|
| 82 |
+
// so we alter it unnoticably to 1. Negative timeouts are in
|
| 83 |
+
// theory supported, but handled poorly by the kernel (long
|
| 84 |
+
// delays) so push them forward too; since all such times have
|
| 85 |
+
// already passed, it's indistinguishable.
|
| 86 |
+
if (x <= 0) x = 1;
|
| 87 |
+
// A time larger than what can be represented to the kernel is treated
|
| 88 |
+
// as no timeout.
|
| 89 |
+
if (x == (std::numeric_limits<int64_t>::max)()) x = 0;
|
| 90 |
+
return x;
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
#ifdef _WIN32
|
| 94 |
+
// Converts to milliseconds from now, or INFINITE when
|
| 95 |
+
// !has_timeout(). For use by SleepConditionVariableSRW on
|
| 96 |
+
// Windows. Callers should recognize that the return value is a
|
| 97 |
+
// relative duration (it should be recomputed by calling this method
|
| 98 |
+
// in the case of a spurious wakeup).
|
| 99 |
+
// This header file may be included transitively by public header files,
|
| 100 |
+
// so we define our own DWORD and INFINITE instead of getting them from
|
| 101 |
+
// <intsafe.h> and <WinBase.h>.
|
| 102 |
+
typedef unsigned long DWord; // NOLINT
|
| 103 |
+
DWord InMillisecondsFromNow() const {
|
| 104 |
+
constexpr DWord kInfinite = (std::numeric_limits<DWord>::max)();
|
| 105 |
+
if (!has_timeout()) {
|
| 106 |
+
return kInfinite;
|
| 107 |
+
}
|
| 108 |
+
// The use of absl::Now() to convert from absolute time to
|
| 109 |
+
// relative time means that absl::Now() cannot use anything that
|
| 110 |
+
// depends on KernelTimeout (for example, Mutex) on Windows.
|
| 111 |
+
int64_t now = ToUnixNanos(absl::Now());
|
| 112 |
+
if (ns_ >= now) {
|
| 113 |
+
// Round up so that Now() + ms_from_now >= ns_.
|
| 114 |
+
constexpr uint64_t max_nanos =
|
| 115 |
+
(std::numeric_limits<int64_t>::max)() - 999999u;
|
| 116 |
+
uint64_t ms_from_now =
|
| 117 |
+
((std::min)(max_nanos, static_cast<uint64_t>(ns_ - now)) + 999999u) /
|
| 118 |
+
1000000u;
|
| 119 |
+
if (ms_from_now > kInfinite) {
|
| 120 |
+
return kInfinite;
|
| 121 |
+
}
|
| 122 |
+
return static_cast<DWord>(ms_from_now);
|
| 123 |
+
}
|
| 124 |
+
return 0;
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
friend class Waiter;
|
| 128 |
+
#endif
|
| 129 |
+
};
|
| 130 |
+
|
| 131 |
+
inline struct timespec KernelTimeout::MakeAbsTimespec() const {
|
| 132 |
+
int64_t n = ns_;
|
| 133 |
+
static const int64_t kNanosPerSecond = 1000 * 1000 * 1000;
|
| 134 |
+
if (n == 0) {
|
| 135 |
+
ABSL_RAW_LOG(
|
| 136 |
+
ERROR, "Tried to create a timespec from a non-timeout; never do this.");
|
| 137 |
+
// But we'll try to continue sanely. no-timeout ~= saturated timeout.
|
| 138 |
+
n = (std::numeric_limits<int64_t>::max)();
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
// Kernel APIs validate timespecs as being at or after the epoch,
|
| 142 |
+
// despite the kernel time type being signed. However, no one can
|
| 143 |
+
// tell the difference between a timeout at or before the epoch (since
|
| 144 |
+
// all such timeouts have expired!)
|
| 145 |
+
if (n < 0) n = 0;
|
| 146 |
+
|
| 147 |
+
struct timespec abstime;
|
| 148 |
+
int64_t seconds = (std::min)(n / kNanosPerSecond,
|
| 149 |
+
int64_t{(std::numeric_limits<time_t>::max)()});
|
| 150 |
+
abstime.tv_sec = static_cast<time_t>(seconds);
|
| 151 |
+
abstime.tv_nsec = static_cast<decltype(abstime.tv_nsec)>(n % kNanosPerSecond);
|
| 152 |
+
return abstime;
|
| 153 |
+
}
|
| 154 |
+
|
| 155 |
+
inline int64_t KernelTimeout::MakeAbsNanos() const {
|
| 156 |
+
if (ns_ == 0) {
|
| 157 |
+
ABSL_RAW_LOG(
|
| 158 |
+
ERROR, "Tried to create a timeout from a non-timeout; never do this.");
|
| 159 |
+
// But we'll try to continue sanely. no-timeout ~= saturated timeout.
|
| 160 |
+
return (std::numeric_limits<int64_t>::max)();
|
| 161 |
+
}
|
| 162 |
+
|
| 163 |
+
return ns_;
|
| 164 |
+
}
|
| 165 |
+
|
| 166 |
+
} // namespace synchronization_internal
|
| 167 |
+
ABSL_NAMESPACE_END
|
| 168 |
+
} // namespace absl
|
| 169 |
+
|
| 170 |
+
#endif // ABSL_SYNCHRONIZATION_INTERNAL_KERNEL_TIMEOUT_H_
|
miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/absl/synchronization/internal/per_thread_sem.h
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2017 The Abseil Authors.
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// https://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
//
|
| 15 |
+
|
| 16 |
+
// PerThreadSem is a low-level synchronization primitive controlling the
|
| 17 |
+
// runnability of a single thread, used internally by Mutex and CondVar.
|
| 18 |
+
//
|
| 19 |
+
// This is NOT a general-purpose synchronization mechanism, and should not be
|
| 20 |
+
// used directly by applications. Applications should use Mutex and CondVar.
|
| 21 |
+
//
|
| 22 |
+
// The semantics of PerThreadSem are the same as that of a counting semaphore.
|
| 23 |
+
// Each thread maintains an abstract "count" value associated with its identity.
|
| 24 |
+
|
| 25 |
+
#ifndef ABSL_SYNCHRONIZATION_INTERNAL_PER_THREAD_SEM_H_
|
| 26 |
+
#define ABSL_SYNCHRONIZATION_INTERNAL_PER_THREAD_SEM_H_
|
| 27 |
+
|
| 28 |
+
#include <atomic>
|
| 29 |
+
|
| 30 |
+
#include "absl/base/internal/thread_identity.h"
|
| 31 |
+
#include "absl/synchronization/internal/create_thread_identity.h"
|
| 32 |
+
#include "absl/synchronization/internal/kernel_timeout.h"
|
| 33 |
+
|
| 34 |
+
namespace absl {
|
| 35 |
+
ABSL_NAMESPACE_BEGIN
|
| 36 |
+
|
| 37 |
+
class Mutex;
|
| 38 |
+
|
| 39 |
+
namespace synchronization_internal {
|
| 40 |
+
|
| 41 |
+
class PerThreadSem {
|
| 42 |
+
public:
|
| 43 |
+
PerThreadSem() = delete;
|
| 44 |
+
PerThreadSem(const PerThreadSem&) = delete;
|
| 45 |
+
PerThreadSem& operator=(const PerThreadSem&) = delete;
|
| 46 |
+
|
| 47 |
+
// Routine invoked periodically (once a second) by a background thread.
|
| 48 |
+
// Has no effect on user-visible state.
|
| 49 |
+
static void Tick(base_internal::ThreadIdentity* identity);
|
| 50 |
+
|
| 51 |
+
// ---------------------------------------------------------------------------
|
| 52 |
+
// Routines used by autosizing threadpools to detect when threads are
|
| 53 |
+
// blocked. Each thread has a counter pointer, initially zero. If non-zero,
|
| 54 |
+
// the implementation atomically increments the counter when it blocks on a
|
| 55 |
+
// semaphore, a decrements it again when it wakes. This allows a threadpool
|
| 56 |
+
// to keep track of how many of its threads are blocked.
|
| 57 |
+
// SetThreadBlockedCounter() should be used only by threadpool
|
| 58 |
+
// implementations. GetThreadBlockedCounter() should be used by modules that
|
| 59 |
+
// block threads; if the pointer returned is non-zero, the location should be
|
| 60 |
+
// incremented before the thread blocks, and decremented after it wakes.
|
| 61 |
+
static void SetThreadBlockedCounter(std::atomic<int> *counter);
|
| 62 |
+
static std::atomic<int> *GetThreadBlockedCounter();
|
| 63 |
+
|
| 64 |
+
private:
|
| 65 |
+
// Create the PerThreadSem associated with "identity". Initializes count=0.
|
| 66 |
+
// REQUIRES: May only be called by ThreadIdentity.
|
| 67 |
+
static void Init(base_internal::ThreadIdentity* identity);
|
| 68 |
+
|
| 69 |
+
// Increments "identity"'s count.
|
| 70 |
+
static inline void Post(base_internal::ThreadIdentity* identity);
|
| 71 |
+
|
| 72 |
+
// Waits until either our count > 0 or t has expired.
|
| 73 |
+
// If count > 0, decrements count and returns true. Otherwise returns false.
|
| 74 |
+
// !t.has_timeout() => Wait(t) will return true.
|
| 75 |
+
static inline bool Wait(KernelTimeout t);
|
| 76 |
+
|
| 77 |
+
// Permitted callers.
|
| 78 |
+
friend class PerThreadSemTest;
|
| 79 |
+
friend class absl::Mutex;
|
| 80 |
+
friend void OneTimeInitThreadIdentity(absl::base_internal::ThreadIdentity*);
|
| 81 |
+
};
|
| 82 |
+
|
| 83 |
+
} // namespace synchronization_internal
|
| 84 |
+
ABSL_NAMESPACE_END
|
| 85 |
+
} // namespace absl
|
| 86 |
+
|
| 87 |
+
// In some build configurations we pass --detect-odr-violations to the
|
| 88 |
+
// gold linker. This causes it to flag weak symbol overrides as ODR
|
| 89 |
+
// violations. Because ODR only applies to C++ and not C,
|
| 90 |
+
// --detect-odr-violations ignores symbols not mangled with C++ names.
|
| 91 |
+
// By changing our extension points to be extern "C", we dodge this
|
| 92 |
+
// check.
|
| 93 |
+
extern "C" {
|
| 94 |
+
void ABSL_INTERNAL_C_SYMBOL(AbslInternalPerThreadSemPost)(
|
| 95 |
+
absl::base_internal::ThreadIdentity* identity);
|
| 96 |
+
bool ABSL_INTERNAL_C_SYMBOL(AbslInternalPerThreadSemWait)(
|
| 97 |
+
absl::synchronization_internal::KernelTimeout t);
|
| 98 |
+
} // extern "C"
|
| 99 |
+
|
| 100 |
+
void absl::synchronization_internal::PerThreadSem::Post(
|
| 101 |
+
absl::base_internal::ThreadIdentity* identity) {
|
| 102 |
+
ABSL_INTERNAL_C_SYMBOL(AbslInternalPerThreadSemPost)(identity);
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
bool absl::synchronization_internal::PerThreadSem::Wait(
|
| 106 |
+
absl::synchronization_internal::KernelTimeout t) {
|
| 107 |
+
return ABSL_INTERNAL_C_SYMBOL(AbslInternalPerThreadSemWait)(t);
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
+
#endif // ABSL_SYNCHRONIZATION_INTERNAL_PER_THREAD_SEM_H_
|
miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/absl/synchronization/internal/waiter.h
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2017 The Abseil Authors.
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// https://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
//
|
| 15 |
+
|
| 16 |
+
#ifndef ABSL_SYNCHRONIZATION_INTERNAL_WAITER_H_
|
| 17 |
+
#define ABSL_SYNCHRONIZATION_INTERNAL_WAITER_H_
|
| 18 |
+
|
| 19 |
+
#include "absl/base/config.h"
|
| 20 |
+
|
| 21 |
+
#ifdef _WIN32
|
| 22 |
+
#include <sdkddkver.h>
|
| 23 |
+
#else
|
| 24 |
+
#include <pthread.h>
|
| 25 |
+
#endif
|
| 26 |
+
|
| 27 |
+
#ifdef __linux__
|
| 28 |
+
#include <linux/futex.h>
|
| 29 |
+
#endif
|
| 30 |
+
|
| 31 |
+
#ifdef ABSL_HAVE_SEMAPHORE_H
|
| 32 |
+
#include <semaphore.h>
|
| 33 |
+
#endif
|
| 34 |
+
|
| 35 |
+
#include <atomic>
|
| 36 |
+
#include <cstdint>
|
| 37 |
+
|
| 38 |
+
#include "absl/base/internal/thread_identity.h"
|
| 39 |
+
#include "absl/synchronization/internal/futex.h"
|
| 40 |
+
#include "absl/synchronization/internal/kernel_timeout.h"
|
| 41 |
+
|
| 42 |
+
// May be chosen at compile time via -DABSL_FORCE_WAITER_MODE=<index>
|
| 43 |
+
#define ABSL_WAITER_MODE_FUTEX 0
|
| 44 |
+
#define ABSL_WAITER_MODE_SEM 1
|
| 45 |
+
#define ABSL_WAITER_MODE_CONDVAR 2
|
| 46 |
+
#define ABSL_WAITER_MODE_WIN32 3
|
| 47 |
+
|
| 48 |
+
#if defined(ABSL_FORCE_WAITER_MODE)
|
| 49 |
+
#define ABSL_WAITER_MODE ABSL_FORCE_WAITER_MODE
|
| 50 |
+
#elif defined(_WIN32) && _WIN32_WINNT >= _WIN32_WINNT_VISTA
|
| 51 |
+
#define ABSL_WAITER_MODE ABSL_WAITER_MODE_WIN32
|
| 52 |
+
#elif defined(ABSL_INTERNAL_HAVE_FUTEX)
|
| 53 |
+
#define ABSL_WAITER_MODE ABSL_WAITER_MODE_FUTEX
|
| 54 |
+
#elif defined(ABSL_HAVE_SEMAPHORE_H)
|
| 55 |
+
#define ABSL_WAITER_MODE ABSL_WAITER_MODE_SEM
|
| 56 |
+
#else
|
| 57 |
+
#define ABSL_WAITER_MODE ABSL_WAITER_MODE_CONDVAR
|
| 58 |
+
#endif
|
| 59 |
+
|
| 60 |
+
namespace absl {
|
| 61 |
+
ABSL_NAMESPACE_BEGIN
|
| 62 |
+
namespace synchronization_internal {
|
| 63 |
+
|
| 64 |
+
// Waiter is an OS-specific semaphore.
|
| 65 |
+
class Waiter {
|
| 66 |
+
public:
|
| 67 |
+
// Prepare any data to track waits.
|
| 68 |
+
Waiter();
|
| 69 |
+
|
| 70 |
+
// Not copyable or movable
|
| 71 |
+
Waiter(const Waiter&) = delete;
|
| 72 |
+
Waiter& operator=(const Waiter&) = delete;
|
| 73 |
+
|
| 74 |
+
// Blocks the calling thread until a matching call to `Post()` or
|
| 75 |
+
// `t` has passed. Returns `true` if woken (`Post()` called),
|
| 76 |
+
// `false` on timeout.
|
| 77 |
+
bool Wait(KernelTimeout t);
|
| 78 |
+
|
| 79 |
+
// Restart the caller of `Wait()` as with a normal semaphore.
|
| 80 |
+
void Post();
|
| 81 |
+
|
| 82 |
+
// If anyone is waiting, wake them up temporarily and cause them to
|
| 83 |
+
// call `MaybeBecomeIdle()`. They will then return to waiting for a
|
| 84 |
+
// `Post()` or timeout.
|
| 85 |
+
void Poke();
|
| 86 |
+
|
| 87 |
+
// Returns the Waiter associated with the identity.
|
| 88 |
+
static Waiter* GetWaiter(base_internal::ThreadIdentity* identity) {
|
| 89 |
+
static_assert(
|
| 90 |
+
sizeof(Waiter) <= sizeof(base_internal::ThreadIdentity::WaiterState),
|
| 91 |
+
"Insufficient space for Waiter");
|
| 92 |
+
return reinterpret_cast<Waiter*>(identity->waiter_state.data);
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
// How many periods to remain idle before releasing resources
|
| 96 |
+
#ifndef ABSL_HAVE_THREAD_SANITIZER
|
| 97 |
+
static constexpr int kIdlePeriods = 60;
|
| 98 |
+
#else
|
| 99 |
+
// Memory consumption under ThreadSanitizer is a serious concern,
|
| 100 |
+
// so we release resources sooner. The value of 1 leads to 1 to 2 second
|
| 101 |
+
// delay before marking a thread as idle.
|
| 102 |
+
static const int kIdlePeriods = 1;
|
| 103 |
+
#endif
|
| 104 |
+
|
| 105 |
+
private:
|
| 106 |
+
// The destructor must not be called since Mutex/CondVar
|
| 107 |
+
// can use PerThreadSem/Waiter after the thread exits.
|
| 108 |
+
// Waiter objects are embedded in ThreadIdentity objects,
|
| 109 |
+
// which are reused via a freelist and are never destroyed.
|
| 110 |
+
~Waiter() = delete;
|
| 111 |
+
|
| 112 |
+
#if ABSL_WAITER_MODE == ABSL_WAITER_MODE_FUTEX
|
| 113 |
+
// Futexes are defined by specification to be 32-bits.
|
| 114 |
+
// Thus std::atomic<int32_t> must be just an int32_t with lockfree methods.
|
| 115 |
+
std::atomic<int32_t> futex_;
|
| 116 |
+
static_assert(sizeof(int32_t) == sizeof(futex_), "Wrong size for futex");
|
| 117 |
+
|
| 118 |
+
#elif ABSL_WAITER_MODE == ABSL_WAITER_MODE_CONDVAR
|
| 119 |
+
// REQUIRES: mu_ must be held.
|
| 120 |
+
void InternalCondVarPoke();
|
| 121 |
+
|
| 122 |
+
pthread_mutex_t mu_;
|
| 123 |
+
pthread_cond_t cv_;
|
| 124 |
+
int waiter_count_;
|
| 125 |
+
int wakeup_count_; // Unclaimed wakeups.
|
| 126 |
+
|
| 127 |
+
#elif ABSL_WAITER_MODE == ABSL_WAITER_MODE_SEM
|
| 128 |
+
sem_t sem_;
|
| 129 |
+
// This seems superfluous, but for Poke() we need to cause spurious
|
| 130 |
+
// wakeups on the semaphore. Hence we can't actually use the
|
| 131 |
+
// semaphore's count.
|
| 132 |
+
std::atomic<int> wakeups_;
|
| 133 |
+
|
| 134 |
+
#elif ABSL_WAITER_MODE == ABSL_WAITER_MODE_WIN32
|
| 135 |
+
// WinHelper - Used to define utilities for accessing the lock and
|
| 136 |
+
// condition variable storage once the types are complete.
|
| 137 |
+
class WinHelper;
|
| 138 |
+
|
| 139 |
+
// REQUIRES: WinHelper::GetLock(this) must be held.
|
| 140 |
+
void InternalCondVarPoke();
|
| 141 |
+
|
| 142 |
+
// We can't include Windows.h in our headers, so we use aligned character
|
| 143 |
+
// buffers to define the storage of SRWLOCK and CONDITION_VARIABLE.
|
| 144 |
+
// SRW locks and condition variables do not need to be explicitly destroyed.
|
| 145 |
+
// https://docs.microsoft.com/en-us/windows/win32/api/synchapi/nf-synchapi-initializesrwlock
|
| 146 |
+
// https://stackoverflow.com/questions/28975958/why-does-windows-have-no-deleteconditionvariable-function-to-go-together-with
|
| 147 |
+
alignas(void*) unsigned char mu_storage_[sizeof(void*)];
|
| 148 |
+
alignas(void*) unsigned char cv_storage_[sizeof(void*)];
|
| 149 |
+
int waiter_count_;
|
| 150 |
+
int wakeup_count_;
|
| 151 |
+
|
| 152 |
+
#else
|
| 153 |
+
#error Unknown ABSL_WAITER_MODE
|
| 154 |
+
#endif
|
| 155 |
+
};
|
| 156 |
+
|
| 157 |
+
} // namespace synchronization_internal
|
| 158 |
+
ABSL_NAMESPACE_END
|
| 159 |
+
} // namespace absl
|
| 160 |
+
|
| 161 |
+
#endif // ABSL_SYNCHRONIZATION_INTERNAL_WAITER_H_
|
miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/absl/synchronization/mutex.h
ADDED
|
@@ -0,0 +1,1129 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2017 The Abseil Authors.
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// https://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
//
|
| 15 |
+
// -----------------------------------------------------------------------------
|
| 16 |
+
// mutex.h
|
| 17 |
+
// -----------------------------------------------------------------------------
|
| 18 |
+
//
|
| 19 |
+
// This header file defines a `Mutex` -- a mutually exclusive lock -- and the
|
| 20 |
+
// most common type of synchronization primitive for facilitating locks on
|
| 21 |
+
// shared resources. A mutex is used to prevent multiple threads from accessing
|
| 22 |
+
// and/or writing to a shared resource concurrently.
|
| 23 |
+
//
|
| 24 |
+
// Unlike a `std::mutex`, the Abseil `Mutex` provides the following additional
|
| 25 |
+
// features:
|
| 26 |
+
// * Conditional predicates intrinsic to the `Mutex` object
|
| 27 |
+
// * Shared/reader locks, in addition to standard exclusive/writer locks
|
| 28 |
+
// * Deadlock detection and debug support.
|
| 29 |
+
//
|
| 30 |
+
// The following helper classes are also defined within this file:
|
| 31 |
+
//
|
| 32 |
+
// MutexLock - An RAII wrapper to acquire and release a `Mutex` for exclusive/
|
| 33 |
+
// write access within the current scope.
|
| 34 |
+
//
|
| 35 |
+
// ReaderMutexLock
|
| 36 |
+
// - An RAII wrapper to acquire and release a `Mutex` for shared/read
|
| 37 |
+
// access within the current scope.
|
| 38 |
+
//
|
| 39 |
+
// WriterMutexLock
|
| 40 |
+
// - Effectively an alias for `MutexLock` above, designed for use in
|
| 41 |
+
// distinguishing reader and writer locks within code.
|
| 42 |
+
//
|
| 43 |
+
// In addition to simple mutex locks, this file also defines ways to perform
|
| 44 |
+
// locking under certain conditions.
|
| 45 |
+
//
|
| 46 |
+
// Condition - (Preferred) Used to wait for a particular predicate that
|
| 47 |
+
// depends on state protected by the `Mutex` to become true.
|
| 48 |
+
// CondVar - A lower-level variant of `Condition` that relies on
|
| 49 |
+
// application code to explicitly signal the `CondVar` when
|
| 50 |
+
// a condition has been met.
|
| 51 |
+
//
|
| 52 |
+
// See below for more information on using `Condition` or `CondVar`.
|
| 53 |
+
//
|
| 54 |
+
// Mutexes and mutex behavior can be quite complicated. The information within
|
| 55 |
+
// this header file is limited, as a result. Please consult the Mutex guide for
|
| 56 |
+
// more complete information and examples.
|
| 57 |
+
|
| 58 |
+
#ifndef ABSL_SYNCHRONIZATION_MUTEX_H_
|
| 59 |
+
#define ABSL_SYNCHRONIZATION_MUTEX_H_
|
| 60 |
+
|
| 61 |
+
#include <atomic>
|
| 62 |
+
#include <cstdint>
|
| 63 |
+
#include <cstring>
|
| 64 |
+
#include <iterator>
|
| 65 |
+
#include <string>
|
| 66 |
+
|
| 67 |
+
#include "absl/base/const_init.h"
|
| 68 |
+
#include "absl/base/internal/identity.h"
|
| 69 |
+
#include "absl/base/internal/low_level_alloc.h"
|
| 70 |
+
#include "absl/base/internal/thread_identity.h"
|
| 71 |
+
#include "absl/base/internal/tsan_mutex_interface.h"
|
| 72 |
+
#include "absl/base/port.h"
|
| 73 |
+
#include "absl/base/thread_annotations.h"
|
| 74 |
+
#include "absl/synchronization/internal/kernel_timeout.h"
|
| 75 |
+
#include "absl/synchronization/internal/per_thread_sem.h"
|
| 76 |
+
#include "absl/time/time.h"
|
| 77 |
+
|
| 78 |
+
namespace absl {
|
| 79 |
+
ABSL_NAMESPACE_BEGIN
|
| 80 |
+
|
| 81 |
+
class Condition;
|
| 82 |
+
struct SynchWaitParams;
|
| 83 |
+
|
| 84 |
+
// -----------------------------------------------------------------------------
|
| 85 |
+
// Mutex
|
| 86 |
+
// -----------------------------------------------------------------------------
|
| 87 |
+
//
|
| 88 |
+
// A `Mutex` is a non-reentrant (aka non-recursive) Mutually Exclusive lock
|
| 89 |
+
// on some resource, typically a variable or data structure with associated
|
| 90 |
+
// invariants. Proper usage of mutexes prevents concurrent access by different
|
| 91 |
+
// threads to the same resource.
|
| 92 |
+
//
|
| 93 |
+
// A `Mutex` has two basic operations: `Mutex::Lock()` and `Mutex::Unlock()`.
|
| 94 |
+
// The `Lock()` operation *acquires* a `Mutex` (in a state known as an
|
| 95 |
+
// *exclusive* -- or write -- lock), while the `Unlock()` operation *releases* a
|
| 96 |
+
// Mutex. During the span of time between the Lock() and Unlock() operations,
|
| 97 |
+
// a mutex is said to be *held*. By design all mutexes support exclusive/write
|
| 98 |
+
// locks, as this is the most common way to use a mutex.
|
| 99 |
+
//
|
| 100 |
+
// The `Mutex` state machine for basic lock/unlock operations is quite simple:
|
| 101 |
+
//
|
| 102 |
+
// | | Lock() | Unlock() |
|
| 103 |
+
// |----------------+------------+----------|
|
| 104 |
+
// | Free | Exclusive | invalid |
|
| 105 |
+
// | Exclusive | blocks | Free |
|
| 106 |
+
//
|
| 107 |
+
// Attempts to `Unlock()` must originate from the thread that performed the
|
| 108 |
+
// corresponding `Lock()` operation.
|
| 109 |
+
//
|
| 110 |
+
// An "invalid" operation is disallowed by the API. The `Mutex` implementation
|
| 111 |
+
// is allowed to do anything on an invalid call, including but not limited to
|
| 112 |
+
// crashing with a useful error message, silently succeeding, or corrupting
|
| 113 |
+
// data structures. In debug mode, the implementation attempts to crash with a
|
| 114 |
+
// useful error message.
|
| 115 |
+
//
|
| 116 |
+
// `Mutex` is not guaranteed to be "fair" in prioritizing waiting threads; it
|
| 117 |
+
// is, however, approximately fair over long periods, and starvation-free for
|
| 118 |
+
// threads at the same priority.
|
| 119 |
+
//
|
| 120 |
+
// The lock/unlock primitives are now annotated with lock annotations
|
| 121 |
+
// defined in (base/thread_annotations.h). When writing multi-threaded code,
|
| 122 |
+
// you should use lock annotations whenever possible to document your lock
|
| 123 |
+
// synchronization policy. Besides acting as documentation, these annotations
|
| 124 |
+
// also help compilers or static analysis tools to identify and warn about
|
| 125 |
+
// issues that could potentially result in race conditions and deadlocks.
|
| 126 |
+
//
|
| 127 |
+
// For more information about the lock annotations, please see
|
| 128 |
+
// [Thread Safety Analysis](http://clang.llvm.org/docs/ThreadSafetyAnalysis.html)
|
| 129 |
+
// in the Clang documentation.
|
| 130 |
+
//
|
| 131 |
+
// See also `MutexLock`, below, for scoped `Mutex` acquisition.
|
| 132 |
+
|
| 133 |
+
class ABSL_LOCKABLE Mutex {
|
| 134 |
+
public:
|
| 135 |
+
// Creates a `Mutex` that is not held by anyone. This constructor is
|
| 136 |
+
// typically used for Mutexes allocated on the heap or the stack.
|
| 137 |
+
//
|
| 138 |
+
// To create `Mutex` instances with static storage duration
|
| 139 |
+
// (e.g. a namespace-scoped or global variable), see
|
| 140 |
+
// `Mutex::Mutex(absl::kConstInit)` below instead.
|
| 141 |
+
Mutex();
|
| 142 |
+
|
| 143 |
+
// Creates a mutex with static storage duration. A global variable
|
| 144 |
+
// constructed this way avoids the lifetime issues that can occur on program
|
| 145 |
+
// startup and shutdown. (See absl/base/const_init.h.)
|
| 146 |
+
//
|
| 147 |
+
// For Mutexes allocated on the heap and stack, instead use the default
|
| 148 |
+
// constructor, which can interact more fully with the thread sanitizer.
|
| 149 |
+
//
|
| 150 |
+
// Example usage:
|
| 151 |
+
// namespace foo {
|
| 152 |
+
// ABSL_CONST_INIT absl::Mutex mu(absl::kConstInit);
|
| 153 |
+
// }
|
| 154 |
+
explicit constexpr Mutex(absl::ConstInitType);
|
| 155 |
+
|
| 156 |
+
~Mutex();
|
| 157 |
+
|
| 158 |
+
// Mutex::Lock()
|
| 159 |
+
//
|
| 160 |
+
// Blocks the calling thread, if necessary, until this `Mutex` is free, and
|
| 161 |
+
// then acquires it exclusively. (This lock is also known as a "write lock.")
|
| 162 |
+
void Lock() ABSL_EXCLUSIVE_LOCK_FUNCTION();
|
| 163 |
+
|
| 164 |
+
// Mutex::Unlock()
|
| 165 |
+
//
|
| 166 |
+
// Releases this `Mutex` and returns it from the exclusive/write state to the
|
| 167 |
+
// free state. Calling thread must hold the `Mutex` exclusively.
|
| 168 |
+
void Unlock() ABSL_UNLOCK_FUNCTION();
|
| 169 |
+
|
| 170 |
+
// Mutex::TryLock()
|
| 171 |
+
//
|
| 172 |
+
// If the mutex can be acquired without blocking, does so exclusively and
|
| 173 |
+
// returns `true`. Otherwise, returns `false`. Returns `true` with high
|
| 174 |
+
// probability if the `Mutex` was free.
|
| 175 |
+
bool TryLock() ABSL_EXCLUSIVE_TRYLOCK_FUNCTION(true);
|
| 176 |
+
|
| 177 |
+
// Mutex::AssertHeld()
|
| 178 |
+
//
|
| 179 |
+
// Require that the mutex be held exclusively (write mode) by this thread.
|
| 180 |
+
//
|
| 181 |
+
// If the mutex is not currently held by this thread, this function may report
|
| 182 |
+
// an error (typically by crashing with a diagnostic) or it may do nothing.
|
| 183 |
+
// This function is intended only as a tool to assist debugging; it doesn't
|
| 184 |
+
// guarantee correctness.
|
| 185 |
+
void AssertHeld() const ABSL_ASSERT_EXCLUSIVE_LOCK();
|
| 186 |
+
|
| 187 |
+
// ---------------------------------------------------------------------------
|
| 188 |
+
// Reader-Writer Locking
|
| 189 |
+
// ---------------------------------------------------------------------------
|
| 190 |
+
|
| 191 |
+
// A Mutex can also be used as a starvation-free reader-writer lock.
|
| 192 |
+
// Neither read-locks nor write-locks are reentrant/recursive to avoid
|
| 193 |
+
// potential client programming errors.
|
| 194 |
+
//
|
| 195 |
+
// The Mutex API provides `Writer*()` aliases for the existing `Lock()`,
|
| 196 |
+
// `Unlock()` and `TryLock()` methods for use within applications mixing
|
| 197 |
+
// reader/writer locks. Using `Reader*()` and `Writer*()` operations in this
|
| 198 |
+
// manner can make locking behavior clearer when mixing read and write modes.
|
| 199 |
+
//
|
| 200 |
+
// Introducing reader locks necessarily complicates the `Mutex` state
|
| 201 |
+
// machine somewhat. The table below illustrates the allowed state transitions
|
| 202 |
+
// of a mutex in such cases. Note that ReaderLock() may block even if the lock
|
| 203 |
+
// is held in shared mode; this occurs when another thread is blocked on a
|
| 204 |
+
// call to WriterLock().
|
| 205 |
+
//
|
| 206 |
+
// ---------------------------------------------------------------------------
|
| 207 |
+
// Operation: WriterLock() Unlock() ReaderLock() ReaderUnlock()
|
| 208 |
+
// ---------------------------------------------------------------------------
|
| 209 |
+
// State
|
| 210 |
+
// ---------------------------------------------------------------------------
|
| 211 |
+
// Free Exclusive invalid Shared(1) invalid
|
| 212 |
+
// Shared(1) blocks invalid Shared(2) or blocks Free
|
| 213 |
+
// Shared(n) n>1 blocks invalid Shared(n+1) or blocks Shared(n-1)
|
| 214 |
+
// Exclusive blocks Free blocks invalid
|
| 215 |
+
// ---------------------------------------------------------------------------
|
| 216 |
+
//
|
| 217 |
+
// In comments below, "shared" refers to a state of Shared(n) for any n > 0.
|
| 218 |
+
|
| 219 |
+
// Mutex::ReaderLock()
|
| 220 |
+
//
|
| 221 |
+
// Blocks the calling thread, if necessary, until this `Mutex` is either free,
|
| 222 |
+
// or in shared mode, and then acquires a share of it. Note that
|
| 223 |
+
// `ReaderLock()` will block if some other thread has an exclusive/writer lock
|
| 224 |
+
// on the mutex.
|
| 225 |
+
|
| 226 |
+
void ReaderLock() ABSL_SHARED_LOCK_FUNCTION();
|
| 227 |
+
|
| 228 |
+
// Mutex::ReaderUnlock()
|
| 229 |
+
//
|
| 230 |
+
// Releases a read share of this `Mutex`. `ReaderUnlock` may return a mutex to
|
| 231 |
+
// the free state if this thread holds the last reader lock on the mutex. Note
|
| 232 |
+
// that you cannot call `ReaderUnlock()` on a mutex held in write mode.
|
| 233 |
+
void ReaderUnlock() ABSL_UNLOCK_FUNCTION();
|
| 234 |
+
|
| 235 |
+
// Mutex::ReaderTryLock()
|
| 236 |
+
//
|
| 237 |
+
// If the mutex can be acquired without blocking, acquires this mutex for
|
| 238 |
+
// shared access and returns `true`. Otherwise, returns `false`. Returns
|
| 239 |
+
// `true` with high probability if the `Mutex` was free or shared.
|
| 240 |
+
bool ReaderTryLock() ABSL_SHARED_TRYLOCK_FUNCTION(true);
|
| 241 |
+
|
| 242 |
+
// Mutex::AssertReaderHeld()
|
| 243 |
+
//
|
| 244 |
+
// Require that the mutex be held at least in shared mode (read mode) by this
|
| 245 |
+
// thread.
|
| 246 |
+
//
|
| 247 |
+
// If the mutex is not currently held by this thread, this function may report
|
| 248 |
+
// an error (typically by crashing with a diagnostic) or it may do nothing.
|
| 249 |
+
// This function is intended only as a tool to assist debugging; it doesn't
|
| 250 |
+
// guarantee correctness.
|
| 251 |
+
void AssertReaderHeld() const ABSL_ASSERT_SHARED_LOCK();
|
| 252 |
+
|
| 253 |
+
// Mutex::WriterLock()
|
| 254 |
+
// Mutex::WriterUnlock()
|
| 255 |
+
// Mutex::WriterTryLock()
|
| 256 |
+
//
|
| 257 |
+
// Aliases for `Mutex::Lock()`, `Mutex::Unlock()`, and `Mutex::TryLock()`.
|
| 258 |
+
//
|
| 259 |
+
// These methods may be used (along with the complementary `Reader*()`
|
| 260 |
+
// methods) to distingish simple exclusive `Mutex` usage (`Lock()`,
|
| 261 |
+
// etc.) from reader/writer lock usage.
|
| 262 |
+
void WriterLock() ABSL_EXCLUSIVE_LOCK_FUNCTION() { this->Lock(); }
|
| 263 |
+
|
| 264 |
+
void WriterUnlock() ABSL_UNLOCK_FUNCTION() { this->Unlock(); }
|
| 265 |
+
|
| 266 |
+
bool WriterTryLock() ABSL_EXCLUSIVE_TRYLOCK_FUNCTION(true) {
|
| 267 |
+
return this->TryLock();
|
| 268 |
+
}
|
| 269 |
+
|
| 270 |
+
// ---------------------------------------------------------------------------
|
| 271 |
+
// Conditional Critical Regions
|
| 272 |
+
// ---------------------------------------------------------------------------
|
| 273 |
+
|
| 274 |
+
// Conditional usage of a `Mutex` can occur using two distinct paradigms:
|
| 275 |
+
//
|
| 276 |
+
// * Use of `Mutex` member functions with `Condition` objects.
|
| 277 |
+
// * Use of the separate `CondVar` abstraction.
|
| 278 |
+
//
|
| 279 |
+
// In general, prefer use of `Condition` and the `Mutex` member functions
|
| 280 |
+
// listed below over `CondVar`. When there are multiple threads waiting on
|
| 281 |
+
// distinctly different conditions, however, a battery of `CondVar`s may be
|
| 282 |
+
// more efficient. This section discusses use of `Condition` objects.
|
| 283 |
+
//
|
| 284 |
+
// `Mutex` contains member functions for performing lock operations only under
|
| 285 |
+
// certain conditions, of class `Condition`. For correctness, the `Condition`
|
| 286 |
+
// must return a boolean that is a pure function, only of state protected by
|
| 287 |
+
// the `Mutex`. The condition must be invariant w.r.t. environmental state
|
| 288 |
+
// such as thread, cpu id, or time, and must be `noexcept`. The condition will
|
| 289 |
+
// always be invoked with the mutex held in at least read mode, so you should
|
| 290 |
+
// not block it for long periods or sleep it on a timer.
|
| 291 |
+
//
|
| 292 |
+
// Since a condition must not depend directly on the current time, use
|
| 293 |
+
// `*WithTimeout()` member function variants to make your condition
|
| 294 |
+
// effectively true after a given duration, or `*WithDeadline()` variants to
|
| 295 |
+
// make your condition effectively true after a given time.
|
| 296 |
+
//
|
| 297 |
+
// The condition function should have no side-effects aside from debug
|
| 298 |
+
// logging; as a special exception, the function may acquire other mutexes
|
| 299 |
+
// provided it releases all those that it acquires. (This exception was
|
| 300 |
+
// required to allow logging.)
|
| 301 |
+
|
| 302 |
+
// Mutex::Await()
|
| 303 |
+
//
|
| 304 |
+
// Unlocks this `Mutex` and blocks until simultaneously both `cond` is `true`
|
| 305 |
+
// and this `Mutex` can be reacquired, then reacquires this `Mutex` in the
|
| 306 |
+
// same mode in which it was previously held. If the condition is initially
|
| 307 |
+
// `true`, `Await()` *may* skip the release/re-acquire step.
|
| 308 |
+
//
|
| 309 |
+
// `Await()` requires that this thread holds this `Mutex` in some mode.
|
| 310 |
+
void Await(const Condition &cond);
|
| 311 |
+
|
| 312 |
+
// Mutex::LockWhen()
|
| 313 |
+
// Mutex::ReaderLockWhen()
|
| 314 |
+
// Mutex::WriterLockWhen()
|
| 315 |
+
//
|
| 316 |
+
// Blocks until simultaneously both `cond` is `true` and this `Mutex` can
|
| 317 |
+
// be acquired, then atomically acquires this `Mutex`. `LockWhen()` is
|
| 318 |
+
// logically equivalent to `*Lock(); Await();` though they may have different
|
| 319 |
+
// performance characteristics.
|
| 320 |
+
void LockWhen(const Condition &cond) ABSL_EXCLUSIVE_LOCK_FUNCTION();
|
| 321 |
+
|
| 322 |
+
void ReaderLockWhen(const Condition &cond) ABSL_SHARED_LOCK_FUNCTION();
|
| 323 |
+
|
| 324 |
+
void WriterLockWhen(const Condition &cond) ABSL_EXCLUSIVE_LOCK_FUNCTION() {
|
| 325 |
+
this->LockWhen(cond);
|
| 326 |
+
}
|
| 327 |
+
|
| 328 |
+
// ---------------------------------------------------------------------------
|
| 329 |
+
// Mutex Variants with Timeouts/Deadlines
|
| 330 |
+
// ---------------------------------------------------------------------------
|
| 331 |
+
|
| 332 |
+
// Mutex::AwaitWithTimeout()
|
| 333 |
+
// Mutex::AwaitWithDeadline()
|
| 334 |
+
//
|
| 335 |
+
// Unlocks this `Mutex` and blocks until simultaneously:
|
| 336 |
+
// - either `cond` is true or the {timeout has expired, deadline has passed}
|
| 337 |
+
// and
|
| 338 |
+
// - this `Mutex` can be reacquired,
|
| 339 |
+
// then reacquire this `Mutex` in the same mode in which it was previously
|
| 340 |
+
// held, returning `true` iff `cond` is `true` on return.
|
| 341 |
+
//
|
| 342 |
+
// If the condition is initially `true`, the implementation *may* skip the
|
| 343 |
+
// release/re-acquire step and return immediately.
|
| 344 |
+
//
|
| 345 |
+
// Deadlines in the past are equivalent to an immediate deadline.
|
| 346 |
+
// Negative timeouts are equivalent to a zero timeout.
|
| 347 |
+
//
|
| 348 |
+
// This method requires that this thread holds this `Mutex` in some mode.
|
| 349 |
+
bool AwaitWithTimeout(const Condition &cond, absl::Duration timeout);
|
| 350 |
+
|
| 351 |
+
bool AwaitWithDeadline(const Condition &cond, absl::Time deadline);
|
| 352 |
+
|
| 353 |
+
// Mutex::LockWhenWithTimeout()
|
| 354 |
+
// Mutex::ReaderLockWhenWithTimeout()
|
| 355 |
+
// Mutex::WriterLockWhenWithTimeout()
|
| 356 |
+
//
|
| 357 |
+
// Blocks until simultaneously both:
|
| 358 |
+
// - either `cond` is `true` or the timeout has expired, and
|
| 359 |
+
// - this `Mutex` can be acquired,
|
| 360 |
+
// then atomically acquires this `Mutex`, returning `true` iff `cond` is
|
| 361 |
+
// `true` on return.
|
| 362 |
+
//
|
| 363 |
+
// Negative timeouts are equivalent to a zero timeout.
|
| 364 |
+
bool LockWhenWithTimeout(const Condition &cond, absl::Duration timeout)
|
| 365 |
+
ABSL_EXCLUSIVE_LOCK_FUNCTION();
|
| 366 |
+
bool ReaderLockWhenWithTimeout(const Condition &cond, absl::Duration timeout)
|
| 367 |
+
ABSL_SHARED_LOCK_FUNCTION();
|
| 368 |
+
bool WriterLockWhenWithTimeout(const Condition &cond, absl::Duration timeout)
|
| 369 |
+
ABSL_EXCLUSIVE_LOCK_FUNCTION() {
|
| 370 |
+
return this->LockWhenWithTimeout(cond, timeout);
|
| 371 |
+
}
|
| 372 |
+
|
| 373 |
+
// Mutex::LockWhenWithDeadline()
|
| 374 |
+
// Mutex::ReaderLockWhenWithDeadline()
|
| 375 |
+
// Mutex::WriterLockWhenWithDeadline()
|
| 376 |
+
//
|
| 377 |
+
// Blocks until simultaneously both:
|
| 378 |
+
// - either `cond` is `true` or the deadline has been passed, and
|
| 379 |
+
// - this `Mutex` can be acquired,
|
| 380 |
+
// then atomically acquires this Mutex, returning `true` iff `cond` is `true`
|
| 381 |
+
// on return.
|
| 382 |
+
//
|
| 383 |
+
// Deadlines in the past are equivalent to an immediate deadline.
|
| 384 |
+
bool LockWhenWithDeadline(const Condition &cond, absl::Time deadline)
|
| 385 |
+
ABSL_EXCLUSIVE_LOCK_FUNCTION();
|
| 386 |
+
bool ReaderLockWhenWithDeadline(const Condition &cond, absl::Time deadline)
|
| 387 |
+
ABSL_SHARED_LOCK_FUNCTION();
|
| 388 |
+
bool WriterLockWhenWithDeadline(const Condition &cond, absl::Time deadline)
|
| 389 |
+
ABSL_EXCLUSIVE_LOCK_FUNCTION() {
|
| 390 |
+
return this->LockWhenWithDeadline(cond, deadline);
|
| 391 |
+
}
|
| 392 |
+
|
| 393 |
+
// ---------------------------------------------------------------------------
|
| 394 |
+
// Debug Support: Invariant Checking, Deadlock Detection, Logging.
|
| 395 |
+
// ---------------------------------------------------------------------------
|
| 396 |
+
|
| 397 |
+
// Mutex::EnableInvariantDebugging()
|
| 398 |
+
//
|
| 399 |
+
// If `invariant`!=null and if invariant debugging has been enabled globally,
|
| 400 |
+
// cause `(*invariant)(arg)` to be called at moments when the invariant for
|
| 401 |
+
// this `Mutex` should hold (for example: just after acquire, just before
|
| 402 |
+
// release).
|
| 403 |
+
//
|
| 404 |
+
// The routine `invariant` should have no side-effects since it is not
|
| 405 |
+
// guaranteed how many times it will be called; it should check the invariant
|
| 406 |
+
// and crash if it does not hold. Enabling global invariant debugging may
|
| 407 |
+
// substantially reduce `Mutex` performance; it should be set only for
|
| 408 |
+
// non-production runs. Optimization options may also disable invariant
|
| 409 |
+
// checks.
|
| 410 |
+
void EnableInvariantDebugging(void (*invariant)(void *), void *arg);
|
| 411 |
+
|
| 412 |
+
// Mutex::EnableDebugLog()
|
| 413 |
+
//
|
| 414 |
+
// Cause all subsequent uses of this `Mutex` to be logged via
|
| 415 |
+
// `ABSL_RAW_LOG(INFO)`. Log entries are tagged with `name` if no previous
|
| 416 |
+
// call to `EnableInvariantDebugging()` or `EnableDebugLog()` has been made.
|
| 417 |
+
//
|
| 418 |
+
// Note: This method substantially reduces `Mutex` performance.
|
| 419 |
+
void EnableDebugLog(const char *name);
|
| 420 |
+
|
| 421 |
+
// Deadlock detection
|
| 422 |
+
|
| 423 |
+
// Mutex::ForgetDeadlockInfo()
|
| 424 |
+
//
|
| 425 |
+
// Forget any deadlock-detection information previously gathered
|
| 426 |
+
// about this `Mutex`. Call this method in debug mode when the lock ordering
|
| 427 |
+
// of a `Mutex` changes.
|
| 428 |
+
void ForgetDeadlockInfo();
|
| 429 |
+
|
| 430 |
+
// Mutex::AssertNotHeld()
|
| 431 |
+
//
|
| 432 |
+
// Return immediately if this thread does not hold this `Mutex` in any
|
| 433 |
+
// mode; otherwise, may report an error (typically by crashing with a
|
| 434 |
+
// diagnostic), or may return immediately.
|
| 435 |
+
//
|
| 436 |
+
// Currently this check is performed only if all of:
|
| 437 |
+
// - in debug mode
|
| 438 |
+
// - SetMutexDeadlockDetectionMode() has been set to kReport or kAbort
|
| 439 |
+
// - number of locks concurrently held by this thread is not large.
|
| 440 |
+
// are true.
|
| 441 |
+
void AssertNotHeld() const;
|
| 442 |
+
|
| 443 |
+
// Special cases.
|
| 444 |
+
|
| 445 |
+
// A `MuHow` is a constant that indicates how a lock should be acquired.
|
| 446 |
+
// Internal implementation detail. Clients should ignore.
|
| 447 |
+
typedef const struct MuHowS *MuHow;
|
| 448 |
+
|
| 449 |
+
// Mutex::InternalAttemptToUseMutexInFatalSignalHandler()
|
| 450 |
+
//
|
| 451 |
+
// Causes the `Mutex` implementation to prepare itself for re-entry caused by
|
| 452 |
+
// future use of `Mutex` within a fatal signal handler. This method is
|
| 453 |
+
// intended for use only for last-ditch attempts to log crash information.
|
| 454 |
+
// It does not guarantee that attempts to use Mutexes within the handler will
|
| 455 |
+
// not deadlock; it merely makes other faults less likely.
|
| 456 |
+
//
|
| 457 |
+
// WARNING: This routine must be invoked from a signal handler, and the
|
| 458 |
+
// signal handler must either loop forever or terminate the process.
|
| 459 |
+
// Attempts to return from (or `longjmp` out of) the signal handler once this
|
| 460 |
+
// call has been made may cause arbitrary program behaviour including
|
| 461 |
+
// crashes and deadlocks.
|
| 462 |
+
static void InternalAttemptToUseMutexInFatalSignalHandler();
|
| 463 |
+
|
| 464 |
+
private:
|
| 465 |
+
std::atomic<intptr_t> mu_; // The Mutex state.
|
| 466 |
+
|
| 467 |
+
// Post()/Wait() versus associated PerThreadSem; in class for required
|
| 468 |
+
// friendship with PerThreadSem.
|
| 469 |
+
static void IncrementSynchSem(Mutex *mu, base_internal::PerThreadSynch *w);
|
| 470 |
+
static bool DecrementSynchSem(Mutex *mu, base_internal::PerThreadSynch *w,
|
| 471 |
+
synchronization_internal::KernelTimeout t);
|
| 472 |
+
|
| 473 |
+
// slow path acquire
|
| 474 |
+
void LockSlowLoop(SynchWaitParams *waitp, int flags);
|
| 475 |
+
// wrappers around LockSlowLoop()
|
| 476 |
+
bool LockSlowWithDeadline(MuHow how, const Condition *cond,
|
| 477 |
+
synchronization_internal::KernelTimeout t,
|
| 478 |
+
int flags);
|
| 479 |
+
void LockSlow(MuHow how, const Condition *cond,
|
| 480 |
+
int flags) ABSL_ATTRIBUTE_COLD;
|
| 481 |
+
// slow path release
|
| 482 |
+
void UnlockSlow(SynchWaitParams *waitp) ABSL_ATTRIBUTE_COLD;
|
| 483 |
+
// Common code between Await() and AwaitWithTimeout/Deadline()
|
| 484 |
+
bool AwaitCommon(const Condition &cond,
|
| 485 |
+
synchronization_internal::KernelTimeout t);
|
| 486 |
+
// Attempt to remove thread s from queue.
|
| 487 |
+
void TryRemove(base_internal::PerThreadSynch *s);
|
| 488 |
+
// Block a thread on mutex.
|
| 489 |
+
void Block(base_internal::PerThreadSynch *s);
|
| 490 |
+
// Wake a thread; return successor.
|
| 491 |
+
base_internal::PerThreadSynch *Wakeup(base_internal::PerThreadSynch *w);
|
| 492 |
+
|
| 493 |
+
friend class CondVar; // for access to Trans()/Fer().
|
| 494 |
+
void Trans(MuHow how); // used for CondVar->Mutex transfer
|
| 495 |
+
void Fer(
|
| 496 |
+
base_internal::PerThreadSynch *w); // used for CondVar->Mutex transfer
|
| 497 |
+
|
| 498 |
+
// Catch the error of writing Mutex when intending MutexLock.
|
| 499 |
+
Mutex(const volatile Mutex * /*ignored*/) {} // NOLINT(runtime/explicit)
|
| 500 |
+
|
| 501 |
+
Mutex(const Mutex&) = delete;
|
| 502 |
+
Mutex& operator=(const Mutex&) = delete;
|
| 503 |
+
};
|
| 504 |
+
|
| 505 |
+
// -----------------------------------------------------------------------------
|
| 506 |
+
// Mutex RAII Wrappers
|
| 507 |
+
// -----------------------------------------------------------------------------
|
| 508 |
+
|
| 509 |
+
// MutexLock
|
| 510 |
+
//
|
| 511 |
+
// `MutexLock` is a helper class, which acquires and releases a `Mutex` via
|
| 512 |
+
// RAII.
|
| 513 |
+
//
|
| 514 |
+
// Example:
|
| 515 |
+
//
|
| 516 |
+
// Class Foo {
|
| 517 |
+
// public:
|
| 518 |
+
// Foo::Bar* Baz() {
|
| 519 |
+
// MutexLock lock(&mu_);
|
| 520 |
+
// ...
|
| 521 |
+
// return bar;
|
| 522 |
+
// }
|
| 523 |
+
//
|
| 524 |
+
// private:
|
| 525 |
+
// Mutex mu_;
|
| 526 |
+
// };
|
| 527 |
+
class ABSL_SCOPED_LOCKABLE MutexLock {
|
| 528 |
+
public:
|
| 529 |
+
// Constructors
|
| 530 |
+
|
| 531 |
+
// Calls `mu->Lock()` and returns when that call returns. That is, `*mu` is
|
| 532 |
+
// guaranteed to be locked when this object is constructed. Requires that
|
| 533 |
+
// `mu` be dereferenceable.
|
| 534 |
+
explicit MutexLock(Mutex *mu) ABSL_EXCLUSIVE_LOCK_FUNCTION(mu) : mu_(mu) {
|
| 535 |
+
this->mu_->Lock();
|
| 536 |
+
}
|
| 537 |
+
|
| 538 |
+
// Like above, but calls `mu->LockWhen(cond)` instead. That is, in addition to
|
| 539 |
+
// the above, the condition given by `cond` is also guaranteed to hold when
|
| 540 |
+
// this object is constructed.
|
| 541 |
+
explicit MutexLock(Mutex *mu, const Condition &cond)
|
| 542 |
+
ABSL_EXCLUSIVE_LOCK_FUNCTION(mu)
|
| 543 |
+
: mu_(mu) {
|
| 544 |
+
this->mu_->LockWhen(cond);
|
| 545 |
+
}
|
| 546 |
+
|
| 547 |
+
MutexLock(const MutexLock &) = delete; // NOLINT(runtime/mutex)
|
| 548 |
+
MutexLock(MutexLock&&) = delete; // NOLINT(runtime/mutex)
|
| 549 |
+
MutexLock& operator=(const MutexLock&) = delete;
|
| 550 |
+
MutexLock& operator=(MutexLock&&) = delete;
|
| 551 |
+
|
| 552 |
+
~MutexLock() ABSL_UNLOCK_FUNCTION() { this->mu_->Unlock(); }
|
| 553 |
+
|
| 554 |
+
private:
|
| 555 |
+
Mutex *const mu_;
|
| 556 |
+
};
|
| 557 |
+
|
| 558 |
+
// ReaderMutexLock
|
| 559 |
+
//
|
| 560 |
+
// The `ReaderMutexLock` is a helper class, like `MutexLock`, which acquires and
|
| 561 |
+
// releases a shared lock on a `Mutex` via RAII.
|
| 562 |
+
class ABSL_SCOPED_LOCKABLE ReaderMutexLock {
|
| 563 |
+
public:
|
| 564 |
+
explicit ReaderMutexLock(Mutex *mu) ABSL_SHARED_LOCK_FUNCTION(mu) : mu_(mu) {
|
| 565 |
+
mu->ReaderLock();
|
| 566 |
+
}
|
| 567 |
+
|
| 568 |
+
explicit ReaderMutexLock(Mutex *mu, const Condition &cond)
|
| 569 |
+
ABSL_SHARED_LOCK_FUNCTION(mu)
|
| 570 |
+
: mu_(mu) {
|
| 571 |
+
mu->ReaderLockWhen(cond);
|
| 572 |
+
}
|
| 573 |
+
|
| 574 |
+
ReaderMutexLock(const ReaderMutexLock&) = delete;
|
| 575 |
+
ReaderMutexLock(ReaderMutexLock&&) = delete;
|
| 576 |
+
ReaderMutexLock& operator=(const ReaderMutexLock&) = delete;
|
| 577 |
+
ReaderMutexLock& operator=(ReaderMutexLock&&) = delete;
|
| 578 |
+
|
| 579 |
+
~ReaderMutexLock() ABSL_UNLOCK_FUNCTION() { this->mu_->ReaderUnlock(); }
|
| 580 |
+
|
| 581 |
+
private:
|
| 582 |
+
Mutex *const mu_;
|
| 583 |
+
};
|
| 584 |
+
|
| 585 |
+
// WriterMutexLock
|
| 586 |
+
//
|
| 587 |
+
// The `WriterMutexLock` is a helper class, like `MutexLock`, which acquires and
|
| 588 |
+
// releases a write (exclusive) lock on a `Mutex` via RAII.
|
| 589 |
+
class ABSL_SCOPED_LOCKABLE WriterMutexLock {
|
| 590 |
+
public:
|
| 591 |
+
explicit WriterMutexLock(Mutex *mu) ABSL_EXCLUSIVE_LOCK_FUNCTION(mu)
|
| 592 |
+
: mu_(mu) {
|
| 593 |
+
mu->WriterLock();
|
| 594 |
+
}
|
| 595 |
+
|
| 596 |
+
explicit WriterMutexLock(Mutex *mu, const Condition &cond)
|
| 597 |
+
ABSL_EXCLUSIVE_LOCK_FUNCTION(mu)
|
| 598 |
+
: mu_(mu) {
|
| 599 |
+
mu->WriterLockWhen(cond);
|
| 600 |
+
}
|
| 601 |
+
|
| 602 |
+
WriterMutexLock(const WriterMutexLock&) = delete;
|
| 603 |
+
WriterMutexLock(WriterMutexLock&&) = delete;
|
| 604 |
+
WriterMutexLock& operator=(const WriterMutexLock&) = delete;
|
| 605 |
+
WriterMutexLock& operator=(WriterMutexLock&&) = delete;
|
| 606 |
+
|
| 607 |
+
~WriterMutexLock() ABSL_UNLOCK_FUNCTION() { this->mu_->WriterUnlock(); }
|
| 608 |
+
|
| 609 |
+
private:
|
| 610 |
+
Mutex *const mu_;
|
| 611 |
+
};
|
| 612 |
+
|
| 613 |
+
// -----------------------------------------------------------------------------
|
| 614 |
+
// Condition
|
| 615 |
+
// -----------------------------------------------------------------------------
|
| 616 |
+
//
|
| 617 |
+
// `Mutex` contains a number of member functions which take a `Condition` as an
|
| 618 |
+
// argument; clients can wait for conditions to become `true` before attempting
|
| 619 |
+
// to acquire the mutex. These sections are known as "condition critical"
|
| 620 |
+
// sections. To use a `Condition`, you simply need to construct it, and use
|
| 621 |
+
// within an appropriate `Mutex` member function; everything else in the
|
| 622 |
+
// `Condition` class is an implementation detail.
|
| 623 |
+
//
|
| 624 |
+
// A `Condition` is specified as a function pointer which returns a boolean.
|
| 625 |
+
// `Condition` functions should be pure functions -- their results should depend
|
| 626 |
+
// only on passed arguments, should not consult any external state (such as
|
| 627 |
+
// clocks), and should have no side-effects, aside from debug logging. Any
|
| 628 |
+
// objects that the function may access should be limited to those which are
|
| 629 |
+
// constant while the mutex is blocked on the condition (e.g. a stack variable),
|
| 630 |
+
// or objects of state protected explicitly by the mutex.
|
| 631 |
+
//
|
| 632 |
+
// No matter which construction is used for `Condition`, the underlying
|
| 633 |
+
// function pointer / functor / callable must not throw any
|
| 634 |
+
// exceptions. Correctness of `Mutex` / `Condition` is not guaranteed in
|
| 635 |
+
// the face of a throwing `Condition`. (When Abseil is allowed to depend
|
| 636 |
+
// on C++17, these function pointers will be explicitly marked
|
| 637 |
+
// `noexcept`; until then this requirement cannot be enforced in the
|
| 638 |
+
// type system.)
|
| 639 |
+
//
|
| 640 |
+
// Note: to use a `Condition`, you need only construct it and pass it to a
|
| 641 |
+
// suitable `Mutex' member function, such as `Mutex::Await()`, or to the
|
| 642 |
+
// constructor of one of the scope guard classes.
|
| 643 |
+
//
|
| 644 |
+
// Example using LockWhen/Unlock:
|
| 645 |
+
//
|
| 646 |
+
// // assume count_ is not internal reference count
|
| 647 |
+
// int count_ ABSL_GUARDED_BY(mu_);
|
| 648 |
+
// Condition count_is_zero(+[](int *count) { return *count == 0; }, &count_);
|
| 649 |
+
//
|
| 650 |
+
// mu_.LockWhen(count_is_zero);
|
| 651 |
+
// // ...
|
| 652 |
+
// mu_.Unlock();
|
| 653 |
+
//
|
| 654 |
+
// Example using a scope guard:
|
| 655 |
+
//
|
| 656 |
+
// {
|
| 657 |
+
// MutexLock lock(&mu_, count_is_zero);
|
| 658 |
+
// // ...
|
| 659 |
+
// }
|
| 660 |
+
//
|
| 661 |
+
// When multiple threads are waiting on exactly the same condition, make sure
|
| 662 |
+
// that they are constructed with the same parameters (same pointer to function
|
| 663 |
+
// + arg, or same pointer to object + method), so that the mutex implementation
|
| 664 |
+
// can avoid redundantly evaluating the same condition for each thread.
|
| 665 |
+
class Condition {
|
| 666 |
+
public:
|
| 667 |
+
// A Condition that returns the result of "(*func)(arg)"
|
| 668 |
+
Condition(bool (*func)(void *), void *arg);
|
| 669 |
+
|
| 670 |
+
// Templated version for people who are averse to casts.
|
| 671 |
+
//
|
| 672 |
+
// To use a lambda, prepend it with unary plus, which converts the lambda
|
| 673 |
+
// into a function pointer:
|
| 674 |
+
// Condition(+[](T* t) { return ...; }, arg).
|
| 675 |
+
//
|
| 676 |
+
// Note: lambdas in this case must contain no bound variables.
|
| 677 |
+
//
|
| 678 |
+
// See class comment for performance advice.
|
| 679 |
+
template<typename T>
|
| 680 |
+
Condition(bool (*func)(T *), T *arg);
|
| 681 |
+
|
| 682 |
+
// Templated version for invoking a method that returns a `bool`.
|
| 683 |
+
//
|
| 684 |
+
// `Condition(object, &Class::Method)` constructs a `Condition` that evaluates
|
| 685 |
+
// `object->Method()`.
|
| 686 |
+
//
|
| 687 |
+
// Implementation Note: `absl::internal::identity` is used to allow methods to
|
| 688 |
+
// come from base classes. A simpler signature like
|
| 689 |
+
// `Condition(T*, bool (T::*)())` does not suffice.
|
| 690 |
+
template<typename T>
|
| 691 |
+
Condition(T *object, bool (absl::internal::identity<T>::type::* method)());
|
| 692 |
+
|
| 693 |
+
// Same as above, for const members
|
| 694 |
+
template<typename T>
|
| 695 |
+
Condition(const T *object,
|
| 696 |
+
bool (absl::internal::identity<T>::type::* method)() const);
|
| 697 |
+
|
| 698 |
+
// A Condition that returns the value of `*cond`
|
| 699 |
+
explicit Condition(const bool *cond);
|
| 700 |
+
|
| 701 |
+
// Templated version for invoking a functor that returns a `bool`.
|
| 702 |
+
// This approach accepts pointers to non-mutable lambdas, `std::function`,
|
| 703 |
+
// the result of` std::bind` and user-defined functors that define
|
| 704 |
+
// `bool F::operator()() const`.
|
| 705 |
+
//
|
| 706 |
+
// Example:
|
| 707 |
+
//
|
| 708 |
+
// auto reached = [this, current]() {
|
| 709 |
+
// mu_.AssertReaderHeld(); // For annotalysis.
|
| 710 |
+
// return processed_ >= current;
|
| 711 |
+
// };
|
| 712 |
+
// mu_.Await(Condition(&reached));
|
| 713 |
+
//
|
| 714 |
+
// NOTE: never use "mu_.AssertHeld()" instead of "mu_.AssertReaderHeld()" in
|
| 715 |
+
// the lambda as it may be called when the mutex is being unlocked from a
|
| 716 |
+
// scope holding only a reader lock, which will make the assertion not
|
| 717 |
+
// fulfilled and crash the binary.
|
| 718 |
+
|
| 719 |
+
// See class comment for performance advice. In particular, if there
|
| 720 |
+
// might be more than one waiter for the same condition, make sure
|
| 721 |
+
// that all waiters construct the condition with the same pointers.
|
| 722 |
+
|
| 723 |
+
// Implementation note: The second template parameter ensures that this
|
| 724 |
+
// constructor doesn't participate in overload resolution if T doesn't have
|
| 725 |
+
// `bool operator() const`.
|
| 726 |
+
template <typename T, typename E = decltype(
|
| 727 |
+
static_cast<bool (T::*)() const>(&T::operator()))>
|
| 728 |
+
explicit Condition(const T *obj)
|
| 729 |
+
: Condition(obj, static_cast<bool (T::*)() const>(&T::operator())) {}
|
| 730 |
+
|
| 731 |
+
// A Condition that always returns `true`.
|
| 732 |
+
ABSL_CONST_INIT static const Condition kTrue;
|
| 733 |
+
|
| 734 |
+
// Evaluates the condition.
|
| 735 |
+
bool Eval() const;
|
| 736 |
+
|
| 737 |
+
// Returns `true` if the two conditions are guaranteed to return the same
|
| 738 |
+
// value if evaluated at the same time, `false` if the evaluation *may* return
|
| 739 |
+
// different results.
|
| 740 |
+
//
|
| 741 |
+
// Two `Condition` values are guaranteed equal if both their `func` and `arg`
|
| 742 |
+
// components are the same. A null pointer is equivalent to a `true`
|
| 743 |
+
// condition.
|
| 744 |
+
static bool GuaranteedEqual(const Condition *a, const Condition *b);
|
| 745 |
+
|
| 746 |
+
private:
|
| 747 |
+
// Sizing an allocation for a method pointer can be subtle. In the Itanium
|
| 748 |
+
// specifications, a method pointer has a predictable, uniform size. On the
|
| 749 |
+
// other hand, MSVC ABI, method pointer sizes vary based on the
|
| 750 |
+
// inheritance of the class. Specifically, method pointers from classes with
|
| 751 |
+
// multiple inheritance are bigger than those of classes with single
|
| 752 |
+
// inheritance. Other variations also exist.
|
| 753 |
+
|
| 754 |
+
#ifndef _MSC_VER
|
| 755 |
+
// Allocation for a function pointer or method pointer.
|
| 756 |
+
// The {0} initializer ensures that all unused bytes of this buffer are
|
| 757 |
+
// always zeroed out. This is necessary, because GuaranteedEqual() compares
|
| 758 |
+
// all of the bytes, unaware of which bytes are relevant to a given `eval_`.
|
| 759 |
+
using MethodPtr = bool (Condition::*)();
|
| 760 |
+
char callback_[sizeof(MethodPtr)] = {0};
|
| 761 |
+
#else
|
| 762 |
+
// It is well known that the larget MSVC pointer-to-member is 24 bytes. This
|
| 763 |
+
// may be the largest known pointer-to-member of any platform. For this
|
| 764 |
+
// reason we will allocate 24 bytes for MSVC platform toolchains.
|
| 765 |
+
char callback_[24] = {0};
|
| 766 |
+
#endif
|
| 767 |
+
|
| 768 |
+
// Function with which to evaluate callbacks and/or arguments.
|
| 769 |
+
bool (*eval_)(const Condition*) = nullptr;
|
| 770 |
+
|
| 771 |
+
// Either an argument for a function call or an object for a method call.
|
| 772 |
+
void *arg_ = nullptr;
|
| 773 |
+
|
| 774 |
+
// Various functions eval_ can point to:
|
| 775 |
+
static bool CallVoidPtrFunction(const Condition*);
|
| 776 |
+
template <typename T> static bool CastAndCallFunction(const Condition* c);
|
| 777 |
+
template <typename T> static bool CastAndCallMethod(const Condition* c);
|
| 778 |
+
|
| 779 |
+
// Helper methods for storing, validating, and reading callback arguments.
|
| 780 |
+
template <typename T>
|
| 781 |
+
inline void StoreCallback(T callback) {
|
| 782 |
+
static_assert(
|
| 783 |
+
sizeof(callback) <= sizeof(callback_),
|
| 784 |
+
"An overlarge pointer was passed as a callback to Condition.");
|
| 785 |
+
std::memcpy(callback_, &callback, sizeof(callback));
|
| 786 |
+
}
|
| 787 |
+
|
| 788 |
+
template <typename T>
|
| 789 |
+
inline void ReadCallback(T *callback) const {
|
| 790 |
+
std::memcpy(callback, callback_, sizeof(*callback));
|
| 791 |
+
}
|
| 792 |
+
|
| 793 |
+
// Used only to create kTrue.
|
| 794 |
+
constexpr Condition() = default;
|
| 795 |
+
};
|
| 796 |
+
|
| 797 |
+
// -----------------------------------------------------------------------------
|
| 798 |
+
// CondVar
|
| 799 |
+
// -----------------------------------------------------------------------------
|
| 800 |
+
//
|
| 801 |
+
// A condition variable, reflecting state evaluated separately outside of the
|
| 802 |
+
// `Mutex` object, which can be signaled to wake callers.
|
| 803 |
+
// This class is not normally needed; use `Mutex` member functions such as
|
| 804 |
+
// `Mutex::Await()` and intrinsic `Condition` abstractions. In rare cases
|
| 805 |
+
// with many threads and many conditions, `CondVar` may be faster.
|
| 806 |
+
//
|
| 807 |
+
// The implementation may deliver signals to any condition variable at
|
| 808 |
+
// any time, even when no call to `Signal()` or `SignalAll()` is made; as a
|
| 809 |
+
// result, upon being awoken, you must check the logical condition you have
|
| 810 |
+
// been waiting upon.
|
| 811 |
+
//
|
| 812 |
+
// Examples:
|
| 813 |
+
//
|
| 814 |
+
// Usage for a thread waiting for some condition C protected by mutex mu:
|
| 815 |
+
// mu.Lock();
|
| 816 |
+
// while (!C) { cv->Wait(&mu); } // releases and reacquires mu
|
| 817 |
+
// // C holds; process data
|
| 818 |
+
// mu.Unlock();
|
| 819 |
+
//
|
| 820 |
+
// Usage to wake T is:
|
| 821 |
+
// mu.Lock();
|
| 822 |
+
// // process data, possibly establishing C
|
| 823 |
+
// if (C) { cv->Signal(); }
|
| 824 |
+
// mu.Unlock();
|
| 825 |
+
//
|
| 826 |
+
// If C may be useful to more than one waiter, use `SignalAll()` instead of
|
| 827 |
+
// `Signal()`.
|
| 828 |
+
//
|
| 829 |
+
// With this implementation it is efficient to use `Signal()/SignalAll()` inside
|
| 830 |
+
// the locked region; this usage can make reasoning about your program easier.
|
| 831 |
+
//
|
| 832 |
+
class CondVar {
|
| 833 |
+
public:
|
| 834 |
+
// A `CondVar` allocated on the heap or on the stack can use the this
|
| 835 |
+
// constructor.
|
| 836 |
+
CondVar();
|
| 837 |
+
~CondVar();
|
| 838 |
+
|
| 839 |
+
// CondVar::Wait()
|
| 840 |
+
//
|
| 841 |
+
// Atomically releases a `Mutex` and blocks on this condition variable.
|
| 842 |
+
// Waits until awakened by a call to `Signal()` or `SignalAll()` (or a
|
| 843 |
+
// spurious wakeup), then reacquires the `Mutex` and returns.
|
| 844 |
+
//
|
| 845 |
+
// Requires and ensures that the current thread holds the `Mutex`.
|
| 846 |
+
void Wait(Mutex *mu);
|
| 847 |
+
|
| 848 |
+
// CondVar::WaitWithTimeout()
|
| 849 |
+
//
|
| 850 |
+
// Atomically releases a `Mutex` and blocks on this condition variable.
|
| 851 |
+
// Waits until awakened by a call to `Signal()` or `SignalAll()` (or a
|
| 852 |
+
// spurious wakeup), or until the timeout has expired, then reacquires
|
| 853 |
+
// the `Mutex` and returns.
|
| 854 |
+
//
|
| 855 |
+
// Returns true if the timeout has expired without this `CondVar`
|
| 856 |
+
// being signalled in any manner. If both the timeout has expired
|
| 857 |
+
// and this `CondVar` has been signalled, the implementation is free
|
| 858 |
+
// to return `true` or `false`.
|
| 859 |
+
//
|
| 860 |
+
// Requires and ensures that the current thread holds the `Mutex`.
|
| 861 |
+
bool WaitWithTimeout(Mutex *mu, absl::Duration timeout);
|
| 862 |
+
|
| 863 |
+
// CondVar::WaitWithDeadline()
|
| 864 |
+
//
|
| 865 |
+
// Atomically releases a `Mutex` and blocks on this condition variable.
|
| 866 |
+
// Waits until awakened by a call to `Signal()` or `SignalAll()` (or a
|
| 867 |
+
// spurious wakeup), or until the deadline has passed, then reacquires
|
| 868 |
+
// the `Mutex` and returns.
|
| 869 |
+
//
|
| 870 |
+
// Deadlines in the past are equivalent to an immediate deadline.
|
| 871 |
+
//
|
| 872 |
+
// Returns true if the deadline has passed without this `CondVar`
|
| 873 |
+
// being signalled in any manner. If both the deadline has passed
|
| 874 |
+
// and this `CondVar` has been signalled, the implementation is free
|
| 875 |
+
// to return `true` or `false`.
|
| 876 |
+
//
|
| 877 |
+
// Requires and ensures that the current thread holds the `Mutex`.
|
| 878 |
+
bool WaitWithDeadline(Mutex *mu, absl::Time deadline);
|
| 879 |
+
|
| 880 |
+
// CondVar::Signal()
|
| 881 |
+
//
|
| 882 |
+
// Signal this `CondVar`; wake at least one waiter if one exists.
|
| 883 |
+
void Signal();
|
| 884 |
+
|
| 885 |
+
// CondVar::SignalAll()
|
| 886 |
+
//
|
| 887 |
+
// Signal this `CondVar`; wake all waiters.
|
| 888 |
+
void SignalAll();
|
| 889 |
+
|
| 890 |
+
// CondVar::EnableDebugLog()
|
| 891 |
+
//
|
| 892 |
+
// Causes all subsequent uses of this `CondVar` to be logged via
|
| 893 |
+
// `ABSL_RAW_LOG(INFO)`. Log entries are tagged with `name` if `name != 0`.
|
| 894 |
+
// Note: this method substantially reduces `CondVar` performance.
|
| 895 |
+
void EnableDebugLog(const char *name);
|
| 896 |
+
|
| 897 |
+
private:
|
| 898 |
+
bool WaitCommon(Mutex *mutex, synchronization_internal::KernelTimeout t);
|
| 899 |
+
void Remove(base_internal::PerThreadSynch *s);
|
| 900 |
+
void Wakeup(base_internal::PerThreadSynch *w);
|
| 901 |
+
std::atomic<intptr_t> cv_; // Condition variable state.
|
| 902 |
+
CondVar(const CondVar&) = delete;
|
| 903 |
+
CondVar& operator=(const CondVar&) = delete;
|
| 904 |
+
};
|
| 905 |
+
|
| 906 |
+
|
| 907 |
+
// Variants of MutexLock.
|
| 908 |
+
//
|
| 909 |
+
// If you find yourself using one of these, consider instead using
|
| 910 |
+
// Mutex::Unlock() and/or if-statements for clarity.
|
| 911 |
+
|
| 912 |
+
// MutexLockMaybe
|
| 913 |
+
//
|
| 914 |
+
// MutexLockMaybe is like MutexLock, but is a no-op when mu is null.
|
| 915 |
+
class ABSL_SCOPED_LOCKABLE MutexLockMaybe {
|
| 916 |
+
public:
|
| 917 |
+
explicit MutexLockMaybe(Mutex *mu) ABSL_EXCLUSIVE_LOCK_FUNCTION(mu)
|
| 918 |
+
: mu_(mu) {
|
| 919 |
+
if (this->mu_ != nullptr) {
|
| 920 |
+
this->mu_->Lock();
|
| 921 |
+
}
|
| 922 |
+
}
|
| 923 |
+
|
| 924 |
+
explicit MutexLockMaybe(Mutex *mu, const Condition &cond)
|
| 925 |
+
ABSL_EXCLUSIVE_LOCK_FUNCTION(mu)
|
| 926 |
+
: mu_(mu) {
|
| 927 |
+
if (this->mu_ != nullptr) {
|
| 928 |
+
this->mu_->LockWhen(cond);
|
| 929 |
+
}
|
| 930 |
+
}
|
| 931 |
+
|
| 932 |
+
~MutexLockMaybe() ABSL_UNLOCK_FUNCTION() {
|
| 933 |
+
if (this->mu_ != nullptr) { this->mu_->Unlock(); }
|
| 934 |
+
}
|
| 935 |
+
|
| 936 |
+
private:
|
| 937 |
+
Mutex *const mu_;
|
| 938 |
+
MutexLockMaybe(const MutexLockMaybe&) = delete;
|
| 939 |
+
MutexLockMaybe(MutexLockMaybe&&) = delete;
|
| 940 |
+
MutexLockMaybe& operator=(const MutexLockMaybe&) = delete;
|
| 941 |
+
MutexLockMaybe& operator=(MutexLockMaybe&&) = delete;
|
| 942 |
+
};
|
| 943 |
+
|
| 944 |
+
// ReleasableMutexLock
|
| 945 |
+
//
|
| 946 |
+
// ReleasableMutexLock is like MutexLock, but permits `Release()` of its
|
| 947 |
+
// mutex before destruction. `Release()` may be called at most once.
|
| 948 |
+
class ABSL_SCOPED_LOCKABLE ReleasableMutexLock {
|
| 949 |
+
public:
|
| 950 |
+
explicit ReleasableMutexLock(Mutex *mu) ABSL_EXCLUSIVE_LOCK_FUNCTION(mu)
|
| 951 |
+
: mu_(mu) {
|
| 952 |
+
this->mu_->Lock();
|
| 953 |
+
}
|
| 954 |
+
|
| 955 |
+
explicit ReleasableMutexLock(Mutex *mu, const Condition &cond)
|
| 956 |
+
ABSL_EXCLUSIVE_LOCK_FUNCTION(mu)
|
| 957 |
+
: mu_(mu) {
|
| 958 |
+
this->mu_->LockWhen(cond);
|
| 959 |
+
}
|
| 960 |
+
|
| 961 |
+
~ReleasableMutexLock() ABSL_UNLOCK_FUNCTION() {
|
| 962 |
+
if (this->mu_ != nullptr) { this->mu_->Unlock(); }
|
| 963 |
+
}
|
| 964 |
+
|
| 965 |
+
void Release() ABSL_UNLOCK_FUNCTION();
|
| 966 |
+
|
| 967 |
+
private:
|
| 968 |
+
Mutex *mu_;
|
| 969 |
+
ReleasableMutexLock(const ReleasableMutexLock&) = delete;
|
| 970 |
+
ReleasableMutexLock(ReleasableMutexLock&&) = delete;
|
| 971 |
+
ReleasableMutexLock& operator=(const ReleasableMutexLock&) = delete;
|
| 972 |
+
ReleasableMutexLock& operator=(ReleasableMutexLock&&) = delete;
|
| 973 |
+
};
|
| 974 |
+
|
| 975 |
+
inline Mutex::Mutex() : mu_(0) {
|
| 976 |
+
ABSL_TSAN_MUTEX_CREATE(this, __tsan_mutex_not_static);
|
| 977 |
+
}
|
| 978 |
+
|
| 979 |
+
inline constexpr Mutex::Mutex(absl::ConstInitType) : mu_(0) {}
|
| 980 |
+
|
| 981 |
+
inline CondVar::CondVar() : cv_(0) {}
|
| 982 |
+
|
| 983 |
+
// static
|
| 984 |
+
template <typename T>
|
| 985 |
+
bool Condition::CastAndCallMethod(const Condition *c) {
|
| 986 |
+
T *object = static_cast<T *>(c->arg_);
|
| 987 |
+
bool (T::*method_pointer)();
|
| 988 |
+
c->ReadCallback(&method_pointer);
|
| 989 |
+
return (object->*method_pointer)();
|
| 990 |
+
}
|
| 991 |
+
|
| 992 |
+
// static
|
| 993 |
+
template <typename T>
|
| 994 |
+
bool Condition::CastAndCallFunction(const Condition *c) {
|
| 995 |
+
bool (*function)(T *);
|
| 996 |
+
c->ReadCallback(&function);
|
| 997 |
+
T *argument = static_cast<T *>(c->arg_);
|
| 998 |
+
return (*function)(argument);
|
| 999 |
+
}
|
| 1000 |
+
|
| 1001 |
+
template <typename T>
|
| 1002 |
+
inline Condition::Condition(bool (*func)(T *), T *arg)
|
| 1003 |
+
: eval_(&CastAndCallFunction<T>),
|
| 1004 |
+
arg_(const_cast<void *>(static_cast<const void *>(arg))) {
|
| 1005 |
+
static_assert(sizeof(&func) <= sizeof(callback_),
|
| 1006 |
+
"An overlarge function pointer was passed to Condition.");
|
| 1007 |
+
StoreCallback(func);
|
| 1008 |
+
}
|
| 1009 |
+
|
| 1010 |
+
template <typename T>
|
| 1011 |
+
inline Condition::Condition(T *object,
|
| 1012 |
+
bool (absl::internal::identity<T>::type::*method)())
|
| 1013 |
+
: eval_(&CastAndCallMethod<T>),
|
| 1014 |
+
arg_(object) {
|
| 1015 |
+
static_assert(sizeof(&method) <= sizeof(callback_),
|
| 1016 |
+
"An overlarge method pointer was passed to Condition.");
|
| 1017 |
+
StoreCallback(method);
|
| 1018 |
+
}
|
| 1019 |
+
|
| 1020 |
+
template <typename T>
|
| 1021 |
+
inline Condition::Condition(const T *object,
|
| 1022 |
+
bool (absl::internal::identity<T>::type::*method)()
|
| 1023 |
+
const)
|
| 1024 |
+
: eval_(&CastAndCallMethod<T>),
|
| 1025 |
+
arg_(reinterpret_cast<void *>(const_cast<T *>(object))) {
|
| 1026 |
+
StoreCallback(method);
|
| 1027 |
+
}
|
| 1028 |
+
|
| 1029 |
+
// Register hooks for profiling support.
|
| 1030 |
+
//
|
| 1031 |
+
// The function pointer registered here will be called whenever a mutex is
|
| 1032 |
+
// contended. The callback is given the cycles for which waiting happened (as
|
| 1033 |
+
// measured by //absl/base/internal/cycleclock.h, and which may not
|
| 1034 |
+
// be real "cycle" counts.)
|
| 1035 |
+
//
|
| 1036 |
+
// There is no ordering guarantee between when the hook is registered and when
|
| 1037 |
+
// callbacks will begin. Only a single profiler can be installed in a running
|
| 1038 |
+
// binary; if this function is called a second time with a different function
|
| 1039 |
+
// pointer, the value is ignored (and will cause an assertion failure in debug
|
| 1040 |
+
// mode.)
|
| 1041 |
+
void RegisterMutexProfiler(void (*fn)(int64_t wait_cycles));
|
| 1042 |
+
|
| 1043 |
+
// Register a hook for Mutex tracing.
|
| 1044 |
+
//
|
| 1045 |
+
// The function pointer registered here will be called whenever a mutex is
|
| 1046 |
+
// contended. The callback is given an opaque handle to the contended mutex,
|
| 1047 |
+
// an event name, and the number of wait cycles (as measured by
|
| 1048 |
+
// //absl/base/internal/cycleclock.h, and which may not be real
|
| 1049 |
+
// "cycle" counts.)
|
| 1050 |
+
//
|
| 1051 |
+
// The only event name currently sent is "slow release".
|
| 1052 |
+
//
|
| 1053 |
+
// This has the same ordering and single-use limitations as
|
| 1054 |
+
// RegisterMutexProfiler() above.
|
| 1055 |
+
void RegisterMutexTracer(void (*fn)(const char *msg, const void *obj,
|
| 1056 |
+
int64_t wait_cycles));
|
| 1057 |
+
|
| 1058 |
+
// Register a hook for CondVar tracing.
|
| 1059 |
+
//
|
| 1060 |
+
// The function pointer registered here will be called here on various CondVar
|
| 1061 |
+
// events. The callback is given an opaque handle to the CondVar object and
|
| 1062 |
+
// a string identifying the event. This is thread-safe, but only a single
|
| 1063 |
+
// tracer can be registered.
|
| 1064 |
+
//
|
| 1065 |
+
// Events that can be sent are "Wait", "Unwait", "Signal wakeup", and
|
| 1066 |
+
// "SignalAll wakeup".
|
| 1067 |
+
//
|
| 1068 |
+
// This has the same ordering and single-use limitations as
|
| 1069 |
+
// RegisterMutexProfiler() above.
|
| 1070 |
+
void RegisterCondVarTracer(void (*fn)(const char *msg, const void *cv));
|
| 1071 |
+
|
| 1072 |
+
// Register a hook for symbolizing stack traces in deadlock detector reports.
|
| 1073 |
+
//
|
| 1074 |
+
// 'pc' is the program counter being symbolized, 'out' is the buffer to write
|
| 1075 |
+
// into, and 'out_size' is the size of the buffer. This function can return
|
| 1076 |
+
// false if symbolizing failed, or true if a NUL-terminated symbol was written
|
| 1077 |
+
// to 'out.'
|
| 1078 |
+
//
|
| 1079 |
+
// This has the same ordering and single-use limitations as
|
| 1080 |
+
// RegisterMutexProfiler() above.
|
| 1081 |
+
//
|
| 1082 |
+
// DEPRECATED: The default symbolizer function is absl::Symbolize() and the
|
| 1083 |
+
// ability to register a different hook for symbolizing stack traces will be
|
| 1084 |
+
// removed on or after 2023-05-01.
|
| 1085 |
+
ABSL_DEPRECATED("absl::RegisterSymbolizer() is deprecated and will be removed "
|
| 1086 |
+
"on or after 2023-05-01")
|
| 1087 |
+
void RegisterSymbolizer(bool (*fn)(const void *pc, char *out, int out_size));
|
| 1088 |
+
|
| 1089 |
+
// EnableMutexInvariantDebugging()
|
| 1090 |
+
//
|
| 1091 |
+
// Enable or disable global support for Mutex invariant debugging. If enabled,
|
| 1092 |
+
// then invariant predicates can be registered per-Mutex for debug checking.
|
| 1093 |
+
// See Mutex::EnableInvariantDebugging().
|
| 1094 |
+
void EnableMutexInvariantDebugging(bool enabled);
|
| 1095 |
+
|
| 1096 |
+
// When in debug mode, and when the feature has been enabled globally, the
|
| 1097 |
+
// implementation will keep track of lock ordering and complain (or optionally
|
| 1098 |
+
// crash) if a cycle is detected in the acquired-before graph.
|
| 1099 |
+
|
| 1100 |
+
// Possible modes of operation for the deadlock detector in debug mode.
|
| 1101 |
+
enum class OnDeadlockCycle {
|
| 1102 |
+
kIgnore, // Neither report on nor attempt to track cycles in lock ordering
|
| 1103 |
+
kReport, // Report lock cycles to stderr when detected
|
| 1104 |
+
kAbort, // Report lock cycles to stderr when detected, then abort
|
| 1105 |
+
};
|
| 1106 |
+
|
| 1107 |
+
// SetMutexDeadlockDetectionMode()
|
| 1108 |
+
//
|
| 1109 |
+
// Enable or disable global support for detection of potential deadlocks
|
| 1110 |
+
// due to Mutex lock ordering inversions. When set to 'kIgnore', tracking of
|
| 1111 |
+
// lock ordering is disabled. Otherwise, in debug builds, a lock ordering graph
|
| 1112 |
+
// will be maintained internally, and detected cycles will be reported in
|
| 1113 |
+
// the manner chosen here.
|
| 1114 |
+
void SetMutexDeadlockDetectionMode(OnDeadlockCycle mode);
|
| 1115 |
+
|
| 1116 |
+
ABSL_NAMESPACE_END
|
| 1117 |
+
} // namespace absl
|
| 1118 |
+
|
| 1119 |
+
// In some build configurations we pass --detect-odr-violations to the
|
| 1120 |
+
// gold linker. This causes it to flag weak symbol overrides as ODR
|
| 1121 |
+
// violations. Because ODR only applies to C++ and not C,
|
| 1122 |
+
// --detect-odr-violations ignores symbols not mangled with C++ names.
|
| 1123 |
+
// By changing our extension points to be extern "C", we dodge this
|
| 1124 |
+
// check.
|
| 1125 |
+
extern "C" {
|
| 1126 |
+
void ABSL_INTERNAL_C_SYMBOL(AbslInternalMutexYield)();
|
| 1127 |
+
} // extern "C"
|
| 1128 |
+
|
| 1129 |
+
#endif // ABSL_SYNCHRONIZATION_MUTEX_H_
|
miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/absl/synchronization/notification.h
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2017 The Abseil Authors.
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// https://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
//
|
| 15 |
+
// -----------------------------------------------------------------------------
|
| 16 |
+
// notification.h
|
| 17 |
+
// -----------------------------------------------------------------------------
|
| 18 |
+
//
|
| 19 |
+
// This header file defines a `Notification` abstraction, which allows threads
|
| 20 |
+
// to receive notification of a single occurrence of a single event.
|
| 21 |
+
//
|
| 22 |
+
// The `Notification` object maintains a private boolean "notified" state that
|
| 23 |
+
// transitions to `true` at most once. The `Notification` class provides the
|
| 24 |
+
// following primary member functions:
|
| 25 |
+
// * `HasBeenNotified()` to query its state
|
| 26 |
+
// * `WaitForNotification*()` to have threads wait until the "notified" state
|
| 27 |
+
// is `true`.
|
| 28 |
+
// * `Notify()` to set the notification's "notified" state to `true` and
|
| 29 |
+
// notify all waiting threads that the event has occurred.
|
| 30 |
+
// This method may only be called once.
|
| 31 |
+
//
|
| 32 |
+
// Note that while `Notify()` may only be called once, it is perfectly valid to
|
| 33 |
+
// call any of the `WaitForNotification*()` methods multiple times, from
|
| 34 |
+
// multiple threads -- even after the notification's "notified" state has been
|
| 35 |
+
// set -- in which case those methods will immediately return.
|
| 36 |
+
//
|
| 37 |
+
// Note that the lifetime of a `Notification` requires careful consideration;
|
| 38 |
+
// it might not be safe to destroy a notification after calling `Notify()` since
|
| 39 |
+
// it is still legal for other threads to call `WaitForNotification*()` methods
|
| 40 |
+
// on the notification. However, observers responding to a "notified" state of
|
| 41 |
+
// `true` can safely delete the notification without interfering with the call
|
| 42 |
+
// to `Notify()` in the other thread.
|
| 43 |
+
//
|
| 44 |
+
// Memory ordering: For any threads X and Y, if X calls `Notify()`, then any
|
| 45 |
+
// action taken by X before it calls `Notify()` is visible to thread Y after:
|
| 46 |
+
// * Y returns from `WaitForNotification()`, or
|
| 47 |
+
// * Y receives a `true` return value from either `HasBeenNotified()` or
|
| 48 |
+
// `WaitForNotificationWithTimeout()`.
|
| 49 |
+
|
| 50 |
+
#ifndef ABSL_SYNCHRONIZATION_NOTIFICATION_H_
|
| 51 |
+
#define ABSL_SYNCHRONIZATION_NOTIFICATION_H_
|
| 52 |
+
|
| 53 |
+
#include <atomic>
|
| 54 |
+
|
| 55 |
+
#include "absl/base/attributes.h"
|
| 56 |
+
#include "absl/synchronization/mutex.h"
|
| 57 |
+
#include "absl/time/time.h"
|
| 58 |
+
|
| 59 |
+
namespace absl {
|
| 60 |
+
ABSL_NAMESPACE_BEGIN
|
| 61 |
+
|
| 62 |
+
// -----------------------------------------------------------------------------
|
| 63 |
+
// Notification
|
| 64 |
+
// -----------------------------------------------------------------------------
|
| 65 |
+
class Notification {
|
| 66 |
+
public:
|
| 67 |
+
// Initializes the "notified" state to unnotified.
|
| 68 |
+
Notification() : notified_yet_(false) {}
|
| 69 |
+
explicit Notification(bool prenotify) : notified_yet_(prenotify) {}
|
| 70 |
+
Notification(const Notification&) = delete;
|
| 71 |
+
Notification& operator=(const Notification&) = delete;
|
| 72 |
+
~Notification();
|
| 73 |
+
|
| 74 |
+
// Notification::HasBeenNotified()
|
| 75 |
+
//
|
| 76 |
+
// Returns the value of the notification's internal "notified" state.
|
| 77 |
+
ABSL_MUST_USE_RESULT bool HasBeenNotified() const {
|
| 78 |
+
return HasBeenNotifiedInternal(&this->notified_yet_);
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
// Notification::WaitForNotification()
|
| 82 |
+
//
|
| 83 |
+
// Blocks the calling thread until the notification's "notified" state is
|
| 84 |
+
// `true`. Note that if `Notify()` has been previously called on this
|
| 85 |
+
// notification, this function will immediately return.
|
| 86 |
+
void WaitForNotification() const;
|
| 87 |
+
|
| 88 |
+
// Notification::WaitForNotificationWithTimeout()
|
| 89 |
+
//
|
| 90 |
+
// Blocks until either the notification's "notified" state is `true` (which
|
| 91 |
+
// may occur immediately) or the timeout has elapsed, returning the value of
|
| 92 |
+
// its "notified" state in either case.
|
| 93 |
+
bool WaitForNotificationWithTimeout(absl::Duration timeout) const;
|
| 94 |
+
|
| 95 |
+
// Notification::WaitForNotificationWithDeadline()
|
| 96 |
+
//
|
| 97 |
+
// Blocks until either the notification's "notified" state is `true` (which
|
| 98 |
+
// may occur immediately) or the deadline has expired, returning the value of
|
| 99 |
+
// its "notified" state in either case.
|
| 100 |
+
bool WaitForNotificationWithDeadline(absl::Time deadline) const;
|
| 101 |
+
|
| 102 |
+
// Notification::Notify()
|
| 103 |
+
//
|
| 104 |
+
// Sets the "notified" state of this notification to `true` and wakes waiting
|
| 105 |
+
// threads. Note: do not call `Notify()` multiple times on the same
|
| 106 |
+
// `Notification`; calling `Notify()` more than once on the same notification
|
| 107 |
+
// results in undefined behavior.
|
| 108 |
+
void Notify();
|
| 109 |
+
|
| 110 |
+
private:
|
| 111 |
+
static inline bool HasBeenNotifiedInternal(
|
| 112 |
+
const std::atomic<bool>* notified_yet) {
|
| 113 |
+
return notified_yet->load(std::memory_order_acquire);
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
mutable Mutex mutex_;
|
| 117 |
+
std::atomic<bool> notified_yet_; // written under mutex_
|
| 118 |
+
};
|
| 119 |
+
|
| 120 |
+
ABSL_NAMESPACE_END
|
| 121 |
+
} // namespace absl
|
| 122 |
+
|
| 123 |
+
#endif // ABSL_SYNCHRONIZATION_NOTIFICATION_H_
|
miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/absl/time/civil_time.h
ADDED
|
@@ -0,0 +1,563 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2018 The Abseil Authors.
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// https://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
//
|
| 15 |
+
// -----------------------------------------------------------------------------
|
| 16 |
+
// File: civil_time.h
|
| 17 |
+
// -----------------------------------------------------------------------------
|
| 18 |
+
//
|
| 19 |
+
// This header file defines abstractions for computing with "civil time".
|
| 20 |
+
// The term "civil time" refers to the legally recognized human-scale time
|
| 21 |
+
// that is represented by the six fields `YYYY-MM-DD hh:mm:ss`. A "date"
|
| 22 |
+
// is perhaps the most common example of a civil time (represented here as
|
| 23 |
+
// an `absl::CivilDay`).
|
| 24 |
+
//
|
| 25 |
+
// Modern-day civil time follows the Gregorian Calendar and is a
|
| 26 |
+
// time-zone-independent concept: a civil time of "2015-06-01 12:00:00", for
|
| 27 |
+
// example, is not tied to a time zone. Put another way, a civil time does not
|
| 28 |
+
// map to a unique point in time; a civil time must be mapped to an absolute
|
| 29 |
+
// time *through* a time zone.
|
| 30 |
+
//
|
| 31 |
+
// Because a civil time is what most people think of as "time," it is common to
|
| 32 |
+
// map absolute times to civil times to present to users.
|
| 33 |
+
//
|
| 34 |
+
// Time zones define the relationship between absolute and civil times. Given an
|
| 35 |
+
// absolute or civil time and a time zone, you can compute the other time:
|
| 36 |
+
//
|
| 37 |
+
// Civil Time = F(Absolute Time, Time Zone)
|
| 38 |
+
// Absolute Time = G(Civil Time, Time Zone)
|
| 39 |
+
//
|
| 40 |
+
// The Abseil time library allows you to construct such civil times from
|
| 41 |
+
// absolute times; consult time.h for such functionality.
|
| 42 |
+
//
|
| 43 |
+
// This library provides six classes for constructing civil-time objects, and
|
| 44 |
+
// provides several helper functions for rounding, iterating, and performing
|
| 45 |
+
// arithmetic on civil-time objects, while avoiding complications like
|
| 46 |
+
// daylight-saving time (DST):
|
| 47 |
+
//
|
| 48 |
+
// * `absl::CivilSecond`
|
| 49 |
+
// * `absl::CivilMinute`
|
| 50 |
+
// * `absl::CivilHour`
|
| 51 |
+
// * `absl::CivilDay`
|
| 52 |
+
// * `absl::CivilMonth`
|
| 53 |
+
// * `absl::CivilYear`
|
| 54 |
+
//
|
| 55 |
+
// Example:
|
| 56 |
+
//
|
| 57 |
+
// // Construct a civil-time object for a specific day
|
| 58 |
+
// const absl::CivilDay cd(1969, 07, 20);
|
| 59 |
+
//
|
| 60 |
+
// // Construct a civil-time object for a specific second
|
| 61 |
+
// const absl::CivilSecond cd(2018, 8, 1, 12, 0, 1);
|
| 62 |
+
//
|
| 63 |
+
// Note: In C++14 and later, this library is usable in a constexpr context.
|
| 64 |
+
//
|
| 65 |
+
// Example:
|
| 66 |
+
//
|
| 67 |
+
// // Valid in C++14
|
| 68 |
+
// constexpr absl::CivilDay cd(1969, 07, 20);
|
| 69 |
+
|
| 70 |
+
#ifndef ABSL_TIME_CIVIL_TIME_H_
|
| 71 |
+
#define ABSL_TIME_CIVIL_TIME_H_
|
| 72 |
+
|
| 73 |
+
#include <iosfwd>
|
| 74 |
+
#include <string>
|
| 75 |
+
|
| 76 |
+
#include "absl/base/config.h"
|
| 77 |
+
#include "absl/strings/string_view.h"
|
| 78 |
+
#include "absl/time/internal/cctz/include/cctz/civil_time.h"
|
| 79 |
+
|
| 80 |
+
namespace absl {
|
| 81 |
+
ABSL_NAMESPACE_BEGIN
|
| 82 |
+
|
| 83 |
+
namespace time_internal {
|
| 84 |
+
struct second_tag : cctz::detail::second_tag {};
|
| 85 |
+
struct minute_tag : second_tag, cctz::detail::minute_tag {};
|
| 86 |
+
struct hour_tag : minute_tag, cctz::detail::hour_tag {};
|
| 87 |
+
struct day_tag : hour_tag, cctz::detail::day_tag {};
|
| 88 |
+
struct month_tag : day_tag, cctz::detail::month_tag {};
|
| 89 |
+
struct year_tag : month_tag, cctz::detail::year_tag {};
|
| 90 |
+
} // namespace time_internal
|
| 91 |
+
|
| 92 |
+
// -----------------------------------------------------------------------------
|
| 93 |
+
// CivilSecond, CivilMinute, CivilHour, CivilDay, CivilMonth, CivilYear
|
| 94 |
+
// -----------------------------------------------------------------------------
|
| 95 |
+
//
|
| 96 |
+
// Each of these civil-time types is a simple value type with the same
|
| 97 |
+
// interface for construction and the same six accessors for each of the civil
|
| 98 |
+
// time fields (year, month, day, hour, minute, and second, aka YMDHMS). These
|
| 99 |
+
// classes differ only in their alignment, which is indicated by the type name
|
| 100 |
+
// and specifies the field on which arithmetic operates.
|
| 101 |
+
//
|
| 102 |
+
// CONSTRUCTION
|
| 103 |
+
//
|
| 104 |
+
// Each of the civil-time types can be constructed in two ways: by directly
|
| 105 |
+
// passing to the constructor up to six integers representing the YMDHMS fields,
|
| 106 |
+
// or by copying the YMDHMS fields from a differently aligned civil-time type.
|
| 107 |
+
// Omitted fields are assigned their minimum valid value. Hours, minutes, and
|
| 108 |
+
// seconds will be set to 0, month and day will be set to 1. Since there is no
|
| 109 |
+
// minimum year, the default is 1970.
|
| 110 |
+
//
|
| 111 |
+
// Examples:
|
| 112 |
+
//
|
| 113 |
+
// absl::CivilDay default_value; // 1970-01-01 00:00:00
|
| 114 |
+
//
|
| 115 |
+
// absl::CivilDay a(2015, 2, 3); // 2015-02-03 00:00:00
|
| 116 |
+
// absl::CivilDay b(2015, 2, 3, 4, 5, 6); // 2015-02-03 00:00:00
|
| 117 |
+
// absl::CivilDay c(2015); // 2015-01-01 00:00:00
|
| 118 |
+
//
|
| 119 |
+
// absl::CivilSecond ss(2015, 2, 3, 4, 5, 6); // 2015-02-03 04:05:06
|
| 120 |
+
// absl::CivilMinute mm(ss); // 2015-02-03 04:05:00
|
| 121 |
+
// absl::CivilHour hh(mm); // 2015-02-03 04:00:00
|
| 122 |
+
// absl::CivilDay d(hh); // 2015-02-03 00:00:00
|
| 123 |
+
// absl::CivilMonth m(d); // 2015-02-01 00:00:00
|
| 124 |
+
// absl::CivilYear y(m); // 2015-01-01 00:00:00
|
| 125 |
+
//
|
| 126 |
+
// m = absl::CivilMonth(y); // 2015-01-01 00:00:00
|
| 127 |
+
// d = absl::CivilDay(m); // 2015-01-01 00:00:00
|
| 128 |
+
// hh = absl::CivilHour(d); // 2015-01-01 00:00:00
|
| 129 |
+
// mm = absl::CivilMinute(hh); // 2015-01-01 00:00:00
|
| 130 |
+
// ss = absl::CivilSecond(mm); // 2015-01-01 00:00:00
|
| 131 |
+
//
|
| 132 |
+
// Each civil-time class is aligned to the civil-time field indicated in the
|
| 133 |
+
// class's name after normalization. Alignment is performed by setting all the
|
| 134 |
+
// inferior fields to their minimum valid value (as described above). The
|
| 135 |
+
// following are examples of how each of the six types would align the fields
|
| 136 |
+
// representing November 22, 2015 at 12:34:56 in the afternoon. (Note: the
|
| 137 |
+
// string format used here is not important; it's just a shorthand way of
|
| 138 |
+
// showing the six YMDHMS fields.)
|
| 139 |
+
//
|
| 140 |
+
// absl::CivilSecond : 2015-11-22 12:34:56
|
| 141 |
+
// absl::CivilMinute : 2015-11-22 12:34:00
|
| 142 |
+
// absl::CivilHour : 2015-11-22 12:00:00
|
| 143 |
+
// absl::CivilDay : 2015-11-22 00:00:00
|
| 144 |
+
// absl::CivilMonth : 2015-11-01 00:00:00
|
| 145 |
+
// absl::CivilYear : 2015-01-01 00:00:00
|
| 146 |
+
//
|
| 147 |
+
// Each civil-time type performs arithmetic on the field to which it is
|
| 148 |
+
// aligned. This means that adding 1 to an absl::CivilDay increments the day
|
| 149 |
+
// field (normalizing as necessary), and subtracting 7 from an absl::CivilMonth
|
| 150 |
+
// operates on the month field (normalizing as necessary). All arithmetic
|
| 151 |
+
// produces a valid civil time. Difference requires two similarly aligned
|
| 152 |
+
// civil-time objects and returns the scalar answer in units of the objects'
|
| 153 |
+
// alignment. For example, the difference between two absl::CivilHour objects
|
| 154 |
+
// will give an answer in units of civil hours.
|
| 155 |
+
//
|
| 156 |
+
// ALIGNMENT CONVERSION
|
| 157 |
+
//
|
| 158 |
+
// The alignment of a civil-time object cannot change, but the object may be
|
| 159 |
+
// used to construct a new object with a different alignment. This is referred
|
| 160 |
+
// to as "realigning". When realigning to a type with the same or more
|
| 161 |
+
// precision (e.g., absl::CivilDay -> absl::CivilSecond), the conversion may be
|
| 162 |
+
// performed implicitly since no information is lost. However, if information
|
| 163 |
+
// could be discarded (e.g., CivilSecond -> CivilDay), the conversion must
|
| 164 |
+
// be explicit at the call site.
|
| 165 |
+
//
|
| 166 |
+
// Examples:
|
| 167 |
+
//
|
| 168 |
+
// void UseDay(absl::CivilDay day);
|
| 169 |
+
//
|
| 170 |
+
// absl::CivilSecond cs;
|
| 171 |
+
// UseDay(cs); // Won't compile because data may be discarded
|
| 172 |
+
// UseDay(absl::CivilDay(cs)); // OK: explicit conversion
|
| 173 |
+
//
|
| 174 |
+
// absl::CivilDay cd;
|
| 175 |
+
// UseDay(cd); // OK: no conversion needed
|
| 176 |
+
//
|
| 177 |
+
// absl::CivilMonth cm;
|
| 178 |
+
// UseDay(cm); // OK: implicit conversion to absl::CivilDay
|
| 179 |
+
//
|
| 180 |
+
// NORMALIZATION
|
| 181 |
+
//
|
| 182 |
+
// Normalization takes invalid values and adjusts them to produce valid values.
|
| 183 |
+
// Within the civil-time library, integer arguments passed to the Civil*
|
| 184 |
+
// constructors may be out-of-range, in which case they are normalized by
|
| 185 |
+
// carrying overflow into a field of courser granularity to produce valid
|
| 186 |
+
// civil-time objects. This normalization enables natural arithmetic on
|
| 187 |
+
// constructor arguments without worrying about the field's range.
|
| 188 |
+
//
|
| 189 |
+
// Examples:
|
| 190 |
+
//
|
| 191 |
+
// // Out-of-range; normalized to 2016-11-01
|
| 192 |
+
// absl::CivilDay d(2016, 10, 32);
|
| 193 |
+
// // Out-of-range, negative: normalized to 2016-10-30T23
|
| 194 |
+
// absl::CivilHour h1(2016, 10, 31, -1);
|
| 195 |
+
// // Normalization is cumulative: normalized to 2016-10-30T23
|
| 196 |
+
// absl::CivilHour h2(2016, 10, 32, -25);
|
| 197 |
+
//
|
| 198 |
+
// Note: If normalization is undesired, you can signal an error by comparing
|
| 199 |
+
// the constructor arguments to the normalized values returned by the YMDHMS
|
| 200 |
+
// properties.
|
| 201 |
+
//
|
| 202 |
+
// COMPARISON
|
| 203 |
+
//
|
| 204 |
+
// Comparison between civil-time objects considers all six YMDHMS fields,
|
| 205 |
+
// regardless of the type's alignment. Comparison between differently aligned
|
| 206 |
+
// civil-time types is allowed.
|
| 207 |
+
//
|
| 208 |
+
// Examples:
|
| 209 |
+
//
|
| 210 |
+
// absl::CivilDay feb_3(2015, 2, 3); // 2015-02-03 00:00:00
|
| 211 |
+
// absl::CivilDay mar_4(2015, 3, 4); // 2015-03-04 00:00:00
|
| 212 |
+
// // feb_3 < mar_4
|
| 213 |
+
// // absl::CivilYear(feb_3) == absl::CivilYear(mar_4)
|
| 214 |
+
//
|
| 215 |
+
// absl::CivilSecond feb_3_noon(2015, 2, 3, 12, 0, 0); // 2015-02-03 12:00:00
|
| 216 |
+
// // feb_3 < feb_3_noon
|
| 217 |
+
// // feb_3 == absl::CivilDay(feb_3_noon)
|
| 218 |
+
//
|
| 219 |
+
// // Iterates all the days of February 2015.
|
| 220 |
+
// for (absl::CivilDay d(2015, 2, 1); d < absl::CivilMonth(2015, 3); ++d) {
|
| 221 |
+
// // ...
|
| 222 |
+
// }
|
| 223 |
+
//
|
| 224 |
+
// ARITHMETIC
|
| 225 |
+
//
|
| 226 |
+
// Civil-time types support natural arithmetic operators such as addition,
|
| 227 |
+
// subtraction, and difference. Arithmetic operates on the civil-time field
|
| 228 |
+
// indicated in the type's name. Difference operators require arguments with
|
| 229 |
+
// the same alignment and return the answer in units of the alignment.
|
| 230 |
+
//
|
| 231 |
+
// Example:
|
| 232 |
+
//
|
| 233 |
+
// absl::CivilDay a(2015, 2, 3);
|
| 234 |
+
// ++a; // 2015-02-04 00:00:00
|
| 235 |
+
// --a; // 2015-02-03 00:00:00
|
| 236 |
+
// absl::CivilDay b = a + 1; // 2015-02-04 00:00:00
|
| 237 |
+
// absl::CivilDay c = 1 + b; // 2015-02-05 00:00:00
|
| 238 |
+
// int n = c - a; // n = 2 (civil days)
|
| 239 |
+
// int m = c - absl::CivilMonth(c); // Won't compile: different types.
|
| 240 |
+
//
|
| 241 |
+
// ACCESSORS
|
| 242 |
+
//
|
| 243 |
+
// Each civil-time type has accessors for all six of the civil-time fields:
|
| 244 |
+
// year, month, day, hour, minute, and second.
|
| 245 |
+
//
|
| 246 |
+
// civil_year_t year()
|
| 247 |
+
// int month()
|
| 248 |
+
// int day()
|
| 249 |
+
// int hour()
|
| 250 |
+
// int minute()
|
| 251 |
+
// int second()
|
| 252 |
+
//
|
| 253 |
+
// Recall that fields inferior to the type's alignment will be set to their
|
| 254 |
+
// minimum valid value.
|
| 255 |
+
//
|
| 256 |
+
// Example:
|
| 257 |
+
//
|
| 258 |
+
// absl::CivilDay d(2015, 6, 28);
|
| 259 |
+
// // d.year() == 2015
|
| 260 |
+
// // d.month() == 6
|
| 261 |
+
// // d.day() == 28
|
| 262 |
+
// // d.hour() == 0
|
| 263 |
+
// // d.minute() == 0
|
| 264 |
+
// // d.second() == 0
|
| 265 |
+
//
|
| 266 |
+
// CASE STUDY: Adding a month to January 31.
|
| 267 |
+
//
|
| 268 |
+
// One of the classic questions that arises when considering a civil time
|
| 269 |
+
// library (or a date library or a date/time library) is this:
|
| 270 |
+
// "What is the result of adding a month to January 31?"
|
| 271 |
+
// This is an interesting question because it is unclear what is meant by a
|
| 272 |
+
// "month", and several different answers are possible, depending on context:
|
| 273 |
+
//
|
| 274 |
+
// 1. March 3 (or 2 if a leap year), if "add a month" means to add a month to
|
| 275 |
+
// the current month, and adjust the date to overflow the extra days into
|
| 276 |
+
// March. In this case the result of "February 31" would be normalized as
|
| 277 |
+
// within the civil-time library.
|
| 278 |
+
// 2. February 28 (or 29 if a leap year), if "add a month" means to add a
|
| 279 |
+
// month, and adjust the date while holding the resulting month constant.
|
| 280 |
+
// In this case, the result of "February 31" would be truncated to the last
|
| 281 |
+
// day in February.
|
| 282 |
+
// 3. An error. The caller may get some error, an exception, an invalid date
|
| 283 |
+
// object, or perhaps return `false`. This may make sense because there is
|
| 284 |
+
// no single unambiguously correct answer to the question.
|
| 285 |
+
//
|
| 286 |
+
// Practically speaking, any answer that is not what the programmer intended
|
| 287 |
+
// is the wrong answer.
|
| 288 |
+
//
|
| 289 |
+
// The Abseil time library avoids this problem by making it impossible to
|
| 290 |
+
// ask ambiguous questions. All civil-time objects are aligned to a particular
|
| 291 |
+
// civil-field boundary (such as aligned to a year, month, day, hour, minute,
|
| 292 |
+
// or second), and arithmetic operates on the field to which the object is
|
| 293 |
+
// aligned. This means that in order to "add a month" the object must first be
|
| 294 |
+
// aligned to a month boundary, which is equivalent to the first day of that
|
| 295 |
+
// month.
|
| 296 |
+
//
|
| 297 |
+
// Of course, there are ways to compute an answer the question at hand using
|
| 298 |
+
// this Abseil time library, but they require the programmer to be explicit
|
| 299 |
+
// about the answer they expect. To illustrate, let's see how to compute all
|
| 300 |
+
// three of the above possible answers to the question of "Jan 31 plus 1
|
| 301 |
+
// month":
|
| 302 |
+
//
|
| 303 |
+
// Example:
|
| 304 |
+
//
|
| 305 |
+
// const absl::CivilDay d(2015, 1, 31);
|
| 306 |
+
//
|
| 307 |
+
// // Answer 1:
|
| 308 |
+
// // Add 1 to the month field in the constructor, and rely on normalization.
|
| 309 |
+
// const auto normalized = absl::CivilDay(d.year(), d.month() + 1, d.day());
|
| 310 |
+
// // normalized == 2015-03-03 (aka Feb 31)
|
| 311 |
+
//
|
| 312 |
+
// // Answer 2:
|
| 313 |
+
// // Add 1 to month field, capping to the end of next month.
|
| 314 |
+
// const auto next_month = absl::CivilMonth(d) + 1;
|
| 315 |
+
// const auto last_day_of_next_month = absl::CivilDay(next_month + 1) - 1;
|
| 316 |
+
// const auto capped = std::min(normalized, last_day_of_next_month);
|
| 317 |
+
// // capped == 2015-02-28
|
| 318 |
+
//
|
| 319 |
+
// // Answer 3:
|
| 320 |
+
// // Signal an error if the normalized answer is not in next month.
|
| 321 |
+
// if (absl::CivilMonth(normalized) != next_month) {
|
| 322 |
+
// // error, month overflow
|
| 323 |
+
// }
|
| 324 |
+
//
|
| 325 |
+
using CivilSecond =
|
| 326 |
+
time_internal::cctz::detail::civil_time<time_internal::second_tag>;
|
| 327 |
+
using CivilMinute =
|
| 328 |
+
time_internal::cctz::detail::civil_time<time_internal::minute_tag>;
|
| 329 |
+
using CivilHour =
|
| 330 |
+
time_internal::cctz::detail::civil_time<time_internal::hour_tag>;
|
| 331 |
+
using CivilDay =
|
| 332 |
+
time_internal::cctz::detail::civil_time<time_internal::day_tag>;
|
| 333 |
+
using CivilMonth =
|
| 334 |
+
time_internal::cctz::detail::civil_time<time_internal::month_tag>;
|
| 335 |
+
using CivilYear =
|
| 336 |
+
time_internal::cctz::detail::civil_time<time_internal::year_tag>;
|
| 337 |
+
|
| 338 |
+
// civil_year_t
|
| 339 |
+
//
|
| 340 |
+
// Type alias of a civil-time year value. This type is guaranteed to (at least)
|
| 341 |
+
// support any year value supported by `time_t`.
|
| 342 |
+
//
|
| 343 |
+
// Example:
|
| 344 |
+
//
|
| 345 |
+
// absl::CivilSecond cs = ...;
|
| 346 |
+
// absl::civil_year_t y = cs.year();
|
| 347 |
+
// cs = absl::CivilSecond(y, 1, 1, 0, 0, 0); // CivilSecond(CivilYear(cs))
|
| 348 |
+
//
|
| 349 |
+
using civil_year_t = time_internal::cctz::year_t;
|
| 350 |
+
|
| 351 |
+
// civil_diff_t
|
| 352 |
+
//
|
| 353 |
+
// Type alias of the difference between two civil-time values.
|
| 354 |
+
// This type is used to indicate arguments that are not
|
| 355 |
+
// normalized (such as parameters to the civil-time constructors), the results
|
| 356 |
+
// of civil-time subtraction, or the operand to civil-time addition.
|
| 357 |
+
//
|
| 358 |
+
// Example:
|
| 359 |
+
//
|
| 360 |
+
// absl::civil_diff_t n_sec = cs1 - cs2; // cs1 == cs2 + n_sec;
|
| 361 |
+
//
|
| 362 |
+
using civil_diff_t = time_internal::cctz::diff_t;
|
| 363 |
+
|
| 364 |
+
// Weekday::monday, Weekday::tuesday, Weekday::wednesday, Weekday::thursday,
|
| 365 |
+
// Weekday::friday, Weekday::saturday, Weekday::sunday
|
| 366 |
+
//
|
| 367 |
+
// The Weekday enum class represents the civil-time concept of a "weekday" with
|
| 368 |
+
// members for all days of the week.
|
| 369 |
+
//
|
| 370 |
+
// absl::Weekday wd = absl::Weekday::thursday;
|
| 371 |
+
//
|
| 372 |
+
using Weekday = time_internal::cctz::weekday;
|
| 373 |
+
|
| 374 |
+
// GetWeekday()
|
| 375 |
+
//
|
| 376 |
+
// Returns the absl::Weekday for the given (realigned) civil-time value.
|
| 377 |
+
//
|
| 378 |
+
// Example:
|
| 379 |
+
//
|
| 380 |
+
// absl::CivilDay a(2015, 8, 13);
|
| 381 |
+
// absl::Weekday wd = absl::GetWeekday(a); // wd == absl::Weekday::thursday
|
| 382 |
+
//
|
| 383 |
+
inline Weekday GetWeekday(CivilSecond cs) {
|
| 384 |
+
return time_internal::cctz::get_weekday(cs);
|
| 385 |
+
}
|
| 386 |
+
|
| 387 |
+
// NextWeekday()
|
| 388 |
+
// PrevWeekday()
|
| 389 |
+
//
|
| 390 |
+
// Returns the absl::CivilDay that strictly follows or precedes a given
|
| 391 |
+
// absl::CivilDay, and that falls on the given absl::Weekday.
|
| 392 |
+
//
|
| 393 |
+
// Example, given the following month:
|
| 394 |
+
//
|
| 395 |
+
// August 2015
|
| 396 |
+
// Su Mo Tu We Th Fr Sa
|
| 397 |
+
// 1
|
| 398 |
+
// 2 3 4 5 6 7 8
|
| 399 |
+
// 9 10 11 12 13 14 15
|
| 400 |
+
// 16 17 18 19 20 21 22
|
| 401 |
+
// 23 24 25 26 27 28 29
|
| 402 |
+
// 30 31
|
| 403 |
+
//
|
| 404 |
+
// absl::CivilDay a(2015, 8, 13);
|
| 405 |
+
// // absl::GetWeekday(a) == absl::Weekday::thursday
|
| 406 |
+
// absl::CivilDay b = absl::NextWeekday(a, absl::Weekday::thursday);
|
| 407 |
+
// // b = 2015-08-20
|
| 408 |
+
// absl::CivilDay c = absl::PrevWeekday(a, absl::Weekday::thursday);
|
| 409 |
+
// // c = 2015-08-06
|
| 410 |
+
//
|
| 411 |
+
// absl::CivilDay d = ...
|
| 412 |
+
// // Gets the following Thursday if d is not already Thursday
|
| 413 |
+
// absl::CivilDay thurs1 = absl::NextWeekday(d - 1, absl::Weekday::thursday);
|
| 414 |
+
// // Gets the previous Thursday if d is not already Thursday
|
| 415 |
+
// absl::CivilDay thurs2 = absl::PrevWeekday(d + 1, absl::Weekday::thursday);
|
| 416 |
+
//
|
| 417 |
+
inline CivilDay NextWeekday(CivilDay cd, Weekday wd) {
|
| 418 |
+
return CivilDay(time_internal::cctz::next_weekday(cd, wd));
|
| 419 |
+
}
|
| 420 |
+
inline CivilDay PrevWeekday(CivilDay cd, Weekday wd) {
|
| 421 |
+
return CivilDay(time_internal::cctz::prev_weekday(cd, wd));
|
| 422 |
+
}
|
| 423 |
+
|
| 424 |
+
// GetYearDay()
|
| 425 |
+
//
|
| 426 |
+
// Returns the day-of-year for the given (realigned) civil-time value.
|
| 427 |
+
//
|
| 428 |
+
// Example:
|
| 429 |
+
//
|
| 430 |
+
// absl::CivilDay a(2015, 1, 1);
|
| 431 |
+
// int yd_jan_1 = absl::GetYearDay(a); // yd_jan_1 = 1
|
| 432 |
+
// absl::CivilDay b(2015, 12, 31);
|
| 433 |
+
// int yd_dec_31 = absl::GetYearDay(b); // yd_dec_31 = 365
|
| 434 |
+
//
|
| 435 |
+
inline int GetYearDay(CivilSecond cs) {
|
| 436 |
+
return time_internal::cctz::get_yearday(cs);
|
| 437 |
+
}
|
| 438 |
+
|
| 439 |
+
// FormatCivilTime()
|
| 440 |
+
//
|
| 441 |
+
// Formats the given civil-time value into a string value of the following
|
| 442 |
+
// format:
|
| 443 |
+
//
|
| 444 |
+
// Type | Format
|
| 445 |
+
// ---------------------------------
|
| 446 |
+
// CivilSecond | YYYY-MM-DDTHH:MM:SS
|
| 447 |
+
// CivilMinute | YYYY-MM-DDTHH:MM
|
| 448 |
+
// CivilHour | YYYY-MM-DDTHH
|
| 449 |
+
// CivilDay | YYYY-MM-DD
|
| 450 |
+
// CivilMonth | YYYY-MM
|
| 451 |
+
// CivilYear | YYYY
|
| 452 |
+
//
|
| 453 |
+
// Example:
|
| 454 |
+
//
|
| 455 |
+
// absl::CivilDay d = absl::CivilDay(1969, 7, 20);
|
| 456 |
+
// std::string day_string = absl::FormatCivilTime(d); // "1969-07-20"
|
| 457 |
+
//
|
| 458 |
+
std::string FormatCivilTime(CivilSecond c);
|
| 459 |
+
std::string FormatCivilTime(CivilMinute c);
|
| 460 |
+
std::string FormatCivilTime(CivilHour c);
|
| 461 |
+
std::string FormatCivilTime(CivilDay c);
|
| 462 |
+
std::string FormatCivilTime(CivilMonth c);
|
| 463 |
+
std::string FormatCivilTime(CivilYear c);
|
| 464 |
+
|
| 465 |
+
// absl::ParseCivilTime()
|
| 466 |
+
//
|
| 467 |
+
// Parses a civil-time value from the specified `absl::string_view` into the
|
| 468 |
+
// passed output parameter. Returns `true` upon successful parsing.
|
| 469 |
+
//
|
| 470 |
+
// The expected form of the input string is as follows:
|
| 471 |
+
//
|
| 472 |
+
// Type | Format
|
| 473 |
+
// ---------------------------------
|
| 474 |
+
// CivilSecond | YYYY-MM-DDTHH:MM:SS
|
| 475 |
+
// CivilMinute | YYYY-MM-DDTHH:MM
|
| 476 |
+
// CivilHour | YYYY-MM-DDTHH
|
| 477 |
+
// CivilDay | YYYY-MM-DD
|
| 478 |
+
// CivilMonth | YYYY-MM
|
| 479 |
+
// CivilYear | YYYY
|
| 480 |
+
//
|
| 481 |
+
// Example:
|
| 482 |
+
//
|
| 483 |
+
// absl::CivilDay d;
|
| 484 |
+
// bool ok = absl::ParseCivilTime("2018-01-02", &d); // OK
|
| 485 |
+
//
|
| 486 |
+
// Note that parsing will fail if the string's format does not match the
|
| 487 |
+
// expected type exactly. `ParseLenientCivilTime()` below is more lenient.
|
| 488 |
+
//
|
| 489 |
+
bool ParseCivilTime(absl::string_view s, CivilSecond* c);
|
| 490 |
+
bool ParseCivilTime(absl::string_view s, CivilMinute* c);
|
| 491 |
+
bool ParseCivilTime(absl::string_view s, CivilHour* c);
|
| 492 |
+
bool ParseCivilTime(absl::string_view s, CivilDay* c);
|
| 493 |
+
bool ParseCivilTime(absl::string_view s, CivilMonth* c);
|
| 494 |
+
bool ParseCivilTime(absl::string_view s, CivilYear* c);
|
| 495 |
+
|
| 496 |
+
// ParseLenientCivilTime()
|
| 497 |
+
//
|
| 498 |
+
// Parses any of the formats accepted by `absl::ParseCivilTime()`, but is more
|
| 499 |
+
// lenient if the format of the string does not exactly match the associated
|
| 500 |
+
// type.
|
| 501 |
+
//
|
| 502 |
+
// Example:
|
| 503 |
+
//
|
| 504 |
+
// absl::CivilDay d;
|
| 505 |
+
// bool ok = absl::ParseLenientCivilTime("1969-07-20", &d); // OK
|
| 506 |
+
// ok = absl::ParseLenientCivilTime("1969-07-20T10", &d); // OK: T10 floored
|
| 507 |
+
// ok = absl::ParseLenientCivilTime("1969-07", &d); // OK: day defaults to 1
|
| 508 |
+
//
|
| 509 |
+
bool ParseLenientCivilTime(absl::string_view s, CivilSecond* c);
|
| 510 |
+
bool ParseLenientCivilTime(absl::string_view s, CivilMinute* c);
|
| 511 |
+
bool ParseLenientCivilTime(absl::string_view s, CivilHour* c);
|
| 512 |
+
bool ParseLenientCivilTime(absl::string_view s, CivilDay* c);
|
| 513 |
+
bool ParseLenientCivilTime(absl::string_view s, CivilMonth* c);
|
| 514 |
+
bool ParseLenientCivilTime(absl::string_view s, CivilYear* c);
|
| 515 |
+
|
| 516 |
+
namespace time_internal { // For functions found via ADL on civil-time tags.
|
| 517 |
+
|
| 518 |
+
// Streaming Operators
|
| 519 |
+
//
|
| 520 |
+
// Each civil-time type may be sent to an output stream using operator<<().
|
| 521 |
+
// The result matches the string produced by `FormatCivilTime()`.
|
| 522 |
+
//
|
| 523 |
+
// Example:
|
| 524 |
+
//
|
| 525 |
+
// absl::CivilDay d = absl::CivilDay(1969, 7, 20);
|
| 526 |
+
// std::cout << "Date is: " << d << "\n";
|
| 527 |
+
//
|
| 528 |
+
std::ostream& operator<<(std::ostream& os, CivilYear y);
|
| 529 |
+
std::ostream& operator<<(std::ostream& os, CivilMonth m);
|
| 530 |
+
std::ostream& operator<<(std::ostream& os, CivilDay d);
|
| 531 |
+
std::ostream& operator<<(std::ostream& os, CivilHour h);
|
| 532 |
+
std::ostream& operator<<(std::ostream& os, CivilMinute m);
|
| 533 |
+
std::ostream& operator<<(std::ostream& os, CivilSecond s);
|
| 534 |
+
|
| 535 |
+
// AbslParseFlag()
|
| 536 |
+
//
|
| 537 |
+
// Parses the command-line flag string representation `s` into a civil-time
|
| 538 |
+
// value. Flags must be specified in a format that is valid for
|
| 539 |
+
// `absl::ParseLenientCivilTime()`.
|
| 540 |
+
bool AbslParseFlag(absl::string_view s, CivilSecond* c, std::string* error);
|
| 541 |
+
bool AbslParseFlag(absl::string_view s, CivilMinute* c, std::string* error);
|
| 542 |
+
bool AbslParseFlag(absl::string_view s, CivilHour* c, std::string* error);
|
| 543 |
+
bool AbslParseFlag(absl::string_view s, CivilDay* c, std::string* error);
|
| 544 |
+
bool AbslParseFlag(absl::string_view s, CivilMonth* c, std::string* error);
|
| 545 |
+
bool AbslParseFlag(absl::string_view s, CivilYear* c, std::string* error);
|
| 546 |
+
|
| 547 |
+
// AbslUnparseFlag()
|
| 548 |
+
//
|
| 549 |
+
// Unparses a civil-time value into a command-line string representation using
|
| 550 |
+
// the format specified by `absl::ParseCivilTime()`.
|
| 551 |
+
std::string AbslUnparseFlag(CivilSecond c);
|
| 552 |
+
std::string AbslUnparseFlag(CivilMinute c);
|
| 553 |
+
std::string AbslUnparseFlag(CivilHour c);
|
| 554 |
+
std::string AbslUnparseFlag(CivilDay c);
|
| 555 |
+
std::string AbslUnparseFlag(CivilMonth c);
|
| 556 |
+
std::string AbslUnparseFlag(CivilYear c);
|
| 557 |
+
|
| 558 |
+
} // namespace time_internal
|
| 559 |
+
|
| 560 |
+
ABSL_NAMESPACE_END
|
| 561 |
+
} // namespace absl
|
| 562 |
+
|
| 563 |
+
#endif // ABSL_TIME_CIVIL_TIME_H_
|
miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/absl/time/clock.h
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2017 The Abseil Authors.
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// https://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
//
|
| 15 |
+
// -----------------------------------------------------------------------------
|
| 16 |
+
// File: clock.h
|
| 17 |
+
// -----------------------------------------------------------------------------
|
| 18 |
+
//
|
| 19 |
+
// This header file contains utility functions for working with the system-wide
|
| 20 |
+
// realtime clock. For descriptions of the main time abstractions used within
|
| 21 |
+
// this header file, consult the time.h header file.
|
| 22 |
+
#ifndef ABSL_TIME_CLOCK_H_
|
| 23 |
+
#define ABSL_TIME_CLOCK_H_
|
| 24 |
+
|
| 25 |
+
#include "absl/base/macros.h"
|
| 26 |
+
#include "absl/time/time.h"
|
| 27 |
+
|
| 28 |
+
namespace absl {
|
| 29 |
+
ABSL_NAMESPACE_BEGIN
|
| 30 |
+
|
| 31 |
+
// Now()
|
| 32 |
+
//
|
| 33 |
+
// Returns the current time, expressed as an `absl::Time` absolute time value.
|
| 34 |
+
absl::Time Now();
|
| 35 |
+
|
| 36 |
+
// GetCurrentTimeNanos()
|
| 37 |
+
//
|
| 38 |
+
// Returns the current time, expressed as a count of nanoseconds since the Unix
|
| 39 |
+
// Epoch (https://en.wikipedia.org/wiki/Unix_time). Prefer `absl::Now()` instead
|
| 40 |
+
// for all but the most performance-sensitive cases (i.e. when you are calling
|
| 41 |
+
// this function hundreds of thousands of times per second).
|
| 42 |
+
int64_t GetCurrentTimeNanos();
|
| 43 |
+
|
| 44 |
+
// SleepFor()
|
| 45 |
+
//
|
| 46 |
+
// Sleeps for the specified duration, expressed as an `absl::Duration`.
|
| 47 |
+
//
|
| 48 |
+
// Notes:
|
| 49 |
+
// * Signal interruptions will not reduce the sleep duration.
|
| 50 |
+
// * Returns immediately when passed a nonpositive duration.
|
| 51 |
+
void SleepFor(absl::Duration duration);
|
| 52 |
+
|
| 53 |
+
ABSL_NAMESPACE_END
|
| 54 |
+
} // namespace absl
|
| 55 |
+
|
| 56 |
+
// -----------------------------------------------------------------------------
|
| 57 |
+
// Implementation Details
|
| 58 |
+
// -----------------------------------------------------------------------------
|
| 59 |
+
|
| 60 |
+
// In some build configurations we pass --detect-odr-violations to the
|
| 61 |
+
// gold linker. This causes it to flag weak symbol overrides as ODR
|
| 62 |
+
// violations. Because ODR only applies to C++ and not C,
|
| 63 |
+
// --detect-odr-violations ignores symbols not mangled with C++ names.
|
| 64 |
+
// By changing our extension points to be extern "C", we dodge this
|
| 65 |
+
// check.
|
| 66 |
+
extern "C" {
|
| 67 |
+
void ABSL_INTERNAL_C_SYMBOL(AbslInternalSleepFor)(absl::Duration duration);
|
| 68 |
+
} // extern "C"
|
| 69 |
+
|
| 70 |
+
inline void absl::SleepFor(absl::Duration duration) {
|
| 71 |
+
ABSL_INTERNAL_C_SYMBOL(AbslInternalSleepFor)(duration);
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
#endif // ABSL_TIME_CLOCK_H_
|
miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/absl/time/internal/cctz/include/cctz/civil_time.h
ADDED
|
@@ -0,0 +1,332 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2016 Google Inc. All Rights Reserved.
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// https://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
|
| 15 |
+
#ifndef ABSL_TIME_INTERNAL_CCTZ_CIVIL_TIME_H_
|
| 16 |
+
#define ABSL_TIME_INTERNAL_CCTZ_CIVIL_TIME_H_
|
| 17 |
+
|
| 18 |
+
#include "absl/base/config.h"
|
| 19 |
+
#include "absl/time/internal/cctz/include/cctz/civil_time_detail.h"
|
| 20 |
+
|
| 21 |
+
namespace absl {
|
| 22 |
+
ABSL_NAMESPACE_BEGIN
|
| 23 |
+
namespace time_internal {
|
| 24 |
+
namespace cctz {
|
| 25 |
+
|
| 26 |
+
// The term "civil time" refers to the legally recognized human-scale time
|
| 27 |
+
// that is represented by the six fields YYYY-MM-DD hh:mm:ss. Modern-day civil
|
| 28 |
+
// time follows the Gregorian Calendar and is a time-zone-independent concept.
|
| 29 |
+
// A "date" is perhaps the most common example of a civil time (represented in
|
| 30 |
+
// this library as cctz::civil_day). This library provides six classes and a
|
| 31 |
+
// handful of functions that help with rounding, iterating, and arithmetic on
|
| 32 |
+
// civil times while avoiding complications like daylight-saving time (DST).
|
| 33 |
+
//
|
| 34 |
+
// The following six classes form the core of this civil-time library:
|
| 35 |
+
//
|
| 36 |
+
// * civil_second
|
| 37 |
+
// * civil_minute
|
| 38 |
+
// * civil_hour
|
| 39 |
+
// * civil_day
|
| 40 |
+
// * civil_month
|
| 41 |
+
// * civil_year
|
| 42 |
+
//
|
| 43 |
+
// Each class is a simple value type with the same interface for construction
|
| 44 |
+
// and the same six accessors for each of the civil fields (year, month, day,
|
| 45 |
+
// hour, minute, and second, aka YMDHMS). These classes differ only in their
|
| 46 |
+
// alignment, which is indicated by the type name and specifies the field on
|
| 47 |
+
// which arithmetic operates.
|
| 48 |
+
//
|
| 49 |
+
// Each class can be constructed by passing up to six optional integer
|
| 50 |
+
// arguments representing the YMDHMS fields (in that order) to the
|
| 51 |
+
// constructor. Omitted fields are assigned their minimum valid value. Hours,
|
| 52 |
+
// minutes, and seconds will be set to 0, month and day will be set to 1, and
|
| 53 |
+
// since there is no minimum valid year, it will be set to 1970. So, a
|
| 54 |
+
// default-constructed civil-time object will have YMDHMS fields representing
|
| 55 |
+
// "1970-01-01 00:00:00". Fields that are out-of-range are normalized (e.g.,
|
| 56 |
+
// October 32 -> November 1) so that all civil-time objects represent valid
|
| 57 |
+
// values.
|
| 58 |
+
//
|
| 59 |
+
// Each civil-time class is aligned to the civil-time field indicated in the
|
| 60 |
+
// class's name after normalization. Alignment is performed by setting all the
|
| 61 |
+
// inferior fields to their minimum valid value (as described above). The
|
| 62 |
+
// following are examples of how each of the six types would align the fields
|
| 63 |
+
// representing November 22, 2015 at 12:34:56 in the afternoon. (Note: the
|
| 64 |
+
// string format used here is not important; it's just a shorthand way of
|
| 65 |
+
// showing the six YMDHMS fields.)
|
| 66 |
+
//
|
| 67 |
+
// civil_second 2015-11-22 12:34:56
|
| 68 |
+
// civil_minute 2015-11-22 12:34:00
|
| 69 |
+
// civil_hour 2015-11-22 12:00:00
|
| 70 |
+
// civil_day 2015-11-22 00:00:00
|
| 71 |
+
// civil_month 2015-11-01 00:00:00
|
| 72 |
+
// civil_year 2015-01-01 00:00:00
|
| 73 |
+
//
|
| 74 |
+
// Each civil-time type performs arithmetic on the field to which it is
|
| 75 |
+
// aligned. This means that adding 1 to a civil_day increments the day field
|
| 76 |
+
// (normalizing as necessary), and subtracting 7 from a civil_month operates
|
| 77 |
+
// on the month field (normalizing as necessary). All arithmetic produces a
|
| 78 |
+
// valid civil time. Difference requires two similarly aligned civil-time
|
| 79 |
+
// objects and returns the scalar answer in units of the objects' alignment.
|
| 80 |
+
// For example, the difference between two civil_hour objects will give an
|
| 81 |
+
// answer in units of civil hours.
|
| 82 |
+
//
|
| 83 |
+
// In addition to the six civil-time types just described, there are
|
| 84 |
+
// a handful of helper functions and algorithms for performing common
|
| 85 |
+
// calculations. These are described below.
|
| 86 |
+
//
|
| 87 |
+
// Note: In C++14 and later, this library is usable in a constexpr context.
|
| 88 |
+
//
|
| 89 |
+
// CONSTRUCTION:
|
| 90 |
+
//
|
| 91 |
+
// Each of the civil-time types can be constructed in two ways: by directly
|
| 92 |
+
// passing to the constructor up to six (optional) integers representing the
|
| 93 |
+
// YMDHMS fields, or by copying the YMDHMS fields from a differently aligned
|
| 94 |
+
// civil-time type.
|
| 95 |
+
//
|
| 96 |
+
// civil_day default_value; // 1970-01-01 00:00:00
|
| 97 |
+
//
|
| 98 |
+
// civil_day a(2015, 2, 3); // 2015-02-03 00:00:00
|
| 99 |
+
// civil_day b(2015, 2, 3, 4, 5, 6); // 2015-02-03 00:00:00
|
| 100 |
+
// civil_day c(2015); // 2015-01-01 00:00:00
|
| 101 |
+
//
|
| 102 |
+
// civil_second ss(2015, 2, 3, 4, 5, 6); // 2015-02-03 04:05:06
|
| 103 |
+
// civil_minute mm(ss); // 2015-02-03 04:05:00
|
| 104 |
+
// civil_hour hh(mm); // 2015-02-03 04:00:00
|
| 105 |
+
// civil_day d(hh); // 2015-02-03 00:00:00
|
| 106 |
+
// civil_month m(d); // 2015-02-01 00:00:00
|
| 107 |
+
// civil_year y(m); // 2015-01-01 00:00:00
|
| 108 |
+
//
|
| 109 |
+
// m = civil_month(y); // 2015-01-01 00:00:00
|
| 110 |
+
// d = civil_day(m); // 2015-01-01 00:00:00
|
| 111 |
+
// hh = civil_hour(d); // 2015-01-01 00:00:00
|
| 112 |
+
// mm = civil_minute(hh); // 2015-01-01 00:00:00
|
| 113 |
+
// ss = civil_second(mm); // 2015-01-01 00:00:00
|
| 114 |
+
//
|
| 115 |
+
// ALIGNMENT CONVERSION:
|
| 116 |
+
//
|
| 117 |
+
// The alignment of a civil-time object cannot change, but the object may be
|
| 118 |
+
// used to construct a new object with a different alignment. This is referred
|
| 119 |
+
// to as "realigning". When realigning to a type with the same or more
|
| 120 |
+
// precision (e.g., civil_day -> civil_second), the conversion may be
|
| 121 |
+
// performed implicitly since no information is lost. However, if information
|
| 122 |
+
// could be discarded (e.g., civil_second -> civil_day), the conversion must
|
| 123 |
+
// be explicit at the call site.
|
| 124 |
+
//
|
| 125 |
+
// void fun(const civil_day& day);
|
| 126 |
+
//
|
| 127 |
+
// civil_second cs;
|
| 128 |
+
// fun(cs); // Won't compile because data may be discarded
|
| 129 |
+
// fun(civil_day(cs)); // OK: explicit conversion
|
| 130 |
+
//
|
| 131 |
+
// civil_day cd;
|
| 132 |
+
// fun(cd); // OK: no conversion needed
|
| 133 |
+
//
|
| 134 |
+
// civil_month cm;
|
| 135 |
+
// fun(cm); // OK: implicit conversion to civil_day
|
| 136 |
+
//
|
| 137 |
+
// NORMALIZATION:
|
| 138 |
+
//
|
| 139 |
+
// Integer arguments passed to the constructor may be out-of-range, in which
|
| 140 |
+
// case they are normalized to produce a valid civil-time object. This enables
|
| 141 |
+
// natural arithmetic on constructor arguments without worrying about the
|
| 142 |
+
// field's range. Normalization guarantees that there are no invalid
|
| 143 |
+
// civil-time objects.
|
| 144 |
+
//
|
| 145 |
+
// civil_day d(2016, 10, 32); // Out-of-range day; normalized to 2016-11-01
|
| 146 |
+
//
|
| 147 |
+
// Note: If normalization is undesired, you can signal an error by comparing
|
| 148 |
+
// the constructor arguments to the normalized values returned by the YMDHMS
|
| 149 |
+
// properties.
|
| 150 |
+
//
|
| 151 |
+
// PROPERTIES:
|
| 152 |
+
//
|
| 153 |
+
// All civil-time types have accessors for all six of the civil-time fields:
|
| 154 |
+
// year, month, day, hour, minute, and second. Recall that fields inferior to
|
| 155 |
+
// the type's alignment will be set to their minimum valid value.
|
| 156 |
+
//
|
| 157 |
+
// civil_day d(2015, 6, 28);
|
| 158 |
+
// // d.year() == 2015
|
| 159 |
+
// // d.month() == 6
|
| 160 |
+
// // d.day() == 28
|
| 161 |
+
// // d.hour() == 0
|
| 162 |
+
// // d.minute() == 0
|
| 163 |
+
// // d.second() == 0
|
| 164 |
+
//
|
| 165 |
+
// COMPARISON:
|
| 166 |
+
//
|
| 167 |
+
// Comparison always considers all six YMDHMS fields, regardless of the type's
|
| 168 |
+
// alignment. Comparison between differently aligned civil-time types is
|
| 169 |
+
// allowed.
|
| 170 |
+
//
|
| 171 |
+
// civil_day feb_3(2015, 2, 3); // 2015-02-03 00:00:00
|
| 172 |
+
// civil_day mar_4(2015, 3, 4); // 2015-03-04 00:00:00
|
| 173 |
+
// // feb_3 < mar_4
|
| 174 |
+
// // civil_year(feb_3) == civil_year(mar_4)
|
| 175 |
+
//
|
| 176 |
+
// civil_second feb_3_noon(2015, 2, 3, 12, 0, 0); // 2015-02-03 12:00:00
|
| 177 |
+
// // feb_3 < feb_3_noon
|
| 178 |
+
// // feb_3 == civil_day(feb_3_noon)
|
| 179 |
+
//
|
| 180 |
+
// // Iterates all the days of February 2015.
|
| 181 |
+
// for (civil_day d(2015, 2, 1); d < civil_month(2015, 3); ++d) {
|
| 182 |
+
// // ...
|
| 183 |
+
// }
|
| 184 |
+
//
|
| 185 |
+
// STREAMING:
|
| 186 |
+
//
|
| 187 |
+
// Each civil-time type may be sent to an output stream using operator<<().
|
| 188 |
+
// The output format follows the pattern "YYYY-MM-DDThh:mm:ss" where fields
|
| 189 |
+
// inferior to the type's alignment are omitted.
|
| 190 |
+
//
|
| 191 |
+
// civil_second cs(2015, 2, 3, 4, 5, 6);
|
| 192 |
+
// std::cout << cs << "\n"; // Outputs: 2015-02-03T04:05:06
|
| 193 |
+
//
|
| 194 |
+
// civil_day cd(cs);
|
| 195 |
+
// std::cout << cd << "\n"; // Outputs: 2015-02-03
|
| 196 |
+
//
|
| 197 |
+
// civil_year cy(cs);
|
| 198 |
+
// std::cout << cy << "\n"; // Outputs: 2015
|
| 199 |
+
//
|
| 200 |
+
// ARITHMETIC:
|
| 201 |
+
//
|
| 202 |
+
// Civil-time types support natural arithmetic operators such as addition,
|
| 203 |
+
// subtraction, and difference. Arithmetic operates on the civil-time field
|
| 204 |
+
// indicated in the type's name. Difference requires arguments with the same
|
| 205 |
+
// alignment and returns the answer in units of the alignment.
|
| 206 |
+
//
|
| 207 |
+
// civil_day a(2015, 2, 3);
|
| 208 |
+
// ++a; // 2015-02-04 00:00:00
|
| 209 |
+
// --a; // 2015-02-03 00:00:00
|
| 210 |
+
// civil_day b = a + 1; // 2015-02-04 00:00:00
|
| 211 |
+
// civil_day c = 1 + b; // 2015-02-05 00:00:00
|
| 212 |
+
// int n = c - a; // n = 2 (civil days)
|
| 213 |
+
// int m = c - civil_month(c); // Won't compile: different types.
|
| 214 |
+
//
|
| 215 |
+
// EXAMPLE: Adding a month to January 31.
|
| 216 |
+
//
|
| 217 |
+
// One of the classic questions that arises when considering a civil-time
|
| 218 |
+
// library (or a date library or a date/time library) is this: "What happens
|
| 219 |
+
// when you add a month to January 31?" This is an interesting question
|
| 220 |
+
// because there could be a number of possible answers:
|
| 221 |
+
//
|
| 222 |
+
// 1. March 3 (or 2 if a leap year). This may make sense if the operation
|
| 223 |
+
// wants the equivalent of February 31.
|
| 224 |
+
// 2. February 28 (or 29 if a leap year). This may make sense if the operation
|
| 225 |
+
// wants the last day of January to go to the last day of February.
|
| 226 |
+
// 3. Error. The caller may get some error, an exception, an invalid date
|
| 227 |
+
// object, or maybe false is returned. This may make sense because there is
|
| 228 |
+
// no single unambiguously correct answer to the question.
|
| 229 |
+
//
|
| 230 |
+
// Practically speaking, any answer that is not what the programmer intended
|
| 231 |
+
// is the wrong answer.
|
| 232 |
+
//
|
| 233 |
+
// This civil-time library avoids the problem by making it impossible to ask
|
| 234 |
+
// ambiguous questions. All civil-time objects are aligned to a particular
|
| 235 |
+
// civil-field boundary (such as aligned to a year, month, day, hour, minute,
|
| 236 |
+
// or second), and arithmetic operates on the field to which the object is
|
| 237 |
+
// aligned. This means that in order to "add a month" the object must first be
|
| 238 |
+
// aligned to a month boundary, which is equivalent to the first day of that
|
| 239 |
+
// month.
|
| 240 |
+
//
|
| 241 |
+
// Of course, there are ways to compute an answer the question at hand using
|
| 242 |
+
// this civil-time library, but they require the programmer to be explicit
|
| 243 |
+
// about the answer they expect. To illustrate, let's see how to compute all
|
| 244 |
+
// three of the above possible answers to the question of "Jan 31 plus 1
|
| 245 |
+
// month":
|
| 246 |
+
//
|
| 247 |
+
// const civil_day d(2015, 1, 31);
|
| 248 |
+
//
|
| 249 |
+
// // Answer 1:
|
| 250 |
+
// // Add 1 to the month field in the constructor, and rely on normalization.
|
| 251 |
+
// const auto ans_normalized = civil_day(d.year(), d.month() + 1, d.day());
|
| 252 |
+
// // ans_normalized == 2015-03-03 (aka Feb 31)
|
| 253 |
+
//
|
| 254 |
+
// // Answer 2:
|
| 255 |
+
// // Add 1 to month field, capping to the end of next month.
|
| 256 |
+
// const auto next_month = civil_month(d) + 1;
|
| 257 |
+
// const auto last_day_of_next_month = civil_day(next_month + 1) - 1;
|
| 258 |
+
// const auto ans_capped = std::min(ans_normalized, last_day_of_next_month);
|
| 259 |
+
// // ans_capped == 2015-02-28
|
| 260 |
+
//
|
| 261 |
+
// // Answer 3:
|
| 262 |
+
// // Signal an error if the normalized answer is not in next month.
|
| 263 |
+
// if (civil_month(ans_normalized) != next_month) {
|
| 264 |
+
// // error, month overflow
|
| 265 |
+
// }
|
| 266 |
+
//
|
| 267 |
+
using civil_year = detail::civil_year;
|
| 268 |
+
using civil_month = detail::civil_month;
|
| 269 |
+
using civil_day = detail::civil_day;
|
| 270 |
+
using civil_hour = detail::civil_hour;
|
| 271 |
+
using civil_minute = detail::civil_minute;
|
| 272 |
+
using civil_second = detail::civil_second;
|
| 273 |
+
|
| 274 |
+
// An enum class with members monday, tuesday, wednesday, thursday, friday,
|
| 275 |
+
// saturday, and sunday. These enum values may be sent to an output stream
|
| 276 |
+
// using operator<<(). The result is the full weekday name in English with a
|
| 277 |
+
// leading capital letter.
|
| 278 |
+
//
|
| 279 |
+
// weekday wd = weekday::thursday;
|
| 280 |
+
// std::cout << wd << "\n"; // Outputs: Thursday
|
| 281 |
+
//
|
| 282 |
+
using detail::weekday;
|
| 283 |
+
|
| 284 |
+
// Returns the weekday for the given civil-time value.
|
| 285 |
+
//
|
| 286 |
+
// civil_day a(2015, 8, 13);
|
| 287 |
+
// weekday wd = get_weekday(a); // wd == weekday::thursday
|
| 288 |
+
//
|
| 289 |
+
using detail::get_weekday;
|
| 290 |
+
|
| 291 |
+
// Returns the civil_day that strictly follows or precedes the given
|
| 292 |
+
// civil_day, and that falls on the given weekday.
|
| 293 |
+
//
|
| 294 |
+
// For example, given:
|
| 295 |
+
//
|
| 296 |
+
// August 2015
|
| 297 |
+
// Su Mo Tu We Th Fr Sa
|
| 298 |
+
// 1
|
| 299 |
+
// 2 3 4 5 6 7 8
|
| 300 |
+
// 9 10 11 12 13 14 15
|
| 301 |
+
// 16 17 18 19 20 21 22
|
| 302 |
+
// 23 24 25 26 27 28 29
|
| 303 |
+
// 30 31
|
| 304 |
+
//
|
| 305 |
+
// civil_day a(2015, 8, 13); // get_weekday(a) == weekday::thursday
|
| 306 |
+
// civil_day b = next_weekday(a, weekday::thursday); // b = 2015-08-20
|
| 307 |
+
// civil_day c = prev_weekday(a, weekday::thursday); // c = 2015-08-06
|
| 308 |
+
//
|
| 309 |
+
// civil_day d = ...
|
| 310 |
+
// // Gets the following Thursday if d is not already Thursday
|
| 311 |
+
// civil_day thurs1 = next_weekday(d - 1, weekday::thursday);
|
| 312 |
+
// // Gets the previous Thursday if d is not already Thursday
|
| 313 |
+
// civil_day thurs2 = prev_weekday(d + 1, weekday::thursday);
|
| 314 |
+
//
|
| 315 |
+
using detail::next_weekday;
|
| 316 |
+
using detail::prev_weekday;
|
| 317 |
+
|
| 318 |
+
// Returns the day-of-year for the given civil-time value.
|
| 319 |
+
//
|
| 320 |
+
// civil_day a(2015, 1, 1);
|
| 321 |
+
// int yd_jan_1 = get_yearday(a); // yd_jan_1 = 1
|
| 322 |
+
// civil_day b(2015, 12, 31);
|
| 323 |
+
// int yd_dec_31 = get_yearday(b); // yd_dec_31 = 365
|
| 324 |
+
//
|
| 325 |
+
using detail::get_yearday;
|
| 326 |
+
|
| 327 |
+
} // namespace cctz
|
| 328 |
+
} // namespace time_internal
|
| 329 |
+
ABSL_NAMESPACE_END
|
| 330 |
+
} // namespace absl
|
| 331 |
+
|
| 332 |
+
#endif // ABSL_TIME_INTERNAL_CCTZ_CIVIL_TIME_H_
|
miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/absl/time/internal/cctz/include/cctz/civil_time_detail.h
ADDED
|
@@ -0,0 +1,632 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// https://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
|
| 15 |
+
#ifndef ABSL_TIME_INTERNAL_CCTZ_CIVIL_TIME_DETAIL_H_
|
| 16 |
+
#define ABSL_TIME_INTERNAL_CCTZ_CIVIL_TIME_DETAIL_H_
|
| 17 |
+
|
| 18 |
+
#include <cstdint>
|
| 19 |
+
#include <limits>
|
| 20 |
+
#include <ostream>
|
| 21 |
+
#include <type_traits>
|
| 22 |
+
|
| 23 |
+
#include "absl/base/config.h"
|
| 24 |
+
|
| 25 |
+
// Disable constexpr support unless we are in C++14 mode.
|
| 26 |
+
#if __cpp_constexpr >= 201304 || (defined(_MSC_VER) && _MSC_VER >= 1910)
|
| 27 |
+
#define CONSTEXPR_D constexpr // data
|
| 28 |
+
#define CONSTEXPR_F constexpr // function
|
| 29 |
+
#define CONSTEXPR_M constexpr // member
|
| 30 |
+
#else
|
| 31 |
+
#define CONSTEXPR_D const
|
| 32 |
+
#define CONSTEXPR_F inline
|
| 33 |
+
#define CONSTEXPR_M
|
| 34 |
+
#endif
|
| 35 |
+
|
| 36 |
+
namespace absl {
|
| 37 |
+
ABSL_NAMESPACE_BEGIN
|
| 38 |
+
namespace time_internal {
|
| 39 |
+
namespace cctz {
|
| 40 |
+
|
| 41 |
+
// Support years that at least span the range of 64-bit time_t values.
|
| 42 |
+
using year_t = std::int_fast64_t;
|
| 43 |
+
|
| 44 |
+
// Type alias that indicates an argument is not normalized (e.g., the
|
| 45 |
+
// constructor parameters and operands/results of addition/subtraction).
|
| 46 |
+
using diff_t = std::int_fast64_t;
|
| 47 |
+
|
| 48 |
+
namespace detail {
|
| 49 |
+
|
| 50 |
+
// Type aliases that indicate normalized argument values.
|
| 51 |
+
using month_t = std::int_fast8_t; // [1:12]
|
| 52 |
+
using day_t = std::int_fast8_t; // [1:31]
|
| 53 |
+
using hour_t = std::int_fast8_t; // [0:23]
|
| 54 |
+
using minute_t = std::int_fast8_t; // [0:59]
|
| 55 |
+
using second_t = std::int_fast8_t; // [0:59]
|
| 56 |
+
|
| 57 |
+
// Normalized civil-time fields: Y-M-D HH:MM:SS.
|
| 58 |
+
struct fields {
|
| 59 |
+
CONSTEXPR_M fields(year_t year, month_t month, day_t day, hour_t hour,
|
| 60 |
+
minute_t minute, second_t second)
|
| 61 |
+
: y(year), m(month), d(day), hh(hour), mm(minute), ss(second) {}
|
| 62 |
+
std::int_least64_t y;
|
| 63 |
+
std::int_least8_t m;
|
| 64 |
+
std::int_least8_t d;
|
| 65 |
+
std::int_least8_t hh;
|
| 66 |
+
std::int_least8_t mm;
|
| 67 |
+
std::int_least8_t ss;
|
| 68 |
+
};
|
| 69 |
+
|
| 70 |
+
struct second_tag {};
|
| 71 |
+
struct minute_tag : second_tag {};
|
| 72 |
+
struct hour_tag : minute_tag {};
|
| 73 |
+
struct day_tag : hour_tag {};
|
| 74 |
+
struct month_tag : day_tag {};
|
| 75 |
+
struct year_tag : month_tag {};
|
| 76 |
+
|
| 77 |
+
////////////////////////////////////////////////////////////////////////
|
| 78 |
+
|
| 79 |
+
// Field normalization (without avoidable overflow).
|
| 80 |
+
|
| 81 |
+
namespace impl {
|
| 82 |
+
|
| 83 |
+
CONSTEXPR_F bool is_leap_year(year_t y) noexcept {
|
| 84 |
+
return y % 4 == 0 && (y % 100 != 0 || y % 400 == 0);
|
| 85 |
+
}
|
| 86 |
+
CONSTEXPR_F int year_index(year_t y, month_t m) noexcept {
|
| 87 |
+
const int yi = static_cast<int>((y + (m > 2)) % 400);
|
| 88 |
+
return yi < 0 ? yi + 400 : yi;
|
| 89 |
+
}
|
| 90 |
+
CONSTEXPR_F int days_per_century(int yi) noexcept {
|
| 91 |
+
return 36524 + (yi == 0 || yi > 300);
|
| 92 |
+
}
|
| 93 |
+
CONSTEXPR_F int days_per_4years(int yi) noexcept {
|
| 94 |
+
return 1460 + (yi == 0 || yi > 300 || (yi - 1) % 100 < 96);
|
| 95 |
+
}
|
| 96 |
+
CONSTEXPR_F int days_per_year(year_t y, month_t m) noexcept {
|
| 97 |
+
return is_leap_year(y + (m > 2)) ? 366 : 365;
|
| 98 |
+
}
|
| 99 |
+
CONSTEXPR_F int days_per_month(year_t y, month_t m) noexcept {
|
| 100 |
+
CONSTEXPR_D int k_days_per_month[1 + 12] = {
|
| 101 |
+
-1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 // non leap year
|
| 102 |
+
};
|
| 103 |
+
return k_days_per_month[m] + (m == 2 && is_leap_year(y));
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
CONSTEXPR_F fields n_day(year_t y, month_t m, diff_t d, diff_t cd, hour_t hh,
|
| 107 |
+
minute_t mm, second_t ss) noexcept {
|
| 108 |
+
year_t ey = y % 400;
|
| 109 |
+
const year_t oey = ey;
|
| 110 |
+
ey += (cd / 146097) * 400;
|
| 111 |
+
cd %= 146097;
|
| 112 |
+
if (cd < 0) {
|
| 113 |
+
ey -= 400;
|
| 114 |
+
cd += 146097;
|
| 115 |
+
}
|
| 116 |
+
ey += (d / 146097) * 400;
|
| 117 |
+
d = d % 146097 + cd;
|
| 118 |
+
if (d > 0) {
|
| 119 |
+
if (d > 146097) {
|
| 120 |
+
ey += 400;
|
| 121 |
+
d -= 146097;
|
| 122 |
+
}
|
| 123 |
+
} else {
|
| 124 |
+
if (d > -365) {
|
| 125 |
+
// We often hit the previous year when stepping a civil time backwards,
|
| 126 |
+
// so special case it to avoid counting up by 100/4/1-year chunks.
|
| 127 |
+
ey -= 1;
|
| 128 |
+
d += days_per_year(ey, m);
|
| 129 |
+
} else {
|
| 130 |
+
ey -= 400;
|
| 131 |
+
d += 146097;
|
| 132 |
+
}
|
| 133 |
+
}
|
| 134 |
+
if (d > 365) {
|
| 135 |
+
int yi = year_index(ey, m); // Index into Gregorian 400 year cycle.
|
| 136 |
+
for (;;) {
|
| 137 |
+
int n = days_per_century(yi);
|
| 138 |
+
if (d <= n) break;
|
| 139 |
+
d -= n;
|
| 140 |
+
ey += 100;
|
| 141 |
+
yi += 100;
|
| 142 |
+
if (yi >= 400) yi -= 400;
|
| 143 |
+
}
|
| 144 |
+
for (;;) {
|
| 145 |
+
int n = days_per_4years(yi);
|
| 146 |
+
if (d <= n) break;
|
| 147 |
+
d -= n;
|
| 148 |
+
ey += 4;
|
| 149 |
+
yi += 4;
|
| 150 |
+
if (yi >= 400) yi -= 400;
|
| 151 |
+
}
|
| 152 |
+
for (;;) {
|
| 153 |
+
int n = days_per_year(ey, m);
|
| 154 |
+
if (d <= n) break;
|
| 155 |
+
d -= n;
|
| 156 |
+
++ey;
|
| 157 |
+
}
|
| 158 |
+
}
|
| 159 |
+
if (d > 28) {
|
| 160 |
+
for (;;) {
|
| 161 |
+
int n = days_per_month(ey, m);
|
| 162 |
+
if (d <= n) break;
|
| 163 |
+
d -= n;
|
| 164 |
+
if (++m > 12) {
|
| 165 |
+
++ey;
|
| 166 |
+
m = 1;
|
| 167 |
+
}
|
| 168 |
+
}
|
| 169 |
+
}
|
| 170 |
+
return fields(y + (ey - oey), m, static_cast<day_t>(d), hh, mm, ss);
|
| 171 |
+
}
|
| 172 |
+
CONSTEXPR_F fields n_mon(year_t y, diff_t m, diff_t d, diff_t cd, hour_t hh,
|
| 173 |
+
minute_t mm, second_t ss) noexcept {
|
| 174 |
+
if (m != 12) {
|
| 175 |
+
y += m / 12;
|
| 176 |
+
m %= 12;
|
| 177 |
+
if (m <= 0) {
|
| 178 |
+
y -= 1;
|
| 179 |
+
m += 12;
|
| 180 |
+
}
|
| 181 |
+
}
|
| 182 |
+
return n_day(y, static_cast<month_t>(m), d, cd, hh, mm, ss);
|
| 183 |
+
}
|
| 184 |
+
CONSTEXPR_F fields n_hour(year_t y, diff_t m, diff_t d, diff_t cd, diff_t hh,
|
| 185 |
+
minute_t mm, second_t ss) noexcept {
|
| 186 |
+
cd += hh / 24;
|
| 187 |
+
hh %= 24;
|
| 188 |
+
if (hh < 0) {
|
| 189 |
+
cd -= 1;
|
| 190 |
+
hh += 24;
|
| 191 |
+
}
|
| 192 |
+
return n_mon(y, m, d, cd, static_cast<hour_t>(hh), mm, ss);
|
| 193 |
+
}
|
| 194 |
+
CONSTEXPR_F fields n_min(year_t y, diff_t m, diff_t d, diff_t hh, diff_t ch,
|
| 195 |
+
diff_t mm, second_t ss) noexcept {
|
| 196 |
+
ch += mm / 60;
|
| 197 |
+
mm %= 60;
|
| 198 |
+
if (mm < 0) {
|
| 199 |
+
ch -= 1;
|
| 200 |
+
mm += 60;
|
| 201 |
+
}
|
| 202 |
+
return n_hour(y, m, d, hh / 24 + ch / 24, hh % 24 + ch % 24,
|
| 203 |
+
static_cast<minute_t>(mm), ss);
|
| 204 |
+
}
|
| 205 |
+
CONSTEXPR_F fields n_sec(year_t y, diff_t m, diff_t d, diff_t hh, diff_t mm,
|
| 206 |
+
diff_t ss) noexcept {
|
| 207 |
+
// Optimization for when (non-constexpr) fields are already normalized.
|
| 208 |
+
if (0 <= ss && ss < 60) {
|
| 209 |
+
const second_t nss = static_cast<second_t>(ss);
|
| 210 |
+
if (0 <= mm && mm < 60) {
|
| 211 |
+
const minute_t nmm = static_cast<minute_t>(mm);
|
| 212 |
+
if (0 <= hh && hh < 24) {
|
| 213 |
+
const hour_t nhh = static_cast<hour_t>(hh);
|
| 214 |
+
if (1 <= d && d <= 28 && 1 <= m && m <= 12) {
|
| 215 |
+
const day_t nd = static_cast<day_t>(d);
|
| 216 |
+
const month_t nm = static_cast<month_t>(m);
|
| 217 |
+
return fields(y, nm, nd, nhh, nmm, nss);
|
| 218 |
+
}
|
| 219 |
+
return n_mon(y, m, d, 0, nhh, nmm, nss);
|
| 220 |
+
}
|
| 221 |
+
return n_hour(y, m, d, hh / 24, hh % 24, nmm, nss);
|
| 222 |
+
}
|
| 223 |
+
return n_min(y, m, d, hh, mm / 60, mm % 60, nss);
|
| 224 |
+
}
|
| 225 |
+
diff_t cm = ss / 60;
|
| 226 |
+
ss %= 60;
|
| 227 |
+
if (ss < 0) {
|
| 228 |
+
cm -= 1;
|
| 229 |
+
ss += 60;
|
| 230 |
+
}
|
| 231 |
+
return n_min(y, m, d, hh, mm / 60 + cm / 60, mm % 60 + cm % 60,
|
| 232 |
+
static_cast<second_t>(ss));
|
| 233 |
+
}
|
| 234 |
+
|
| 235 |
+
} // namespace impl
|
| 236 |
+
|
| 237 |
+
////////////////////////////////////////////////////////////////////////
|
| 238 |
+
|
| 239 |
+
// Increments the indicated (normalized) field by "n".
|
| 240 |
+
CONSTEXPR_F fields step(second_tag, fields f, diff_t n) noexcept {
|
| 241 |
+
return impl::n_sec(f.y, f.m, f.d, f.hh, f.mm + n / 60, f.ss + n % 60);
|
| 242 |
+
}
|
| 243 |
+
CONSTEXPR_F fields step(minute_tag, fields f, diff_t n) noexcept {
|
| 244 |
+
return impl::n_min(f.y, f.m, f.d, f.hh + n / 60, 0, f.mm + n % 60, f.ss);
|
| 245 |
+
}
|
| 246 |
+
CONSTEXPR_F fields step(hour_tag, fields f, diff_t n) noexcept {
|
| 247 |
+
return impl::n_hour(f.y, f.m, f.d + n / 24, 0, f.hh + n % 24, f.mm, f.ss);
|
| 248 |
+
}
|
| 249 |
+
CONSTEXPR_F fields step(day_tag, fields f, diff_t n) noexcept {
|
| 250 |
+
return impl::n_day(f.y, f.m, f.d, n, f.hh, f.mm, f.ss);
|
| 251 |
+
}
|
| 252 |
+
CONSTEXPR_F fields step(month_tag, fields f, diff_t n) noexcept {
|
| 253 |
+
return impl::n_mon(f.y + n / 12, f.m + n % 12, f.d, 0, f.hh, f.mm, f.ss);
|
| 254 |
+
}
|
| 255 |
+
CONSTEXPR_F fields step(year_tag, fields f, diff_t n) noexcept {
|
| 256 |
+
return fields(f.y + n, f.m, f.d, f.hh, f.mm, f.ss);
|
| 257 |
+
}
|
| 258 |
+
|
| 259 |
+
////////////////////////////////////////////////////////////////////////
|
| 260 |
+
|
| 261 |
+
namespace impl {
|
| 262 |
+
|
| 263 |
+
// Returns (v * f + a) but avoiding intermediate overflow when possible.
|
| 264 |
+
CONSTEXPR_F diff_t scale_add(diff_t v, diff_t f, diff_t a) noexcept {
|
| 265 |
+
return (v < 0) ? ((v + 1) * f + a) - f : ((v - 1) * f + a) + f;
|
| 266 |
+
}
|
| 267 |
+
|
| 268 |
+
// Map a (normalized) Y/M/D to the number of days before/after 1970-01-01.
|
| 269 |
+
// Probably overflows for years outside [-292277022656:292277026595].
|
| 270 |
+
CONSTEXPR_F diff_t ymd_ord(year_t y, month_t m, day_t d) noexcept {
|
| 271 |
+
const diff_t eyear = (m <= 2) ? y - 1 : y;
|
| 272 |
+
const diff_t era = (eyear >= 0 ? eyear : eyear - 399) / 400;
|
| 273 |
+
const diff_t yoe = eyear - era * 400;
|
| 274 |
+
const diff_t doy = (153 * (m + (m > 2 ? -3 : 9)) + 2) / 5 + d - 1;
|
| 275 |
+
const diff_t doe = yoe * 365 + yoe / 4 - yoe / 100 + doy;
|
| 276 |
+
return era * 146097 + doe - 719468;
|
| 277 |
+
}
|
| 278 |
+
|
| 279 |
+
// Returns the difference in days between two normalized Y-M-D tuples.
|
| 280 |
+
// ymd_ord() will encounter integer overflow given extreme year values,
|
| 281 |
+
// yet the difference between two such extreme values may actually be
|
| 282 |
+
// small, so we take a little care to avoid overflow when possible by
|
| 283 |
+
// exploiting the 146097-day cycle.
|
| 284 |
+
CONSTEXPR_F diff_t day_difference(year_t y1, month_t m1, day_t d1, year_t y2,
|
| 285 |
+
month_t m2, day_t d2) noexcept {
|
| 286 |
+
const diff_t a_c4_off = y1 % 400;
|
| 287 |
+
const diff_t b_c4_off = y2 % 400;
|
| 288 |
+
diff_t c4_diff = (y1 - a_c4_off) - (y2 - b_c4_off);
|
| 289 |
+
diff_t delta = ymd_ord(a_c4_off, m1, d1) - ymd_ord(b_c4_off, m2, d2);
|
| 290 |
+
if (c4_diff > 0 && delta < 0) {
|
| 291 |
+
delta += 2 * 146097;
|
| 292 |
+
c4_diff -= 2 * 400;
|
| 293 |
+
} else if (c4_diff < 0 && delta > 0) {
|
| 294 |
+
delta -= 2 * 146097;
|
| 295 |
+
c4_diff += 2 * 400;
|
| 296 |
+
}
|
| 297 |
+
return (c4_diff / 400 * 146097) + delta;
|
| 298 |
+
}
|
| 299 |
+
|
| 300 |
+
} // namespace impl
|
| 301 |
+
|
| 302 |
+
// Returns the difference between fields structs using the indicated unit.
|
| 303 |
+
CONSTEXPR_F diff_t difference(year_tag, fields f1, fields f2) noexcept {
|
| 304 |
+
return f1.y - f2.y;
|
| 305 |
+
}
|
| 306 |
+
CONSTEXPR_F diff_t difference(month_tag, fields f1, fields f2) noexcept {
|
| 307 |
+
return impl::scale_add(difference(year_tag{}, f1, f2), 12, (f1.m - f2.m));
|
| 308 |
+
}
|
| 309 |
+
CONSTEXPR_F diff_t difference(day_tag, fields f1, fields f2) noexcept {
|
| 310 |
+
return impl::day_difference(f1.y, f1.m, f1.d, f2.y, f2.m, f2.d);
|
| 311 |
+
}
|
| 312 |
+
CONSTEXPR_F diff_t difference(hour_tag, fields f1, fields f2) noexcept {
|
| 313 |
+
return impl::scale_add(difference(day_tag{}, f1, f2), 24, (f1.hh - f2.hh));
|
| 314 |
+
}
|
| 315 |
+
CONSTEXPR_F diff_t difference(minute_tag, fields f1, fields f2) noexcept {
|
| 316 |
+
return impl::scale_add(difference(hour_tag{}, f1, f2), 60, (f1.mm - f2.mm));
|
| 317 |
+
}
|
| 318 |
+
CONSTEXPR_F diff_t difference(second_tag, fields f1, fields f2) noexcept {
|
| 319 |
+
return impl::scale_add(difference(minute_tag{}, f1, f2), 60, f1.ss - f2.ss);
|
| 320 |
+
}
|
| 321 |
+
|
| 322 |
+
////////////////////////////////////////////////////////////////////////
|
| 323 |
+
|
| 324 |
+
// Aligns the (normalized) fields struct to the indicated field.
|
| 325 |
+
CONSTEXPR_F fields align(second_tag, fields f) noexcept { return f; }
|
| 326 |
+
CONSTEXPR_F fields align(minute_tag, fields f) noexcept {
|
| 327 |
+
return fields{f.y, f.m, f.d, f.hh, f.mm, 0};
|
| 328 |
+
}
|
| 329 |
+
CONSTEXPR_F fields align(hour_tag, fields f) noexcept {
|
| 330 |
+
return fields{f.y, f.m, f.d, f.hh, 0, 0};
|
| 331 |
+
}
|
| 332 |
+
CONSTEXPR_F fields align(day_tag, fields f) noexcept {
|
| 333 |
+
return fields{f.y, f.m, f.d, 0, 0, 0};
|
| 334 |
+
}
|
| 335 |
+
CONSTEXPR_F fields align(month_tag, fields f) noexcept {
|
| 336 |
+
return fields{f.y, f.m, 1, 0, 0, 0};
|
| 337 |
+
}
|
| 338 |
+
CONSTEXPR_F fields align(year_tag, fields f) noexcept {
|
| 339 |
+
return fields{f.y, 1, 1, 0, 0, 0};
|
| 340 |
+
}
|
| 341 |
+
|
| 342 |
+
////////////////////////////////////////////////////////////////////////
|
| 343 |
+
|
| 344 |
+
namespace impl {
|
| 345 |
+
|
| 346 |
+
template <typename H>
|
| 347 |
+
H AbslHashValueImpl(second_tag, H h, fields f) {
|
| 348 |
+
return H::combine(std::move(h), f.y, f.m, f.d, f.hh, f.mm, f.ss);
|
| 349 |
+
}
|
| 350 |
+
template <typename H>
|
| 351 |
+
H AbslHashValueImpl(minute_tag, H h, fields f) {
|
| 352 |
+
return H::combine(std::move(h), f.y, f.m, f.d, f.hh, f.mm);
|
| 353 |
+
}
|
| 354 |
+
template <typename H>
|
| 355 |
+
H AbslHashValueImpl(hour_tag, H h, fields f) {
|
| 356 |
+
return H::combine(std::move(h), f.y, f.m, f.d, f.hh);
|
| 357 |
+
}
|
| 358 |
+
template <typename H>
|
| 359 |
+
H AbslHashValueImpl(day_tag, H h, fields f) {
|
| 360 |
+
return H::combine(std::move(h), f.y, f.m, f.d);
|
| 361 |
+
}
|
| 362 |
+
template <typename H>
|
| 363 |
+
H AbslHashValueImpl(month_tag, H h, fields f) {
|
| 364 |
+
return H::combine(std::move(h), f.y, f.m);
|
| 365 |
+
}
|
| 366 |
+
template <typename H>
|
| 367 |
+
H AbslHashValueImpl(year_tag, H h, fields f) {
|
| 368 |
+
return H::combine(std::move(h), f.y);
|
| 369 |
+
}
|
| 370 |
+
|
| 371 |
+
} // namespace impl
|
| 372 |
+
|
| 373 |
+
////////////////////////////////////////////////////////////////////////
|
| 374 |
+
|
| 375 |
+
template <typename T>
|
| 376 |
+
class civil_time {
|
| 377 |
+
public:
|
| 378 |
+
explicit CONSTEXPR_M civil_time(year_t y, diff_t m = 1, diff_t d = 1,
|
| 379 |
+
diff_t hh = 0, diff_t mm = 0,
|
| 380 |
+
diff_t ss = 0) noexcept
|
| 381 |
+
: civil_time(impl::n_sec(y, m, d, hh, mm, ss)) {}
|
| 382 |
+
|
| 383 |
+
CONSTEXPR_M civil_time() noexcept : f_{1970, 1, 1, 0, 0, 0} {}
|
| 384 |
+
civil_time(const civil_time&) = default;
|
| 385 |
+
civil_time& operator=(const civil_time&) = default;
|
| 386 |
+
|
| 387 |
+
// Conversion between civil times of different alignment. Conversion to
|
| 388 |
+
// a more precise alignment is allowed implicitly (e.g., day -> hour),
|
| 389 |
+
// but conversion where information is discarded must be explicit
|
| 390 |
+
// (e.g., second -> minute).
|
| 391 |
+
template <typename U, typename S>
|
| 392 |
+
using preserves_data =
|
| 393 |
+
typename std::enable_if<std::is_base_of<U, S>::value>::type;
|
| 394 |
+
template <typename U>
|
| 395 |
+
CONSTEXPR_M civil_time(const civil_time<U>& ct,
|
| 396 |
+
preserves_data<T, U>* = nullptr) noexcept
|
| 397 |
+
: civil_time(ct.f_) {}
|
| 398 |
+
template <typename U>
|
| 399 |
+
explicit CONSTEXPR_M civil_time(const civil_time<U>& ct,
|
| 400 |
+
preserves_data<U, T>* = nullptr) noexcept
|
| 401 |
+
: civil_time(ct.f_) {}
|
| 402 |
+
|
| 403 |
+
// Factories for the maximum/minimum representable civil_time.
|
| 404 |
+
static CONSTEXPR_F civil_time(max)() {
|
| 405 |
+
const auto max_year = (std::numeric_limits<std::int_least64_t>::max)();
|
| 406 |
+
return civil_time(max_year, 12, 31, 23, 59, 59);
|
| 407 |
+
}
|
| 408 |
+
static CONSTEXPR_F civil_time(min)() {
|
| 409 |
+
const auto min_year = (std::numeric_limits<std::int_least64_t>::min)();
|
| 410 |
+
return civil_time(min_year, 1, 1, 0, 0, 0);
|
| 411 |
+
}
|
| 412 |
+
|
| 413 |
+
// Field accessors. Note: All but year() return an int.
|
| 414 |
+
CONSTEXPR_M year_t year() const noexcept { return f_.y; }
|
| 415 |
+
CONSTEXPR_M int month() const noexcept { return f_.m; }
|
| 416 |
+
CONSTEXPR_M int day() const noexcept { return f_.d; }
|
| 417 |
+
CONSTEXPR_M int hour() const noexcept { return f_.hh; }
|
| 418 |
+
CONSTEXPR_M int minute() const noexcept { return f_.mm; }
|
| 419 |
+
CONSTEXPR_M int second() const noexcept { return f_.ss; }
|
| 420 |
+
|
| 421 |
+
// Assigning arithmetic.
|
| 422 |
+
CONSTEXPR_M civil_time& operator+=(diff_t n) noexcept {
|
| 423 |
+
return *this = *this + n;
|
| 424 |
+
}
|
| 425 |
+
CONSTEXPR_M civil_time& operator-=(diff_t n) noexcept {
|
| 426 |
+
return *this = *this - n;
|
| 427 |
+
}
|
| 428 |
+
CONSTEXPR_M civil_time& operator++() noexcept { return *this += 1; }
|
| 429 |
+
CONSTEXPR_M civil_time operator++(int) noexcept {
|
| 430 |
+
const civil_time a = *this;
|
| 431 |
+
++*this;
|
| 432 |
+
return a;
|
| 433 |
+
}
|
| 434 |
+
CONSTEXPR_M civil_time& operator--() noexcept { return *this -= 1; }
|
| 435 |
+
CONSTEXPR_M civil_time operator--(int) noexcept {
|
| 436 |
+
const civil_time a = *this;
|
| 437 |
+
--*this;
|
| 438 |
+
return a;
|
| 439 |
+
}
|
| 440 |
+
|
| 441 |
+
// Binary arithmetic operators.
|
| 442 |
+
friend CONSTEXPR_F civil_time operator+(civil_time a, diff_t n) noexcept {
|
| 443 |
+
return civil_time(step(T{}, a.f_, n));
|
| 444 |
+
}
|
| 445 |
+
friend CONSTEXPR_F civil_time operator+(diff_t n, civil_time a) noexcept {
|
| 446 |
+
return a + n;
|
| 447 |
+
}
|
| 448 |
+
friend CONSTEXPR_F civil_time operator-(civil_time a, diff_t n) noexcept {
|
| 449 |
+
return n != (std::numeric_limits<diff_t>::min)()
|
| 450 |
+
? civil_time(step(T{}, a.f_, -n))
|
| 451 |
+
: civil_time(step(T{}, step(T{}, a.f_, -(n + 1)), 1));
|
| 452 |
+
}
|
| 453 |
+
friend CONSTEXPR_F diff_t operator-(civil_time lhs, civil_time rhs) noexcept {
|
| 454 |
+
return difference(T{}, lhs.f_, rhs.f_);
|
| 455 |
+
}
|
| 456 |
+
|
| 457 |
+
template <typename H>
|
| 458 |
+
friend H AbslHashValue(H h, civil_time a) {
|
| 459 |
+
return impl::AbslHashValueImpl(T{}, std::move(h), a.f_);
|
| 460 |
+
}
|
| 461 |
+
|
| 462 |
+
private:
|
| 463 |
+
// All instantiations of this template are allowed to call the following
|
| 464 |
+
// private constructor and access the private fields member.
|
| 465 |
+
template <typename U>
|
| 466 |
+
friend class civil_time;
|
| 467 |
+
|
| 468 |
+
// The designated constructor that all others eventually call.
|
| 469 |
+
explicit CONSTEXPR_M civil_time(fields f) noexcept : f_(align(T{}, f)) {}
|
| 470 |
+
|
| 471 |
+
fields f_;
|
| 472 |
+
};
|
| 473 |
+
|
| 474 |
+
// Disallows difference between differently aligned types.
|
| 475 |
+
// auto n = civil_day(...) - civil_hour(...); // would be confusing.
|
| 476 |
+
template <typename T, typename U>
|
| 477 |
+
CONSTEXPR_F diff_t operator-(civil_time<T>, civil_time<U>) = delete;
|
| 478 |
+
|
| 479 |
+
using civil_year = civil_time<year_tag>;
|
| 480 |
+
using civil_month = civil_time<month_tag>;
|
| 481 |
+
using civil_day = civil_time<day_tag>;
|
| 482 |
+
using civil_hour = civil_time<hour_tag>;
|
| 483 |
+
using civil_minute = civil_time<minute_tag>;
|
| 484 |
+
using civil_second = civil_time<second_tag>;
|
| 485 |
+
|
| 486 |
+
////////////////////////////////////////////////////////////////////////
|
| 487 |
+
|
| 488 |
+
// Relational operators that work with differently aligned objects.
|
| 489 |
+
// Always compares all six fields.
|
| 490 |
+
template <typename T1, typename T2>
|
| 491 |
+
CONSTEXPR_F bool operator<(const civil_time<T1>& lhs,
|
| 492 |
+
const civil_time<T2>& rhs) noexcept {
|
| 493 |
+
return (
|
| 494 |
+
lhs.year() < rhs.year() ||
|
| 495 |
+
(lhs.year() == rhs.year() &&
|
| 496 |
+
(lhs.month() < rhs.month() ||
|
| 497 |
+
(lhs.month() == rhs.month() &&
|
| 498 |
+
(lhs.day() < rhs.day() || (lhs.day() == rhs.day() &&
|
| 499 |
+
(lhs.hour() < rhs.hour() ||
|
| 500 |
+
(lhs.hour() == rhs.hour() &&
|
| 501 |
+
(lhs.minute() < rhs.minute() ||
|
| 502 |
+
(lhs.minute() == rhs.minute() &&
|
| 503 |
+
(lhs.second() < rhs.second())))))))))));
|
| 504 |
+
}
|
| 505 |
+
template <typename T1, typename T2>
|
| 506 |
+
CONSTEXPR_F bool operator<=(const civil_time<T1>& lhs,
|
| 507 |
+
const civil_time<T2>& rhs) noexcept {
|
| 508 |
+
return !(rhs < lhs);
|
| 509 |
+
}
|
| 510 |
+
template <typename T1, typename T2>
|
| 511 |
+
CONSTEXPR_F bool operator>=(const civil_time<T1>& lhs,
|
| 512 |
+
const civil_time<T2>& rhs) noexcept {
|
| 513 |
+
return !(lhs < rhs);
|
| 514 |
+
}
|
| 515 |
+
template <typename T1, typename T2>
|
| 516 |
+
CONSTEXPR_F bool operator>(const civil_time<T1>& lhs,
|
| 517 |
+
const civil_time<T2>& rhs) noexcept {
|
| 518 |
+
return rhs < lhs;
|
| 519 |
+
}
|
| 520 |
+
template <typename T1, typename T2>
|
| 521 |
+
CONSTEXPR_F bool operator==(const civil_time<T1>& lhs,
|
| 522 |
+
const civil_time<T2>& rhs) noexcept {
|
| 523 |
+
return lhs.year() == rhs.year() && lhs.month() == rhs.month() &&
|
| 524 |
+
lhs.day() == rhs.day() && lhs.hour() == rhs.hour() &&
|
| 525 |
+
lhs.minute() == rhs.minute() && lhs.second() == rhs.second();
|
| 526 |
+
}
|
| 527 |
+
template <typename T1, typename T2>
|
| 528 |
+
CONSTEXPR_F bool operator!=(const civil_time<T1>& lhs,
|
| 529 |
+
const civil_time<T2>& rhs) noexcept {
|
| 530 |
+
return !(lhs == rhs);
|
| 531 |
+
}
|
| 532 |
+
|
| 533 |
+
////////////////////////////////////////////////////////////////////////
|
| 534 |
+
|
| 535 |
+
enum class weekday {
|
| 536 |
+
monday,
|
| 537 |
+
tuesday,
|
| 538 |
+
wednesday,
|
| 539 |
+
thursday,
|
| 540 |
+
friday,
|
| 541 |
+
saturday,
|
| 542 |
+
sunday,
|
| 543 |
+
};
|
| 544 |
+
|
| 545 |
+
CONSTEXPR_F weekday get_weekday(const civil_second& cs) noexcept {
|
| 546 |
+
CONSTEXPR_D weekday k_weekday_by_mon_off[13] = {
|
| 547 |
+
weekday::monday, weekday::tuesday, weekday::wednesday,
|
| 548 |
+
weekday::thursday, weekday::friday, weekday::saturday,
|
| 549 |
+
weekday::sunday, weekday::monday, weekday::tuesday,
|
| 550 |
+
weekday::wednesday, weekday::thursday, weekday::friday,
|
| 551 |
+
weekday::saturday,
|
| 552 |
+
};
|
| 553 |
+
CONSTEXPR_D int k_weekday_offsets[1 + 12] = {
|
| 554 |
+
-1, 0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4,
|
| 555 |
+
};
|
| 556 |
+
year_t wd = 2400 + (cs.year() % 400) - (cs.month() < 3);
|
| 557 |
+
wd += wd / 4 - wd / 100 + wd / 400;
|
| 558 |
+
wd += k_weekday_offsets[cs.month()] + cs.day();
|
| 559 |
+
return k_weekday_by_mon_off[wd % 7 + 6];
|
| 560 |
+
}
|
| 561 |
+
|
| 562 |
+
////////////////////////////////////////////////////////////////////////
|
| 563 |
+
|
| 564 |
+
CONSTEXPR_F civil_day next_weekday(civil_day cd, weekday wd) noexcept {
|
| 565 |
+
CONSTEXPR_D weekday k_weekdays_forw[14] = {
|
| 566 |
+
weekday::monday, weekday::tuesday, weekday::wednesday,
|
| 567 |
+
weekday::thursday, weekday::friday, weekday::saturday,
|
| 568 |
+
weekday::sunday, weekday::monday, weekday::tuesday,
|
| 569 |
+
weekday::wednesday, weekday::thursday, weekday::friday,
|
| 570 |
+
weekday::saturday, weekday::sunday,
|
| 571 |
+
};
|
| 572 |
+
weekday base = get_weekday(cd);
|
| 573 |
+
for (int i = 0;; ++i) {
|
| 574 |
+
if (base == k_weekdays_forw[i]) {
|
| 575 |
+
for (int j = i + 1;; ++j) {
|
| 576 |
+
if (wd == k_weekdays_forw[j]) {
|
| 577 |
+
return cd + (j - i);
|
| 578 |
+
}
|
| 579 |
+
}
|
| 580 |
+
}
|
| 581 |
+
}
|
| 582 |
+
}
|
| 583 |
+
|
| 584 |
+
CONSTEXPR_F civil_day prev_weekday(civil_day cd, weekday wd) noexcept {
|
| 585 |
+
CONSTEXPR_D weekday k_weekdays_back[14] = {
|
| 586 |
+
weekday::sunday, weekday::saturday, weekday::friday,
|
| 587 |
+
weekday::thursday, weekday::wednesday, weekday::tuesday,
|
| 588 |
+
weekday::monday, weekday::sunday, weekday::saturday,
|
| 589 |
+
weekday::friday, weekday::thursday, weekday::wednesday,
|
| 590 |
+
weekday::tuesday, weekday::monday,
|
| 591 |
+
};
|
| 592 |
+
weekday base = get_weekday(cd);
|
| 593 |
+
for (int i = 0;; ++i) {
|
| 594 |
+
if (base == k_weekdays_back[i]) {
|
| 595 |
+
for (int j = i + 1;; ++j) {
|
| 596 |
+
if (wd == k_weekdays_back[j]) {
|
| 597 |
+
return cd - (j - i);
|
| 598 |
+
}
|
| 599 |
+
}
|
| 600 |
+
}
|
| 601 |
+
}
|
| 602 |
+
}
|
| 603 |
+
|
| 604 |
+
CONSTEXPR_F int get_yearday(const civil_second& cs) noexcept {
|
| 605 |
+
CONSTEXPR_D int k_month_offsets[1 + 12] = {
|
| 606 |
+
-1, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334,
|
| 607 |
+
};
|
| 608 |
+
const int feb29 = (cs.month() > 2 && impl::is_leap_year(cs.year()));
|
| 609 |
+
return k_month_offsets[cs.month()] + feb29 + cs.day();
|
| 610 |
+
}
|
| 611 |
+
|
| 612 |
+
////////////////////////////////////////////////////////////////////////
|
| 613 |
+
|
| 614 |
+
std::ostream& operator<<(std::ostream& os, const civil_year& y);
|
| 615 |
+
std::ostream& operator<<(std::ostream& os, const civil_month& m);
|
| 616 |
+
std::ostream& operator<<(std::ostream& os, const civil_day& d);
|
| 617 |
+
std::ostream& operator<<(std::ostream& os, const civil_hour& h);
|
| 618 |
+
std::ostream& operator<<(std::ostream& os, const civil_minute& m);
|
| 619 |
+
std::ostream& operator<<(std::ostream& os, const civil_second& s);
|
| 620 |
+
std::ostream& operator<<(std::ostream& os, weekday wd);
|
| 621 |
+
|
| 622 |
+
} // namespace detail
|
| 623 |
+
} // namespace cctz
|
| 624 |
+
} // namespace time_internal
|
| 625 |
+
ABSL_NAMESPACE_END
|
| 626 |
+
} // namespace absl
|
| 627 |
+
|
| 628 |
+
#undef CONSTEXPR_M
|
| 629 |
+
#undef CONSTEXPR_F
|
| 630 |
+
#undef CONSTEXPR_D
|
| 631 |
+
|
| 632 |
+
#endif // ABSL_TIME_INTERNAL_CCTZ_CIVIL_TIME_DETAIL_H_
|
miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/absl/time/internal/cctz/include/cctz/time_zone.h
ADDED
|
@@ -0,0 +1,459 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2016 Google Inc. All Rights Reserved.
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// https://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
|
| 15 |
+
// A library for translating between absolute times (represented by
|
| 16 |
+
// std::chrono::time_points of the std::chrono::system_clock) and civil
|
| 17 |
+
// times (represented by cctz::civil_second) using the rules defined by
|
| 18 |
+
// a time zone (cctz::time_zone).
|
| 19 |
+
|
| 20 |
+
#ifndef ABSL_TIME_INTERNAL_CCTZ_TIME_ZONE_H_
|
| 21 |
+
#define ABSL_TIME_INTERNAL_CCTZ_TIME_ZONE_H_
|
| 22 |
+
|
| 23 |
+
#include <chrono>
|
| 24 |
+
#include <cstdint>
|
| 25 |
+
#include <limits>
|
| 26 |
+
#include <string>
|
| 27 |
+
#include <utility>
|
| 28 |
+
|
| 29 |
+
#include "absl/base/config.h"
|
| 30 |
+
#include "absl/time/internal/cctz/include/cctz/civil_time.h"
|
| 31 |
+
|
| 32 |
+
namespace absl {
|
| 33 |
+
ABSL_NAMESPACE_BEGIN
|
| 34 |
+
namespace time_internal {
|
| 35 |
+
namespace cctz {
|
| 36 |
+
|
| 37 |
+
// Convenience aliases. Not intended as public API points.
|
| 38 |
+
template <typename D>
|
| 39 |
+
using time_point = std::chrono::time_point<std::chrono::system_clock, D>;
|
| 40 |
+
using seconds = std::chrono::duration<std::int_fast64_t>;
|
| 41 |
+
using sys_seconds = seconds; // Deprecated. Use cctz::seconds instead.
|
| 42 |
+
|
| 43 |
+
namespace detail {
|
| 44 |
+
template <typename D>
|
| 45 |
+
std::pair<time_point<seconds>, D> split_seconds(const time_point<D>& tp);
|
| 46 |
+
std::pair<time_point<seconds>, seconds> split_seconds(
|
| 47 |
+
const time_point<seconds>& tp);
|
| 48 |
+
} // namespace detail
|
| 49 |
+
|
| 50 |
+
// cctz::time_zone is an opaque, small, value-type class representing a
|
| 51 |
+
// geo-political region within which particular rules are used for mapping
|
| 52 |
+
// between absolute and civil times. Time zones are named using the TZ
|
| 53 |
+
// identifiers from the IANA Time Zone Database, such as "America/Los_Angeles"
|
| 54 |
+
// or "Australia/Sydney". Time zones are created from factory functions such
|
| 55 |
+
// as load_time_zone(). Note: strings like "PST" and "EDT" are not valid TZ
|
| 56 |
+
// identifiers.
|
| 57 |
+
//
|
| 58 |
+
// Example:
|
| 59 |
+
// cctz::time_zone utc = cctz::utc_time_zone();
|
| 60 |
+
// cctz::time_zone pst = cctz::fixed_time_zone(std::chrono::hours(-8));
|
| 61 |
+
// cctz::time_zone loc = cctz::local_time_zone();
|
| 62 |
+
// cctz::time_zone lax;
|
| 63 |
+
// if (!cctz::load_time_zone("America/Los_Angeles", &lax)) { ... }
|
| 64 |
+
//
|
| 65 |
+
// See also:
|
| 66 |
+
// - http://www.iana.org/time-zones
|
| 67 |
+
// - https://en.wikipedia.org/wiki/Zoneinfo
|
| 68 |
+
class time_zone {
|
| 69 |
+
public:
|
| 70 |
+
time_zone() : time_zone(nullptr) {} // Equivalent to UTC
|
| 71 |
+
time_zone(const time_zone&) = default;
|
| 72 |
+
time_zone& operator=(const time_zone&) = default;
|
| 73 |
+
|
| 74 |
+
std::string name() const;
|
| 75 |
+
|
| 76 |
+
// An absolute_lookup represents the civil time (cctz::civil_second) within
|
| 77 |
+
// this time_zone at the given absolute time (time_point). There are
|
| 78 |
+
// additionally a few other fields that may be useful when working with
|
| 79 |
+
// older APIs, such as std::tm.
|
| 80 |
+
//
|
| 81 |
+
// Example:
|
| 82 |
+
// const cctz::time_zone tz = ...
|
| 83 |
+
// const auto tp = std::chrono::system_clock::now();
|
| 84 |
+
// const cctz::time_zone::absolute_lookup al = tz.lookup(tp);
|
| 85 |
+
struct absolute_lookup {
|
| 86 |
+
civil_second cs;
|
| 87 |
+
// Note: The following fields exist for backward compatibility with older
|
| 88 |
+
// APIs. Accessing these fields directly is a sign of imprudent logic in
|
| 89 |
+
// the calling code. Modern time-related code should only access this data
|
| 90 |
+
// indirectly by way of cctz::format().
|
| 91 |
+
int offset; // civil seconds east of UTC
|
| 92 |
+
bool is_dst; // is offset non-standard?
|
| 93 |
+
const char* abbr; // time-zone abbreviation (e.g., "PST")
|
| 94 |
+
};
|
| 95 |
+
absolute_lookup lookup(const time_point<seconds>& tp) const;
|
| 96 |
+
template <typename D>
|
| 97 |
+
absolute_lookup lookup(const time_point<D>& tp) const {
|
| 98 |
+
return lookup(detail::split_seconds(tp).first);
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
// A civil_lookup represents the absolute time(s) (time_point) that
|
| 102 |
+
// correspond to the given civil time (cctz::civil_second) within this
|
| 103 |
+
// time_zone. Usually the given civil time represents a unique instant
|
| 104 |
+
// in time, in which case the conversion is unambiguous. However,
|
| 105 |
+
// within this time zone, the given civil time may be skipped (e.g.,
|
| 106 |
+
// during a positive UTC offset shift), or repeated (e.g., during a
|
| 107 |
+
// negative UTC offset shift). To account for these possibilities,
|
| 108 |
+
// civil_lookup is richer than just a single time_point.
|
| 109 |
+
//
|
| 110 |
+
// In all cases the civil_lookup::kind enum will indicate the nature
|
| 111 |
+
// of the given civil-time argument, and the pre, trans, and post
|
| 112 |
+
// members will give the absolute time answers using the pre-transition
|
| 113 |
+
// offset, the transition point itself, and the post-transition offset,
|
| 114 |
+
// respectively (all three times are equal if kind == UNIQUE). If any
|
| 115 |
+
// of these three absolute times is outside the representable range of a
|
| 116 |
+
// time_point<seconds> the field is set to its maximum/minimum value.
|
| 117 |
+
//
|
| 118 |
+
// Example:
|
| 119 |
+
// cctz::time_zone lax;
|
| 120 |
+
// if (!cctz::load_time_zone("America/Los_Angeles", &lax)) { ... }
|
| 121 |
+
//
|
| 122 |
+
// // A unique civil time.
|
| 123 |
+
// auto jan01 = lax.lookup(cctz::civil_second(2011, 1, 1, 0, 0, 0));
|
| 124 |
+
// // jan01.kind == cctz::time_zone::civil_lookup::UNIQUE
|
| 125 |
+
// // jan01.pre is 2011/01/01 00:00:00 -0800
|
| 126 |
+
// // jan01.trans is 2011/01/01 00:00:00 -0800
|
| 127 |
+
// // jan01.post is 2011/01/01 00:00:00 -0800
|
| 128 |
+
//
|
| 129 |
+
// // A Spring DST transition, when there is a gap in civil time.
|
| 130 |
+
// auto mar13 = lax.lookup(cctz::civil_second(2011, 3, 13, 2, 15, 0));
|
| 131 |
+
// // mar13.kind == cctz::time_zone::civil_lookup::SKIPPED
|
| 132 |
+
// // mar13.pre is 2011/03/13 03:15:00 -0700
|
| 133 |
+
// // mar13.trans is 2011/03/13 03:00:00 -0700
|
| 134 |
+
// // mar13.post is 2011/03/13 01:15:00 -0800
|
| 135 |
+
//
|
| 136 |
+
// // A Fall DST transition, when civil times are repeated.
|
| 137 |
+
// auto nov06 = lax.lookup(cctz::civil_second(2011, 11, 6, 1, 15, 0));
|
| 138 |
+
// // nov06.kind == cctz::time_zone::civil_lookup::REPEATED
|
| 139 |
+
// // nov06.pre is 2011/11/06 01:15:00 -0700
|
| 140 |
+
// // nov06.trans is 2011/11/06 01:00:00 -0800
|
| 141 |
+
// // nov06.post is 2011/11/06 01:15:00 -0800
|
| 142 |
+
struct civil_lookup {
|
| 143 |
+
enum civil_kind {
|
| 144 |
+
UNIQUE, // the civil time was singular (pre == trans == post)
|
| 145 |
+
SKIPPED, // the civil time did not exist (pre >= trans > post)
|
| 146 |
+
REPEATED, // the civil time was ambiguous (pre < trans <= post)
|
| 147 |
+
} kind;
|
| 148 |
+
time_point<seconds> pre; // uses the pre-transition offset
|
| 149 |
+
time_point<seconds> trans; // instant of civil-offset change
|
| 150 |
+
time_point<seconds> post; // uses the post-transition offset
|
| 151 |
+
};
|
| 152 |
+
civil_lookup lookup(const civil_second& cs) const;
|
| 153 |
+
|
| 154 |
+
// Finds the time of the next/previous offset change in this time zone.
|
| 155 |
+
//
|
| 156 |
+
// By definition, next_transition(tp, &trans) returns false when tp has
|
| 157 |
+
// its maximum value, and prev_transition(tp, &trans) returns false
|
| 158 |
+
// when tp has its minimum value. If the zone has no transitions, the
|
| 159 |
+
// result will also be false no matter what the argument.
|
| 160 |
+
//
|
| 161 |
+
// Otherwise, when tp has its minimum value, next_transition(tp, &trans)
|
| 162 |
+
// returns true and sets trans to the first recorded transition. Chains
|
| 163 |
+
// of calls to next_transition()/prev_transition() will eventually return
|
| 164 |
+
// false, but it is unspecified exactly when next_transition(tp, &trans)
|
| 165 |
+
// jumps to false, or what time is set by prev_transition(tp, &trans) for
|
| 166 |
+
// a very distant tp.
|
| 167 |
+
//
|
| 168 |
+
// Note: Enumeration of time-zone transitions is for informational purposes
|
| 169 |
+
// only. Modern time-related code should not care about when offset changes
|
| 170 |
+
// occur.
|
| 171 |
+
//
|
| 172 |
+
// Example:
|
| 173 |
+
// cctz::time_zone nyc;
|
| 174 |
+
// if (!cctz::load_time_zone("America/New_York", &nyc)) { ... }
|
| 175 |
+
// const auto now = std::chrono::system_clock::now();
|
| 176 |
+
// auto tp = cctz::time_point<cctz::seconds>::min();
|
| 177 |
+
// cctz::time_zone::civil_transition trans;
|
| 178 |
+
// while (tp <= now && nyc.next_transition(tp, &trans)) {
|
| 179 |
+
// // transition: trans.from -> trans.to
|
| 180 |
+
// tp = nyc.lookup(trans.to).trans;
|
| 181 |
+
// }
|
| 182 |
+
struct civil_transition {
|
| 183 |
+
civil_second from; // the civil time we jump from
|
| 184 |
+
civil_second to; // the civil time we jump to
|
| 185 |
+
};
|
| 186 |
+
bool next_transition(const time_point<seconds>& tp,
|
| 187 |
+
civil_transition* trans) const;
|
| 188 |
+
template <typename D>
|
| 189 |
+
bool next_transition(const time_point<D>& tp, civil_transition* trans) const {
|
| 190 |
+
return next_transition(detail::split_seconds(tp).first, trans);
|
| 191 |
+
}
|
| 192 |
+
bool prev_transition(const time_point<seconds>& tp,
|
| 193 |
+
civil_transition* trans) const;
|
| 194 |
+
template <typename D>
|
| 195 |
+
bool prev_transition(const time_point<D>& tp, civil_transition* trans) const {
|
| 196 |
+
return prev_transition(detail::split_seconds(tp).first, trans);
|
| 197 |
+
}
|
| 198 |
+
|
| 199 |
+
// version() and description() provide additional information about the
|
| 200 |
+
// time zone. The content of each of the returned strings is unspecified,
|
| 201 |
+
// however, when the IANA Time Zone Database is the underlying data source
|
| 202 |
+
// the version() string will be in the familar form (e.g, "2018e") or
|
| 203 |
+
// empty when unavailable.
|
| 204 |
+
//
|
| 205 |
+
// Note: These functions are for informational or testing purposes only.
|
| 206 |
+
std::string version() const; // empty when unknown
|
| 207 |
+
std::string description() const;
|
| 208 |
+
|
| 209 |
+
// Relational operators.
|
| 210 |
+
friend bool operator==(time_zone lhs, time_zone rhs) {
|
| 211 |
+
return &lhs.effective_impl() == &rhs.effective_impl();
|
| 212 |
+
}
|
| 213 |
+
friend bool operator!=(time_zone lhs, time_zone rhs) { return !(lhs == rhs); }
|
| 214 |
+
|
| 215 |
+
template <typename H>
|
| 216 |
+
friend H AbslHashValue(H h, time_zone tz) {
|
| 217 |
+
return H::combine(std::move(h), &tz.effective_impl());
|
| 218 |
+
}
|
| 219 |
+
|
| 220 |
+
class Impl;
|
| 221 |
+
|
| 222 |
+
private:
|
| 223 |
+
explicit time_zone(const Impl* impl) : impl_(impl) {}
|
| 224 |
+
const Impl& effective_impl() const; // handles implicit UTC
|
| 225 |
+
const Impl* impl_;
|
| 226 |
+
};
|
| 227 |
+
|
| 228 |
+
// Loads the named time zone. May perform I/O on the initial load.
|
| 229 |
+
// If the name is invalid, or some other kind of error occurs, returns
|
| 230 |
+
// false and "*tz" is set to the UTC time zone.
|
| 231 |
+
bool load_time_zone(const std::string& name, time_zone* tz);
|
| 232 |
+
|
| 233 |
+
// Returns a time_zone representing UTC. Cannot fail.
|
| 234 |
+
time_zone utc_time_zone();
|
| 235 |
+
|
| 236 |
+
// Returns a time zone that is a fixed offset (seconds east) from UTC.
|
| 237 |
+
// Note: If the absolute value of the offset is greater than 24 hours
|
| 238 |
+
// you'll get UTC (i.e., zero offset) instead.
|
| 239 |
+
time_zone fixed_time_zone(const seconds& offset);
|
| 240 |
+
|
| 241 |
+
// Returns a time zone representing the local time zone. Falls back to UTC.
|
| 242 |
+
// Note: local_time_zone.name() may only be something like "localtime".
|
| 243 |
+
time_zone local_time_zone();
|
| 244 |
+
|
| 245 |
+
// Returns the civil time (cctz::civil_second) within the given time zone at
|
| 246 |
+
// the given absolute time (time_point). Since the additional fields provided
|
| 247 |
+
// by the time_zone::absolute_lookup struct should rarely be needed in modern
|
| 248 |
+
// code, this convert() function is simpler and should be preferred.
|
| 249 |
+
template <typename D>
|
| 250 |
+
inline civil_second convert(const time_point<D>& tp, const time_zone& tz) {
|
| 251 |
+
return tz.lookup(tp).cs;
|
| 252 |
+
}
|
| 253 |
+
|
| 254 |
+
// Returns the absolute time (time_point) that corresponds to the given civil
|
| 255 |
+
// time within the given time zone. If the civil time is not unique (i.e., if
|
| 256 |
+
// it was either repeated or non-existent), then the returned time_point is
|
| 257 |
+
// the best estimate that preserves relative order. That is, this function
|
| 258 |
+
// guarantees that if cs1 < cs2, then convert(cs1, tz) <= convert(cs2, tz).
|
| 259 |
+
inline time_point<seconds> convert(const civil_second& cs,
|
| 260 |
+
const time_zone& tz) {
|
| 261 |
+
const time_zone::civil_lookup cl = tz.lookup(cs);
|
| 262 |
+
if (cl.kind == time_zone::civil_lookup::SKIPPED) return cl.trans;
|
| 263 |
+
return cl.pre;
|
| 264 |
+
}
|
| 265 |
+
|
| 266 |
+
namespace detail {
|
| 267 |
+
using femtoseconds = std::chrono::duration<std::int_fast64_t, std::femto>;
|
| 268 |
+
std::string format(const std::string&, const time_point<seconds>&,
|
| 269 |
+
const femtoseconds&, const time_zone&);
|
| 270 |
+
bool parse(const std::string&, const std::string&, const time_zone&,
|
| 271 |
+
time_point<seconds>*, femtoseconds*, std::string* err = nullptr);
|
| 272 |
+
template <typename Rep, std::intmax_t Denom>
|
| 273 |
+
bool join_seconds(
|
| 274 |
+
const time_point<seconds>& sec, const femtoseconds& fs,
|
| 275 |
+
time_point<std::chrono::duration<Rep, std::ratio<1, Denom>>>* tpp);
|
| 276 |
+
template <typename Rep, std::intmax_t Num>
|
| 277 |
+
bool join_seconds(
|
| 278 |
+
const time_point<seconds>& sec, const femtoseconds& fs,
|
| 279 |
+
time_point<std::chrono::duration<Rep, std::ratio<Num, 1>>>* tpp);
|
| 280 |
+
template <typename Rep>
|
| 281 |
+
bool join_seconds(
|
| 282 |
+
const time_point<seconds>& sec, const femtoseconds& fs,
|
| 283 |
+
time_point<std::chrono::duration<Rep, std::ratio<1, 1>>>* tpp);
|
| 284 |
+
bool join_seconds(const time_point<seconds>& sec, const femtoseconds&,
|
| 285 |
+
time_point<seconds>* tpp);
|
| 286 |
+
} // namespace detail
|
| 287 |
+
|
| 288 |
+
// Formats the given time_point in the given cctz::time_zone according to
|
| 289 |
+
// the provided format string. Uses strftime()-like formatting options,
|
| 290 |
+
// with the following extensions:
|
| 291 |
+
//
|
| 292 |
+
// - %Ez - RFC3339-compatible numeric UTC offset (+hh:mm or -hh:mm)
|
| 293 |
+
// - %E*z - Full-resolution numeric UTC offset (+hh:mm:ss or -hh:mm:ss)
|
| 294 |
+
// - %E#S - Seconds with # digits of fractional precision
|
| 295 |
+
// - %E*S - Seconds with full fractional precision (a literal '*')
|
| 296 |
+
// - %E#f - Fractional seconds with # digits of precision
|
| 297 |
+
// - %E*f - Fractional seconds with full precision (a literal '*')
|
| 298 |
+
// - %E4Y - Four-character years (-999 ... -001, 0000, 0001 ... 9999)
|
| 299 |
+
// - %ET - The RFC3339 "date-time" separator "T"
|
| 300 |
+
//
|
| 301 |
+
// Note that %E0S behaves like %S, and %E0f produces no characters. In
|
| 302 |
+
// contrast %E*f always produces at least one digit, which may be '0'.
|
| 303 |
+
//
|
| 304 |
+
// Note that %Y produces as many characters as it takes to fully render the
|
| 305 |
+
// year. A year outside of [-999:9999] when formatted with %E4Y will produce
|
| 306 |
+
// more than four characters, just like %Y.
|
| 307 |
+
//
|
| 308 |
+
// Tip: Format strings should include the UTC offset (e.g., %z, %Ez, or %E*z)
|
| 309 |
+
// so that the resulting string uniquely identifies an absolute time.
|
| 310 |
+
//
|
| 311 |
+
// Example:
|
| 312 |
+
// cctz::time_zone lax;
|
| 313 |
+
// if (!cctz::load_time_zone("America/Los_Angeles", &lax)) { ... }
|
| 314 |
+
// auto tp = cctz::convert(cctz::civil_second(2013, 1, 2, 3, 4, 5), lax);
|
| 315 |
+
// std::string f = cctz::format("%H:%M:%S", tp, lax); // "03:04:05"
|
| 316 |
+
// f = cctz::format("%H:%M:%E3S", tp, lax); // "03:04:05.000"
|
| 317 |
+
template <typename D>
|
| 318 |
+
inline std::string format(const std::string& fmt, const time_point<D>& tp,
|
| 319 |
+
const time_zone& tz) {
|
| 320 |
+
const auto p = detail::split_seconds(tp);
|
| 321 |
+
const auto n = std::chrono::duration_cast<detail::femtoseconds>(p.second);
|
| 322 |
+
return detail::format(fmt, p.first, n, tz);
|
| 323 |
+
}
|
| 324 |
+
|
| 325 |
+
// Parses an input string according to the provided format string and
|
| 326 |
+
// returns the corresponding time_point. Uses strftime()-like formatting
|
| 327 |
+
// options, with the same extensions as cctz::format(), but with the
|
| 328 |
+
// exceptions that %E#S is interpreted as %E*S, and %E#f as %E*f. %Ez
|
| 329 |
+
// and %E*z also accept the same inputs, which (along with %z) includes
|
| 330 |
+
// 'z' and 'Z' as synonyms for +00:00. %ET accepts either 'T' or 't'.
|
| 331 |
+
//
|
| 332 |
+
// %Y consumes as many numeric characters as it can, so the matching data
|
| 333 |
+
// should always be terminated with a non-numeric. %E4Y always consumes
|
| 334 |
+
// exactly four characters, including any sign.
|
| 335 |
+
//
|
| 336 |
+
// Unspecified fields are taken from the default date and time of ...
|
| 337 |
+
//
|
| 338 |
+
// "1970-01-01 00:00:00.0 +0000"
|
| 339 |
+
//
|
| 340 |
+
// For example, parsing a string of "15:45" (%H:%M) will return a time_point
|
| 341 |
+
// that represents "1970-01-01 15:45:00.0 +0000".
|
| 342 |
+
//
|
| 343 |
+
// Note that parse() returns time instants, so it makes most sense to parse
|
| 344 |
+
// fully-specified date/time strings that include a UTC offset (%z, %Ez, or
|
| 345 |
+
// %E*z).
|
| 346 |
+
//
|
| 347 |
+
// Note also that parse() only heeds the fields year, month, day, hour,
|
| 348 |
+
// minute, (fractional) second, and UTC offset. Other fields, like weekday (%a
|
| 349 |
+
// or %A), while parsed for syntactic validity, are ignored in the conversion.
|
| 350 |
+
//
|
| 351 |
+
// Date and time fields that are out-of-range will be treated as errors rather
|
| 352 |
+
// than normalizing them like cctz::civil_second() would do. For example, it
|
| 353 |
+
// is an error to parse the date "Oct 32, 2013" because 32 is out of range.
|
| 354 |
+
//
|
| 355 |
+
// A second of ":60" is normalized to ":00" of the following minute with
|
| 356 |
+
// fractional seconds discarded. The following table shows how the given
|
| 357 |
+
// seconds and subseconds will be parsed:
|
| 358 |
+
//
|
| 359 |
+
// "59.x" -> 59.x // exact
|
| 360 |
+
// "60.x" -> 00.0 // normalized
|
| 361 |
+
// "00.x" -> 00.x // exact
|
| 362 |
+
//
|
| 363 |
+
// Errors are indicated by returning false.
|
| 364 |
+
//
|
| 365 |
+
// Example:
|
| 366 |
+
// const cctz::time_zone tz = ...
|
| 367 |
+
// std::chrono::system_clock::time_point tp;
|
| 368 |
+
// if (cctz::parse("%Y-%m-%d", "2015-10-09", tz, &tp)) {
|
| 369 |
+
// ...
|
| 370 |
+
// }
|
| 371 |
+
template <typename D>
|
| 372 |
+
inline bool parse(const std::string& fmt, const std::string& input,
|
| 373 |
+
const time_zone& tz, time_point<D>* tpp) {
|
| 374 |
+
time_point<seconds> sec;
|
| 375 |
+
detail::femtoseconds fs;
|
| 376 |
+
return detail::parse(fmt, input, tz, &sec, &fs) &&
|
| 377 |
+
detail::join_seconds(sec, fs, tpp);
|
| 378 |
+
}
|
| 379 |
+
|
| 380 |
+
namespace detail {
|
| 381 |
+
|
| 382 |
+
// Split a time_point<D> into a time_point<seconds> and a D subseconds.
|
| 383 |
+
// Undefined behavior if time_point<seconds> is not of sufficient range.
|
| 384 |
+
// Note that this means it is UB to call cctz::time_zone::lookup(tp) or
|
| 385 |
+
// cctz::format(fmt, tp, tz) with a time_point that is outside the range
|
| 386 |
+
// of a 64-bit std::time_t.
|
| 387 |
+
template <typename D>
|
| 388 |
+
std::pair<time_point<seconds>, D> split_seconds(const time_point<D>& tp) {
|
| 389 |
+
auto sec = std::chrono::time_point_cast<seconds>(tp);
|
| 390 |
+
auto sub = tp - sec;
|
| 391 |
+
if (sub.count() < 0) {
|
| 392 |
+
sec -= seconds(1);
|
| 393 |
+
sub += seconds(1);
|
| 394 |
+
}
|
| 395 |
+
return {sec, std::chrono::duration_cast<D>(sub)};
|
| 396 |
+
}
|
| 397 |
+
|
| 398 |
+
inline std::pair<time_point<seconds>, seconds> split_seconds(
|
| 399 |
+
const time_point<seconds>& tp) {
|
| 400 |
+
return {tp, seconds::zero()};
|
| 401 |
+
}
|
| 402 |
+
|
| 403 |
+
// Join a time_point<seconds> and femto subseconds into a time_point<D>.
|
| 404 |
+
// Floors to the resolution of time_point<D>. Returns false if time_point<D>
|
| 405 |
+
// is not of sufficient range.
|
| 406 |
+
template <typename Rep, std::intmax_t Denom>
|
| 407 |
+
bool join_seconds(
|
| 408 |
+
const time_point<seconds>& sec, const femtoseconds& fs,
|
| 409 |
+
time_point<std::chrono::duration<Rep, std::ratio<1, Denom>>>* tpp) {
|
| 410 |
+
using D = std::chrono::duration<Rep, std::ratio<1, Denom>>;
|
| 411 |
+
// TODO(#199): Return false if result unrepresentable as a time_point<D>.
|
| 412 |
+
*tpp = std::chrono::time_point_cast<D>(sec);
|
| 413 |
+
*tpp += std::chrono::duration_cast<D>(fs);
|
| 414 |
+
return true;
|
| 415 |
+
}
|
| 416 |
+
|
| 417 |
+
template <typename Rep, std::intmax_t Num>
|
| 418 |
+
bool join_seconds(
|
| 419 |
+
const time_point<seconds>& sec, const femtoseconds&,
|
| 420 |
+
time_point<std::chrono::duration<Rep, std::ratio<Num, 1>>>* tpp) {
|
| 421 |
+
using D = std::chrono::duration<Rep, std::ratio<Num, 1>>;
|
| 422 |
+
auto count = sec.time_since_epoch().count();
|
| 423 |
+
if (count >= 0 || count % Num == 0) {
|
| 424 |
+
count /= Num;
|
| 425 |
+
} else {
|
| 426 |
+
count /= Num;
|
| 427 |
+
count -= 1;
|
| 428 |
+
}
|
| 429 |
+
if (count > (std::numeric_limits<Rep>::max)()) return false;
|
| 430 |
+
if (count < (std::numeric_limits<Rep>::min)()) return false;
|
| 431 |
+
*tpp = time_point<D>() + D{static_cast<Rep>(count)};
|
| 432 |
+
return true;
|
| 433 |
+
}
|
| 434 |
+
|
| 435 |
+
template <typename Rep>
|
| 436 |
+
bool join_seconds(
|
| 437 |
+
const time_point<seconds>& sec, const femtoseconds&,
|
| 438 |
+
time_point<std::chrono::duration<Rep, std::ratio<1, 1>>>* tpp) {
|
| 439 |
+
using D = std::chrono::duration<Rep, std::ratio<1, 1>>;
|
| 440 |
+
auto count = sec.time_since_epoch().count();
|
| 441 |
+
if (count > (std::numeric_limits<Rep>::max)()) return false;
|
| 442 |
+
if (count < (std::numeric_limits<Rep>::min)()) return false;
|
| 443 |
+
*tpp = time_point<D>() + D{static_cast<Rep>(count)};
|
| 444 |
+
return true;
|
| 445 |
+
}
|
| 446 |
+
|
| 447 |
+
inline bool join_seconds(const time_point<seconds>& sec, const femtoseconds&,
|
| 448 |
+
time_point<seconds>* tpp) {
|
| 449 |
+
*tpp = sec;
|
| 450 |
+
return true;
|
| 451 |
+
}
|
| 452 |
+
|
| 453 |
+
} // namespace detail
|
| 454 |
+
} // namespace cctz
|
| 455 |
+
} // namespace time_internal
|
| 456 |
+
ABSL_NAMESPACE_END
|
| 457 |
+
} // namespace absl
|
| 458 |
+
|
| 459 |
+
#endif // ABSL_TIME_INTERNAL_CCTZ_TIME_ZONE_H_
|
miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/absl/time/internal/cctz/include/cctz/zone_info_source.h
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2016 Google Inc. All Rights Reserved.
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// https://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
|
| 15 |
+
#ifndef ABSL_TIME_INTERNAL_CCTZ_ZONE_INFO_SOURCE_H_
|
| 16 |
+
#define ABSL_TIME_INTERNAL_CCTZ_ZONE_INFO_SOURCE_H_
|
| 17 |
+
|
| 18 |
+
#include <cstddef>
|
| 19 |
+
#include <functional>
|
| 20 |
+
#include <memory>
|
| 21 |
+
#include <string>
|
| 22 |
+
|
| 23 |
+
#include "absl/base/config.h"
|
| 24 |
+
|
| 25 |
+
namespace absl {
|
| 26 |
+
ABSL_NAMESPACE_BEGIN
|
| 27 |
+
namespace time_internal {
|
| 28 |
+
namespace cctz {
|
| 29 |
+
|
| 30 |
+
// A stdio-like interface for providing zoneinfo data for a particular zone.
|
| 31 |
+
class ZoneInfoSource {
|
| 32 |
+
public:
|
| 33 |
+
virtual ~ZoneInfoSource();
|
| 34 |
+
|
| 35 |
+
virtual std::size_t Read(void* ptr, std::size_t size) = 0; // like fread()
|
| 36 |
+
virtual int Skip(std::size_t offset) = 0; // like fseek()
|
| 37 |
+
|
| 38 |
+
// Until the zoneinfo data supports versioning information, we provide
|
| 39 |
+
// a way for a ZoneInfoSource to indicate it out-of-band. The default
|
| 40 |
+
// implementation returns an empty string.
|
| 41 |
+
virtual std::string Version() const;
|
| 42 |
+
};
|
| 43 |
+
|
| 44 |
+
} // namespace cctz
|
| 45 |
+
} // namespace time_internal
|
| 46 |
+
ABSL_NAMESPACE_END
|
| 47 |
+
} // namespace absl
|
| 48 |
+
|
| 49 |
+
namespace absl {
|
| 50 |
+
ABSL_NAMESPACE_BEGIN
|
| 51 |
+
namespace time_internal {
|
| 52 |
+
namespace cctz_extension {
|
| 53 |
+
|
| 54 |
+
// A function-pointer type for a factory that returns a ZoneInfoSource
|
| 55 |
+
// given the name of a time zone and a fallback factory. Returns null
|
| 56 |
+
// when the data for the named zone cannot be found.
|
| 57 |
+
using ZoneInfoSourceFactory =
|
| 58 |
+
std::unique_ptr<absl::time_internal::cctz::ZoneInfoSource> (*)(
|
| 59 |
+
const std::string&,
|
| 60 |
+
const std::function<std::unique_ptr<
|
| 61 |
+
absl::time_internal::cctz::ZoneInfoSource>(const std::string&)>&);
|
| 62 |
+
|
| 63 |
+
// The user can control the mapping of zone names to zoneinfo data by
|
| 64 |
+
// providing a definition for cctz_extension::zone_info_source_factory.
|
| 65 |
+
// For example, given functions my_factory() and my_other_factory() that
|
| 66 |
+
// can return a ZoneInfoSource for a named zone, we could inject them into
|
| 67 |
+
// cctz::load_time_zone() with:
|
| 68 |
+
//
|
| 69 |
+
// namespace cctz_extension {
|
| 70 |
+
// namespace {
|
| 71 |
+
// std::unique_ptr<cctz::ZoneInfoSource> CustomFactory(
|
| 72 |
+
// const std::string& name,
|
| 73 |
+
// const std::function<std::unique_ptr<cctz::ZoneInfoSource>(
|
| 74 |
+
// const std::string& name)>& fallback_factory) {
|
| 75 |
+
// if (auto zip = my_factory(name)) return zip;
|
| 76 |
+
// if (auto zip = fallback_factory(name)) return zip;
|
| 77 |
+
// if (auto zip = my_other_factory(name)) return zip;
|
| 78 |
+
// return nullptr;
|
| 79 |
+
// }
|
| 80 |
+
// } // namespace
|
| 81 |
+
// ZoneInfoSourceFactory zone_info_source_factory = CustomFactory;
|
| 82 |
+
// } // namespace cctz_extension
|
| 83 |
+
//
|
| 84 |
+
// This might be used, say, to use zoneinfo data embedded in the program,
|
| 85 |
+
// or read from a (possibly compressed) file archive, or both.
|
| 86 |
+
//
|
| 87 |
+
// cctz_extension::zone_info_source_factory() will be called:
|
| 88 |
+
// (1) from the same thread as the cctz::load_time_zone() call,
|
| 89 |
+
// (2) only once for any zone name, and
|
| 90 |
+
// (3) serially (i.e., no concurrent execution).
|
| 91 |
+
//
|
| 92 |
+
// The fallback factory obtains zoneinfo data by reading files in ${TZDIR},
|
| 93 |
+
// and it is used automatically when no zone_info_source_factory definition
|
| 94 |
+
// is linked into the program.
|
| 95 |
+
extern ZoneInfoSourceFactory zone_info_source_factory;
|
| 96 |
+
|
| 97 |
+
} // namespace cctz_extension
|
| 98 |
+
} // namespace time_internal
|
| 99 |
+
ABSL_NAMESPACE_END
|
| 100 |
+
} // namespace absl
|
| 101 |
+
|
| 102 |
+
#endif // ABSL_TIME_INTERNAL_CCTZ_ZONE_INFO_SOURCE_H_
|
miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/absl/time/internal/cctz/src/time_zone_fixed.h
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2016 Google Inc. All Rights Reserved.
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// https://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
|
| 15 |
+
#ifndef ABSL_TIME_INTERNAL_CCTZ_TIME_ZONE_FIXED_H_
|
| 16 |
+
#define ABSL_TIME_INTERNAL_CCTZ_TIME_ZONE_FIXED_H_
|
| 17 |
+
|
| 18 |
+
#include <string>
|
| 19 |
+
|
| 20 |
+
#include "absl/base/config.h"
|
| 21 |
+
#include "absl/time/internal/cctz/include/cctz/time_zone.h"
|
| 22 |
+
|
| 23 |
+
namespace absl {
|
| 24 |
+
ABSL_NAMESPACE_BEGIN
|
| 25 |
+
namespace time_internal {
|
| 26 |
+
namespace cctz {
|
| 27 |
+
|
| 28 |
+
// Helper functions for dealing with the names and abbreviations
|
| 29 |
+
// of time zones that are a fixed offset (seconds east) from UTC.
|
| 30 |
+
// FixedOffsetFromName() extracts the offset from a valid fixed-offset
|
| 31 |
+
// name, while FixedOffsetToName() and FixedOffsetToAbbr() generate
|
| 32 |
+
// the canonical zone name and abbreviation respectively for the given
|
| 33 |
+
// offset.
|
| 34 |
+
//
|
| 35 |
+
// A fixed-offset name looks like "Fixed/UTC<+-><hours>:<mins>:<secs>".
|
| 36 |
+
// Its abbreviation is of the form "UTC(<+->H?H(MM(SS)?)?)?" where the
|
| 37 |
+
// optional pieces are omitted when their values are zero. (Note that
|
| 38 |
+
// the sign is the opposite of that used in a POSIX TZ specification.)
|
| 39 |
+
//
|
| 40 |
+
// Note: FixedOffsetFromName() fails on syntax errors or when the parsed
|
| 41 |
+
// offset exceeds 24 hours. FixedOffsetToName() and FixedOffsetToAbbr()
|
| 42 |
+
// both produce "UTC" when the argument offset exceeds 24 hours.
|
| 43 |
+
bool FixedOffsetFromName(const std::string& name, seconds* offset);
|
| 44 |
+
std::string FixedOffsetToName(const seconds& offset);
|
| 45 |
+
std::string FixedOffsetToAbbr(const seconds& offset);
|
| 46 |
+
|
| 47 |
+
} // namespace cctz
|
| 48 |
+
} // namespace time_internal
|
| 49 |
+
ABSL_NAMESPACE_END
|
| 50 |
+
} // namespace absl
|
| 51 |
+
|
| 52 |
+
#endif // ABSL_TIME_INTERNAL_CCTZ_TIME_ZONE_FIXED_H_
|
miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/absl/time/internal/cctz/src/time_zone_if.h
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2016 Google Inc. All Rights Reserved.
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// https://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
|
| 15 |
+
#ifndef ABSL_TIME_INTERNAL_CCTZ_TIME_ZONE_IF_H_
|
| 16 |
+
#define ABSL_TIME_INTERNAL_CCTZ_TIME_ZONE_IF_H_
|
| 17 |
+
|
| 18 |
+
#include <chrono>
|
| 19 |
+
#include <cstdint>
|
| 20 |
+
#include <memory>
|
| 21 |
+
#include <string>
|
| 22 |
+
|
| 23 |
+
#include "absl/base/config.h"
|
| 24 |
+
#include "absl/time/internal/cctz/include/cctz/civil_time.h"
|
| 25 |
+
#include "absl/time/internal/cctz/include/cctz/time_zone.h"
|
| 26 |
+
|
| 27 |
+
namespace absl {
|
| 28 |
+
ABSL_NAMESPACE_BEGIN
|
| 29 |
+
namespace time_internal {
|
| 30 |
+
namespace cctz {
|
| 31 |
+
|
| 32 |
+
// A simple interface used to hide time-zone complexities from time_zone::Impl.
|
| 33 |
+
// Subclasses implement the functions for civil-time conversions in the zone.
|
| 34 |
+
class TimeZoneIf {
|
| 35 |
+
public:
|
| 36 |
+
// A factory function for TimeZoneIf implementations.
|
| 37 |
+
static std::unique_ptr<TimeZoneIf> Load(const std::string& name);
|
| 38 |
+
|
| 39 |
+
virtual ~TimeZoneIf();
|
| 40 |
+
|
| 41 |
+
virtual time_zone::absolute_lookup BreakTime(
|
| 42 |
+
const time_point<seconds>& tp) const = 0;
|
| 43 |
+
virtual time_zone::civil_lookup MakeTime(const civil_second& cs) const = 0;
|
| 44 |
+
|
| 45 |
+
virtual bool NextTransition(const time_point<seconds>& tp,
|
| 46 |
+
time_zone::civil_transition* trans) const = 0;
|
| 47 |
+
virtual bool PrevTransition(const time_point<seconds>& tp,
|
| 48 |
+
time_zone::civil_transition* trans) const = 0;
|
| 49 |
+
|
| 50 |
+
virtual std::string Version() const = 0;
|
| 51 |
+
virtual std::string Description() const = 0;
|
| 52 |
+
|
| 53 |
+
protected:
|
| 54 |
+
TimeZoneIf() {}
|
| 55 |
+
};
|
| 56 |
+
|
| 57 |
+
// Convert between time_point<seconds> and a count of seconds since the
|
| 58 |
+
// Unix epoch. We assume that the std::chrono::system_clock and the
|
| 59 |
+
// Unix clock are second aligned, and that the results are representable.
|
| 60 |
+
// (That is, that they share an epoch, which is required since C++20.)
|
| 61 |
+
inline std::int_fast64_t ToUnixSeconds(const time_point<seconds>& tp) {
|
| 62 |
+
return (tp - std::chrono::time_point_cast<seconds>(
|
| 63 |
+
std::chrono::system_clock::from_time_t(0)))
|
| 64 |
+
.count();
|
| 65 |
+
}
|
| 66 |
+
inline time_point<seconds> FromUnixSeconds(std::int_fast64_t t) {
|
| 67 |
+
return std::chrono::time_point_cast<seconds>(
|
| 68 |
+
std::chrono::system_clock::from_time_t(0)) +
|
| 69 |
+
seconds(t);
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
} // namespace cctz
|
| 73 |
+
} // namespace time_internal
|
| 74 |
+
ABSL_NAMESPACE_END
|
| 75 |
+
} // namespace absl
|
| 76 |
+
|
| 77 |
+
#endif // ABSL_TIME_INTERNAL_CCTZ_TIME_ZONE_IF_H_
|
miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/absl/time/internal/cctz/src/time_zone_impl.h
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2016 Google Inc. All Rights Reserved.
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// https://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
|
| 15 |
+
#ifndef ABSL_TIME_INTERNAL_CCTZ_TIME_ZONE_IMPL_H_
|
| 16 |
+
#define ABSL_TIME_INTERNAL_CCTZ_TIME_ZONE_IMPL_H_
|
| 17 |
+
|
| 18 |
+
#include <memory>
|
| 19 |
+
#include <string>
|
| 20 |
+
|
| 21 |
+
#include "absl/base/config.h"
|
| 22 |
+
#include "absl/time/internal/cctz/include/cctz/civil_time.h"
|
| 23 |
+
#include "absl/time/internal/cctz/include/cctz/time_zone.h"
|
| 24 |
+
#include "time_zone_if.h"
|
| 25 |
+
#include "time_zone_info.h"
|
| 26 |
+
|
| 27 |
+
namespace absl {
|
| 28 |
+
ABSL_NAMESPACE_BEGIN
|
| 29 |
+
namespace time_internal {
|
| 30 |
+
namespace cctz {
|
| 31 |
+
|
| 32 |
+
// time_zone::Impl is the internal object referenced by a cctz::time_zone.
|
| 33 |
+
class time_zone::Impl {
|
| 34 |
+
public:
|
| 35 |
+
// The UTC time zone. Also used for other time zones that fail to load.
|
| 36 |
+
static time_zone UTC();
|
| 37 |
+
|
| 38 |
+
// Load a named time zone. Returns false if the name is invalid, or if
|
| 39 |
+
// some other kind of error occurs. Note that loading "UTC" never fails.
|
| 40 |
+
static bool LoadTimeZone(const std::string& name, time_zone* tz);
|
| 41 |
+
|
| 42 |
+
// Clears the map of cached time zones. Primarily for use in benchmarks
|
| 43 |
+
// that gauge the performance of loading/parsing the time-zone data.
|
| 44 |
+
static void ClearTimeZoneMapTestOnly();
|
| 45 |
+
|
| 46 |
+
// The primary key is the time-zone ID (e.g., "America/New_York").
|
| 47 |
+
const std::string& Name() const {
|
| 48 |
+
// TODO: It would nice if the zoneinfo data included the zone name.
|
| 49 |
+
return name_;
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
// Breaks a time_point down to civil-time components in this time zone.
|
| 53 |
+
time_zone::absolute_lookup BreakTime(const time_point<seconds>& tp) const {
|
| 54 |
+
return zone_->BreakTime(tp);
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
// Converts the civil-time components in this time zone into a time_point.
|
| 58 |
+
// That is, the opposite of BreakTime(). The requested civil time may be
|
| 59 |
+
// ambiguous or illegal due to a change of UTC offset.
|
| 60 |
+
time_zone::civil_lookup MakeTime(const civil_second& cs) const {
|
| 61 |
+
return zone_->MakeTime(cs);
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
// Finds the time of the next/previous offset change in this time zone.
|
| 65 |
+
bool NextTransition(const time_point<seconds>& tp,
|
| 66 |
+
time_zone::civil_transition* trans) const {
|
| 67 |
+
return zone_->NextTransition(tp, trans);
|
| 68 |
+
}
|
| 69 |
+
bool PrevTransition(const time_point<seconds>& tp,
|
| 70 |
+
time_zone::civil_transition* trans) const {
|
| 71 |
+
return zone_->PrevTransition(tp, trans);
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
// Returns an implementation-defined version string for this time zone.
|
| 75 |
+
std::string Version() const { return zone_->Version(); }
|
| 76 |
+
|
| 77 |
+
// Returns an implementation-defined description of this time zone.
|
| 78 |
+
std::string Description() const { return zone_->Description(); }
|
| 79 |
+
|
| 80 |
+
private:
|
| 81 |
+
explicit Impl(const std::string& name);
|
| 82 |
+
static const Impl* UTCImpl();
|
| 83 |
+
|
| 84 |
+
const std::string name_;
|
| 85 |
+
std::unique_ptr<TimeZoneIf> zone_;
|
| 86 |
+
};
|
| 87 |
+
|
| 88 |
+
} // namespace cctz
|
| 89 |
+
} // namespace time_internal
|
| 90 |
+
ABSL_NAMESPACE_END
|
| 91 |
+
} // namespace absl
|
| 92 |
+
|
| 93 |
+
#endif // ABSL_TIME_INTERNAL_CCTZ_TIME_ZONE_IMPL_H_
|
miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/absl/time/internal/cctz/src/time_zone_info.h
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2016 Google Inc. All Rights Reserved.
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// https://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
|
| 15 |
+
#ifndef ABSL_TIME_INTERNAL_CCTZ_TIME_ZONE_INFO_H_
|
| 16 |
+
#define ABSL_TIME_INTERNAL_CCTZ_TIME_ZONE_INFO_H_
|
| 17 |
+
|
| 18 |
+
#include <atomic>
|
| 19 |
+
#include <cstddef>
|
| 20 |
+
#include <cstdint>
|
| 21 |
+
#include <string>
|
| 22 |
+
#include <vector>
|
| 23 |
+
|
| 24 |
+
#include "absl/base/config.h"
|
| 25 |
+
#include "absl/time/internal/cctz/include/cctz/civil_time.h"
|
| 26 |
+
#include "absl/time/internal/cctz/include/cctz/time_zone.h"
|
| 27 |
+
#include "absl/time/internal/cctz/include/cctz/zone_info_source.h"
|
| 28 |
+
#include "time_zone_if.h"
|
| 29 |
+
#include "tzfile.h"
|
| 30 |
+
|
| 31 |
+
namespace absl {
|
| 32 |
+
ABSL_NAMESPACE_BEGIN
|
| 33 |
+
namespace time_internal {
|
| 34 |
+
namespace cctz {
|
| 35 |
+
|
| 36 |
+
// A transition to a new UTC offset.
|
| 37 |
+
struct Transition {
|
| 38 |
+
std::int_least64_t unix_time; // the instant of this transition
|
| 39 |
+
std::uint_least8_t type_index; // index of the transition type
|
| 40 |
+
civil_second civil_sec; // local civil time of transition
|
| 41 |
+
civil_second prev_civil_sec; // local civil time one second earlier
|
| 42 |
+
|
| 43 |
+
struct ByUnixTime {
|
| 44 |
+
inline bool operator()(const Transition& lhs, const Transition& rhs) const {
|
| 45 |
+
return lhs.unix_time < rhs.unix_time;
|
| 46 |
+
}
|
| 47 |
+
};
|
| 48 |
+
struct ByCivilTime {
|
| 49 |
+
inline bool operator()(const Transition& lhs, const Transition& rhs) const {
|
| 50 |
+
return lhs.civil_sec < rhs.civil_sec;
|
| 51 |
+
}
|
| 52 |
+
};
|
| 53 |
+
};
|
| 54 |
+
|
| 55 |
+
// The characteristics of a particular transition.
|
| 56 |
+
struct TransitionType {
|
| 57 |
+
std::int_least32_t utc_offset; // the new prevailing UTC offset
|
| 58 |
+
civil_second civil_max; // max convertible civil time for offset
|
| 59 |
+
civil_second civil_min; // min convertible civil time for offset
|
| 60 |
+
bool is_dst; // did we move into daylight-saving time
|
| 61 |
+
std::uint_least8_t abbr_index; // index of the new abbreviation
|
| 62 |
+
};
|
| 63 |
+
|
| 64 |
+
// A time zone backed by the IANA Time Zone Database (zoneinfo).
|
| 65 |
+
class TimeZoneInfo : public TimeZoneIf {
|
| 66 |
+
public:
|
| 67 |
+
TimeZoneInfo() = default;
|
| 68 |
+
TimeZoneInfo(const TimeZoneInfo&) = delete;
|
| 69 |
+
TimeZoneInfo& operator=(const TimeZoneInfo&) = delete;
|
| 70 |
+
|
| 71 |
+
// Loads the zoneinfo for the given name, returning true if successful.
|
| 72 |
+
bool Load(const std::string& name);
|
| 73 |
+
|
| 74 |
+
// TimeZoneIf implementations.
|
| 75 |
+
time_zone::absolute_lookup BreakTime(
|
| 76 |
+
const time_point<seconds>& tp) const override;
|
| 77 |
+
time_zone::civil_lookup MakeTime(const civil_second& cs) const override;
|
| 78 |
+
bool NextTransition(const time_point<seconds>& tp,
|
| 79 |
+
time_zone::civil_transition* trans) const override;
|
| 80 |
+
bool PrevTransition(const time_point<seconds>& tp,
|
| 81 |
+
time_zone::civil_transition* trans) const override;
|
| 82 |
+
std::string Version() const override;
|
| 83 |
+
std::string Description() const override;
|
| 84 |
+
|
| 85 |
+
private:
|
| 86 |
+
struct Header { // counts of:
|
| 87 |
+
std::size_t timecnt; // transition times
|
| 88 |
+
std::size_t typecnt; // transition types
|
| 89 |
+
std::size_t charcnt; // zone abbreviation characters
|
| 90 |
+
std::size_t leapcnt; // leap seconds (we expect none)
|
| 91 |
+
std::size_t ttisstdcnt; // UTC/local indicators (unused)
|
| 92 |
+
std::size_t ttisutcnt; // standard/wall indicators (unused)
|
| 93 |
+
|
| 94 |
+
bool Build(const tzhead& tzh);
|
| 95 |
+
std::size_t DataLength(std::size_t time_len) const;
|
| 96 |
+
};
|
| 97 |
+
|
| 98 |
+
bool GetTransitionType(std::int_fast32_t utc_offset, bool is_dst,
|
| 99 |
+
const std::string& abbr, std::uint_least8_t* index);
|
| 100 |
+
bool EquivTransitions(std::uint_fast8_t tt1_index,
|
| 101 |
+
std::uint_fast8_t tt2_index) const;
|
| 102 |
+
bool ExtendTransitions();
|
| 103 |
+
|
| 104 |
+
bool ResetToBuiltinUTC(const seconds& offset);
|
| 105 |
+
bool Load(ZoneInfoSource* zip);
|
| 106 |
+
|
| 107 |
+
// Helpers for BreakTime() and MakeTime().
|
| 108 |
+
time_zone::absolute_lookup LocalTime(std::int_fast64_t unix_time,
|
| 109 |
+
const TransitionType& tt) const;
|
| 110 |
+
time_zone::absolute_lookup LocalTime(std::int_fast64_t unix_time,
|
| 111 |
+
const Transition& tr) const;
|
| 112 |
+
time_zone::civil_lookup TimeLocal(const civil_second& cs,
|
| 113 |
+
year_t c4_shift) const;
|
| 114 |
+
|
| 115 |
+
std::vector<Transition> transitions_; // ordered by unix_time and civil_sec
|
| 116 |
+
std::vector<TransitionType> transition_types_; // distinct transition types
|
| 117 |
+
std::uint_fast8_t default_transition_type_; // for before first transition
|
| 118 |
+
std::string abbreviations_; // all the NUL-terminated abbreviations
|
| 119 |
+
|
| 120 |
+
std::string version_; // the tzdata version if available
|
| 121 |
+
std::string future_spec_; // for after the last zic transition
|
| 122 |
+
bool extended_; // future_spec_ was used to generate transitions
|
| 123 |
+
year_t last_year_; // the final year of the generated transitions
|
| 124 |
+
|
| 125 |
+
// We remember the transitions found during the last BreakTime() and
|
| 126 |
+
// MakeTime() calls. If the next request is for the same transition we
|
| 127 |
+
// will avoid re-searching.
|
| 128 |
+
mutable std::atomic<std::size_t> local_time_hint_ = {}; // BreakTime() hint
|
| 129 |
+
mutable std::atomic<std::size_t> time_local_hint_ = {}; // MakeTime() hint
|
| 130 |
+
};
|
| 131 |
+
|
| 132 |
+
} // namespace cctz
|
| 133 |
+
} // namespace time_internal
|
| 134 |
+
ABSL_NAMESPACE_END
|
| 135 |
+
} // namespace absl
|
| 136 |
+
|
| 137 |
+
#endif // ABSL_TIME_INTERNAL_CCTZ_TIME_ZONE_INFO_H_
|
miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/absl/time/internal/cctz/src/time_zone_libc.h
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2016 Google Inc. All Rights Reserved.
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// https://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
|
| 15 |
+
#ifndef ABSL_TIME_INTERNAL_CCTZ_TIME_ZONE_LIBC_H_
|
| 16 |
+
#define ABSL_TIME_INTERNAL_CCTZ_TIME_ZONE_LIBC_H_
|
| 17 |
+
|
| 18 |
+
#include <string>
|
| 19 |
+
|
| 20 |
+
#include "absl/base/config.h"
|
| 21 |
+
#include "time_zone_if.h"
|
| 22 |
+
|
| 23 |
+
namespace absl {
|
| 24 |
+
ABSL_NAMESPACE_BEGIN
|
| 25 |
+
namespace time_internal {
|
| 26 |
+
namespace cctz {
|
| 27 |
+
|
| 28 |
+
// A time zone backed by gmtime_r(3), localtime_r(3), and mktime(3),
|
| 29 |
+
// and which therefore only supports UTC and the local time zone.
|
| 30 |
+
// TODO: Add support for fixed offsets from UTC.
|
| 31 |
+
class TimeZoneLibC : public TimeZoneIf {
|
| 32 |
+
public:
|
| 33 |
+
explicit TimeZoneLibC(const std::string& name);
|
| 34 |
+
|
| 35 |
+
// TimeZoneIf implementations.
|
| 36 |
+
time_zone::absolute_lookup BreakTime(
|
| 37 |
+
const time_point<seconds>& tp) const override;
|
| 38 |
+
time_zone::civil_lookup MakeTime(const civil_second& cs) const override;
|
| 39 |
+
bool NextTransition(const time_point<seconds>& tp,
|
| 40 |
+
time_zone::civil_transition* trans) const override;
|
| 41 |
+
bool PrevTransition(const time_point<seconds>& tp,
|
| 42 |
+
time_zone::civil_transition* trans) const override;
|
| 43 |
+
std::string Version() const override;
|
| 44 |
+
std::string Description() const override;
|
| 45 |
+
|
| 46 |
+
private:
|
| 47 |
+
const bool local_; // localtime or UTC
|
| 48 |
+
};
|
| 49 |
+
|
| 50 |
+
} // namespace cctz
|
| 51 |
+
} // namespace time_internal
|
| 52 |
+
ABSL_NAMESPACE_END
|
| 53 |
+
} // namespace absl
|
| 54 |
+
|
| 55 |
+
#endif // ABSL_TIME_INTERNAL_CCTZ_TIME_ZONE_LIBC_H_
|
miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/absl/time/internal/cctz/src/time_zone_posix.h
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2016 Google Inc. All Rights Reserved.
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// https://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
|
| 15 |
+
// Parsing of a POSIX zone spec as described in the TZ part of section 8.3 in
|
| 16 |
+
// http://pubs.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap08.html.
|
| 17 |
+
//
|
| 18 |
+
// The current POSIX spec for America/Los_Angeles is "PST8PDT,M3.2.0,M11.1.0",
|
| 19 |
+
// which would be broken down as ...
|
| 20 |
+
//
|
| 21 |
+
// PosixTimeZone {
|
| 22 |
+
// std_abbr = "PST"
|
| 23 |
+
// std_offset = -28800
|
| 24 |
+
// dst_abbr = "PDT"
|
| 25 |
+
// dst_offset = -25200
|
| 26 |
+
// dst_start = PosixTransition {
|
| 27 |
+
// date {
|
| 28 |
+
// m {
|
| 29 |
+
// month = 3
|
| 30 |
+
// week = 2
|
| 31 |
+
// weekday = 0
|
| 32 |
+
// }
|
| 33 |
+
// }
|
| 34 |
+
// time {
|
| 35 |
+
// offset = 7200
|
| 36 |
+
// }
|
| 37 |
+
// }
|
| 38 |
+
// dst_end = PosixTransition {
|
| 39 |
+
// date {
|
| 40 |
+
// m {
|
| 41 |
+
// month = 11
|
| 42 |
+
// week = 1
|
| 43 |
+
// weekday = 0
|
| 44 |
+
// }
|
| 45 |
+
// }
|
| 46 |
+
// time {
|
| 47 |
+
// offset = 7200
|
| 48 |
+
// }
|
| 49 |
+
// }
|
| 50 |
+
// }
|
| 51 |
+
|
| 52 |
+
#ifndef ABSL_TIME_INTERNAL_CCTZ_TIME_ZONE_POSIX_H_
|
| 53 |
+
#define ABSL_TIME_INTERNAL_CCTZ_TIME_ZONE_POSIX_H_
|
| 54 |
+
|
| 55 |
+
#include <cstdint>
|
| 56 |
+
#include <string>
|
| 57 |
+
|
| 58 |
+
#include "absl/base/config.h"
|
| 59 |
+
|
| 60 |
+
namespace absl {
|
| 61 |
+
ABSL_NAMESPACE_BEGIN
|
| 62 |
+
namespace time_internal {
|
| 63 |
+
namespace cctz {
|
| 64 |
+
|
| 65 |
+
// The date/time of the transition. The date is specified as either:
|
| 66 |
+
// (J) the Nth day of the year (1 <= N <= 365), excluding leap days, or
|
| 67 |
+
// (N) the Nth day of the year (0 <= N <= 365), including leap days, or
|
| 68 |
+
// (M) the Nth weekday of a month (e.g., the 2nd Sunday in March).
|
| 69 |
+
// The time, specified as a day offset, identifies the particular moment
|
| 70 |
+
// of the transition, and may be negative or >= 24h, and in which case
|
| 71 |
+
// it would take us to another day, and perhaps week, or even month.
|
| 72 |
+
struct PosixTransition {
|
| 73 |
+
enum DateFormat { J, N, M };
|
| 74 |
+
|
| 75 |
+
struct Date {
|
| 76 |
+
struct NonLeapDay {
|
| 77 |
+
std::int_fast16_t day; // day of non-leap year [1:365]
|
| 78 |
+
};
|
| 79 |
+
struct Day {
|
| 80 |
+
std::int_fast16_t day; // day of year [0:365]
|
| 81 |
+
};
|
| 82 |
+
struct MonthWeekWeekday {
|
| 83 |
+
std::int_fast8_t month; // month of year [1:12]
|
| 84 |
+
std::int_fast8_t week; // week of month [1:5] (5==last)
|
| 85 |
+
std::int_fast8_t weekday; // 0==Sun, ..., 6=Sat
|
| 86 |
+
};
|
| 87 |
+
|
| 88 |
+
DateFormat fmt;
|
| 89 |
+
|
| 90 |
+
union {
|
| 91 |
+
NonLeapDay j;
|
| 92 |
+
Day n;
|
| 93 |
+
MonthWeekWeekday m;
|
| 94 |
+
};
|
| 95 |
+
};
|
| 96 |
+
|
| 97 |
+
struct Time {
|
| 98 |
+
std::int_fast32_t offset; // seconds before/after 00:00:00
|
| 99 |
+
};
|
| 100 |
+
|
| 101 |
+
Date date;
|
| 102 |
+
Time time;
|
| 103 |
+
};
|
| 104 |
+
|
| 105 |
+
// The entirety of a POSIX-string specified time-zone rule. The standard
|
| 106 |
+
// abbreviation and offset are always given. If the time zone includes
|
| 107 |
+
// daylight saving, then the daylight abbrevation is non-empty and the
|
| 108 |
+
// remaining fields are also valid. Note that the start/end transitions
|
| 109 |
+
// are not ordered---in the southern hemisphere the transition to end
|
| 110 |
+
// daylight time occurs first in any particular year.
|
| 111 |
+
struct PosixTimeZone {
|
| 112 |
+
std::string std_abbr;
|
| 113 |
+
std::int_fast32_t std_offset;
|
| 114 |
+
|
| 115 |
+
std::string dst_abbr;
|
| 116 |
+
std::int_fast32_t dst_offset;
|
| 117 |
+
PosixTransition dst_start;
|
| 118 |
+
PosixTransition dst_end;
|
| 119 |
+
};
|
| 120 |
+
|
| 121 |
+
// Breaks down a POSIX time-zone specification into its constituent pieces,
|
| 122 |
+
// filling in any missing values (DST offset, or start/end transition times)
|
| 123 |
+
// with the standard-defined defaults. Returns false if the specification
|
| 124 |
+
// could not be parsed (although some fields of *res may have been altered).
|
| 125 |
+
bool ParsePosixSpec(const std::string& spec, PosixTimeZone* res);
|
| 126 |
+
|
| 127 |
+
} // namespace cctz
|
| 128 |
+
} // namespace time_internal
|
| 129 |
+
ABSL_NAMESPACE_END
|
| 130 |
+
} // namespace absl
|
| 131 |
+
|
| 132 |
+
#endif // ABSL_TIME_INTERNAL_CCTZ_TIME_ZONE_POSIX_H_
|
miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/absl/time/internal/cctz/src/tzfile.h
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* Layout and location of TZif files. */
|
| 2 |
+
|
| 3 |
+
#ifndef TZFILE_H
|
| 4 |
+
|
| 5 |
+
#define TZFILE_H
|
| 6 |
+
|
| 7 |
+
/*
|
| 8 |
+
** This file is in the public domain, so clarified as of
|
| 9 |
+
** 1996-06-05 by Arthur David Olson.
|
| 10 |
+
*/
|
| 11 |
+
|
| 12 |
+
/*
|
| 13 |
+
** This header is for use ONLY with the time conversion code.
|
| 14 |
+
** There is no guarantee that it will remain unchanged,
|
| 15 |
+
** or that it will remain at all.
|
| 16 |
+
** Do NOT copy it to any system include directory.
|
| 17 |
+
** Thank you!
|
| 18 |
+
*/
|
| 19 |
+
|
| 20 |
+
/*
|
| 21 |
+
** Information about time zone files.
|
| 22 |
+
*/
|
| 23 |
+
|
| 24 |
+
#ifndef TZDIR
|
| 25 |
+
#define TZDIR "/usr/share/zoneinfo" /* Time zone object file directory */
|
| 26 |
+
#endif /* !defined TZDIR */
|
| 27 |
+
|
| 28 |
+
#ifndef TZDEFAULT
|
| 29 |
+
#define TZDEFAULT "/etc/localtime"
|
| 30 |
+
#endif /* !defined TZDEFAULT */
|
| 31 |
+
|
| 32 |
+
#ifndef TZDEFRULES
|
| 33 |
+
#define TZDEFRULES "posixrules"
|
| 34 |
+
#endif /* !defined TZDEFRULES */
|
| 35 |
+
|
| 36 |
+
/* See Internet RFC 8536 for more details about the following format. */
|
| 37 |
+
|
| 38 |
+
/*
|
| 39 |
+
** Each file begins with. . .
|
| 40 |
+
*/
|
| 41 |
+
|
| 42 |
+
#define TZ_MAGIC "TZif"
|
| 43 |
+
|
| 44 |
+
struct tzhead {
|
| 45 |
+
char tzh_magic[4]; /* TZ_MAGIC */
|
| 46 |
+
char tzh_version[1]; /* '\0' or '2'-'4' as of 2021 */
|
| 47 |
+
char tzh_reserved[15]; /* reserved; must be zero */
|
| 48 |
+
char tzh_ttisutcnt[4]; /* coded number of trans. time flags */
|
| 49 |
+
char tzh_ttisstdcnt[4]; /* coded number of trans. time flags */
|
| 50 |
+
char tzh_leapcnt[4]; /* coded number of leap seconds */
|
| 51 |
+
char tzh_timecnt[4]; /* coded number of transition times */
|
| 52 |
+
char tzh_typecnt[4]; /* coded number of local time types */
|
| 53 |
+
char tzh_charcnt[4]; /* coded number of abbr. chars */
|
| 54 |
+
};
|
| 55 |
+
|
| 56 |
+
/*
|
| 57 |
+
** . . .followed by. . .
|
| 58 |
+
**
|
| 59 |
+
** tzh_timecnt (char [4])s coded transition times a la time(2)
|
| 60 |
+
** tzh_timecnt (unsigned char)s types of local time starting at above
|
| 61 |
+
** tzh_typecnt repetitions of
|
| 62 |
+
** one (char [4]) coded UT offset in seconds
|
| 63 |
+
** one (unsigned char) used to set tm_isdst
|
| 64 |
+
** one (unsigned char) that's an abbreviation list index
|
| 65 |
+
** tzh_charcnt (char)s '\0'-terminated zone abbreviations
|
| 66 |
+
** tzh_leapcnt repetitions of
|
| 67 |
+
** one (char [4]) coded leap second transition times
|
| 68 |
+
** one (char [4]) total correction after above
|
| 69 |
+
** tzh_ttisstdcnt (char)s indexed by type; if 1, transition
|
| 70 |
+
** time is standard time, if 0,
|
| 71 |
+
** transition time is local (wall clock)
|
| 72 |
+
** time; if absent, transition times are
|
| 73 |
+
** assumed to be local time
|
| 74 |
+
** tzh_ttisutcnt (char)s indexed by type; if 1, transition
|
| 75 |
+
** time is UT, if 0, transition time is
|
| 76 |
+
** local time; if absent, transition
|
| 77 |
+
** times are assumed to be local time.
|
| 78 |
+
** When this is 1, the corresponding
|
| 79 |
+
** std/wall indicator must also be 1.
|
| 80 |
+
*/
|
| 81 |
+
|
| 82 |
+
/*
|
| 83 |
+
** If tzh_version is '2' or greater, the above is followed by a second instance
|
| 84 |
+
** of tzhead and a second instance of the data in which each coded transition
|
| 85 |
+
** time uses 8 rather than 4 chars,
|
| 86 |
+
** then a POSIX-TZ-environment-variable-style string for use in handling
|
| 87 |
+
** instants after the last transition time stored in the file
|
| 88 |
+
** (with nothing between the newlines if there is no POSIX representation for
|
| 89 |
+
** such instants).
|
| 90 |
+
**
|
| 91 |
+
** If tz_version is '3' or greater, the above is extended as follows.
|
| 92 |
+
** First, the POSIX TZ string's hour offset may range from -167
|
| 93 |
+
** through 167 as compared to the POSIX-required 0 through 24.
|
| 94 |
+
** Second, its DST start time may be January 1 at 00:00 and its stop
|
| 95 |
+
** time December 31 at 24:00 plus the difference between DST and
|
| 96 |
+
** standard time, indicating DST all year.
|
| 97 |
+
*/
|
| 98 |
+
|
| 99 |
+
/*
|
| 100 |
+
** In the current implementation, "tzset()" refuses to deal with files that
|
| 101 |
+
** exceed any of the limits below.
|
| 102 |
+
*/
|
| 103 |
+
|
| 104 |
+
#ifndef TZ_MAX_TIMES
|
| 105 |
+
#define TZ_MAX_TIMES 2000
|
| 106 |
+
#endif /* !defined TZ_MAX_TIMES */
|
| 107 |
+
|
| 108 |
+
#ifndef TZ_MAX_TYPES
|
| 109 |
+
/* This must be at least 17 for Europe/Samara and Europe/Vilnius. */
|
| 110 |
+
#define TZ_MAX_TYPES 256 /* Limited by what (unsigned char)'s can hold */
|
| 111 |
+
#endif /* !defined TZ_MAX_TYPES */
|
| 112 |
+
|
| 113 |
+
#ifndef TZ_MAX_CHARS
|
| 114 |
+
#define TZ_MAX_CHARS 50 /* Maximum number of abbreviation characters */
|
| 115 |
+
/* (limited by what unsigned chars can hold) */
|
| 116 |
+
#endif /* !defined TZ_MAX_CHARS */
|
| 117 |
+
|
| 118 |
+
#ifndef TZ_MAX_LEAPS
|
| 119 |
+
#define TZ_MAX_LEAPS 50 /* Maximum number of leap second corrections */
|
| 120 |
+
#endif /* !defined TZ_MAX_LEAPS */
|
| 121 |
+
|
| 122 |
+
#endif /* !defined TZFILE_H */
|
miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/absl/time/internal/get_current_time_chrono.inc
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2018 The Abseil Authors.
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// https://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
|
| 15 |
+
#include <chrono>
|
| 16 |
+
#include <cstdint>
|
| 17 |
+
|
| 18 |
+
namespace absl {
|
| 19 |
+
ABSL_NAMESPACE_BEGIN
|
| 20 |
+
namespace time_internal {
|
| 21 |
+
|
| 22 |
+
static int64_t GetCurrentTimeNanosFromSystem() {
|
| 23 |
+
return std::chrono::duration_cast<std::chrono::nanoseconds>(
|
| 24 |
+
std::chrono::system_clock::now() -
|
| 25 |
+
std::chrono::system_clock::from_time_t(0))
|
| 26 |
+
.count();
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
} // namespace time_internal
|
| 30 |
+
ABSL_NAMESPACE_END
|
| 31 |
+
} // namespace absl
|
miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/absl/time/internal/get_current_time_posix.inc
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include "absl/time/clock.h"
|
| 2 |
+
|
| 3 |
+
#include <sys/time.h>
|
| 4 |
+
#include <ctime>
|
| 5 |
+
#include <cstdint>
|
| 6 |
+
|
| 7 |
+
#include "absl/base/internal/raw_logging.h"
|
| 8 |
+
|
| 9 |
+
namespace absl {
|
| 10 |
+
ABSL_NAMESPACE_BEGIN
|
| 11 |
+
namespace time_internal {
|
| 12 |
+
|
| 13 |
+
static int64_t GetCurrentTimeNanosFromSystem() {
|
| 14 |
+
const int64_t kNanosPerSecond = 1000 * 1000 * 1000;
|
| 15 |
+
struct timespec ts;
|
| 16 |
+
ABSL_RAW_CHECK(clock_gettime(CLOCK_REALTIME, &ts) == 0,
|
| 17 |
+
"Failed to read real-time clock.");
|
| 18 |
+
return (int64_t{ts.tv_sec} * kNanosPerSecond +
|
| 19 |
+
int64_t{ts.tv_nsec});
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
} // namespace time_internal
|
| 23 |
+
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2017 The Abseil Authors.
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// https://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
//
|
| 15 |
+
// -----------------------------------------------------------------------------
|
| 16 |
+
// File: time.h
|
| 17 |
+
// -----------------------------------------------------------------------------
|
| 18 |
+
//
|
| 19 |
+
// This header file defines abstractions for computing with absolute points
|
| 20 |
+
// in time, durations of time, and formatting and parsing time within a given
|
| 21 |
+
// time zone. The following abstractions are defined:
|
| 22 |
+
//
|
| 23 |
+
// * `absl::Time` defines an absolute, specific instance in time
|
| 24 |
+
// * `absl::Duration` defines a signed, fixed-length span of time
|
| 25 |
+
// * `absl::TimeZone` defines geopolitical time zone regions (as collected
|
| 26 |
+
// within the IANA Time Zone database (https://www.iana.org/time-zones)).
|
| 27 |
+
//
|
| 28 |
+
// Note: Absolute times are distinct from civil times, which refer to the
|
| 29 |
+
// human-scale time commonly represented by `YYYY-MM-DD hh:mm:ss`. The mapping
|
| 30 |
+
// between absolute and civil times can be specified by use of time zones
|
| 31 |
+
// (`absl::TimeZone` within this API). That is:
|
| 32 |
+
//
|
| 33 |
+
// Civil Time = F(Absolute Time, Time Zone)
|
| 34 |
+
// Absolute Time = G(Civil Time, Time Zone)
|
| 35 |
+
//
|
| 36 |
+
// See civil_time.h for abstractions related to constructing and manipulating
|
| 37 |
+
// civil time.
|
| 38 |
+
//
|
| 39 |
+
// Example:
|
| 40 |
+
//
|
| 41 |
+
// absl::TimeZone nyc;
|
| 42 |
+
// // LoadTimeZone() may fail so it's always better to check for success.
|
| 43 |
+
// if (!absl::LoadTimeZone("America/New_York", &nyc)) {
|
| 44 |
+
// // handle error case
|
| 45 |
+
// }
|
| 46 |
+
//
|
| 47 |
+
// // My flight leaves NYC on Jan 2, 2017 at 03:04:05
|
| 48 |
+
// absl::CivilSecond cs(2017, 1, 2, 3, 4, 5);
|
| 49 |
+
// absl::Time takeoff = absl::FromCivil(cs, nyc);
|
| 50 |
+
//
|
| 51 |
+
// absl::Duration flight_duration = absl::Hours(21) + absl::Minutes(35);
|
| 52 |
+
// absl::Time landing = takeoff + flight_duration;
|
| 53 |
+
//
|
| 54 |
+
// absl::TimeZone syd;
|
| 55 |
+
// if (!absl::LoadTimeZone("Australia/Sydney", &syd)) {
|
| 56 |
+
// // handle error case
|
| 57 |
+
// }
|
| 58 |
+
// std::string s = absl::FormatTime(
|
| 59 |
+
// "My flight will land in Sydney on %Y-%m-%d at %H:%M:%S",
|
| 60 |
+
// landing, syd);
|
| 61 |
+
|
| 62 |
+
#ifndef ABSL_TIME_TIME_H_
|
| 63 |
+
#define ABSL_TIME_TIME_H_
|
| 64 |
+
|
| 65 |
+
#if !defined(_MSC_VER)
|
| 66 |
+
#include <sys/time.h>
|
| 67 |
+
#else
|
| 68 |
+
// We don't include `winsock2.h` because it drags in `windows.h` and friends,
|
| 69 |
+
// and they define conflicting macros like OPAQUE, ERROR, and more. This has the
|
| 70 |
+
// potential to break Abseil users.
|
| 71 |
+
//
|
| 72 |
+
// Instead we only forward declare `timeval` and require Windows users include
|
| 73 |
+
// `winsock2.h` themselves. This is both inconsistent and troublesome, but so is
|
| 74 |
+
// including 'windows.h' so we are picking the lesser of two evils here.
|
| 75 |
+
struct timeval;
|
| 76 |
+
#endif
|
| 77 |
+
#include <chrono> // NOLINT(build/c++11)
|
| 78 |
+
#include <cmath>
|
| 79 |
+
#include <cstdint>
|
| 80 |
+
#include <ctime>
|
| 81 |
+
#include <limits>
|
| 82 |
+
#include <ostream>
|
| 83 |
+
#include <string>
|
| 84 |
+
#include <type_traits>
|
| 85 |
+
#include <utility>
|
| 86 |
+
|
| 87 |
+
#include "absl/base/macros.h"
|
| 88 |
+
#include "absl/strings/string_view.h"
|
| 89 |
+
#include "absl/time/civil_time.h"
|
| 90 |
+
#include "absl/time/internal/cctz/include/cctz/time_zone.h"
|
| 91 |
+
|
| 92 |
+
namespace absl {
|
| 93 |
+
ABSL_NAMESPACE_BEGIN
|
| 94 |
+
|
| 95 |
+
class Duration; // Defined below
|
| 96 |
+
class Time; // Defined below
|
| 97 |
+
class TimeZone; // Defined below
|
| 98 |
+
|
| 99 |
+
namespace time_internal {
|
| 100 |
+
int64_t IDivDuration(bool satq, Duration num, Duration den, Duration* rem);
|
| 101 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION constexpr Time FromUnixDuration(Duration d);
|
| 102 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION constexpr Duration ToUnixDuration(Time t);
|
| 103 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION constexpr int64_t GetRepHi(Duration d);
|
| 104 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION constexpr uint32_t GetRepLo(Duration d);
|
| 105 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION constexpr Duration MakeDuration(int64_t hi,
|
| 106 |
+
uint32_t lo);
|
| 107 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION constexpr Duration MakeDuration(int64_t hi,
|
| 108 |
+
int64_t lo);
|
| 109 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION inline Duration MakePosDoubleDuration(double n);
|
| 110 |
+
constexpr int64_t kTicksPerNanosecond = 4;
|
| 111 |
+
constexpr int64_t kTicksPerSecond = 1000 * 1000 * 1000 * kTicksPerNanosecond;
|
| 112 |
+
template <std::intmax_t N>
|
| 113 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION constexpr Duration FromInt64(int64_t v,
|
| 114 |
+
std::ratio<1, N>);
|
| 115 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION constexpr Duration FromInt64(int64_t v,
|
| 116 |
+
std::ratio<60>);
|
| 117 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION constexpr Duration FromInt64(int64_t v,
|
| 118 |
+
std::ratio<3600>);
|
| 119 |
+
template <typename T>
|
| 120 |
+
using EnableIfIntegral = typename std::enable_if<
|
| 121 |
+
std::is_integral<T>::value || std::is_enum<T>::value, int>::type;
|
| 122 |
+
template <typename T>
|
| 123 |
+
using EnableIfFloat =
|
| 124 |
+
typename std::enable_if<std::is_floating_point<T>::value, int>::type;
|
| 125 |
+
} // namespace time_internal
|
| 126 |
+
|
| 127 |
+
// Duration
|
| 128 |
+
//
|
| 129 |
+
// The `absl::Duration` class represents a signed, fixed-length amount of time.
|
| 130 |
+
// A `Duration` is generated using a unit-specific factory function, or is
|
| 131 |
+
// the result of subtracting one `absl::Time` from another. Durations behave
|
| 132 |
+
// like unit-safe integers and they support all the natural integer-like
|
| 133 |
+
// arithmetic operations. Arithmetic overflows and saturates at +/- infinity.
|
| 134 |
+
// `Duration` should be passed by value rather than const reference.
|
| 135 |
+
//
|
| 136 |
+
// Factory functions `Nanoseconds()`, `Microseconds()`, `Milliseconds()`,
|
| 137 |
+
// `Seconds()`, `Minutes()`, `Hours()` and `InfiniteDuration()` allow for
|
| 138 |
+
// creation of constexpr `Duration` values
|
| 139 |
+
//
|
| 140 |
+
// Examples:
|
| 141 |
+
//
|
| 142 |
+
// constexpr absl::Duration ten_ns = absl::Nanoseconds(10);
|
| 143 |
+
// constexpr absl::Duration min = absl::Minutes(1);
|
| 144 |
+
// constexpr absl::Duration hour = absl::Hours(1);
|
| 145 |
+
// absl::Duration dur = 60 * min; // dur == hour
|
| 146 |
+
// absl::Duration half_sec = absl::Milliseconds(500);
|
| 147 |
+
// absl::Duration quarter_sec = 0.25 * absl::Seconds(1);
|
| 148 |
+
//
|
| 149 |
+
// `Duration` values can be easily converted to an integral number of units
|
| 150 |
+
// using the division operator.
|
| 151 |
+
//
|
| 152 |
+
// Example:
|
| 153 |
+
//
|
| 154 |
+
// constexpr absl::Duration dur = absl::Milliseconds(1500);
|
| 155 |
+
// int64_t ns = dur / absl::Nanoseconds(1); // ns == 1500000000
|
| 156 |
+
// int64_t ms = dur / absl::Milliseconds(1); // ms == 1500
|
| 157 |
+
// int64_t sec = dur / absl::Seconds(1); // sec == 1 (subseconds truncated)
|
| 158 |
+
// int64_t min = dur / absl::Minutes(1); // min == 0
|
| 159 |
+
//
|
| 160 |
+
// See the `IDivDuration()` and `FDivDuration()` functions below for details on
|
| 161 |
+
// how to access the fractional parts of the quotient.
|
| 162 |
+
//
|
| 163 |
+
// Alternatively, conversions can be performed using helpers such as
|
| 164 |
+
// `ToInt64Microseconds()` and `ToDoubleSeconds()`.
|
| 165 |
+
class Duration {
|
| 166 |
+
public:
|
| 167 |
+
// Value semantics.
|
| 168 |
+
constexpr Duration() : rep_hi_(0), rep_lo_(0) {} // zero-length duration
|
| 169 |
+
|
| 170 |
+
// Copyable.
|
| 171 |
+
#if !defined(__clang__) && defined(_MSC_VER) && _MSC_VER < 1930
|
| 172 |
+
// Explicitly defining the constexpr copy constructor avoids an MSVC bug.
|
| 173 |
+
constexpr Duration(const Duration& d)
|
| 174 |
+
: rep_hi_(d.rep_hi_), rep_lo_(d.rep_lo_) {}
|
| 175 |
+
#else
|
| 176 |
+
constexpr Duration(const Duration& d) = default;
|
| 177 |
+
#endif
|
| 178 |
+
Duration& operator=(const Duration& d) = default;
|
| 179 |
+
|
| 180 |
+
// Compound assignment operators.
|
| 181 |
+
Duration& operator+=(Duration d);
|
| 182 |
+
Duration& operator-=(Duration d);
|
| 183 |
+
Duration& operator*=(int64_t r);
|
| 184 |
+
Duration& operator*=(double r);
|
| 185 |
+
Duration& operator/=(int64_t r);
|
| 186 |
+
Duration& operator/=(double r);
|
| 187 |
+
Duration& operator%=(Duration rhs);
|
| 188 |
+
|
| 189 |
+
// Overloads that forward to either the int64_t or double overloads above.
|
| 190 |
+
// Integer operands must be representable as int64_t.
|
| 191 |
+
template <typename T, time_internal::EnableIfIntegral<T> = 0>
|
| 192 |
+
Duration& operator*=(T r) {
|
| 193 |
+
int64_t x = r;
|
| 194 |
+
return *this *= x;
|
| 195 |
+
}
|
| 196 |
+
|
| 197 |
+
template <typename T, time_internal::EnableIfIntegral<T> = 0>
|
| 198 |
+
Duration& operator/=(T r) {
|
| 199 |
+
int64_t x = r;
|
| 200 |
+
return *this /= x;
|
| 201 |
+
}
|
| 202 |
+
|
| 203 |
+
template <typename T, time_internal::EnableIfFloat<T> = 0>
|
| 204 |
+
Duration& operator*=(T r) {
|
| 205 |
+
double x = r;
|
| 206 |
+
return *this *= x;
|
| 207 |
+
}
|
| 208 |
+
|
| 209 |
+
template <typename T, time_internal::EnableIfFloat<T> = 0>
|
| 210 |
+
Duration& operator/=(T r) {
|
| 211 |
+
double x = r;
|
| 212 |
+
return *this /= x;
|
| 213 |
+
}
|
| 214 |
+
|
| 215 |
+
template <typename H>
|
| 216 |
+
friend H AbslHashValue(H h, Duration d) {
|
| 217 |
+
return H::combine(std::move(h), d.rep_hi_, d.rep_lo_);
|
| 218 |
+
}
|
| 219 |
+
|
| 220 |
+
private:
|
| 221 |
+
friend constexpr int64_t time_internal::GetRepHi(Duration d);
|
| 222 |
+
friend constexpr uint32_t time_internal::GetRepLo(Duration d);
|
| 223 |
+
friend constexpr Duration time_internal::MakeDuration(int64_t hi,
|
| 224 |
+
uint32_t lo);
|
| 225 |
+
constexpr Duration(int64_t hi, uint32_t lo) : rep_hi_(hi), rep_lo_(lo) {}
|
| 226 |
+
int64_t rep_hi_;
|
| 227 |
+
uint32_t rep_lo_;
|
| 228 |
+
};
|
| 229 |
+
|
| 230 |
+
// Relational Operators
|
| 231 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION constexpr bool operator<(Duration lhs,
|
| 232 |
+
Duration rhs);
|
| 233 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION constexpr bool operator>(Duration lhs,
|
| 234 |
+
Duration rhs) {
|
| 235 |
+
return rhs < lhs;
|
| 236 |
+
}
|
| 237 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION constexpr bool operator>=(Duration lhs,
|
| 238 |
+
Duration rhs) {
|
| 239 |
+
return !(lhs < rhs);
|
| 240 |
+
}
|
| 241 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION constexpr bool operator<=(Duration lhs,
|
| 242 |
+
Duration rhs) {
|
| 243 |
+
return !(rhs < lhs);
|
| 244 |
+
}
|
| 245 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION constexpr bool operator==(Duration lhs,
|
| 246 |
+
Duration rhs);
|
| 247 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION constexpr bool operator!=(Duration lhs,
|
| 248 |
+
Duration rhs) {
|
| 249 |
+
return !(lhs == rhs);
|
| 250 |
+
}
|
| 251 |
+
|
| 252 |
+
// Additive Operators
|
| 253 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION constexpr Duration operator-(Duration d);
|
| 254 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION inline Duration operator+(Duration lhs,
|
| 255 |
+
Duration rhs) {
|
| 256 |
+
return lhs += rhs;
|
| 257 |
+
}
|
| 258 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION inline Duration operator-(Duration lhs,
|
| 259 |
+
Duration rhs) {
|
| 260 |
+
return lhs -= rhs;
|
| 261 |
+
}
|
| 262 |
+
|
| 263 |
+
// Multiplicative Operators
|
| 264 |
+
// Integer operands must be representable as int64_t.
|
| 265 |
+
template <typename T>
|
| 266 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION Duration operator*(Duration lhs, T rhs) {
|
| 267 |
+
return lhs *= rhs;
|
| 268 |
+
}
|
| 269 |
+
template <typename T>
|
| 270 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION Duration operator*(T lhs, Duration rhs) {
|
| 271 |
+
return rhs *= lhs;
|
| 272 |
+
}
|
| 273 |
+
template <typename T>
|
| 274 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION Duration operator/(Duration lhs, T rhs) {
|
| 275 |
+
return lhs /= rhs;
|
| 276 |
+
}
|
| 277 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION inline int64_t operator/(Duration lhs,
|
| 278 |
+
Duration rhs) {
|
| 279 |
+
return time_internal::IDivDuration(true, lhs, rhs,
|
| 280 |
+
&lhs); // trunc towards zero
|
| 281 |
+
}
|
| 282 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION inline Duration operator%(Duration lhs,
|
| 283 |
+
Duration rhs) {
|
| 284 |
+
return lhs %= rhs;
|
| 285 |
+
}
|
| 286 |
+
|
| 287 |
+
// IDivDuration()
|
| 288 |
+
//
|
| 289 |
+
// Divides a numerator `Duration` by a denominator `Duration`, returning the
|
| 290 |
+
// quotient and remainder. The remainder always has the same sign as the
|
| 291 |
+
// numerator. The returned quotient and remainder respect the identity:
|
| 292 |
+
//
|
| 293 |
+
// numerator = denominator * quotient + remainder
|
| 294 |
+
//
|
| 295 |
+
// Returned quotients are capped to the range of `int64_t`, with the difference
|
| 296 |
+
// spilling into the remainder to uphold the above identity. This means that the
|
| 297 |
+
// remainder returned could differ from the remainder returned by
|
| 298 |
+
// `Duration::operator%` for huge quotients.
|
| 299 |
+
//
|
| 300 |
+
// See also the notes on `InfiniteDuration()` below regarding the behavior of
|
| 301 |
+
// division involving zero and infinite durations.
|
| 302 |
+
//
|
| 303 |
+
// Example:
|
| 304 |
+
//
|
| 305 |
+
// constexpr absl::Duration a =
|
| 306 |
+
// absl::Seconds(std::numeric_limits<int64_t>::max()); // big
|
| 307 |
+
// constexpr absl::Duration b = absl::Nanoseconds(1); // small
|
| 308 |
+
//
|
| 309 |
+
// absl::Duration rem = a % b;
|
| 310 |
+
// // rem == absl::ZeroDuration()
|
| 311 |
+
//
|
| 312 |
+
// // Here, q would overflow int64_t, so rem accounts for the difference.
|
| 313 |
+
// int64_t q = absl::IDivDuration(a, b, &rem);
|
| 314 |
+
// // q == std::numeric_limits<int64_t>::max(), rem == a - b * q
|
| 315 |
+
inline int64_t IDivDuration(Duration num, Duration den, Duration* rem) {
|
| 316 |
+
return time_internal::IDivDuration(true, num, den,
|
| 317 |
+
rem); // trunc towards zero
|
| 318 |
+
}
|
| 319 |
+
|
| 320 |
+
// FDivDuration()
|
| 321 |
+
//
|
| 322 |
+
// Divides a `Duration` numerator into a fractional number of units of a
|
| 323 |
+
// `Duration` denominator.
|
| 324 |
+
//
|
| 325 |
+
// See also the notes on `InfiniteDuration()` below regarding the behavior of
|
| 326 |
+
// division involving zero and infinite durations.
|
| 327 |
+
//
|
| 328 |
+
// Example:
|
| 329 |
+
//
|
| 330 |
+
// double d = absl::FDivDuration(absl::Milliseconds(1500), absl::Seconds(1));
|
| 331 |
+
// // d == 1.5
|
| 332 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION double FDivDuration(Duration num, Duration den);
|
| 333 |
+
|
| 334 |
+
// ZeroDuration()
|
| 335 |
+
//
|
| 336 |
+
// Returns a zero-length duration. This function behaves just like the default
|
| 337 |
+
// constructor, but the name helps make the semantics clear at call sites.
|
| 338 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION constexpr Duration ZeroDuration() {
|
| 339 |
+
return Duration();
|
| 340 |
+
}
|
| 341 |
+
|
| 342 |
+
// AbsDuration()
|
| 343 |
+
//
|
| 344 |
+
// Returns the absolute value of a duration.
|
| 345 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION inline Duration AbsDuration(Duration d) {
|
| 346 |
+
return (d < ZeroDuration()) ? -d : d;
|
| 347 |
+
}
|
| 348 |
+
|
| 349 |
+
// Trunc()
|
| 350 |
+
//
|
| 351 |
+
// Truncates a duration (toward zero) to a multiple of a non-zero unit.
|
| 352 |
+
//
|
| 353 |
+
// Example:
|
| 354 |
+
//
|
| 355 |
+
// absl::Duration d = absl::Nanoseconds(123456789);
|
| 356 |
+
// absl::Duration a = absl::Trunc(d, absl::Microseconds(1)); // 123456us
|
| 357 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION Duration Trunc(Duration d, Duration unit);
|
| 358 |
+
|
| 359 |
+
// Floor()
|
| 360 |
+
//
|
| 361 |
+
// Floors a duration using the passed duration unit to its largest value not
|
| 362 |
+
// greater than the duration.
|
| 363 |
+
//
|
| 364 |
+
// Example:
|
| 365 |
+
//
|
| 366 |
+
// absl::Duration d = absl::Nanoseconds(123456789);
|
| 367 |
+
// absl::Duration b = absl::Floor(d, absl::Microseconds(1)); // 123456us
|
| 368 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION Duration Floor(Duration d, Duration unit);
|
| 369 |
+
|
| 370 |
+
// Ceil()
|
| 371 |
+
//
|
| 372 |
+
// Returns the ceiling of a duration using the passed duration unit to its
|
| 373 |
+
// smallest value not less than the duration.
|
| 374 |
+
//
|
| 375 |
+
// Example:
|
| 376 |
+
//
|
| 377 |
+
// absl::Duration d = absl::Nanoseconds(123456789);
|
| 378 |
+
// absl::Duration c = absl::Ceil(d, absl::Microseconds(1)); // 123457us
|
| 379 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION Duration Ceil(Duration d, Duration unit);
|
| 380 |
+
|
| 381 |
+
// InfiniteDuration()
|
| 382 |
+
//
|
| 383 |
+
// Returns an infinite `Duration`. To get a `Duration` representing negative
|
| 384 |
+
// infinity, use `-InfiniteDuration()`.
|
| 385 |
+
//
|
| 386 |
+
// Duration arithmetic overflows to +/- infinity and saturates. In general,
|
| 387 |
+
// arithmetic with `Duration` infinities is similar to IEEE 754 infinities
|
| 388 |
+
// except where IEEE 754 NaN would be involved, in which case +/-
|
| 389 |
+
// `InfiniteDuration()` is used in place of a "nan" Duration.
|
| 390 |
+
//
|
| 391 |
+
// Examples:
|
| 392 |
+
//
|
| 393 |
+
// constexpr absl::Duration inf = absl::InfiniteDuration();
|
| 394 |
+
// const absl::Duration d = ... any finite duration ...
|
| 395 |
+
//
|
| 396 |
+
// inf == inf + inf
|
| 397 |
+
// inf == inf + d
|
| 398 |
+
// inf == inf - inf
|
| 399 |
+
// -inf == d - inf
|
| 400 |
+
//
|
| 401 |
+
// inf == d * 1e100
|
| 402 |
+
// inf == inf / 2
|
| 403 |
+
// 0 == d / inf
|
| 404 |
+
// INT64_MAX == inf / d
|
| 405 |
+
//
|
| 406 |
+
// d < inf
|
| 407 |
+
// -inf < d
|
| 408 |
+
//
|
| 409 |
+
// // Division by zero returns infinity, or INT64_MIN/MAX where appropriate.
|
| 410 |
+
// inf == d / 0
|
| 411 |
+
// INT64_MAX == d / absl::ZeroDuration()
|
| 412 |
+
//
|
| 413 |
+
// The examples involving the `/` operator above also apply to `IDivDuration()`
|
| 414 |
+
// and `FDivDuration()`.
|
| 415 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION constexpr Duration InfiniteDuration();
|
| 416 |
+
|
| 417 |
+
// Nanoseconds()
|
| 418 |
+
// Microseconds()
|
| 419 |
+
// Milliseconds()
|
| 420 |
+
// Seconds()
|
| 421 |
+
// Minutes()
|
| 422 |
+
// Hours()
|
| 423 |
+
//
|
| 424 |
+
// Factory functions for constructing `Duration` values from an integral number
|
| 425 |
+
// of the unit indicated by the factory function's name. The number must be
|
| 426 |
+
// representable as int64_t.
|
| 427 |
+
//
|
| 428 |
+
// NOTE: no "Days()" factory function exists because "a day" is ambiguous.
|
| 429 |
+
// Civil days are not always 24 hours long, and a 24-hour duration often does
|
| 430 |
+
// not correspond with a civil day. If a 24-hour duration is needed, use
|
| 431 |
+
// `absl::Hours(24)`. If you actually want a civil day, use absl::CivilDay
|
| 432 |
+
// from civil_time.h.
|
| 433 |
+
//
|
| 434 |
+
// Example:
|
| 435 |
+
//
|
| 436 |
+
// absl::Duration a = absl::Seconds(60);
|
| 437 |
+
// absl::Duration b = absl::Minutes(1); // b == a
|
| 438 |
+
template <typename T, time_internal::EnableIfIntegral<T> = 0>
|
| 439 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION constexpr Duration Nanoseconds(T n) {
|
| 440 |
+
return time_internal::FromInt64(n, std::nano{});
|
| 441 |
+
}
|
| 442 |
+
template <typename T, time_internal::EnableIfIntegral<T> = 0>
|
| 443 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION constexpr Duration Microseconds(T n) {
|
| 444 |
+
return time_internal::FromInt64(n, std::micro{});
|
| 445 |
+
}
|
| 446 |
+
template <typename T, time_internal::EnableIfIntegral<T> = 0>
|
| 447 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION constexpr Duration Milliseconds(T n) {
|
| 448 |
+
return time_internal::FromInt64(n, std::milli{});
|
| 449 |
+
}
|
| 450 |
+
template <typename T, time_internal::EnableIfIntegral<T> = 0>
|
| 451 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION constexpr Duration Seconds(T n) {
|
| 452 |
+
return time_internal::FromInt64(n, std::ratio<1>{});
|
| 453 |
+
}
|
| 454 |
+
template <typename T, time_internal::EnableIfIntegral<T> = 0>
|
| 455 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION constexpr Duration Minutes(T n) {
|
| 456 |
+
return time_internal::FromInt64(n, std::ratio<60>{});
|
| 457 |
+
}
|
| 458 |
+
template <typename T, time_internal::EnableIfIntegral<T> = 0>
|
| 459 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION constexpr Duration Hours(T n) {
|
| 460 |
+
return time_internal::FromInt64(n, std::ratio<3600>{});
|
| 461 |
+
}
|
| 462 |
+
|
| 463 |
+
// Factory overloads for constructing `Duration` values from a floating-point
|
| 464 |
+
// number of the unit indicated by the factory function's name. These functions
|
| 465 |
+
// exist for convenience, but they are not as efficient as the integral
|
| 466 |
+
// factories, which should be preferred.
|
| 467 |
+
//
|
| 468 |
+
// Example:
|
| 469 |
+
//
|
| 470 |
+
// auto a = absl::Seconds(1.5); // OK
|
| 471 |
+
// auto b = absl::Milliseconds(1500); // BETTER
|
| 472 |
+
template <typename T, time_internal::EnableIfFloat<T> = 0>
|
| 473 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION Duration Nanoseconds(T n) {
|
| 474 |
+
return n * Nanoseconds(1);
|
| 475 |
+
}
|
| 476 |
+
template <typename T, time_internal::EnableIfFloat<T> = 0>
|
| 477 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION Duration Microseconds(T n) {
|
| 478 |
+
return n * Microseconds(1);
|
| 479 |
+
}
|
| 480 |
+
template <typename T, time_internal::EnableIfFloat<T> = 0>
|
| 481 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION Duration Milliseconds(T n) {
|
| 482 |
+
return n * Milliseconds(1);
|
| 483 |
+
}
|
| 484 |
+
template <typename T, time_internal::EnableIfFloat<T> = 0>
|
| 485 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION Duration Seconds(T n) {
|
| 486 |
+
if (n >= 0) { // Note: `NaN >= 0` is false.
|
| 487 |
+
if (n >= static_cast<T>((std::numeric_limits<int64_t>::max)())) {
|
| 488 |
+
return InfiniteDuration();
|
| 489 |
+
}
|
| 490 |
+
return time_internal::MakePosDoubleDuration(n);
|
| 491 |
+
} else {
|
| 492 |
+
if (std::isnan(n))
|
| 493 |
+
return std::signbit(n) ? -InfiniteDuration() : InfiniteDuration();
|
| 494 |
+
if (n <= (std::numeric_limits<int64_t>::min)()) return -InfiniteDuration();
|
| 495 |
+
return -time_internal::MakePosDoubleDuration(-n);
|
| 496 |
+
}
|
| 497 |
+
}
|
| 498 |
+
template <typename T, time_internal::EnableIfFloat<T> = 0>
|
| 499 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION Duration Minutes(T n) {
|
| 500 |
+
return n * Minutes(1);
|
| 501 |
+
}
|
| 502 |
+
template <typename T, time_internal::EnableIfFloat<T> = 0>
|
| 503 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION Duration Hours(T n) {
|
| 504 |
+
return n * Hours(1);
|
| 505 |
+
}
|
| 506 |
+
|
| 507 |
+
// ToInt64Nanoseconds()
|
| 508 |
+
// ToInt64Microseconds()
|
| 509 |
+
// ToInt64Milliseconds()
|
| 510 |
+
// ToInt64Seconds()
|
| 511 |
+
// ToInt64Minutes()
|
| 512 |
+
// ToInt64Hours()
|
| 513 |
+
//
|
| 514 |
+
// Helper functions that convert a Duration to an integral count of the
|
| 515 |
+
// indicated unit. These return the same results as the `IDivDuration()`
|
| 516 |
+
// function, though they usually do so more efficiently; see the
|
| 517 |
+
// documentation of `IDivDuration()` for details about overflow, etc.
|
| 518 |
+
//
|
| 519 |
+
// Example:
|
| 520 |
+
//
|
| 521 |
+
// absl::Duration d = absl::Milliseconds(1500);
|
| 522 |
+
// int64_t isec = absl::ToInt64Seconds(d); // isec == 1
|
| 523 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION int64_t ToInt64Nanoseconds(Duration d);
|
| 524 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION int64_t ToInt64Microseconds(Duration d);
|
| 525 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION int64_t ToInt64Milliseconds(Duration d);
|
| 526 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION int64_t ToInt64Seconds(Duration d);
|
| 527 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION int64_t ToInt64Minutes(Duration d);
|
| 528 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION int64_t ToInt64Hours(Duration d);
|
| 529 |
+
|
| 530 |
+
// ToDoubleNanoseconds()
|
| 531 |
+
// ToDoubleMicroseconds()
|
| 532 |
+
// ToDoubleMilliseconds()
|
| 533 |
+
// ToDoubleSeconds()
|
| 534 |
+
// ToDoubleMinutes()
|
| 535 |
+
// ToDoubleHours()
|
| 536 |
+
//
|
| 537 |
+
// Helper functions that convert a Duration to a floating point count of the
|
| 538 |
+
// indicated unit. These functions are shorthand for the `FDivDuration()`
|
| 539 |
+
// function above; see its documentation for details about overflow, etc.
|
| 540 |
+
//
|
| 541 |
+
// Example:
|
| 542 |
+
//
|
| 543 |
+
// absl::Duration d = absl::Milliseconds(1500);
|
| 544 |
+
// double dsec = absl::ToDoubleSeconds(d); // dsec == 1.5
|
| 545 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION double ToDoubleNanoseconds(Duration d);
|
| 546 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION double ToDoubleMicroseconds(Duration d);
|
| 547 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION double ToDoubleMilliseconds(Duration d);
|
| 548 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION double ToDoubleSeconds(Duration d);
|
| 549 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION double ToDoubleMinutes(Duration d);
|
| 550 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION double ToDoubleHours(Duration d);
|
| 551 |
+
|
| 552 |
+
// FromChrono()
|
| 553 |
+
//
|
| 554 |
+
// Converts any of the pre-defined std::chrono durations to an absl::Duration.
|
| 555 |
+
//
|
| 556 |
+
// Example:
|
| 557 |
+
//
|
| 558 |
+
// std::chrono::milliseconds ms(123);
|
| 559 |
+
// absl::Duration d = absl::FromChrono(ms);
|
| 560 |
+
ABSL_ATTRIBUTE_PURE_FUNCTION constexpr Duration FromChrono(
|
| 561 |
+
const std::chrono::nanoseconds& d);
|
| 562 |
+
ABSL_ATTRIBUTE_PURE_FUNCTION constexpr Duration FromChrono(
|
| 563 |
+
const std::chrono::microseconds& d);
|
| 564 |
+
ABSL_ATTRIBUTE_PURE_FUNCTION constexpr Duration FromChrono(
|
| 565 |
+
const std::chrono::milliseconds& d);
|
| 566 |
+
ABSL_ATTRIBUTE_PURE_FUNCTION constexpr Duration FromChrono(
|
| 567 |
+
const std::chrono::seconds& d);
|
| 568 |
+
ABSL_ATTRIBUTE_PURE_FUNCTION constexpr Duration FromChrono(
|
| 569 |
+
const std::chrono::minutes& d);
|
| 570 |
+
ABSL_ATTRIBUTE_PURE_FUNCTION constexpr Duration FromChrono(
|
| 571 |
+
const std::chrono::hours& d);
|
| 572 |
+
|
| 573 |
+
// ToChronoNanoseconds()
|
| 574 |
+
// ToChronoMicroseconds()
|
| 575 |
+
// ToChronoMilliseconds()
|
| 576 |
+
// ToChronoSeconds()
|
| 577 |
+
// ToChronoMinutes()
|
| 578 |
+
// ToChronoHours()
|
| 579 |
+
//
|
| 580 |
+
// Converts an absl::Duration to any of the pre-defined std::chrono durations.
|
| 581 |
+
// If overflow would occur, the returned value will saturate at the min/max
|
| 582 |
+
// chrono duration value instead.
|
| 583 |
+
//
|
| 584 |
+
// Example:
|
| 585 |
+
//
|
| 586 |
+
// absl::Duration d = absl::Microseconds(123);
|
| 587 |
+
// auto x = absl::ToChronoMicroseconds(d);
|
| 588 |
+
// auto y = absl::ToChronoNanoseconds(d); // x == y
|
| 589 |
+
// auto z = absl::ToChronoSeconds(absl::InfiniteDuration());
|
| 590 |
+
// // z == std::chrono::seconds::max()
|
| 591 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION std::chrono::nanoseconds ToChronoNanoseconds(
|
| 592 |
+
Duration d);
|
| 593 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION std::chrono::microseconds ToChronoMicroseconds(
|
| 594 |
+
Duration d);
|
| 595 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION std::chrono::milliseconds ToChronoMilliseconds(
|
| 596 |
+
Duration d);
|
| 597 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION std::chrono::seconds ToChronoSeconds(Duration d);
|
| 598 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION std::chrono::minutes ToChronoMinutes(Duration d);
|
| 599 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION std::chrono::hours ToChronoHours(Duration d);
|
| 600 |
+
|
| 601 |
+
// FormatDuration()
|
| 602 |
+
//
|
| 603 |
+
// Returns a string representing the duration in the form "72h3m0.5s".
|
| 604 |
+
// Returns "inf" or "-inf" for +/- `InfiniteDuration()`.
|
| 605 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION std::string FormatDuration(Duration d);
|
| 606 |
+
|
| 607 |
+
// Output stream operator.
|
| 608 |
+
inline std::ostream& operator<<(std::ostream& os, Duration d) {
|
| 609 |
+
return os << FormatDuration(d);
|
| 610 |
+
}
|
| 611 |
+
|
| 612 |
+
// ParseDuration()
|
| 613 |
+
//
|
| 614 |
+
// Parses a duration string consisting of a possibly signed sequence of
|
| 615 |
+
// decimal numbers, each with an optional fractional part and a unit
|
| 616 |
+
// suffix. The valid suffixes are "ns", "us" "ms", "s", "m", and "h".
|
| 617 |
+
// Simple examples include "300ms", "-1.5h", and "2h45m". Parses "0" as
|
| 618 |
+
// `ZeroDuration()`. Parses "inf" and "-inf" as +/- `InfiniteDuration()`.
|
| 619 |
+
bool ParseDuration(absl::string_view dur_string, Duration* d);
|
| 620 |
+
|
| 621 |
+
// AbslParseFlag()
|
| 622 |
+
//
|
| 623 |
+
// Parses a command-line flag string representation `text` into a Duration
|
| 624 |
+
// value. Duration flags must be specified in a format that is valid input for
|
| 625 |
+
// `absl::ParseDuration()`.
|
| 626 |
+
bool AbslParseFlag(absl::string_view text, Duration* dst, std::string* error);
|
| 627 |
+
|
| 628 |
+
|
| 629 |
+
// AbslUnparseFlag()
|
| 630 |
+
//
|
| 631 |
+
// Unparses a Duration value into a command-line string representation using
|
| 632 |
+
// the format specified by `absl::ParseDuration()`.
|
| 633 |
+
std::string AbslUnparseFlag(Duration d);
|
| 634 |
+
|
| 635 |
+
ABSL_DEPRECATED("Use AbslParseFlag() instead.")
|
| 636 |
+
bool ParseFlag(const std::string& text, Duration* dst, std::string* error);
|
| 637 |
+
ABSL_DEPRECATED("Use AbslUnparseFlag() instead.")
|
| 638 |
+
std::string UnparseFlag(Duration d);
|
| 639 |
+
|
| 640 |
+
// Time
|
| 641 |
+
//
|
| 642 |
+
// An `absl::Time` represents a specific instant in time. Arithmetic operators
|
| 643 |
+
// are provided for naturally expressing time calculations. Instances are
|
| 644 |
+
// created using `absl::Now()` and the `absl::From*()` factory functions that
|
| 645 |
+
// accept the gamut of other time representations. Formatting and parsing
|
| 646 |
+
// functions are provided for conversion to and from strings. `absl::Time`
|
| 647 |
+
// should be passed by value rather than const reference.
|
| 648 |
+
//
|
| 649 |
+
// `absl::Time` assumes there are 60 seconds in a minute, which means the
|
| 650 |
+
// underlying time scales must be "smeared" to eliminate leap seconds.
|
| 651 |
+
// See https://developers.google.com/time/smear.
|
| 652 |
+
//
|
| 653 |
+
// Even though `absl::Time` supports a wide range of timestamps, exercise
|
| 654 |
+
// caution when using values in the distant past. `absl::Time` uses the
|
| 655 |
+
// Proleptic Gregorian calendar, which extends the Gregorian calendar backward
|
| 656 |
+
// to dates before its introduction in 1582.
|
| 657 |
+
// See https://en.wikipedia.org/wiki/Proleptic_Gregorian_calendar
|
| 658 |
+
// for more information. Use the ICU calendar classes to convert a date in
|
| 659 |
+
// some other calendar (http://userguide.icu-project.org/datetime/calendar).
|
| 660 |
+
//
|
| 661 |
+
// Similarly, standardized time zones are a reasonably recent innovation, with
|
| 662 |
+
// the Greenwich prime meridian being established in 1884. The TZ database
|
| 663 |
+
// itself does not profess accurate offsets for timestamps prior to 1970. The
|
| 664 |
+
// breakdown of future timestamps is subject to the whim of regional
|
| 665 |
+
// governments.
|
| 666 |
+
//
|
| 667 |
+
// The `absl::Time` class represents an instant in time as a count of clock
|
| 668 |
+
// ticks of some granularity (resolution) from some starting point (epoch).
|
| 669 |
+
//
|
| 670 |
+
// `absl::Time` uses a resolution that is high enough to avoid loss in
|
| 671 |
+
// precision, and a range that is wide enough to avoid overflow, when
|
| 672 |
+
// converting between tick counts in most Google time scales (i.e., resolution
|
| 673 |
+
// of at least one nanosecond, and range +/-100 billion years). Conversions
|
| 674 |
+
// between the time scales are performed by truncating (towards negative
|
| 675 |
+
// infinity) to the nearest representable point.
|
| 676 |
+
//
|
| 677 |
+
// Examples:
|
| 678 |
+
//
|
| 679 |
+
// absl::Time t1 = ...;
|
| 680 |
+
// absl::Time t2 = t1 + absl::Minutes(2);
|
| 681 |
+
// absl::Duration d = t2 - t1; // == absl::Minutes(2)
|
| 682 |
+
//
|
| 683 |
+
class Time {
|
| 684 |
+
public:
|
| 685 |
+
// Value semantics.
|
| 686 |
+
|
| 687 |
+
// Returns the Unix epoch. However, those reading your code may not know
|
| 688 |
+
// or expect the Unix epoch as the default value, so make your code more
|
| 689 |
+
// readable by explicitly initializing all instances before use.
|
| 690 |
+
//
|
| 691 |
+
// Example:
|
| 692 |
+
// absl::Time t = absl::UnixEpoch();
|
| 693 |
+
// absl::Time t = absl::Now();
|
| 694 |
+
// absl::Time t = absl::TimeFromTimeval(tv);
|
| 695 |
+
// absl::Time t = absl::InfinitePast();
|
| 696 |
+
constexpr Time() = default;
|
| 697 |
+
|
| 698 |
+
// Copyable.
|
| 699 |
+
constexpr Time(const Time& t) = default;
|
| 700 |
+
Time& operator=(const Time& t) = default;
|
| 701 |
+
|
| 702 |
+
// Assignment operators.
|
| 703 |
+
Time& operator+=(Duration d) {
|
| 704 |
+
rep_ += d;
|
| 705 |
+
return *this;
|
| 706 |
+
}
|
| 707 |
+
Time& operator-=(Duration d) {
|
| 708 |
+
rep_ -= d;
|
| 709 |
+
return *this;
|
| 710 |
+
}
|
| 711 |
+
|
| 712 |
+
// Time::Breakdown
|
| 713 |
+
//
|
| 714 |
+
// The calendar and wall-clock (aka "civil time") components of an
|
| 715 |
+
// `absl::Time` in a certain `absl::TimeZone`. This struct is not
|
| 716 |
+
// intended to represent an instant in time. So, rather than passing
|
| 717 |
+
// a `Time::Breakdown` to a function, pass an `absl::Time` and an
|
| 718 |
+
// `absl::TimeZone`.
|
| 719 |
+
//
|
| 720 |
+
// Deprecated. Use `absl::TimeZone::CivilInfo`.
|
| 721 |
+
struct
|
| 722 |
+
Breakdown {
|
| 723 |
+
int64_t year; // year (e.g., 2013)
|
| 724 |
+
int month; // month of year [1:12]
|
| 725 |
+
int day; // day of month [1:31]
|
| 726 |
+
int hour; // hour of day [0:23]
|
| 727 |
+
int minute; // minute of hour [0:59]
|
| 728 |
+
int second; // second of minute [0:59]
|
| 729 |
+
Duration subsecond; // [Seconds(0):Seconds(1)) if finite
|
| 730 |
+
int weekday; // 1==Mon, ..., 7=Sun
|
| 731 |
+
int yearday; // day of year [1:366]
|
| 732 |
+
|
| 733 |
+
// Note: The following fields exist for backward compatibility
|
| 734 |
+
// with older APIs. Accessing these fields directly is a sign of
|
| 735 |
+
// imprudent logic in the calling code. Modern time-related code
|
| 736 |
+
// should only access this data indirectly by way of FormatTime().
|
| 737 |
+
// These fields are undefined for InfiniteFuture() and InfinitePast().
|
| 738 |
+
int offset; // seconds east of UTC
|
| 739 |
+
bool is_dst; // is offset non-standard?
|
| 740 |
+
const char* zone_abbr; // time-zone abbreviation (e.g., "PST")
|
| 741 |
+
};
|
| 742 |
+
|
| 743 |
+
// Time::In()
|
| 744 |
+
//
|
| 745 |
+
// Returns the breakdown of this instant in the given TimeZone.
|
| 746 |
+
//
|
| 747 |
+
// Deprecated. Use `absl::TimeZone::At(Time)`.
|
| 748 |
+
Breakdown In(TimeZone tz) const;
|
| 749 |
+
|
| 750 |
+
template <typename H>
|
| 751 |
+
friend H AbslHashValue(H h, Time t) {
|
| 752 |
+
return H::combine(std::move(h), t.rep_);
|
| 753 |
+
}
|
| 754 |
+
|
| 755 |
+
private:
|
| 756 |
+
friend constexpr Time time_internal::FromUnixDuration(Duration d);
|
| 757 |
+
friend constexpr Duration time_internal::ToUnixDuration(Time t);
|
| 758 |
+
friend constexpr bool operator<(Time lhs, Time rhs);
|
| 759 |
+
friend constexpr bool operator==(Time lhs, Time rhs);
|
| 760 |
+
friend Duration operator-(Time lhs, Time rhs);
|
| 761 |
+
friend constexpr Time UniversalEpoch();
|
| 762 |
+
friend constexpr Time InfiniteFuture();
|
| 763 |
+
friend constexpr Time InfinitePast();
|
| 764 |
+
constexpr explicit Time(Duration rep) : rep_(rep) {}
|
| 765 |
+
Duration rep_;
|
| 766 |
+
};
|
| 767 |
+
|
| 768 |
+
// Relational Operators
|
| 769 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION constexpr bool operator<(Time lhs, Time rhs) {
|
| 770 |
+
return lhs.rep_ < rhs.rep_;
|
| 771 |
+
}
|
| 772 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION constexpr bool operator>(Time lhs, Time rhs) {
|
| 773 |
+
return rhs < lhs;
|
| 774 |
+
}
|
| 775 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION constexpr bool operator>=(Time lhs, Time rhs) {
|
| 776 |
+
return !(lhs < rhs);
|
| 777 |
+
}
|
| 778 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION constexpr bool operator<=(Time lhs, Time rhs) {
|
| 779 |
+
return !(rhs < lhs);
|
| 780 |
+
}
|
| 781 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION constexpr bool operator==(Time lhs, Time rhs) {
|
| 782 |
+
return lhs.rep_ == rhs.rep_;
|
| 783 |
+
}
|
| 784 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION constexpr bool operator!=(Time lhs, Time rhs) {
|
| 785 |
+
return !(lhs == rhs);
|
| 786 |
+
}
|
| 787 |
+
|
| 788 |
+
// Additive Operators
|
| 789 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION inline Time operator+(Time lhs, Duration rhs) {
|
| 790 |
+
return lhs += rhs;
|
| 791 |
+
}
|
| 792 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION inline Time operator+(Duration lhs, Time rhs) {
|
| 793 |
+
return rhs += lhs;
|
| 794 |
+
}
|
| 795 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION inline Time operator-(Time lhs, Duration rhs) {
|
| 796 |
+
return lhs -= rhs;
|
| 797 |
+
}
|
| 798 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION inline Duration operator-(Time lhs, Time rhs) {
|
| 799 |
+
return lhs.rep_ - rhs.rep_;
|
| 800 |
+
}
|
| 801 |
+
|
| 802 |
+
// UnixEpoch()
|
| 803 |
+
//
|
| 804 |
+
// Returns the `absl::Time` representing "1970-01-01 00:00:00.0 +0000".
|
| 805 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION constexpr Time UnixEpoch() { return Time(); }
|
| 806 |
+
|
| 807 |
+
// UniversalEpoch()
|
| 808 |
+
//
|
| 809 |
+
// Returns the `absl::Time` representing "0001-01-01 00:00:00.0 +0000", the
|
| 810 |
+
// epoch of the ICU Universal Time Scale.
|
| 811 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION constexpr Time UniversalEpoch() {
|
| 812 |
+
// 719162 is the number of days from 0001-01-01 to 1970-01-01,
|
| 813 |
+
// assuming the Gregorian calendar.
|
| 814 |
+
return Time(
|
| 815 |
+
time_internal::MakeDuration(-24 * 719162 * int64_t{3600}, uint32_t{0}));
|
| 816 |
+
}
|
| 817 |
+
|
| 818 |
+
// InfiniteFuture()
|
| 819 |
+
//
|
| 820 |
+
// Returns an `absl::Time` that is infinitely far in the future.
|
| 821 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION constexpr Time InfiniteFuture() {
|
| 822 |
+
return Time(time_internal::MakeDuration((std::numeric_limits<int64_t>::max)(),
|
| 823 |
+
~uint32_t{0}));
|
| 824 |
+
}
|
| 825 |
+
|
| 826 |
+
// InfinitePast()
|
| 827 |
+
//
|
| 828 |
+
// Returns an `absl::Time` that is infinitely far in the past.
|
| 829 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION constexpr Time InfinitePast() {
|
| 830 |
+
return Time(time_internal::MakeDuration((std::numeric_limits<int64_t>::min)(),
|
| 831 |
+
~uint32_t{0}));
|
| 832 |
+
}
|
| 833 |
+
|
| 834 |
+
// FromUnixNanos()
|
| 835 |
+
// FromUnixMicros()
|
| 836 |
+
// FromUnixMillis()
|
| 837 |
+
// FromUnixSeconds()
|
| 838 |
+
// FromTimeT()
|
| 839 |
+
// FromUDate()
|
| 840 |
+
// FromUniversal()
|
| 841 |
+
//
|
| 842 |
+
// Creates an `absl::Time` from a variety of other representations.
|
| 843 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION constexpr Time FromUnixNanos(int64_t ns);
|
| 844 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION constexpr Time FromUnixMicros(int64_t us);
|
| 845 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION constexpr Time FromUnixMillis(int64_t ms);
|
| 846 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION constexpr Time FromUnixSeconds(int64_t s);
|
| 847 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION constexpr Time FromTimeT(time_t t);
|
| 848 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION Time FromUDate(double udate);
|
| 849 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION Time FromUniversal(int64_t universal);
|
| 850 |
+
|
| 851 |
+
// ToUnixNanos()
|
| 852 |
+
// ToUnixMicros()
|
| 853 |
+
// ToUnixMillis()
|
| 854 |
+
// ToUnixSeconds()
|
| 855 |
+
// ToTimeT()
|
| 856 |
+
// ToUDate()
|
| 857 |
+
// ToUniversal()
|
| 858 |
+
//
|
| 859 |
+
// Converts an `absl::Time` to a variety of other representations. Note that
|
| 860 |
+
// these operations round down toward negative infinity where necessary to
|
| 861 |
+
// adjust to the resolution of the result type. Beware of possible time_t
|
| 862 |
+
// over/underflow in ToTime{T,val,spec}() on 32-bit platforms.
|
| 863 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION int64_t ToUnixNanos(Time t);
|
| 864 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION int64_t ToUnixMicros(Time t);
|
| 865 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION int64_t ToUnixMillis(Time t);
|
| 866 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION int64_t ToUnixSeconds(Time t);
|
| 867 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION time_t ToTimeT(Time t);
|
| 868 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION double ToUDate(Time t);
|
| 869 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION int64_t ToUniversal(Time t);
|
| 870 |
+
|
| 871 |
+
// DurationFromTimespec()
|
| 872 |
+
// DurationFromTimeval()
|
| 873 |
+
// ToTimespec()
|
| 874 |
+
// ToTimeval()
|
| 875 |
+
// TimeFromTimespec()
|
| 876 |
+
// TimeFromTimeval()
|
| 877 |
+
// ToTimespec()
|
| 878 |
+
// ToTimeval()
|
| 879 |
+
//
|
| 880 |
+
// Some APIs use a timespec or a timeval as a Duration (e.g., nanosleep(2)
|
| 881 |
+
// and select(2)), while others use them as a Time (e.g. clock_gettime(2)
|
| 882 |
+
// and gettimeofday(2)), so conversion functions are provided for both cases.
|
| 883 |
+
// The "to timespec/val" direction is easily handled via overloading, but
|
| 884 |
+
// for "from timespec/val" the desired type is part of the function name.
|
| 885 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION Duration DurationFromTimespec(timespec ts);
|
| 886 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION Duration DurationFromTimeval(timeval tv);
|
| 887 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION timespec ToTimespec(Duration d);
|
| 888 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION timeval ToTimeval(Duration d);
|
| 889 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION Time TimeFromTimespec(timespec ts);
|
| 890 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION Time TimeFromTimeval(timeval tv);
|
| 891 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION timespec ToTimespec(Time t);
|
| 892 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION timeval ToTimeval(Time t);
|
| 893 |
+
|
| 894 |
+
// FromChrono()
|
| 895 |
+
//
|
| 896 |
+
// Converts a std::chrono::system_clock::time_point to an absl::Time.
|
| 897 |
+
//
|
| 898 |
+
// Example:
|
| 899 |
+
//
|
| 900 |
+
// auto tp = std::chrono::system_clock::from_time_t(123);
|
| 901 |
+
// absl::Time t = absl::FromChrono(tp);
|
| 902 |
+
// // t == absl::FromTimeT(123)
|
| 903 |
+
ABSL_ATTRIBUTE_PURE_FUNCTION Time
|
| 904 |
+
FromChrono(const std::chrono::system_clock::time_point& tp);
|
| 905 |
+
|
| 906 |
+
// ToChronoTime()
|
| 907 |
+
//
|
| 908 |
+
// Converts an absl::Time to a std::chrono::system_clock::time_point. If
|
| 909 |
+
// overflow would occur, the returned value will saturate at the min/max time
|
| 910 |
+
// point value instead.
|
| 911 |
+
//
|
| 912 |
+
// Example:
|
| 913 |
+
//
|
| 914 |
+
// absl::Time t = absl::FromTimeT(123);
|
| 915 |
+
// auto tp = absl::ToChronoTime(t);
|
| 916 |
+
// // tp == std::chrono::system_clock::from_time_t(123);
|
| 917 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION std::chrono::system_clock::time_point
|
| 918 |
+
ToChronoTime(Time);
|
| 919 |
+
|
| 920 |
+
// AbslParseFlag()
|
| 921 |
+
//
|
| 922 |
+
// Parses the command-line flag string representation `text` into a Time value.
|
| 923 |
+
// Time flags must be specified in a format that matches absl::RFC3339_full.
|
| 924 |
+
//
|
| 925 |
+
// For example:
|
| 926 |
+
//
|
| 927 |
+
// --start_time=2016-01-02T03:04:05.678+08:00
|
| 928 |
+
//
|
| 929 |
+
// Note: A UTC offset (or 'Z' indicating a zero-offset from UTC) is required.
|
| 930 |
+
//
|
| 931 |
+
// Additionally, if you'd like to specify a time as a count of
|
| 932 |
+
// seconds/milliseconds/etc from the Unix epoch, use an absl::Duration flag
|
| 933 |
+
// and add that duration to absl::UnixEpoch() to get an absl::Time.
|
| 934 |
+
bool AbslParseFlag(absl::string_view text, Time* t, std::string* error);
|
| 935 |
+
|
| 936 |
+
// AbslUnparseFlag()
|
| 937 |
+
//
|
| 938 |
+
// Unparses a Time value into a command-line string representation using
|
| 939 |
+
// the format specified by `absl::ParseTime()`.
|
| 940 |
+
std::string AbslUnparseFlag(Time t);
|
| 941 |
+
|
| 942 |
+
ABSL_DEPRECATED("Use AbslParseFlag() instead.")
|
| 943 |
+
bool ParseFlag(const std::string& text, Time* t, std::string* error);
|
| 944 |
+
ABSL_DEPRECATED("Use AbslUnparseFlag() instead.")
|
| 945 |
+
std::string UnparseFlag(Time t);
|
| 946 |
+
|
| 947 |
+
// TimeZone
|
| 948 |
+
//
|
| 949 |
+
// The `absl::TimeZone` is an opaque, small, value-type class representing a
|
| 950 |
+
// geo-political region within which particular rules are used for converting
|
| 951 |
+
// between absolute and civil times (see https://git.io/v59Ly). `absl::TimeZone`
|
| 952 |
+
// values are named using the TZ identifiers from the IANA Time Zone Database,
|
| 953 |
+
// such as "America/Los_Angeles" or "Australia/Sydney". `absl::TimeZone` values
|
| 954 |
+
// are created from factory functions such as `absl::LoadTimeZone()`. Note:
|
| 955 |
+
// strings like "PST" and "EDT" are not valid TZ identifiers. Prefer to pass by
|
| 956 |
+
// value rather than const reference.
|
| 957 |
+
//
|
| 958 |
+
// For more on the fundamental concepts of time zones, absolute times, and civil
|
| 959 |
+
// times, see https://github.com/google/cctz#fundamental-concepts
|
| 960 |
+
//
|
| 961 |
+
// Examples:
|
| 962 |
+
//
|
| 963 |
+
// absl::TimeZone utc = absl::UTCTimeZone();
|
| 964 |
+
// absl::TimeZone pst = absl::FixedTimeZone(-8 * 60 * 60);
|
| 965 |
+
// absl::TimeZone loc = absl::LocalTimeZone();
|
| 966 |
+
// absl::TimeZone lax;
|
| 967 |
+
// if (!absl::LoadTimeZone("America/Los_Angeles", &lax)) {
|
| 968 |
+
// // handle error case
|
| 969 |
+
// }
|
| 970 |
+
//
|
| 971 |
+
// See also:
|
| 972 |
+
// - https://github.com/google/cctz
|
| 973 |
+
// - https://www.iana.org/time-zones
|
| 974 |
+
// - https://en.wikipedia.org/wiki/Zoneinfo
|
| 975 |
+
class TimeZone {
|
| 976 |
+
public:
|
| 977 |
+
explicit TimeZone(time_internal::cctz::time_zone tz) : cz_(tz) {}
|
| 978 |
+
TimeZone() = default; // UTC, but prefer UTCTimeZone() to be explicit.
|
| 979 |
+
|
| 980 |
+
// Copyable.
|
| 981 |
+
TimeZone(const TimeZone&) = default;
|
| 982 |
+
TimeZone& operator=(const TimeZone&) = default;
|
| 983 |
+
|
| 984 |
+
explicit operator time_internal::cctz::time_zone() const { return cz_; }
|
| 985 |
+
|
| 986 |
+
std::string name() const { return cz_.name(); }
|
| 987 |
+
|
| 988 |
+
// TimeZone::CivilInfo
|
| 989 |
+
//
|
| 990 |
+
// Information about the civil time corresponding to an absolute time.
|
| 991 |
+
// This struct is not intended to represent an instant in time. So, rather
|
| 992 |
+
// than passing a `TimeZone::CivilInfo` to a function, pass an `absl::Time`
|
| 993 |
+
// and an `absl::TimeZone`.
|
| 994 |
+
struct CivilInfo {
|
| 995 |
+
CivilSecond cs;
|
| 996 |
+
Duration subsecond;
|
| 997 |
+
|
| 998 |
+
// Note: The following fields exist for backward compatibility
|
| 999 |
+
// with older APIs. Accessing these fields directly is a sign of
|
| 1000 |
+
// imprudent logic in the calling code. Modern time-related code
|
| 1001 |
+
// should only access this data indirectly by way of FormatTime().
|
| 1002 |
+
// These fields are undefined for InfiniteFuture() and InfinitePast().
|
| 1003 |
+
int offset; // seconds east of UTC
|
| 1004 |
+
bool is_dst; // is offset non-standard?
|
| 1005 |
+
const char* zone_abbr; // time-zone abbreviation (e.g., "PST")
|
| 1006 |
+
};
|
| 1007 |
+
|
| 1008 |
+
// TimeZone::At(Time)
|
| 1009 |
+
//
|
| 1010 |
+
// Returns the civil time for this TimeZone at a certain `absl::Time`.
|
| 1011 |
+
// If the input time is infinite, the output civil second will be set to
|
| 1012 |
+
// CivilSecond::max() or min(), and the subsecond will be infinite.
|
| 1013 |
+
//
|
| 1014 |
+
// Example:
|
| 1015 |
+
//
|
| 1016 |
+
// const auto epoch = lax.At(absl::UnixEpoch());
|
| 1017 |
+
// // epoch.cs == 1969-12-31 16:00:00
|
| 1018 |
+
// // epoch.subsecond == absl::ZeroDuration()
|
| 1019 |
+
// // epoch.offset == -28800
|
| 1020 |
+
// // epoch.is_dst == false
|
| 1021 |
+
// // epoch.abbr == "PST"
|
| 1022 |
+
CivilInfo At(Time t) const;
|
| 1023 |
+
|
| 1024 |
+
// TimeZone::TimeInfo
|
| 1025 |
+
//
|
| 1026 |
+
// Information about the absolute times corresponding to a civil time.
|
| 1027 |
+
// (Subseconds must be handled separately.)
|
| 1028 |
+
//
|
| 1029 |
+
// It is possible for a caller to pass a civil-time value that does
|
| 1030 |
+
// not represent an actual or unique instant in time (due to a shift
|
| 1031 |
+
// in UTC offset in the TimeZone, which results in a discontinuity in
|
| 1032 |
+
// the civil-time components). For example, a daylight-saving-time
|
| 1033 |
+
// transition skips or repeats civil times---in the United States,
|
| 1034 |
+
// March 13, 2011 02:15 never occurred, while November 6, 2011 01:15
|
| 1035 |
+
// occurred twice---so requests for such times are not well-defined.
|
| 1036 |
+
// To account for these possibilities, `absl::TimeZone::TimeInfo` is
|
| 1037 |
+
// richer than just a single `absl::Time`.
|
| 1038 |
+
struct TimeInfo {
|
| 1039 |
+
enum CivilKind {
|
| 1040 |
+
UNIQUE, // the civil time was singular (pre == trans == post)
|
| 1041 |
+
SKIPPED, // the civil time did not exist (pre >= trans > post)
|
| 1042 |
+
REPEATED, // the civil time was ambiguous (pre < trans <= post)
|
| 1043 |
+
} kind;
|
| 1044 |
+
Time pre; // time calculated using the pre-transition offset
|
| 1045 |
+
Time trans; // when the civil-time discontinuity occurred
|
| 1046 |
+
Time post; // time calculated using the post-transition offset
|
| 1047 |
+
};
|
| 1048 |
+
|
| 1049 |
+
// TimeZone::At(CivilSecond)
|
| 1050 |
+
//
|
| 1051 |
+
// Returns an `absl::TimeInfo` containing the absolute time(s) for this
|
| 1052 |
+
// TimeZone at an `absl::CivilSecond`. When the civil time is skipped or
|
| 1053 |
+
// repeated, returns times calculated using the pre-transition and post-
|
| 1054 |
+
// transition UTC offsets, plus the transition time itself.
|
| 1055 |
+
//
|
| 1056 |
+
// Examples:
|
| 1057 |
+
//
|
| 1058 |
+
// // A unique civil time
|
| 1059 |
+
// const auto jan01 = lax.At(absl::CivilSecond(2011, 1, 1, 0, 0, 0));
|
| 1060 |
+
// // jan01.kind == TimeZone::TimeInfo::UNIQUE
|
| 1061 |
+
// // jan01.pre is 2011-01-01 00:00:00 -0800
|
| 1062 |
+
// // jan01.trans is 2011-01-01 00:00:00 -0800
|
| 1063 |
+
// // jan01.post is 2011-01-01 00:00:00 -0800
|
| 1064 |
+
//
|
| 1065 |
+
// // A Spring DST transition, when there is a gap in civil time
|
| 1066 |
+
// const auto mar13 = lax.At(absl::CivilSecond(2011, 3, 13, 2, 15, 0));
|
| 1067 |
+
// // mar13.kind == TimeZone::TimeInfo::SKIPPED
|
| 1068 |
+
// // mar13.pre is 2011-03-13 03:15:00 -0700
|
| 1069 |
+
// // mar13.trans is 2011-03-13 03:00:00 -0700
|
| 1070 |
+
// // mar13.post is 2011-03-13 01:15:00 -0800
|
| 1071 |
+
//
|
| 1072 |
+
// // A Fall DST transition, when civil times are repeated
|
| 1073 |
+
// const auto nov06 = lax.At(absl::CivilSecond(2011, 11, 6, 1, 15, 0));
|
| 1074 |
+
// // nov06.kind == TimeZone::TimeInfo::REPEATED
|
| 1075 |
+
// // nov06.pre is 2011-11-06 01:15:00 -0700
|
| 1076 |
+
// // nov06.trans is 2011-11-06 01:00:00 -0800
|
| 1077 |
+
// // nov06.post is 2011-11-06 01:15:00 -0800
|
| 1078 |
+
TimeInfo At(CivilSecond ct) const;
|
| 1079 |
+
|
| 1080 |
+
// TimeZone::NextTransition()
|
| 1081 |
+
// TimeZone::PrevTransition()
|
| 1082 |
+
//
|
| 1083 |
+
// Finds the time of the next/previous offset change in this time zone.
|
| 1084 |
+
//
|
| 1085 |
+
// By definition, `NextTransition(t, &trans)` returns false when `t` is
|
| 1086 |
+
// `InfiniteFuture()`, and `PrevTransition(t, &trans)` returns false
|
| 1087 |
+
// when `t` is `InfinitePast()`. If the zone has no transitions, the
|
| 1088 |
+
// result will also be false no matter what the argument.
|
| 1089 |
+
//
|
| 1090 |
+
// Otherwise, when `t` is `InfinitePast()`, `NextTransition(t, &trans)`
|
| 1091 |
+
// returns true and sets `trans` to the first recorded transition. Chains
|
| 1092 |
+
// of calls to `NextTransition()/PrevTransition()` will eventually return
|
| 1093 |
+
// false, but it is unspecified exactly when `NextTransition(t, &trans)`
|
| 1094 |
+
// jumps to false, or what time is set by `PrevTransition(t, &trans)` for
|
| 1095 |
+
// a very distant `t`.
|
| 1096 |
+
//
|
| 1097 |
+
// Note: Enumeration of time-zone transitions is for informational purposes
|
| 1098 |
+
// only. Modern time-related code should not care about when offset changes
|
| 1099 |
+
// occur.
|
| 1100 |
+
//
|
| 1101 |
+
// Example:
|
| 1102 |
+
// absl::TimeZone nyc;
|
| 1103 |
+
// if (!absl::LoadTimeZone("America/New_York", &nyc)) { ... }
|
| 1104 |
+
// const auto now = absl::Now();
|
| 1105 |
+
// auto t = absl::InfinitePast();
|
| 1106 |
+
// absl::TimeZone::CivilTransition trans;
|
| 1107 |
+
// while (t <= now && nyc.NextTransition(t, &trans)) {
|
| 1108 |
+
// // transition: trans.from -> trans.to
|
| 1109 |
+
// t = nyc.At(trans.to).trans;
|
| 1110 |
+
// }
|
| 1111 |
+
struct CivilTransition {
|
| 1112 |
+
CivilSecond from; // the civil time we jump from
|
| 1113 |
+
CivilSecond to; // the civil time we jump to
|
| 1114 |
+
};
|
| 1115 |
+
bool NextTransition(Time t, CivilTransition* trans) const;
|
| 1116 |
+
bool PrevTransition(Time t, CivilTransition* trans) const;
|
| 1117 |
+
|
| 1118 |
+
template <typename H>
|
| 1119 |
+
friend H AbslHashValue(H h, TimeZone tz) {
|
| 1120 |
+
return H::combine(std::move(h), tz.cz_);
|
| 1121 |
+
}
|
| 1122 |
+
|
| 1123 |
+
private:
|
| 1124 |
+
friend bool operator==(TimeZone a, TimeZone b) { return a.cz_ == b.cz_; }
|
| 1125 |
+
friend bool operator!=(TimeZone a, TimeZone b) { return a.cz_ != b.cz_; }
|
| 1126 |
+
friend std::ostream& operator<<(std::ostream& os, TimeZone tz) {
|
| 1127 |
+
return os << tz.name();
|
| 1128 |
+
}
|
| 1129 |
+
|
| 1130 |
+
time_internal::cctz::time_zone cz_;
|
| 1131 |
+
};
|
| 1132 |
+
|
| 1133 |
+
// LoadTimeZone()
|
| 1134 |
+
//
|
| 1135 |
+
// Loads the named zone. May perform I/O on the initial load of the named
|
| 1136 |
+
// zone. If the name is invalid, or some other kind of error occurs, returns
|
| 1137 |
+
// `false` and `*tz` is set to the UTC time zone.
|
| 1138 |
+
inline bool LoadTimeZone(absl::string_view name, TimeZone* tz) {
|
| 1139 |
+
if (name == "localtime") {
|
| 1140 |
+
*tz = TimeZone(time_internal::cctz::local_time_zone());
|
| 1141 |
+
return true;
|
| 1142 |
+
}
|
| 1143 |
+
time_internal::cctz::time_zone cz;
|
| 1144 |
+
const bool b = time_internal::cctz::load_time_zone(std::string(name), &cz);
|
| 1145 |
+
*tz = TimeZone(cz);
|
| 1146 |
+
return b;
|
| 1147 |
+
}
|
| 1148 |
+
|
| 1149 |
+
// FixedTimeZone()
|
| 1150 |
+
//
|
| 1151 |
+
// Returns a TimeZone that is a fixed offset (seconds east) from UTC.
|
| 1152 |
+
// Note: If the absolute value of the offset is greater than 24 hours
|
| 1153 |
+
// you'll get UTC (i.e., no offset) instead.
|
| 1154 |
+
inline TimeZone FixedTimeZone(int seconds) {
|
| 1155 |
+
return TimeZone(
|
| 1156 |
+
time_internal::cctz::fixed_time_zone(std::chrono::seconds(seconds)));
|
| 1157 |
+
}
|
| 1158 |
+
|
| 1159 |
+
// UTCTimeZone()
|
| 1160 |
+
//
|
| 1161 |
+
// Convenience method returning the UTC time zone.
|
| 1162 |
+
inline TimeZone UTCTimeZone() {
|
| 1163 |
+
return TimeZone(time_internal::cctz::utc_time_zone());
|
| 1164 |
+
}
|
| 1165 |
+
|
| 1166 |
+
// LocalTimeZone()
|
| 1167 |
+
//
|
| 1168 |
+
// Convenience method returning the local time zone, or UTC if there is
|
| 1169 |
+
// no configured local zone. Warning: Be wary of using LocalTimeZone(),
|
| 1170 |
+
// and particularly so in a server process, as the zone configured for the
|
| 1171 |
+
// local machine should be irrelevant. Prefer an explicit zone name.
|
| 1172 |
+
inline TimeZone LocalTimeZone() {
|
| 1173 |
+
return TimeZone(time_internal::cctz::local_time_zone());
|
| 1174 |
+
}
|
| 1175 |
+
|
| 1176 |
+
// ToCivilSecond()
|
| 1177 |
+
// ToCivilMinute()
|
| 1178 |
+
// ToCivilHour()
|
| 1179 |
+
// ToCivilDay()
|
| 1180 |
+
// ToCivilMonth()
|
| 1181 |
+
// ToCivilYear()
|
| 1182 |
+
//
|
| 1183 |
+
// Helpers for TimeZone::At(Time) to return particularly aligned civil times.
|
| 1184 |
+
//
|
| 1185 |
+
// Example:
|
| 1186 |
+
//
|
| 1187 |
+
// absl::Time t = ...;
|
| 1188 |
+
// absl::TimeZone tz = ...;
|
| 1189 |
+
// const auto cd = absl::ToCivilDay(t, tz);
|
| 1190 |
+
ABSL_ATTRIBUTE_PURE_FUNCTION inline CivilSecond ToCivilSecond(Time t,
|
| 1191 |
+
TimeZone tz) {
|
| 1192 |
+
return tz.At(t).cs; // already a CivilSecond
|
| 1193 |
+
}
|
| 1194 |
+
ABSL_ATTRIBUTE_PURE_FUNCTION inline CivilMinute ToCivilMinute(Time t,
|
| 1195 |
+
TimeZone tz) {
|
| 1196 |
+
return CivilMinute(tz.At(t).cs);
|
| 1197 |
+
}
|
| 1198 |
+
ABSL_ATTRIBUTE_PURE_FUNCTION inline CivilHour ToCivilHour(Time t, TimeZone tz) {
|
| 1199 |
+
return CivilHour(tz.At(t).cs);
|
| 1200 |
+
}
|
| 1201 |
+
ABSL_ATTRIBUTE_PURE_FUNCTION inline CivilDay ToCivilDay(Time t, TimeZone tz) {
|
| 1202 |
+
return CivilDay(tz.At(t).cs);
|
| 1203 |
+
}
|
| 1204 |
+
ABSL_ATTRIBUTE_PURE_FUNCTION inline CivilMonth ToCivilMonth(Time t,
|
| 1205 |
+
TimeZone tz) {
|
| 1206 |
+
return CivilMonth(tz.At(t).cs);
|
| 1207 |
+
}
|
| 1208 |
+
ABSL_ATTRIBUTE_PURE_FUNCTION inline CivilYear ToCivilYear(Time t, TimeZone tz) {
|
| 1209 |
+
return CivilYear(tz.At(t).cs);
|
| 1210 |
+
}
|
| 1211 |
+
|
| 1212 |
+
// FromCivil()
|
| 1213 |
+
//
|
| 1214 |
+
// Helper for TimeZone::At(CivilSecond) that provides "order-preserving
|
| 1215 |
+
// semantics." If the civil time maps to a unique time, that time is
|
| 1216 |
+
// returned. If the civil time is repeated in the given time zone, the
|
| 1217 |
+
// time using the pre-transition offset is returned. Otherwise, the
|
| 1218 |
+
// civil time is skipped in the given time zone, and the transition time
|
| 1219 |
+
// is returned. This means that for any two civil times, ct1 and ct2,
|
| 1220 |
+
// (ct1 < ct2) => (FromCivil(ct1) <= FromCivil(ct2)), the equal case
|
| 1221 |
+
// being when two non-existent civil times map to the same transition time.
|
| 1222 |
+
//
|
| 1223 |
+
// Note: Accepts civil times of any alignment.
|
| 1224 |
+
ABSL_ATTRIBUTE_PURE_FUNCTION inline Time FromCivil(CivilSecond ct,
|
| 1225 |
+
TimeZone tz) {
|
| 1226 |
+
const auto ti = tz.At(ct);
|
| 1227 |
+
if (ti.kind == TimeZone::TimeInfo::SKIPPED) return ti.trans;
|
| 1228 |
+
return ti.pre;
|
| 1229 |
+
}
|
| 1230 |
+
|
| 1231 |
+
// TimeConversion
|
| 1232 |
+
//
|
| 1233 |
+
// An `absl::TimeConversion` represents the conversion of year, month, day,
|
| 1234 |
+
// hour, minute, and second values (i.e., a civil time), in a particular
|
| 1235 |
+
// `absl::TimeZone`, to a time instant (an absolute time), as returned by
|
| 1236 |
+
// `absl::ConvertDateTime()`. Legacy version of `absl::TimeZone::TimeInfo`.
|
| 1237 |
+
//
|
| 1238 |
+
// Deprecated. Use `absl::TimeZone::TimeInfo`.
|
| 1239 |
+
struct
|
| 1240 |
+
TimeConversion {
|
| 1241 |
+
Time pre; // time calculated using the pre-transition offset
|
| 1242 |
+
Time trans; // when the civil-time discontinuity occurred
|
| 1243 |
+
Time post; // time calculated using the post-transition offset
|
| 1244 |
+
|
| 1245 |
+
enum Kind {
|
| 1246 |
+
UNIQUE, // the civil time was singular (pre == trans == post)
|
| 1247 |
+
SKIPPED, // the civil time did not exist
|
| 1248 |
+
REPEATED, // the civil time was ambiguous
|
| 1249 |
+
};
|
| 1250 |
+
Kind kind;
|
| 1251 |
+
|
| 1252 |
+
bool normalized; // input values were outside their valid ranges
|
| 1253 |
+
};
|
| 1254 |
+
|
| 1255 |
+
// ConvertDateTime()
|
| 1256 |
+
//
|
| 1257 |
+
// Legacy version of `absl::TimeZone::At(absl::CivilSecond)` that takes
|
| 1258 |
+
// the civil time as six, separate values (YMDHMS).
|
| 1259 |
+
//
|
| 1260 |
+
// The input month, day, hour, minute, and second values can be outside
|
| 1261 |
+
// of their valid ranges, in which case they will be "normalized" during
|
| 1262 |
+
// the conversion.
|
| 1263 |
+
//
|
| 1264 |
+
// Example:
|
| 1265 |
+
//
|
| 1266 |
+
// // "October 32" normalizes to "November 1".
|
| 1267 |
+
// absl::TimeConversion tc =
|
| 1268 |
+
// absl::ConvertDateTime(2013, 10, 32, 8, 30, 0, lax);
|
| 1269 |
+
// // tc.kind == TimeConversion::UNIQUE && tc.normalized == true
|
| 1270 |
+
// // absl::ToCivilDay(tc.pre, tz).month() == 11
|
| 1271 |
+
// // absl::ToCivilDay(tc.pre, tz).day() == 1
|
| 1272 |
+
//
|
| 1273 |
+
// Deprecated. Use `absl::TimeZone::At(CivilSecond)`.
|
| 1274 |
+
TimeConversion ConvertDateTime(int64_t year, int mon, int day, int hour,
|
| 1275 |
+
int min, int sec, TimeZone tz);
|
| 1276 |
+
|
| 1277 |
+
// FromDateTime()
|
| 1278 |
+
//
|
| 1279 |
+
// A convenience wrapper for `absl::ConvertDateTime()` that simply returns
|
| 1280 |
+
// the "pre" `absl::Time`. That is, the unique result, or the instant that
|
| 1281 |
+
// is correct using the pre-transition offset (as if the transition never
|
| 1282 |
+
// happened).
|
| 1283 |
+
//
|
| 1284 |
+
// Example:
|
| 1285 |
+
//
|
| 1286 |
+
// absl::Time t = absl::FromDateTime(2017, 9, 26, 9, 30, 0, lax);
|
| 1287 |
+
// // t = 2017-09-26 09:30:00 -0700
|
| 1288 |
+
//
|
| 1289 |
+
// Deprecated. Use `absl::FromCivil(CivilSecond, TimeZone)`. Note that the
|
| 1290 |
+
// behavior of `FromCivil()` differs from `FromDateTime()` for skipped civil
|
| 1291 |
+
// times. If you care about that see `absl::TimeZone::At(absl::CivilSecond)`.
|
| 1292 |
+
inline Time FromDateTime(int64_t year, int mon, int day, int hour,
|
| 1293 |
+
int min, int sec, TimeZone tz) {
|
| 1294 |
+
return ConvertDateTime(year, mon, day, hour, min, sec, tz).pre;
|
| 1295 |
+
}
|
| 1296 |
+
|
| 1297 |
+
// FromTM()
|
| 1298 |
+
//
|
| 1299 |
+
// Converts the `tm_year`, `tm_mon`, `tm_mday`, `tm_hour`, `tm_min`, and
|
| 1300 |
+
// `tm_sec` fields to an `absl::Time` using the given time zone. See ctime(3)
|
| 1301 |
+
// for a description of the expected values of the tm fields. If the civil time
|
| 1302 |
+
// is unique (see `absl::TimeZone::At(absl::CivilSecond)` above), the matching
|
| 1303 |
+
// time instant is returned. Otherwise, the `tm_isdst` field is consulted to
|
| 1304 |
+
// choose between the possible results. For a repeated civil time, `tm_isdst !=
|
| 1305 |
+
// 0` returns the matching DST instant, while `tm_isdst == 0` returns the
|
| 1306 |
+
// matching non-DST instant. For a skipped civil time there is no matching
|
| 1307 |
+
// instant, so `tm_isdst != 0` returns the DST instant, and `tm_isdst == 0`
|
| 1308 |
+
// returns the non-DST instant, that would have matched if the transition never
|
| 1309 |
+
// happened.
|
| 1310 |
+
ABSL_ATTRIBUTE_PURE_FUNCTION Time FromTM(const struct tm& tm, TimeZone tz);
|
| 1311 |
+
|
| 1312 |
+
// ToTM()
|
| 1313 |
+
//
|
| 1314 |
+
// Converts the given `absl::Time` to a struct tm using the given time zone.
|
| 1315 |
+
// See ctime(3) for a description of the values of the tm fields.
|
| 1316 |
+
ABSL_ATTRIBUTE_PURE_FUNCTION struct tm ToTM(Time t, TimeZone tz);
|
| 1317 |
+
|
| 1318 |
+
// RFC3339_full
|
| 1319 |
+
// RFC3339_sec
|
| 1320 |
+
//
|
| 1321 |
+
// FormatTime()/ParseTime() format specifiers for RFC3339 date/time strings,
|
| 1322 |
+
// with trailing zeros trimmed or with fractional seconds omitted altogether.
|
| 1323 |
+
//
|
| 1324 |
+
// Note that RFC3339_sec[] matches an ISO 8601 extended format for date and
|
| 1325 |
+
// time with UTC offset. Also note the use of "%Y": RFC3339 mandates that
|
| 1326 |
+
// years have exactly four digits, but we allow them to take their natural
|
| 1327 |
+
// width.
|
| 1328 |
+
ABSL_DLL extern const char RFC3339_full[]; // %Y-%m-%d%ET%H:%M:%E*S%Ez
|
| 1329 |
+
ABSL_DLL extern const char RFC3339_sec[]; // %Y-%m-%d%ET%H:%M:%S%Ez
|
| 1330 |
+
|
| 1331 |
+
// RFC1123_full
|
| 1332 |
+
// RFC1123_no_wday
|
| 1333 |
+
//
|
| 1334 |
+
// FormatTime()/ParseTime() format specifiers for RFC1123 date/time strings.
|
| 1335 |
+
ABSL_DLL extern const char RFC1123_full[]; // %a, %d %b %E4Y %H:%M:%S %z
|
| 1336 |
+
ABSL_DLL extern const char RFC1123_no_wday[]; // %d %b %E4Y %H:%M:%S %z
|
| 1337 |
+
|
| 1338 |
+
// FormatTime()
|
| 1339 |
+
//
|
| 1340 |
+
// Formats the given `absl::Time` in the `absl::TimeZone` according to the
|
| 1341 |
+
// provided format string. Uses strftime()-like formatting options, with
|
| 1342 |
+
// the following extensions:
|
| 1343 |
+
//
|
| 1344 |
+
// - %Ez - RFC3339-compatible numeric UTC offset (+hh:mm or -hh:mm)
|
| 1345 |
+
// - %E*z - Full-resolution numeric UTC offset (+hh:mm:ss or -hh:mm:ss)
|
| 1346 |
+
// - %E#S - Seconds with # digits of fractional precision
|
| 1347 |
+
// - %E*S - Seconds with full fractional precision (a literal '*')
|
| 1348 |
+
// - %E#f - Fractional seconds with # digits of precision
|
| 1349 |
+
// - %E*f - Fractional seconds with full precision (a literal '*')
|
| 1350 |
+
// - %E4Y - Four-character years (-999 ... -001, 0000, 0001 ... 9999)
|
| 1351 |
+
// - %ET - The RFC3339 "date-time" separator "T"
|
| 1352 |
+
//
|
| 1353 |
+
// Note that %E0S behaves like %S, and %E0f produces no characters. In
|
| 1354 |
+
// contrast %E*f always produces at least one digit, which may be '0'.
|
| 1355 |
+
//
|
| 1356 |
+
// Note that %Y produces as many characters as it takes to fully render the
|
| 1357 |
+
// year. A year outside of [-999:9999] when formatted with %E4Y will produce
|
| 1358 |
+
// more than four characters, just like %Y.
|
| 1359 |
+
//
|
| 1360 |
+
// We recommend that format strings include the UTC offset (%z, %Ez, or %E*z)
|
| 1361 |
+
// so that the result uniquely identifies a time instant.
|
| 1362 |
+
//
|
| 1363 |
+
// Example:
|
| 1364 |
+
//
|
| 1365 |
+
// absl::CivilSecond cs(2013, 1, 2, 3, 4, 5);
|
| 1366 |
+
// absl::Time t = absl::FromCivil(cs, lax);
|
| 1367 |
+
// std::string f = absl::FormatTime("%H:%M:%S", t, lax); // "03:04:05"
|
| 1368 |
+
// f = absl::FormatTime("%H:%M:%E3S", t, lax); // "03:04:05.000"
|
| 1369 |
+
//
|
| 1370 |
+
// Note: If the given `absl::Time` is `absl::InfiniteFuture()`, the returned
|
| 1371 |
+
// string will be exactly "infinite-future". If the given `absl::Time` is
|
| 1372 |
+
// `absl::InfinitePast()`, the returned string will be exactly "infinite-past".
|
| 1373 |
+
// In both cases the given format string and `absl::TimeZone` are ignored.
|
| 1374 |
+
//
|
| 1375 |
+
ABSL_ATTRIBUTE_PURE_FUNCTION std::string FormatTime(absl::string_view format,
|
| 1376 |
+
Time t, TimeZone tz);
|
| 1377 |
+
|
| 1378 |
+
// Convenience functions that format the given time using the RFC3339_full
|
| 1379 |
+
// format. The first overload uses the provided TimeZone, while the second
|
| 1380 |
+
// uses LocalTimeZone().
|
| 1381 |
+
ABSL_ATTRIBUTE_PURE_FUNCTION std::string FormatTime(Time t, TimeZone tz);
|
| 1382 |
+
ABSL_ATTRIBUTE_PURE_FUNCTION std::string FormatTime(Time t);
|
| 1383 |
+
|
| 1384 |
+
// Output stream operator.
|
| 1385 |
+
inline std::ostream& operator<<(std::ostream& os, Time t) {
|
| 1386 |
+
return os << FormatTime(t);
|
| 1387 |
+
}
|
| 1388 |
+
|
| 1389 |
+
// ParseTime()
|
| 1390 |
+
//
|
| 1391 |
+
// Parses an input string according to the provided format string and
|
| 1392 |
+
// returns the corresponding `absl::Time`. Uses strftime()-like formatting
|
| 1393 |
+
// options, with the same extensions as FormatTime(), but with the
|
| 1394 |
+
// exceptions that %E#S is interpreted as %E*S, and %E#f as %E*f. %Ez
|
| 1395 |
+
// and %E*z also accept the same inputs, which (along with %z) includes
|
| 1396 |
+
// 'z' and 'Z' as synonyms for +00:00. %ET accepts either 'T' or 't'.
|
| 1397 |
+
//
|
| 1398 |
+
// %Y consumes as many numeric characters as it can, so the matching data
|
| 1399 |
+
// should always be terminated with a non-numeric. %E4Y always consumes
|
| 1400 |
+
// exactly four characters, including any sign.
|
| 1401 |
+
//
|
| 1402 |
+
// Unspecified fields are taken from the default date and time of ...
|
| 1403 |
+
//
|
| 1404 |
+
// "1970-01-01 00:00:00.0 +0000"
|
| 1405 |
+
//
|
| 1406 |
+
// For example, parsing a string of "15:45" (%H:%M) will return an absl::Time
|
| 1407 |
+
// that represents "1970-01-01 15:45:00.0 +0000".
|
| 1408 |
+
//
|
| 1409 |
+
// Note that since ParseTime() returns time instants, it makes the most sense
|
| 1410 |
+
// to parse fully-specified date/time strings that include a UTC offset (%z,
|
| 1411 |
+
// %Ez, or %E*z).
|
| 1412 |
+
//
|
| 1413 |
+
// Note also that `absl::ParseTime()` only heeds the fields year, month, day,
|
| 1414 |
+
// hour, minute, (fractional) second, and UTC offset. Other fields, like
|
| 1415 |
+
// weekday (%a or %A), while parsed for syntactic validity, are ignored
|
| 1416 |
+
// in the conversion.
|
| 1417 |
+
//
|
| 1418 |
+
// Date and time fields that are out-of-range will be treated as errors
|
| 1419 |
+
// rather than normalizing them like `absl::CivilSecond` does. For example,
|
| 1420 |
+
// it is an error to parse the date "Oct 32, 2013" because 32 is out of range.
|
| 1421 |
+
//
|
| 1422 |
+
// A leap second of ":60" is normalized to ":00" of the following minute
|
| 1423 |
+
// with fractional seconds discarded. The following table shows how the
|
| 1424 |
+
// given seconds and subseconds will be parsed:
|
| 1425 |
+
//
|
| 1426 |
+
// "59.x" -> 59.x // exact
|
| 1427 |
+
// "60.x" -> 00.0 // normalized
|
| 1428 |
+
// "00.x" -> 00.x // exact
|
| 1429 |
+
//
|
| 1430 |
+
// Errors are indicated by returning false and assigning an error message
|
| 1431 |
+
// to the "err" out param if it is non-null.
|
| 1432 |
+
//
|
| 1433 |
+
// Note: If the input string is exactly "infinite-future", the returned
|
| 1434 |
+
// `absl::Time` will be `absl::InfiniteFuture()` and `true` will be returned.
|
| 1435 |
+
// If the input string is "infinite-past", the returned `absl::Time` will be
|
| 1436 |
+
// `absl::InfinitePast()` and `true` will be returned.
|
| 1437 |
+
//
|
| 1438 |
+
bool ParseTime(absl::string_view format, absl::string_view input, Time* time,
|
| 1439 |
+
std::string* err);
|
| 1440 |
+
|
| 1441 |
+
// Like ParseTime() above, but if the format string does not contain a UTC
|
| 1442 |
+
// offset specification (%z/%Ez/%E*z) then the input is interpreted in the
|
| 1443 |
+
// given TimeZone. This means that the input, by itself, does not identify a
|
| 1444 |
+
// unique instant. Being time-zone dependent, it also admits the possibility
|
| 1445 |
+
// of ambiguity or non-existence, in which case the "pre" time (as defined
|
| 1446 |
+
// by TimeZone::TimeInfo) is returned. For these reasons we recommend that
|
| 1447 |
+
// all date/time strings include a UTC offset so they're context independent.
|
| 1448 |
+
bool ParseTime(absl::string_view format, absl::string_view input, TimeZone tz,
|
| 1449 |
+
Time* time, std::string* err);
|
| 1450 |
+
|
| 1451 |
+
// ============================================================================
|
| 1452 |
+
// Implementation Details Follow
|
| 1453 |
+
// ============================================================================
|
| 1454 |
+
|
| 1455 |
+
namespace time_internal {
|
| 1456 |
+
|
| 1457 |
+
// Creates a Duration with a given representation.
|
| 1458 |
+
// REQUIRES: hi,lo is a valid representation of a Duration as specified
|
| 1459 |
+
// in time/duration.cc.
|
| 1460 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION constexpr Duration MakeDuration(int64_t hi,
|
| 1461 |
+
uint32_t lo = 0) {
|
| 1462 |
+
return Duration(hi, lo);
|
| 1463 |
+
}
|
| 1464 |
+
|
| 1465 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION constexpr Duration MakeDuration(int64_t hi,
|
| 1466 |
+
int64_t lo) {
|
| 1467 |
+
return MakeDuration(hi, static_cast<uint32_t>(lo));
|
| 1468 |
+
}
|
| 1469 |
+
|
| 1470 |
+
// Make a Duration value from a floating-point number, as long as that number
|
| 1471 |
+
// is in the range [ 0 .. numeric_limits<int64_t>::max ), that is, as long as
|
| 1472 |
+
// it's positive and can be converted to int64_t without risk of UB.
|
| 1473 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION inline Duration MakePosDoubleDuration(double n) {
|
| 1474 |
+
const int64_t int_secs = static_cast<int64_t>(n);
|
| 1475 |
+
const uint32_t ticks = static_cast<uint32_t>(
|
| 1476 |
+
std::round((n - static_cast<double>(int_secs)) * kTicksPerSecond));
|
| 1477 |
+
return ticks < kTicksPerSecond
|
| 1478 |
+
? MakeDuration(int_secs, ticks)
|
| 1479 |
+
: MakeDuration(int_secs + 1, ticks - kTicksPerSecond);
|
| 1480 |
+
}
|
| 1481 |
+
|
| 1482 |
+
// Creates a normalized Duration from an almost-normalized (sec,ticks)
|
| 1483 |
+
// pair. sec may be positive or negative. ticks must be in the range
|
| 1484 |
+
// -kTicksPerSecond < *ticks < kTicksPerSecond. If ticks is negative it
|
| 1485 |
+
// will be normalized to a positive value in the resulting Duration.
|
| 1486 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION constexpr Duration MakeNormalizedDuration(
|
| 1487 |
+
int64_t sec, int64_t ticks) {
|
| 1488 |
+
return (ticks < 0) ? MakeDuration(sec - 1, ticks + kTicksPerSecond)
|
| 1489 |
+
: MakeDuration(sec, ticks);
|
| 1490 |
+
}
|
| 1491 |
+
|
| 1492 |
+
// Provide access to the Duration representation.
|
| 1493 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION constexpr int64_t GetRepHi(Duration d) {
|
| 1494 |
+
return d.rep_hi_;
|
| 1495 |
+
}
|
| 1496 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION constexpr uint32_t GetRepLo(Duration d) {
|
| 1497 |
+
return d.rep_lo_;
|
| 1498 |
+
}
|
| 1499 |
+
|
| 1500 |
+
// Returns true iff d is positive or negative infinity.
|
| 1501 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION constexpr bool IsInfiniteDuration(Duration d) {
|
| 1502 |
+
return GetRepLo(d) == ~uint32_t{0};
|
| 1503 |
+
}
|
| 1504 |
+
|
| 1505 |
+
// Returns an infinite Duration with the opposite sign.
|
| 1506 |
+
// REQUIRES: IsInfiniteDuration(d)
|
| 1507 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION constexpr Duration OppositeInfinity(Duration d) {
|
| 1508 |
+
return GetRepHi(d) < 0
|
| 1509 |
+
? MakeDuration((std::numeric_limits<int64_t>::max)(), ~uint32_t{0})
|
| 1510 |
+
: MakeDuration((std::numeric_limits<int64_t>::min)(),
|
| 1511 |
+
~uint32_t{0});
|
| 1512 |
+
}
|
| 1513 |
+
|
| 1514 |
+
// Returns (-n)-1 (equivalently -(n+1)) without avoidable overflow.
|
| 1515 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION constexpr int64_t NegateAndSubtractOne(
|
| 1516 |
+
int64_t n) {
|
| 1517 |
+
// Note: Good compilers will optimize this expression to ~n when using
|
| 1518 |
+
// a two's-complement representation (which is required for int64_t).
|
| 1519 |
+
return (n < 0) ? -(n + 1) : (-n) - 1;
|
| 1520 |
+
}
|
| 1521 |
+
|
| 1522 |
+
// Map between a Time and a Duration since the Unix epoch. Note that these
|
| 1523 |
+
// functions depend on the above mentioned choice of the Unix epoch for the
|
| 1524 |
+
// Time representation (and both need to be Time friends). Without this
|
| 1525 |
+
// knowledge, we would need to add-in/subtract-out UnixEpoch() respectively.
|
| 1526 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION constexpr Time FromUnixDuration(Duration d) {
|
| 1527 |
+
return Time(d);
|
| 1528 |
+
}
|
| 1529 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION constexpr Duration ToUnixDuration(Time t) {
|
| 1530 |
+
return t.rep_;
|
| 1531 |
+
}
|
| 1532 |
+
|
| 1533 |
+
template <std::intmax_t N>
|
| 1534 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION constexpr Duration FromInt64(int64_t v,
|
| 1535 |
+
std::ratio<1, N>) {
|
| 1536 |
+
static_assert(0 < N && N <= 1000 * 1000 * 1000, "Unsupported ratio");
|
| 1537 |
+
// Subsecond ratios cannot overflow.
|
| 1538 |
+
return MakeNormalizedDuration(
|
| 1539 |
+
v / N, v % N * kTicksPerNanosecond * 1000 * 1000 * 1000 / N);
|
| 1540 |
+
}
|
| 1541 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION constexpr Duration FromInt64(int64_t v,
|
| 1542 |
+
std::ratio<60>) {
|
| 1543 |
+
return (v <= (std::numeric_limits<int64_t>::max)() / 60 &&
|
| 1544 |
+
v >= (std::numeric_limits<int64_t>::min)() / 60)
|
| 1545 |
+
? MakeDuration(v * 60)
|
| 1546 |
+
: v > 0 ? InfiniteDuration() : -InfiniteDuration();
|
| 1547 |
+
}
|
| 1548 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION constexpr Duration FromInt64(int64_t v,
|
| 1549 |
+
std::ratio<3600>) {
|
| 1550 |
+
return (v <= (std::numeric_limits<int64_t>::max)() / 3600 &&
|
| 1551 |
+
v >= (std::numeric_limits<int64_t>::min)() / 3600)
|
| 1552 |
+
? MakeDuration(v * 3600)
|
| 1553 |
+
: v > 0 ? InfiniteDuration() : -InfiniteDuration();
|
| 1554 |
+
}
|
| 1555 |
+
|
| 1556 |
+
// IsValidRep64<T>(0) is true if the expression `int64_t{std::declval<T>()}` is
|
| 1557 |
+
// valid. That is, if a T can be assigned to an int64_t without narrowing.
|
| 1558 |
+
template <typename T>
|
| 1559 |
+
constexpr auto IsValidRep64(int) -> decltype(int64_t{std::declval<T>()} == 0) {
|
| 1560 |
+
return true;
|
| 1561 |
+
}
|
| 1562 |
+
template <typename T>
|
| 1563 |
+
constexpr auto IsValidRep64(char) -> bool {
|
| 1564 |
+
return false;
|
| 1565 |
+
}
|
| 1566 |
+
|
| 1567 |
+
// Converts a std::chrono::duration to an absl::Duration.
|
| 1568 |
+
template <typename Rep, typename Period>
|
| 1569 |
+
ABSL_ATTRIBUTE_PURE_FUNCTION constexpr Duration FromChrono(
|
| 1570 |
+
const std::chrono::duration<Rep, Period>& d) {
|
| 1571 |
+
static_assert(IsValidRep64<Rep>(0), "duration::rep is invalid");
|
| 1572 |
+
return FromInt64(int64_t{d.count()}, Period{});
|
| 1573 |
+
}
|
| 1574 |
+
|
| 1575 |
+
template <typename Ratio>
|
| 1576 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION int64_t ToInt64(Duration d, Ratio) {
|
| 1577 |
+
// Note: This may be used on MSVC, which may have a system_clock period of
|
| 1578 |
+
// std::ratio<1, 10 * 1000 * 1000>
|
| 1579 |
+
return ToInt64Seconds(d * Ratio::den / Ratio::num);
|
| 1580 |
+
}
|
| 1581 |
+
// Fastpath implementations for the 6 common duration units.
|
| 1582 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION inline int64_t ToInt64(Duration d, std::nano) {
|
| 1583 |
+
return ToInt64Nanoseconds(d);
|
| 1584 |
+
}
|
| 1585 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION inline int64_t ToInt64(Duration d, std::micro) {
|
| 1586 |
+
return ToInt64Microseconds(d);
|
| 1587 |
+
}
|
| 1588 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION inline int64_t ToInt64(Duration d, std::milli) {
|
| 1589 |
+
return ToInt64Milliseconds(d);
|
| 1590 |
+
}
|
| 1591 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION inline int64_t ToInt64(Duration d,
|
| 1592 |
+
std::ratio<1>) {
|
| 1593 |
+
return ToInt64Seconds(d);
|
| 1594 |
+
}
|
| 1595 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION inline int64_t ToInt64(Duration d,
|
| 1596 |
+
std::ratio<60>) {
|
| 1597 |
+
return ToInt64Minutes(d);
|
| 1598 |
+
}
|
| 1599 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION inline int64_t ToInt64(Duration d,
|
| 1600 |
+
std::ratio<3600>) {
|
| 1601 |
+
return ToInt64Hours(d);
|
| 1602 |
+
}
|
| 1603 |
+
|
| 1604 |
+
// Converts an absl::Duration to a chrono duration of type T.
|
| 1605 |
+
template <typename T>
|
| 1606 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION T ToChronoDuration(Duration d) {
|
| 1607 |
+
using Rep = typename T::rep;
|
| 1608 |
+
using Period = typename T::period;
|
| 1609 |
+
static_assert(IsValidRep64<Rep>(0), "duration::rep is invalid");
|
| 1610 |
+
if (time_internal::IsInfiniteDuration(d))
|
| 1611 |
+
return d < ZeroDuration() ? (T::min)() : (T::max)();
|
| 1612 |
+
const auto v = ToInt64(d, Period{});
|
| 1613 |
+
if (v > (std::numeric_limits<Rep>::max)()) return (T::max)();
|
| 1614 |
+
if (v < (std::numeric_limits<Rep>::min)()) return (T::min)();
|
| 1615 |
+
return T{v};
|
| 1616 |
+
}
|
| 1617 |
+
|
| 1618 |
+
} // namespace time_internal
|
| 1619 |
+
|
| 1620 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION constexpr bool operator<(Duration lhs,
|
| 1621 |
+
Duration rhs) {
|
| 1622 |
+
return time_internal::GetRepHi(lhs) != time_internal::GetRepHi(rhs)
|
| 1623 |
+
? time_internal::GetRepHi(lhs) < time_internal::GetRepHi(rhs)
|
| 1624 |
+
: time_internal::GetRepHi(lhs) == (std::numeric_limits<int64_t>::min)()
|
| 1625 |
+
? time_internal::GetRepLo(lhs) + 1 <
|
| 1626 |
+
time_internal::GetRepLo(rhs) + 1
|
| 1627 |
+
: time_internal::GetRepLo(lhs) < time_internal::GetRepLo(rhs);
|
| 1628 |
+
}
|
| 1629 |
+
|
| 1630 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION constexpr bool operator==(Duration lhs,
|
| 1631 |
+
Duration rhs) {
|
| 1632 |
+
return time_internal::GetRepHi(lhs) == time_internal::GetRepHi(rhs) &&
|
| 1633 |
+
time_internal::GetRepLo(lhs) == time_internal::GetRepLo(rhs);
|
| 1634 |
+
}
|
| 1635 |
+
|
| 1636 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION constexpr Duration operator-(Duration d) {
|
| 1637 |
+
// This is a little interesting because of the special cases.
|
| 1638 |
+
//
|
| 1639 |
+
// If rep_lo_ is zero, we have it easy; it's safe to negate rep_hi_, we're
|
| 1640 |
+
// dealing with an integral number of seconds, and the only special case is
|
| 1641 |
+
// the maximum negative finite duration, which can't be negated.
|
| 1642 |
+
//
|
| 1643 |
+
// Infinities stay infinite, and just change direction.
|
| 1644 |
+
//
|
| 1645 |
+
// Finally we're in the case where rep_lo_ is non-zero, and we can borrow
|
| 1646 |
+
// a second's worth of ticks and avoid overflow (as negating int64_t-min + 1
|
| 1647 |
+
// is safe).
|
| 1648 |
+
return time_internal::GetRepLo(d) == 0
|
| 1649 |
+
? time_internal::GetRepHi(d) ==
|
| 1650 |
+
(std::numeric_limits<int64_t>::min)()
|
| 1651 |
+
? InfiniteDuration()
|
| 1652 |
+
: time_internal::MakeDuration(-time_internal::GetRepHi(d))
|
| 1653 |
+
: time_internal::IsInfiniteDuration(d)
|
| 1654 |
+
? time_internal::OppositeInfinity(d)
|
| 1655 |
+
: time_internal::MakeDuration(
|
| 1656 |
+
time_internal::NegateAndSubtractOne(
|
| 1657 |
+
time_internal::GetRepHi(d)),
|
| 1658 |
+
time_internal::kTicksPerSecond -
|
| 1659 |
+
time_internal::GetRepLo(d));
|
| 1660 |
+
}
|
| 1661 |
+
|
| 1662 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION constexpr Duration InfiniteDuration() {
|
| 1663 |
+
return time_internal::MakeDuration((std::numeric_limits<int64_t>::max)(),
|
| 1664 |
+
~uint32_t{0});
|
| 1665 |
+
}
|
| 1666 |
+
|
| 1667 |
+
ABSL_ATTRIBUTE_PURE_FUNCTION constexpr Duration FromChrono(
|
| 1668 |
+
const std::chrono::nanoseconds& d) {
|
| 1669 |
+
return time_internal::FromChrono(d);
|
| 1670 |
+
}
|
| 1671 |
+
ABSL_ATTRIBUTE_PURE_FUNCTION constexpr Duration FromChrono(
|
| 1672 |
+
const std::chrono::microseconds& d) {
|
| 1673 |
+
return time_internal::FromChrono(d);
|
| 1674 |
+
}
|
| 1675 |
+
ABSL_ATTRIBUTE_PURE_FUNCTION constexpr Duration FromChrono(
|
| 1676 |
+
const std::chrono::milliseconds& d) {
|
| 1677 |
+
return time_internal::FromChrono(d);
|
| 1678 |
+
}
|
| 1679 |
+
ABSL_ATTRIBUTE_PURE_FUNCTION constexpr Duration FromChrono(
|
| 1680 |
+
const std::chrono::seconds& d) {
|
| 1681 |
+
return time_internal::FromChrono(d);
|
| 1682 |
+
}
|
| 1683 |
+
ABSL_ATTRIBUTE_PURE_FUNCTION constexpr Duration FromChrono(
|
| 1684 |
+
const std::chrono::minutes& d) {
|
| 1685 |
+
return time_internal::FromChrono(d);
|
| 1686 |
+
}
|
| 1687 |
+
ABSL_ATTRIBUTE_PURE_FUNCTION constexpr Duration FromChrono(
|
| 1688 |
+
const std::chrono::hours& d) {
|
| 1689 |
+
return time_internal::FromChrono(d);
|
| 1690 |
+
}
|
| 1691 |
+
|
| 1692 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION constexpr Time FromUnixNanos(int64_t ns) {
|
| 1693 |
+
return time_internal::FromUnixDuration(Nanoseconds(ns));
|
| 1694 |
+
}
|
| 1695 |
+
|
| 1696 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION constexpr Time FromUnixMicros(int64_t us) {
|
| 1697 |
+
return time_internal::FromUnixDuration(Microseconds(us));
|
| 1698 |
+
}
|
| 1699 |
+
|
| 1700 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION constexpr Time FromUnixMillis(int64_t ms) {
|
| 1701 |
+
return time_internal::FromUnixDuration(Milliseconds(ms));
|
| 1702 |
+
}
|
| 1703 |
+
|
| 1704 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION constexpr Time FromUnixSeconds(int64_t s) {
|
| 1705 |
+
return time_internal::FromUnixDuration(Seconds(s));
|
| 1706 |
+
}
|
| 1707 |
+
|
| 1708 |
+
ABSL_ATTRIBUTE_CONST_FUNCTION constexpr Time FromTimeT(time_t t) {
|
| 1709 |
+
return time_internal::FromUnixDuration(Seconds(t));
|
| 1710 |
+
}
|
| 1711 |
+
|
| 1712 |
+
ABSL_NAMESPACE_END
|
| 1713 |
+
} // namespace absl
|
| 1714 |
+
|
| 1715 |
+
#endif // ABSL_TIME_TIME_H_
|
miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/absl/types/bad_optional_access.h
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2018 The Abseil Authors.
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// https://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
//
|
| 15 |
+
// -----------------------------------------------------------------------------
|
| 16 |
+
// bad_optional_access.h
|
| 17 |
+
// -----------------------------------------------------------------------------
|
| 18 |
+
//
|
| 19 |
+
// This header file defines the `absl::bad_optional_access` type.
|
| 20 |
+
|
| 21 |
+
#ifndef ABSL_TYPES_BAD_OPTIONAL_ACCESS_H_
|
| 22 |
+
#define ABSL_TYPES_BAD_OPTIONAL_ACCESS_H_
|
| 23 |
+
|
| 24 |
+
#include <stdexcept>
|
| 25 |
+
|
| 26 |
+
#include "absl/base/config.h"
|
| 27 |
+
|
| 28 |
+
#ifdef ABSL_USES_STD_OPTIONAL
|
| 29 |
+
|
| 30 |
+
#include <optional>
|
| 31 |
+
|
| 32 |
+
namespace absl {
|
| 33 |
+
ABSL_NAMESPACE_BEGIN
|
| 34 |
+
using std::bad_optional_access;
|
| 35 |
+
ABSL_NAMESPACE_END
|
| 36 |
+
} // namespace absl
|
| 37 |
+
|
| 38 |
+
#else // ABSL_USES_STD_OPTIONAL
|
| 39 |
+
|
| 40 |
+
namespace absl {
|
| 41 |
+
ABSL_NAMESPACE_BEGIN
|
| 42 |
+
|
| 43 |
+
// -----------------------------------------------------------------------------
|
| 44 |
+
// bad_optional_access
|
| 45 |
+
// -----------------------------------------------------------------------------
|
| 46 |
+
//
|
| 47 |
+
// An `absl::bad_optional_access` type is an exception type that is thrown when
|
| 48 |
+
// attempting to access an `absl::optional` object that does not contain a
|
| 49 |
+
// value.
|
| 50 |
+
//
|
| 51 |
+
// Example:
|
| 52 |
+
//
|
| 53 |
+
// absl::optional<int> o;
|
| 54 |
+
//
|
| 55 |
+
// try {
|
| 56 |
+
// int n = o.value();
|
| 57 |
+
// } catch(const absl::bad_optional_access& e) {
|
| 58 |
+
// std::cout << "Bad optional access: " << e.what() << '\n';
|
| 59 |
+
// }
|
| 60 |
+
class bad_optional_access : public std::exception {
|
| 61 |
+
public:
|
| 62 |
+
bad_optional_access() = default;
|
| 63 |
+
~bad_optional_access() override;
|
| 64 |
+
const char* what() const noexcept override;
|
| 65 |
+
};
|
| 66 |
+
|
| 67 |
+
namespace optional_internal {
|
| 68 |
+
|
| 69 |
+
// throw delegator
|
| 70 |
+
[[noreturn]] ABSL_DLL void throw_bad_optional_access();
|
| 71 |
+
|
| 72 |
+
} // namespace optional_internal
|
| 73 |
+
ABSL_NAMESPACE_END
|
| 74 |
+
} // namespace absl
|
| 75 |
+
|
| 76 |
+
#endif // ABSL_USES_STD_OPTIONAL
|
| 77 |
+
|
| 78 |
+
#endif // ABSL_TYPES_BAD_OPTIONAL_ACCESS_H_
|
miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/absl/types/bad_variant_access.h
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2018 The Abseil Authors.
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// https://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
//
|
| 15 |
+
// -----------------------------------------------------------------------------
|
| 16 |
+
// bad_variant_access.h
|
| 17 |
+
// -----------------------------------------------------------------------------
|
| 18 |
+
//
|
| 19 |
+
// This header file defines the `absl::bad_variant_access` type.
|
| 20 |
+
|
| 21 |
+
#ifndef ABSL_TYPES_BAD_VARIANT_ACCESS_H_
|
| 22 |
+
#define ABSL_TYPES_BAD_VARIANT_ACCESS_H_
|
| 23 |
+
|
| 24 |
+
#include <stdexcept>
|
| 25 |
+
|
| 26 |
+
#include "absl/base/config.h"
|
| 27 |
+
|
| 28 |
+
#ifdef ABSL_USES_STD_VARIANT
|
| 29 |
+
|
| 30 |
+
#include <variant>
|
| 31 |
+
|
| 32 |
+
namespace absl {
|
| 33 |
+
ABSL_NAMESPACE_BEGIN
|
| 34 |
+
using std::bad_variant_access;
|
| 35 |
+
ABSL_NAMESPACE_END
|
| 36 |
+
} // namespace absl
|
| 37 |
+
|
| 38 |
+
#else // ABSL_USES_STD_VARIANT
|
| 39 |
+
|
| 40 |
+
namespace absl {
|
| 41 |
+
ABSL_NAMESPACE_BEGIN
|
| 42 |
+
|
| 43 |
+
// -----------------------------------------------------------------------------
|
| 44 |
+
// bad_variant_access
|
| 45 |
+
// -----------------------------------------------------------------------------
|
| 46 |
+
//
|
| 47 |
+
// An `absl::bad_variant_access` type is an exception type that is thrown in
|
| 48 |
+
// the following cases:
|
| 49 |
+
//
|
| 50 |
+
// * Calling `absl::get(absl::variant) with an index or type that does not
|
| 51 |
+
// match the currently selected alternative type
|
| 52 |
+
// * Calling `absl::visit on an `absl::variant` that is in the
|
| 53 |
+
// `variant::valueless_by_exception` state.
|
| 54 |
+
//
|
| 55 |
+
// Example:
|
| 56 |
+
//
|
| 57 |
+
// absl::variant<int, std::string> v;
|
| 58 |
+
// v = 1;
|
| 59 |
+
// try {
|
| 60 |
+
// absl::get<std::string>(v);
|
| 61 |
+
// } catch(const absl::bad_variant_access& e) {
|
| 62 |
+
// std::cout << "Bad variant access: " << e.what() << '\n';
|
| 63 |
+
// }
|
| 64 |
+
class bad_variant_access : public std::exception {
|
| 65 |
+
public:
|
| 66 |
+
bad_variant_access() noexcept = default;
|
| 67 |
+
~bad_variant_access() override;
|
| 68 |
+
const char* what() const noexcept override;
|
| 69 |
+
};
|
| 70 |
+
|
| 71 |
+
namespace variant_internal {
|
| 72 |
+
|
| 73 |
+
[[noreturn]] ABSL_DLL void ThrowBadVariantAccess();
|
| 74 |
+
[[noreturn]] ABSL_DLL void Rethrow();
|
| 75 |
+
|
| 76 |
+
} // namespace variant_internal
|
| 77 |
+
ABSL_NAMESPACE_END
|
| 78 |
+
} // namespace absl
|
| 79 |
+
|
| 80 |
+
#endif // ABSL_USES_STD_VARIANT
|
| 81 |
+
|
| 82 |
+
#endif // ABSL_TYPES_BAD_VARIANT_ACCESS_H_
|
miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/absl/types/compare.h
ADDED
|
@@ -0,0 +1,599 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2018 The Abseil Authors.
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// https://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
//
|
| 15 |
+
// -----------------------------------------------------------------------------
|
| 16 |
+
// compare.h
|
| 17 |
+
// -----------------------------------------------------------------------------
|
| 18 |
+
//
|
| 19 |
+
// This header file defines the `absl::weak_equality`, `absl::strong_equality`,
|
| 20 |
+
// `absl::partial_ordering`, `absl::weak_ordering`, and `absl::strong_ordering`
|
| 21 |
+
// types for storing the results of three way comparisons.
|
| 22 |
+
//
|
| 23 |
+
// Example:
|
| 24 |
+
// absl::weak_ordering compare(const std::string& a, const std::string& b);
|
| 25 |
+
//
|
| 26 |
+
// These are C++11 compatible versions of the C++20 corresponding types
|
| 27 |
+
// (`std::weak_equality`, etc.) and are designed to be drop-in replacements
|
| 28 |
+
// for code compliant with C++20.
|
| 29 |
+
|
| 30 |
+
#ifndef ABSL_TYPES_COMPARE_H_
|
| 31 |
+
#define ABSL_TYPES_COMPARE_H_
|
| 32 |
+
|
| 33 |
+
#include <cstddef>
|
| 34 |
+
#include <cstdint>
|
| 35 |
+
#include <cstdlib>
|
| 36 |
+
#include <type_traits>
|
| 37 |
+
|
| 38 |
+
#include "absl/base/attributes.h"
|
| 39 |
+
#include "absl/meta/type_traits.h"
|
| 40 |
+
|
| 41 |
+
namespace absl {
|
| 42 |
+
ABSL_NAMESPACE_BEGIN
|
| 43 |
+
namespace compare_internal {
|
| 44 |
+
|
| 45 |
+
using value_type = int8_t;
|
| 46 |
+
|
| 47 |
+
class OnlyLiteralZero {
|
| 48 |
+
// A private type which cannot be named to explicitly cast to it.
|
| 49 |
+
struct MatchLiteralZero;
|
| 50 |
+
|
| 51 |
+
public:
|
| 52 |
+
// Accept only literal zero since it can be implicitly converted to a pointer
|
| 53 |
+
// type. nullptr constants will be caught by the other constructor which
|
| 54 |
+
// accepts a nullptr_t.
|
| 55 |
+
constexpr OnlyLiteralZero(MatchLiteralZero *) noexcept {} // NOLINT
|
| 56 |
+
|
| 57 |
+
// Fails compilation when `nullptr` or integral type arguments other than
|
| 58 |
+
// `int` are passed. This constructor doesn't accept `int` because literal `0`
|
| 59 |
+
// has type `int`. Literal `0` arguments will be implicitly converted to
|
| 60 |
+
// `std::nullptr_t` and accepted by the above constructor, while other `int`
|
| 61 |
+
// arguments will fail to be converted and cause compilation failure.
|
| 62 |
+
template <typename T, typename = typename std::enable_if<
|
| 63 |
+
std::is_same<T, std::nullptr_t>::value ||
|
| 64 |
+
(std::is_integral<T>::value &&
|
| 65 |
+
!std::is_same<T, int>::value)>::type>
|
| 66 |
+
OnlyLiteralZero(T) { // NOLINT
|
| 67 |
+
static_assert(sizeof(T) < 0, "Only literal `0` is allowed.");
|
| 68 |
+
}
|
| 69 |
+
};
|
| 70 |
+
|
| 71 |
+
enum class eq : value_type {
|
| 72 |
+
equal = 0,
|
| 73 |
+
equivalent = equal,
|
| 74 |
+
nonequal = 1,
|
| 75 |
+
nonequivalent = nonequal,
|
| 76 |
+
};
|
| 77 |
+
|
| 78 |
+
enum class ord : value_type { less = -1, greater = 1 };
|
| 79 |
+
|
| 80 |
+
enum class ncmp : value_type { unordered = -127 };
|
| 81 |
+
|
| 82 |
+
// Define macros to allow for creation or emulation of C++17 inline variables
|
| 83 |
+
// based on whether the feature is supported. Note: we can't use
|
| 84 |
+
// ABSL_INTERNAL_INLINE_CONSTEXPR here because the variables here are of
|
| 85 |
+
// incomplete types so they need to be defined after the types are complete.
|
| 86 |
+
#ifdef __cpp_inline_variables
|
| 87 |
+
|
| 88 |
+
// A no-op expansion that can be followed by a semicolon at class level.
|
| 89 |
+
#define ABSL_COMPARE_INLINE_BASECLASS_DECL(name) static_assert(true, "")
|
| 90 |
+
|
| 91 |
+
#define ABSL_COMPARE_INLINE_SUBCLASS_DECL(type, name) \
|
| 92 |
+
static const type name
|
| 93 |
+
|
| 94 |
+
#define ABSL_COMPARE_INLINE_INIT(type, name, init) \
|
| 95 |
+
inline constexpr type type::name(init)
|
| 96 |
+
|
| 97 |
+
#else // __cpp_inline_variables
|
| 98 |
+
|
| 99 |
+
#define ABSL_COMPARE_INLINE_BASECLASS_DECL(name) \
|
| 100 |
+
ABSL_CONST_INIT static const T name
|
| 101 |
+
|
| 102 |
+
// A no-op expansion that can be followed by a semicolon at class level.
|
| 103 |
+
#define ABSL_COMPARE_INLINE_SUBCLASS_DECL(type, name) static_assert(true, "")
|
| 104 |
+
|
| 105 |
+
#define ABSL_COMPARE_INLINE_INIT(type, name, init) \
|
| 106 |
+
template <typename T> \
|
| 107 |
+
const T compare_internal::type##_base<T>::name(init)
|
| 108 |
+
|
| 109 |
+
#endif // __cpp_inline_variables
|
| 110 |
+
|
| 111 |
+
// These template base classes allow for defining the values of the constants
|
| 112 |
+
// in the header file (for performance) without using inline variables (which
|
| 113 |
+
// aren't available in C++11).
|
| 114 |
+
template <typename T>
|
| 115 |
+
struct weak_equality_base {
|
| 116 |
+
ABSL_COMPARE_INLINE_BASECLASS_DECL(equivalent);
|
| 117 |
+
ABSL_COMPARE_INLINE_BASECLASS_DECL(nonequivalent);
|
| 118 |
+
};
|
| 119 |
+
|
| 120 |
+
template <typename T>
|
| 121 |
+
struct strong_equality_base {
|
| 122 |
+
ABSL_COMPARE_INLINE_BASECLASS_DECL(equal);
|
| 123 |
+
ABSL_COMPARE_INLINE_BASECLASS_DECL(nonequal);
|
| 124 |
+
ABSL_COMPARE_INLINE_BASECLASS_DECL(equivalent);
|
| 125 |
+
ABSL_COMPARE_INLINE_BASECLASS_DECL(nonequivalent);
|
| 126 |
+
};
|
| 127 |
+
|
| 128 |
+
template <typename T>
|
| 129 |
+
struct partial_ordering_base {
|
| 130 |
+
ABSL_COMPARE_INLINE_BASECLASS_DECL(less);
|
| 131 |
+
ABSL_COMPARE_INLINE_BASECLASS_DECL(equivalent);
|
| 132 |
+
ABSL_COMPARE_INLINE_BASECLASS_DECL(greater);
|
| 133 |
+
ABSL_COMPARE_INLINE_BASECLASS_DECL(unordered);
|
| 134 |
+
};
|
| 135 |
+
|
| 136 |
+
template <typename T>
|
| 137 |
+
struct weak_ordering_base {
|
| 138 |
+
ABSL_COMPARE_INLINE_BASECLASS_DECL(less);
|
| 139 |
+
ABSL_COMPARE_INLINE_BASECLASS_DECL(equivalent);
|
| 140 |
+
ABSL_COMPARE_INLINE_BASECLASS_DECL(greater);
|
| 141 |
+
};
|
| 142 |
+
|
| 143 |
+
template <typename T>
|
| 144 |
+
struct strong_ordering_base {
|
| 145 |
+
ABSL_COMPARE_INLINE_BASECLASS_DECL(less);
|
| 146 |
+
ABSL_COMPARE_INLINE_BASECLASS_DECL(equal);
|
| 147 |
+
ABSL_COMPARE_INLINE_BASECLASS_DECL(equivalent);
|
| 148 |
+
ABSL_COMPARE_INLINE_BASECLASS_DECL(greater);
|
| 149 |
+
};
|
| 150 |
+
|
| 151 |
+
} // namespace compare_internal
|
| 152 |
+
|
| 153 |
+
class weak_equality
|
| 154 |
+
: public compare_internal::weak_equality_base<weak_equality> {
|
| 155 |
+
explicit constexpr weak_equality(compare_internal::eq v) noexcept
|
| 156 |
+
: value_(static_cast<compare_internal::value_type>(v)) {}
|
| 157 |
+
friend struct compare_internal::weak_equality_base<weak_equality>;
|
| 158 |
+
|
| 159 |
+
public:
|
| 160 |
+
ABSL_COMPARE_INLINE_SUBCLASS_DECL(weak_equality, equivalent);
|
| 161 |
+
ABSL_COMPARE_INLINE_SUBCLASS_DECL(weak_equality, nonequivalent);
|
| 162 |
+
|
| 163 |
+
// Comparisons
|
| 164 |
+
friend constexpr bool operator==(
|
| 165 |
+
weak_equality v, compare_internal::OnlyLiteralZero) noexcept {
|
| 166 |
+
return v.value_ == 0;
|
| 167 |
+
}
|
| 168 |
+
friend constexpr bool operator!=(
|
| 169 |
+
weak_equality v, compare_internal::OnlyLiteralZero) noexcept {
|
| 170 |
+
return v.value_ != 0;
|
| 171 |
+
}
|
| 172 |
+
friend constexpr bool operator==(compare_internal::OnlyLiteralZero,
|
| 173 |
+
weak_equality v) noexcept {
|
| 174 |
+
return 0 == v.value_;
|
| 175 |
+
}
|
| 176 |
+
friend constexpr bool operator!=(compare_internal::OnlyLiteralZero,
|
| 177 |
+
weak_equality v) noexcept {
|
| 178 |
+
return 0 != v.value_;
|
| 179 |
+
}
|
| 180 |
+
friend constexpr bool operator==(weak_equality v1,
|
| 181 |
+
weak_equality v2) noexcept {
|
| 182 |
+
return v1.value_ == v2.value_;
|
| 183 |
+
}
|
| 184 |
+
friend constexpr bool operator!=(weak_equality v1,
|
| 185 |
+
weak_equality v2) noexcept {
|
| 186 |
+
return v1.value_ != v2.value_;
|
| 187 |
+
}
|
| 188 |
+
|
| 189 |
+
private:
|
| 190 |
+
compare_internal::value_type value_;
|
| 191 |
+
};
|
| 192 |
+
ABSL_COMPARE_INLINE_INIT(weak_equality, equivalent,
|
| 193 |
+
compare_internal::eq::equivalent);
|
| 194 |
+
ABSL_COMPARE_INLINE_INIT(weak_equality, nonequivalent,
|
| 195 |
+
compare_internal::eq::nonequivalent);
|
| 196 |
+
|
| 197 |
+
class strong_equality
|
| 198 |
+
: public compare_internal::strong_equality_base<strong_equality> {
|
| 199 |
+
explicit constexpr strong_equality(compare_internal::eq v) noexcept
|
| 200 |
+
: value_(static_cast<compare_internal::value_type>(v)) {}
|
| 201 |
+
friend struct compare_internal::strong_equality_base<strong_equality>;
|
| 202 |
+
|
| 203 |
+
public:
|
| 204 |
+
ABSL_COMPARE_INLINE_SUBCLASS_DECL(strong_equality, equal);
|
| 205 |
+
ABSL_COMPARE_INLINE_SUBCLASS_DECL(strong_equality, nonequal);
|
| 206 |
+
ABSL_COMPARE_INLINE_SUBCLASS_DECL(strong_equality, equivalent);
|
| 207 |
+
ABSL_COMPARE_INLINE_SUBCLASS_DECL(strong_equality, nonequivalent);
|
| 208 |
+
|
| 209 |
+
// Conversion
|
| 210 |
+
constexpr operator weak_equality() const noexcept { // NOLINT
|
| 211 |
+
return value_ == 0 ? weak_equality::equivalent
|
| 212 |
+
: weak_equality::nonequivalent;
|
| 213 |
+
}
|
| 214 |
+
// Comparisons
|
| 215 |
+
friend constexpr bool operator==(
|
| 216 |
+
strong_equality v, compare_internal::OnlyLiteralZero) noexcept {
|
| 217 |
+
return v.value_ == 0;
|
| 218 |
+
}
|
| 219 |
+
friend constexpr bool operator!=(
|
| 220 |
+
strong_equality v, compare_internal::OnlyLiteralZero) noexcept {
|
| 221 |
+
return v.value_ != 0;
|
| 222 |
+
}
|
| 223 |
+
friend constexpr bool operator==(compare_internal::OnlyLiteralZero,
|
| 224 |
+
strong_equality v) noexcept {
|
| 225 |
+
return 0 == v.value_;
|
| 226 |
+
}
|
| 227 |
+
friend constexpr bool operator!=(compare_internal::OnlyLiteralZero,
|
| 228 |
+
strong_equality v) noexcept {
|
| 229 |
+
return 0 != v.value_;
|
| 230 |
+
}
|
| 231 |
+
friend constexpr bool operator==(strong_equality v1,
|
| 232 |
+
strong_equality v2) noexcept {
|
| 233 |
+
return v1.value_ == v2.value_;
|
| 234 |
+
}
|
| 235 |
+
friend constexpr bool operator!=(strong_equality v1,
|
| 236 |
+
strong_equality v2) noexcept {
|
| 237 |
+
return v1.value_ != v2.value_;
|
| 238 |
+
}
|
| 239 |
+
|
| 240 |
+
private:
|
| 241 |
+
compare_internal::value_type value_;
|
| 242 |
+
};
|
| 243 |
+
ABSL_COMPARE_INLINE_INIT(strong_equality, equal, compare_internal::eq::equal);
|
| 244 |
+
ABSL_COMPARE_INLINE_INIT(strong_equality, nonequal,
|
| 245 |
+
compare_internal::eq::nonequal);
|
| 246 |
+
ABSL_COMPARE_INLINE_INIT(strong_equality, equivalent,
|
| 247 |
+
compare_internal::eq::equivalent);
|
| 248 |
+
ABSL_COMPARE_INLINE_INIT(strong_equality, nonequivalent,
|
| 249 |
+
compare_internal::eq::nonequivalent);
|
| 250 |
+
|
| 251 |
+
class partial_ordering
|
| 252 |
+
: public compare_internal::partial_ordering_base<partial_ordering> {
|
| 253 |
+
explicit constexpr partial_ordering(compare_internal::eq v) noexcept
|
| 254 |
+
: value_(static_cast<compare_internal::value_type>(v)) {}
|
| 255 |
+
explicit constexpr partial_ordering(compare_internal::ord v) noexcept
|
| 256 |
+
: value_(static_cast<compare_internal::value_type>(v)) {}
|
| 257 |
+
explicit constexpr partial_ordering(compare_internal::ncmp v) noexcept
|
| 258 |
+
: value_(static_cast<compare_internal::value_type>(v)) {}
|
| 259 |
+
friend struct compare_internal::partial_ordering_base<partial_ordering>;
|
| 260 |
+
|
| 261 |
+
constexpr bool is_ordered() const noexcept {
|
| 262 |
+
return value_ !=
|
| 263 |
+
compare_internal::value_type(compare_internal::ncmp::unordered);
|
| 264 |
+
}
|
| 265 |
+
|
| 266 |
+
public:
|
| 267 |
+
ABSL_COMPARE_INLINE_SUBCLASS_DECL(partial_ordering, less);
|
| 268 |
+
ABSL_COMPARE_INLINE_SUBCLASS_DECL(partial_ordering, equivalent);
|
| 269 |
+
ABSL_COMPARE_INLINE_SUBCLASS_DECL(partial_ordering, greater);
|
| 270 |
+
ABSL_COMPARE_INLINE_SUBCLASS_DECL(partial_ordering, unordered);
|
| 271 |
+
|
| 272 |
+
// Conversion
|
| 273 |
+
constexpr operator weak_equality() const noexcept { // NOLINT
|
| 274 |
+
return value_ == 0 ? weak_equality::equivalent
|
| 275 |
+
: weak_equality::nonequivalent;
|
| 276 |
+
}
|
| 277 |
+
// Comparisons
|
| 278 |
+
friend constexpr bool operator==(
|
| 279 |
+
partial_ordering v, compare_internal::OnlyLiteralZero) noexcept {
|
| 280 |
+
return v.is_ordered() && v.value_ == 0;
|
| 281 |
+
}
|
| 282 |
+
friend constexpr bool operator!=(
|
| 283 |
+
partial_ordering v, compare_internal::OnlyLiteralZero) noexcept {
|
| 284 |
+
return !v.is_ordered() || v.value_ != 0;
|
| 285 |
+
}
|
| 286 |
+
friend constexpr bool operator<(
|
| 287 |
+
partial_ordering v, compare_internal::OnlyLiteralZero) noexcept {
|
| 288 |
+
return v.is_ordered() && v.value_ < 0;
|
| 289 |
+
}
|
| 290 |
+
friend constexpr bool operator<=(
|
| 291 |
+
partial_ordering v, compare_internal::OnlyLiteralZero) noexcept {
|
| 292 |
+
return v.is_ordered() && v.value_ <= 0;
|
| 293 |
+
}
|
| 294 |
+
friend constexpr bool operator>(
|
| 295 |
+
partial_ordering v, compare_internal::OnlyLiteralZero) noexcept {
|
| 296 |
+
return v.is_ordered() && v.value_ > 0;
|
| 297 |
+
}
|
| 298 |
+
friend constexpr bool operator>=(
|
| 299 |
+
partial_ordering v, compare_internal::OnlyLiteralZero) noexcept {
|
| 300 |
+
return v.is_ordered() && v.value_ >= 0;
|
| 301 |
+
}
|
| 302 |
+
friend constexpr bool operator==(compare_internal::OnlyLiteralZero,
|
| 303 |
+
partial_ordering v) noexcept {
|
| 304 |
+
return v.is_ordered() && 0 == v.value_;
|
| 305 |
+
}
|
| 306 |
+
friend constexpr bool operator!=(compare_internal::OnlyLiteralZero,
|
| 307 |
+
partial_ordering v) noexcept {
|
| 308 |
+
return !v.is_ordered() || 0 != v.value_;
|
| 309 |
+
}
|
| 310 |
+
friend constexpr bool operator<(compare_internal::OnlyLiteralZero,
|
| 311 |
+
partial_ordering v) noexcept {
|
| 312 |
+
return v.is_ordered() && 0 < v.value_;
|
| 313 |
+
}
|
| 314 |
+
friend constexpr bool operator<=(compare_internal::OnlyLiteralZero,
|
| 315 |
+
partial_ordering v) noexcept {
|
| 316 |
+
return v.is_ordered() && 0 <= v.value_;
|
| 317 |
+
}
|
| 318 |
+
friend constexpr bool operator>(compare_internal::OnlyLiteralZero,
|
| 319 |
+
partial_ordering v) noexcept {
|
| 320 |
+
return v.is_ordered() && 0 > v.value_;
|
| 321 |
+
}
|
| 322 |
+
friend constexpr bool operator>=(compare_internal::OnlyLiteralZero,
|
| 323 |
+
partial_ordering v) noexcept {
|
| 324 |
+
return v.is_ordered() && 0 >= v.value_;
|
| 325 |
+
}
|
| 326 |
+
friend constexpr bool operator==(partial_ordering v1,
|
| 327 |
+
partial_ordering v2) noexcept {
|
| 328 |
+
return v1.value_ == v2.value_;
|
| 329 |
+
}
|
| 330 |
+
friend constexpr bool operator!=(partial_ordering v1,
|
| 331 |
+
partial_ordering v2) noexcept {
|
| 332 |
+
return v1.value_ != v2.value_;
|
| 333 |
+
}
|
| 334 |
+
|
| 335 |
+
private:
|
| 336 |
+
compare_internal::value_type value_;
|
| 337 |
+
};
|
| 338 |
+
ABSL_COMPARE_INLINE_INIT(partial_ordering, less, compare_internal::ord::less);
|
| 339 |
+
ABSL_COMPARE_INLINE_INIT(partial_ordering, equivalent,
|
| 340 |
+
compare_internal::eq::equivalent);
|
| 341 |
+
ABSL_COMPARE_INLINE_INIT(partial_ordering, greater,
|
| 342 |
+
compare_internal::ord::greater);
|
| 343 |
+
ABSL_COMPARE_INLINE_INIT(partial_ordering, unordered,
|
| 344 |
+
compare_internal::ncmp::unordered);
|
| 345 |
+
|
| 346 |
+
class weak_ordering
|
| 347 |
+
: public compare_internal::weak_ordering_base<weak_ordering> {
|
| 348 |
+
explicit constexpr weak_ordering(compare_internal::eq v) noexcept
|
| 349 |
+
: value_(static_cast<compare_internal::value_type>(v)) {}
|
| 350 |
+
explicit constexpr weak_ordering(compare_internal::ord v) noexcept
|
| 351 |
+
: value_(static_cast<compare_internal::value_type>(v)) {}
|
| 352 |
+
friend struct compare_internal::weak_ordering_base<weak_ordering>;
|
| 353 |
+
|
| 354 |
+
public:
|
| 355 |
+
ABSL_COMPARE_INLINE_SUBCLASS_DECL(weak_ordering, less);
|
| 356 |
+
ABSL_COMPARE_INLINE_SUBCLASS_DECL(weak_ordering, equivalent);
|
| 357 |
+
ABSL_COMPARE_INLINE_SUBCLASS_DECL(weak_ordering, greater);
|
| 358 |
+
|
| 359 |
+
// Conversions
|
| 360 |
+
constexpr operator weak_equality() const noexcept { // NOLINT
|
| 361 |
+
return value_ == 0 ? weak_equality::equivalent
|
| 362 |
+
: weak_equality::nonequivalent;
|
| 363 |
+
}
|
| 364 |
+
constexpr operator partial_ordering() const noexcept { // NOLINT
|
| 365 |
+
return value_ == 0 ? partial_ordering::equivalent
|
| 366 |
+
: (value_ < 0 ? partial_ordering::less
|
| 367 |
+
: partial_ordering::greater);
|
| 368 |
+
}
|
| 369 |
+
// Comparisons
|
| 370 |
+
friend constexpr bool operator==(
|
| 371 |
+
weak_ordering v, compare_internal::OnlyLiteralZero) noexcept {
|
| 372 |
+
return v.value_ == 0;
|
| 373 |
+
}
|
| 374 |
+
friend constexpr bool operator!=(
|
| 375 |
+
weak_ordering v, compare_internal::OnlyLiteralZero) noexcept {
|
| 376 |
+
return v.value_ != 0;
|
| 377 |
+
}
|
| 378 |
+
friend constexpr bool operator<(
|
| 379 |
+
weak_ordering v, compare_internal::OnlyLiteralZero) noexcept {
|
| 380 |
+
return v.value_ < 0;
|
| 381 |
+
}
|
| 382 |
+
friend constexpr bool operator<=(
|
| 383 |
+
weak_ordering v, compare_internal::OnlyLiteralZero) noexcept {
|
| 384 |
+
return v.value_ <= 0;
|
| 385 |
+
}
|
| 386 |
+
friend constexpr bool operator>(
|
| 387 |
+
weak_ordering v, compare_internal::OnlyLiteralZero) noexcept {
|
| 388 |
+
return v.value_ > 0;
|
| 389 |
+
}
|
| 390 |
+
friend constexpr bool operator>=(
|
| 391 |
+
weak_ordering v, compare_internal::OnlyLiteralZero) noexcept {
|
| 392 |
+
return v.value_ >= 0;
|
| 393 |
+
}
|
| 394 |
+
friend constexpr bool operator==(compare_internal::OnlyLiteralZero,
|
| 395 |
+
weak_ordering v) noexcept {
|
| 396 |
+
return 0 == v.value_;
|
| 397 |
+
}
|
| 398 |
+
friend constexpr bool operator!=(compare_internal::OnlyLiteralZero,
|
| 399 |
+
weak_ordering v) noexcept {
|
| 400 |
+
return 0 != v.value_;
|
| 401 |
+
}
|
| 402 |
+
friend constexpr bool operator<(compare_internal::OnlyLiteralZero,
|
| 403 |
+
weak_ordering v) noexcept {
|
| 404 |
+
return 0 < v.value_;
|
| 405 |
+
}
|
| 406 |
+
friend constexpr bool operator<=(compare_internal::OnlyLiteralZero,
|
| 407 |
+
weak_ordering v) noexcept {
|
| 408 |
+
return 0 <= v.value_;
|
| 409 |
+
}
|
| 410 |
+
friend constexpr bool operator>(compare_internal::OnlyLiteralZero,
|
| 411 |
+
weak_ordering v) noexcept {
|
| 412 |
+
return 0 > v.value_;
|
| 413 |
+
}
|
| 414 |
+
friend constexpr bool operator>=(compare_internal::OnlyLiteralZero,
|
| 415 |
+
weak_ordering v) noexcept {
|
| 416 |
+
return 0 >= v.value_;
|
| 417 |
+
}
|
| 418 |
+
friend constexpr bool operator==(weak_ordering v1,
|
| 419 |
+
weak_ordering v2) noexcept {
|
| 420 |
+
return v1.value_ == v2.value_;
|
| 421 |
+
}
|
| 422 |
+
friend constexpr bool operator!=(weak_ordering v1,
|
| 423 |
+
weak_ordering v2) noexcept {
|
| 424 |
+
return v1.value_ != v2.value_;
|
| 425 |
+
}
|
| 426 |
+
|
| 427 |
+
private:
|
| 428 |
+
compare_internal::value_type value_;
|
| 429 |
+
};
|
| 430 |
+
ABSL_COMPARE_INLINE_INIT(weak_ordering, less, compare_internal::ord::less);
|
| 431 |
+
ABSL_COMPARE_INLINE_INIT(weak_ordering, equivalent,
|
| 432 |
+
compare_internal::eq::equivalent);
|
| 433 |
+
ABSL_COMPARE_INLINE_INIT(weak_ordering, greater,
|
| 434 |
+
compare_internal::ord::greater);
|
| 435 |
+
|
| 436 |
+
class strong_ordering
|
| 437 |
+
: public compare_internal::strong_ordering_base<strong_ordering> {
|
| 438 |
+
explicit constexpr strong_ordering(compare_internal::eq v) noexcept
|
| 439 |
+
: value_(static_cast<compare_internal::value_type>(v)) {}
|
| 440 |
+
explicit constexpr strong_ordering(compare_internal::ord v) noexcept
|
| 441 |
+
: value_(static_cast<compare_internal::value_type>(v)) {}
|
| 442 |
+
friend struct compare_internal::strong_ordering_base<strong_ordering>;
|
| 443 |
+
|
| 444 |
+
public:
|
| 445 |
+
ABSL_COMPARE_INLINE_SUBCLASS_DECL(strong_ordering, less);
|
| 446 |
+
ABSL_COMPARE_INLINE_SUBCLASS_DECL(strong_ordering, equal);
|
| 447 |
+
ABSL_COMPARE_INLINE_SUBCLASS_DECL(strong_ordering, equivalent);
|
| 448 |
+
ABSL_COMPARE_INLINE_SUBCLASS_DECL(strong_ordering, greater);
|
| 449 |
+
|
| 450 |
+
// Conversions
|
| 451 |
+
constexpr operator weak_equality() const noexcept { // NOLINT
|
| 452 |
+
return value_ == 0 ? weak_equality::equivalent
|
| 453 |
+
: weak_equality::nonequivalent;
|
| 454 |
+
}
|
| 455 |
+
constexpr operator strong_equality() const noexcept { // NOLINT
|
| 456 |
+
return value_ == 0 ? strong_equality::equal : strong_equality::nonequal;
|
| 457 |
+
}
|
| 458 |
+
constexpr operator partial_ordering() const noexcept { // NOLINT
|
| 459 |
+
return value_ == 0 ? partial_ordering::equivalent
|
| 460 |
+
: (value_ < 0 ? partial_ordering::less
|
| 461 |
+
: partial_ordering::greater);
|
| 462 |
+
}
|
| 463 |
+
constexpr operator weak_ordering() const noexcept { // NOLINT
|
| 464 |
+
return value_ == 0
|
| 465 |
+
? weak_ordering::equivalent
|
| 466 |
+
: (value_ < 0 ? weak_ordering::less : weak_ordering::greater);
|
| 467 |
+
}
|
| 468 |
+
// Comparisons
|
| 469 |
+
friend constexpr bool operator==(
|
| 470 |
+
strong_ordering v, compare_internal::OnlyLiteralZero) noexcept {
|
| 471 |
+
return v.value_ == 0;
|
| 472 |
+
}
|
| 473 |
+
friend constexpr bool operator!=(
|
| 474 |
+
strong_ordering v, compare_internal::OnlyLiteralZero) noexcept {
|
| 475 |
+
return v.value_ != 0;
|
| 476 |
+
}
|
| 477 |
+
friend constexpr bool operator<(
|
| 478 |
+
strong_ordering v, compare_internal::OnlyLiteralZero) noexcept {
|
| 479 |
+
return v.value_ < 0;
|
| 480 |
+
}
|
| 481 |
+
friend constexpr bool operator<=(
|
| 482 |
+
strong_ordering v, compare_internal::OnlyLiteralZero) noexcept {
|
| 483 |
+
return v.value_ <= 0;
|
| 484 |
+
}
|
| 485 |
+
friend constexpr bool operator>(
|
| 486 |
+
strong_ordering v, compare_internal::OnlyLiteralZero) noexcept {
|
| 487 |
+
return v.value_ > 0;
|
| 488 |
+
}
|
| 489 |
+
friend constexpr bool operator>=(
|
| 490 |
+
strong_ordering v, compare_internal::OnlyLiteralZero) noexcept {
|
| 491 |
+
return v.value_ >= 0;
|
| 492 |
+
}
|
| 493 |
+
friend constexpr bool operator==(compare_internal::OnlyLiteralZero,
|
| 494 |
+
strong_ordering v) noexcept {
|
| 495 |
+
return 0 == v.value_;
|
| 496 |
+
}
|
| 497 |
+
friend constexpr bool operator!=(compare_internal::OnlyLiteralZero,
|
| 498 |
+
strong_ordering v) noexcept {
|
| 499 |
+
return 0 != v.value_;
|
| 500 |
+
}
|
| 501 |
+
friend constexpr bool operator<(compare_internal::OnlyLiteralZero,
|
| 502 |
+
strong_ordering v) noexcept {
|
| 503 |
+
return 0 < v.value_;
|
| 504 |
+
}
|
| 505 |
+
friend constexpr bool operator<=(compare_internal::OnlyLiteralZero,
|
| 506 |
+
strong_ordering v) noexcept {
|
| 507 |
+
return 0 <= v.value_;
|
| 508 |
+
}
|
| 509 |
+
friend constexpr bool operator>(compare_internal::OnlyLiteralZero,
|
| 510 |
+
strong_ordering v) noexcept {
|
| 511 |
+
return 0 > v.value_;
|
| 512 |
+
}
|
| 513 |
+
friend constexpr bool operator>=(compare_internal::OnlyLiteralZero,
|
| 514 |
+
strong_ordering v) noexcept {
|
| 515 |
+
return 0 >= v.value_;
|
| 516 |
+
}
|
| 517 |
+
friend constexpr bool operator==(strong_ordering v1,
|
| 518 |
+
strong_ordering v2) noexcept {
|
| 519 |
+
return v1.value_ == v2.value_;
|
| 520 |
+
}
|
| 521 |
+
friend constexpr bool operator!=(strong_ordering v1,
|
| 522 |
+
strong_ordering v2) noexcept {
|
| 523 |
+
return v1.value_ != v2.value_;
|
| 524 |
+
}
|
| 525 |
+
|
| 526 |
+
private:
|
| 527 |
+
compare_internal::value_type value_;
|
| 528 |
+
};
|
| 529 |
+
ABSL_COMPARE_INLINE_INIT(strong_ordering, less, compare_internal::ord::less);
|
| 530 |
+
ABSL_COMPARE_INLINE_INIT(strong_ordering, equal, compare_internal::eq::equal);
|
| 531 |
+
ABSL_COMPARE_INLINE_INIT(strong_ordering, equivalent,
|
| 532 |
+
compare_internal::eq::equivalent);
|
| 533 |
+
ABSL_COMPARE_INLINE_INIT(strong_ordering, greater,
|
| 534 |
+
compare_internal::ord::greater);
|
| 535 |
+
|
| 536 |
+
#undef ABSL_COMPARE_INLINE_BASECLASS_DECL
|
| 537 |
+
#undef ABSL_COMPARE_INLINE_SUBCLASS_DECL
|
| 538 |
+
#undef ABSL_COMPARE_INLINE_INIT
|
| 539 |
+
|
| 540 |
+
namespace compare_internal {
|
| 541 |
+
// We also provide these comparator adapter functions for internal absl use.
|
| 542 |
+
|
| 543 |
+
// Helper functions to do a boolean comparison of two keys given a boolean
|
| 544 |
+
// or three-way comparator.
|
| 545 |
+
// SFINAE prevents implicit conversions to bool (such as from int).
|
| 546 |
+
template <typename BoolT,
|
| 547 |
+
absl::enable_if_t<std::is_same<bool, BoolT>::value, int> = 0>
|
| 548 |
+
constexpr bool compare_result_as_less_than(const BoolT r) { return r; }
|
| 549 |
+
constexpr bool compare_result_as_less_than(const absl::weak_ordering r) {
|
| 550 |
+
return r < 0;
|
| 551 |
+
}
|
| 552 |
+
|
| 553 |
+
template <typename Compare, typename K, typename LK>
|
| 554 |
+
constexpr bool do_less_than_comparison(const Compare &compare, const K &x,
|
| 555 |
+
const LK &y) {
|
| 556 |
+
return compare_result_as_less_than(compare(x, y));
|
| 557 |
+
}
|
| 558 |
+
|
| 559 |
+
// Helper functions to do a three-way comparison of two keys given a boolean or
|
| 560 |
+
// three-way comparator.
|
| 561 |
+
// SFINAE prevents implicit conversions to int (such as from bool).
|
| 562 |
+
template <typename Int,
|
| 563 |
+
absl::enable_if_t<std::is_same<int, Int>::value, int> = 0>
|
| 564 |
+
constexpr absl::weak_ordering compare_result_as_ordering(const Int c) {
|
| 565 |
+
return c < 0 ? absl::weak_ordering::less
|
| 566 |
+
: c == 0 ? absl::weak_ordering::equivalent
|
| 567 |
+
: absl::weak_ordering::greater;
|
| 568 |
+
}
|
| 569 |
+
constexpr absl::weak_ordering compare_result_as_ordering(
|
| 570 |
+
const absl::weak_ordering c) {
|
| 571 |
+
return c;
|
| 572 |
+
}
|
| 573 |
+
|
| 574 |
+
template <
|
| 575 |
+
typename Compare, typename K, typename LK,
|
| 576 |
+
absl::enable_if_t<!std::is_same<bool, absl::result_of_t<Compare(
|
| 577 |
+
const K &, const LK &)>>::value,
|
| 578 |
+
int> = 0>
|
| 579 |
+
constexpr absl::weak_ordering do_three_way_comparison(const Compare &compare,
|
| 580 |
+
const K &x, const LK &y) {
|
| 581 |
+
return compare_result_as_ordering(compare(x, y));
|
| 582 |
+
}
|
| 583 |
+
template <
|
| 584 |
+
typename Compare, typename K, typename LK,
|
| 585 |
+
absl::enable_if_t<std::is_same<bool, absl::result_of_t<Compare(
|
| 586 |
+
const K &, const LK &)>>::value,
|
| 587 |
+
int> = 0>
|
| 588 |
+
constexpr absl::weak_ordering do_three_way_comparison(const Compare &compare,
|
| 589 |
+
const K &x, const LK &y) {
|
| 590 |
+
return compare(x, y) ? absl::weak_ordering::less
|
| 591 |
+
: compare(y, x) ? absl::weak_ordering::greater
|
| 592 |
+
: absl::weak_ordering::equivalent;
|
| 593 |
+
}
|
| 594 |
+
|
| 595 |
+
} // namespace compare_internal
|
| 596 |
+
ABSL_NAMESPACE_END
|
| 597 |
+
} // namespace absl
|
| 598 |
+
|
| 599 |
+
#endif // ABSL_TYPES_COMPARE_H_
|
miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/absl/types/internal/optional.h
ADDED
|
@@ -0,0 +1,404 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2017 The Abseil Authors.
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// https://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
//
|
| 15 |
+
#ifndef ABSL_TYPES_INTERNAL_OPTIONAL_H_
|
| 16 |
+
#define ABSL_TYPES_INTERNAL_OPTIONAL_H_
|
| 17 |
+
|
| 18 |
+
#include <functional>
|
| 19 |
+
#include <new>
|
| 20 |
+
#include <type_traits>
|
| 21 |
+
#include <utility>
|
| 22 |
+
|
| 23 |
+
#include "absl/base/internal/inline_variable.h"
|
| 24 |
+
#include "absl/memory/memory.h"
|
| 25 |
+
#include "absl/meta/type_traits.h"
|
| 26 |
+
#include "absl/utility/utility.h"
|
| 27 |
+
|
| 28 |
+
// ABSL_OPTIONAL_USE_INHERITING_CONSTRUCTORS
|
| 29 |
+
//
|
| 30 |
+
// Inheriting constructors is supported in GCC 4.8+, Clang 3.3+ and MSVC 2015.
|
| 31 |
+
// __cpp_inheriting_constructors is a predefined macro and a recommended way to
|
| 32 |
+
// check for this language feature, but GCC doesn't support it until 5.0 and
|
| 33 |
+
// Clang doesn't support it until 3.6.
|
| 34 |
+
// Also, MSVC 2015 has a bug: it doesn't inherit the constexpr template
|
| 35 |
+
// constructor. For example, the following code won't work on MSVC 2015 Update3:
|
| 36 |
+
// struct Base {
|
| 37 |
+
// int t;
|
| 38 |
+
// template <typename T>
|
| 39 |
+
// constexpr Base(T t_) : t(t_) {}
|
| 40 |
+
// };
|
| 41 |
+
// struct Foo : Base {
|
| 42 |
+
// using Base::Base;
|
| 43 |
+
// }
|
| 44 |
+
// constexpr Foo foo(0); // doesn't work on MSVC 2015
|
| 45 |
+
#if defined(__clang__)
|
| 46 |
+
#if __has_feature(cxx_inheriting_constructors)
|
| 47 |
+
#define ABSL_OPTIONAL_USE_INHERITING_CONSTRUCTORS 1
|
| 48 |
+
#endif
|
| 49 |
+
#elif (defined(__GNUC__) && \
|
| 50 |
+
(__GNUC__ > 4 || __GNUC__ == 4 && __GNUC_MINOR__ >= 8)) || \
|
| 51 |
+
(__cpp_inheriting_constructors >= 200802) || \
|
| 52 |
+
(defined(_MSC_VER) && _MSC_VER >= 1910)
|
| 53 |
+
#define ABSL_OPTIONAL_USE_INHERITING_CONSTRUCTORS 1
|
| 54 |
+
#endif
|
| 55 |
+
|
| 56 |
+
namespace absl {
|
| 57 |
+
ABSL_NAMESPACE_BEGIN
|
| 58 |
+
|
| 59 |
+
// Forward declaration
|
| 60 |
+
template <typename T>
|
| 61 |
+
class optional;
|
| 62 |
+
|
| 63 |
+
namespace optional_internal {
|
| 64 |
+
|
| 65 |
+
// This tag type is used as a constructor parameter type for `nullopt_t`.
|
| 66 |
+
struct init_t {
|
| 67 |
+
explicit init_t() = default;
|
| 68 |
+
};
|
| 69 |
+
|
| 70 |
+
struct empty_struct {};
|
| 71 |
+
|
| 72 |
+
// This class stores the data in optional<T>.
|
| 73 |
+
// It is specialized based on whether T is trivially destructible.
|
| 74 |
+
// This is the specialization for non trivially destructible type.
|
| 75 |
+
template <typename T, bool unused = std::is_trivially_destructible<T>::value>
|
| 76 |
+
class optional_data_dtor_base {
|
| 77 |
+
struct dummy_type {
|
| 78 |
+
static_assert(sizeof(T) % sizeof(empty_struct) == 0, "");
|
| 79 |
+
// Use an array to avoid GCC 6 placement-new warning.
|
| 80 |
+
empty_struct data[sizeof(T) / sizeof(empty_struct)];
|
| 81 |
+
};
|
| 82 |
+
|
| 83 |
+
protected:
|
| 84 |
+
// Whether there is data or not.
|
| 85 |
+
bool engaged_;
|
| 86 |
+
// Data storage
|
| 87 |
+
union {
|
| 88 |
+
T data_;
|
| 89 |
+
dummy_type dummy_;
|
| 90 |
+
};
|
| 91 |
+
|
| 92 |
+
void destruct() noexcept {
|
| 93 |
+
if (engaged_) {
|
| 94 |
+
// `data_` must be initialized if `engaged_` is true.
|
| 95 |
+
#if ABSL_INTERNAL_HAVE_MIN_GNUC_VERSION(12, 0)
|
| 96 |
+
#pragma GCC diagnostic push
|
| 97 |
+
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
|
| 98 |
+
#endif
|
| 99 |
+
data_.~T();
|
| 100 |
+
#if ABSL_INTERNAL_HAVE_MIN_GNUC_VERSION(12, 0)
|
| 101 |
+
#pragma GCC diagnostic pop
|
| 102 |
+
#endif
|
| 103 |
+
engaged_ = false;
|
| 104 |
+
}
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
// dummy_ must be initialized for constexpr constructor.
|
| 108 |
+
constexpr optional_data_dtor_base() noexcept : engaged_(false), dummy_{{}} {}
|
| 109 |
+
|
| 110 |
+
template <typename... Args>
|
| 111 |
+
constexpr explicit optional_data_dtor_base(in_place_t, Args&&... args)
|
| 112 |
+
: engaged_(true), data_(absl::forward<Args>(args)...) {}
|
| 113 |
+
|
| 114 |
+
~optional_data_dtor_base() { destruct(); }
|
| 115 |
+
};
|
| 116 |
+
|
| 117 |
+
// Specialization for trivially destructible type.
|
| 118 |
+
template <typename T>
|
| 119 |
+
class optional_data_dtor_base<T, true> {
|
| 120 |
+
struct dummy_type {
|
| 121 |
+
static_assert(sizeof(T) % sizeof(empty_struct) == 0, "");
|
| 122 |
+
// Use array to avoid GCC 6 placement-new warning.
|
| 123 |
+
empty_struct data[sizeof(T) / sizeof(empty_struct)];
|
| 124 |
+
};
|
| 125 |
+
|
| 126 |
+
protected:
|
| 127 |
+
// Whether there is data or not.
|
| 128 |
+
bool engaged_;
|
| 129 |
+
// Data storage
|
| 130 |
+
union {
|
| 131 |
+
T data_;
|
| 132 |
+
dummy_type dummy_;
|
| 133 |
+
};
|
| 134 |
+
void destruct() noexcept { engaged_ = false; }
|
| 135 |
+
|
| 136 |
+
// dummy_ must be initialized for constexpr constructor.
|
| 137 |
+
constexpr optional_data_dtor_base() noexcept : engaged_(false), dummy_{{}} {}
|
| 138 |
+
|
| 139 |
+
template <typename... Args>
|
| 140 |
+
constexpr explicit optional_data_dtor_base(in_place_t, Args&&... args)
|
| 141 |
+
: engaged_(true), data_(absl::forward<Args>(args)...) {}
|
| 142 |
+
};
|
| 143 |
+
|
| 144 |
+
template <typename T>
|
| 145 |
+
class optional_data_base : public optional_data_dtor_base<T> {
|
| 146 |
+
protected:
|
| 147 |
+
using base = optional_data_dtor_base<T>;
|
| 148 |
+
#ifdef ABSL_OPTIONAL_USE_INHERITING_CONSTRUCTORS
|
| 149 |
+
using base::base;
|
| 150 |
+
#else
|
| 151 |
+
optional_data_base() = default;
|
| 152 |
+
|
| 153 |
+
template <typename... Args>
|
| 154 |
+
constexpr explicit optional_data_base(in_place_t t, Args&&... args)
|
| 155 |
+
: base(t, absl::forward<Args>(args)...) {}
|
| 156 |
+
#endif
|
| 157 |
+
|
| 158 |
+
template <typename... Args>
|
| 159 |
+
void construct(Args&&... args) {
|
| 160 |
+
// Use dummy_'s address to work around casting cv-qualified T* to void*.
|
| 161 |
+
::new (static_cast<void*>(&this->dummy_)) T(std::forward<Args>(args)...);
|
| 162 |
+
this->engaged_ = true;
|
| 163 |
+
}
|
| 164 |
+
|
| 165 |
+
template <typename U>
|
| 166 |
+
void assign(U&& u) {
|
| 167 |
+
if (this->engaged_) {
|
| 168 |
+
this->data_ = std::forward<U>(u);
|
| 169 |
+
} else {
|
| 170 |
+
construct(std::forward<U>(u));
|
| 171 |
+
}
|
| 172 |
+
}
|
| 173 |
+
};
|
| 174 |
+
|
| 175 |
+
// TODO(absl-team): Add another class using
|
| 176 |
+
// std::is_trivially_move_constructible trait when available to match
|
| 177 |
+
// http://cplusplus.github.io/LWG/lwg-defects.html#2900, for types that
|
| 178 |
+
// have trivial move but nontrivial copy.
|
| 179 |
+
// Also, we should be checking is_trivially_copyable here, which is not
|
| 180 |
+
// supported now, so we use is_trivially_* traits instead.
|
| 181 |
+
template <typename T,
|
| 182 |
+
bool unused = absl::is_trivially_copy_constructible<T>::value&&
|
| 183 |
+
absl::is_trivially_copy_assignable<typename std::remove_cv<
|
| 184 |
+
T>::type>::value&& std::is_trivially_destructible<T>::value>
|
| 185 |
+
class optional_data;
|
| 186 |
+
|
| 187 |
+
// Trivially copyable types
|
| 188 |
+
template <typename T>
|
| 189 |
+
class optional_data<T, true> : public optional_data_base<T> {
|
| 190 |
+
protected:
|
| 191 |
+
#ifdef ABSL_OPTIONAL_USE_INHERITING_CONSTRUCTORS
|
| 192 |
+
using optional_data_base<T>::optional_data_base;
|
| 193 |
+
#else
|
| 194 |
+
optional_data() = default;
|
| 195 |
+
|
| 196 |
+
template <typename... Args>
|
| 197 |
+
constexpr explicit optional_data(in_place_t t, Args&&... args)
|
| 198 |
+
: optional_data_base<T>(t, absl::forward<Args>(args)...) {}
|
| 199 |
+
#endif
|
| 200 |
+
};
|
| 201 |
+
|
| 202 |
+
template <typename T>
|
| 203 |
+
class optional_data<T, false> : public optional_data_base<T> {
|
| 204 |
+
protected:
|
| 205 |
+
#ifdef ABSL_OPTIONAL_USE_INHERITING_CONSTRUCTORS
|
| 206 |
+
using optional_data_base<T>::optional_data_base;
|
| 207 |
+
#else
|
| 208 |
+
template <typename... Args>
|
| 209 |
+
constexpr explicit optional_data(in_place_t t, Args&&... args)
|
| 210 |
+
: optional_data_base<T>(t, absl::forward<Args>(args)...) {}
|
| 211 |
+
#endif
|
| 212 |
+
|
| 213 |
+
optional_data() = default;
|
| 214 |
+
|
| 215 |
+
optional_data(const optional_data& rhs) : optional_data_base<T>() {
|
| 216 |
+
if (rhs.engaged_) {
|
| 217 |
+
this->construct(rhs.data_);
|
| 218 |
+
}
|
| 219 |
+
}
|
| 220 |
+
|
| 221 |
+
optional_data(optional_data&& rhs) noexcept(
|
| 222 |
+
absl::default_allocator_is_nothrow::value ||
|
| 223 |
+
std::is_nothrow_move_constructible<T>::value)
|
| 224 |
+
: optional_data_base<T>() {
|
| 225 |
+
if (rhs.engaged_) {
|
| 226 |
+
this->construct(std::move(rhs.data_));
|
| 227 |
+
}
|
| 228 |
+
}
|
| 229 |
+
|
| 230 |
+
optional_data& operator=(const optional_data& rhs) {
|
| 231 |
+
if (rhs.engaged_) {
|
| 232 |
+
this->assign(rhs.data_);
|
| 233 |
+
} else {
|
| 234 |
+
this->destruct();
|
| 235 |
+
}
|
| 236 |
+
return *this;
|
| 237 |
+
}
|
| 238 |
+
|
| 239 |
+
optional_data& operator=(optional_data&& rhs) noexcept(
|
| 240 |
+
std::is_nothrow_move_assignable<T>::value&&
|
| 241 |
+
std::is_nothrow_move_constructible<T>::value) {
|
| 242 |
+
if (rhs.engaged_) {
|
| 243 |
+
this->assign(std::move(rhs.data_));
|
| 244 |
+
} else {
|
| 245 |
+
this->destruct();
|
| 246 |
+
}
|
| 247 |
+
return *this;
|
| 248 |
+
}
|
| 249 |
+
};
|
| 250 |
+
|
| 251 |
+
// Ordered by level of restriction, from low to high.
|
| 252 |
+
// Copyable implies movable.
|
| 253 |
+
enum class copy_traits { copyable = 0, movable = 1, non_movable = 2 };
|
| 254 |
+
|
| 255 |
+
// Base class for enabling/disabling copy/move constructor.
|
| 256 |
+
template <copy_traits>
|
| 257 |
+
class optional_ctor_base;
|
| 258 |
+
|
| 259 |
+
template <>
|
| 260 |
+
class optional_ctor_base<copy_traits::copyable> {
|
| 261 |
+
public:
|
| 262 |
+
constexpr optional_ctor_base() = default;
|
| 263 |
+
optional_ctor_base(const optional_ctor_base&) = default;
|
| 264 |
+
optional_ctor_base(optional_ctor_base&&) = default;
|
| 265 |
+
optional_ctor_base& operator=(const optional_ctor_base&) = default;
|
| 266 |
+
optional_ctor_base& operator=(optional_ctor_base&&) = default;
|
| 267 |
+
};
|
| 268 |
+
|
| 269 |
+
template <>
|
| 270 |
+
class optional_ctor_base<copy_traits::movable> {
|
| 271 |
+
public:
|
| 272 |
+
constexpr optional_ctor_base() = default;
|
| 273 |
+
optional_ctor_base(const optional_ctor_base&) = delete;
|
| 274 |
+
optional_ctor_base(optional_ctor_base&&) = default;
|
| 275 |
+
optional_ctor_base& operator=(const optional_ctor_base&) = default;
|
| 276 |
+
optional_ctor_base& operator=(optional_ctor_base&&) = default;
|
| 277 |
+
};
|
| 278 |
+
|
| 279 |
+
template <>
|
| 280 |
+
class optional_ctor_base<copy_traits::non_movable> {
|
| 281 |
+
public:
|
| 282 |
+
constexpr optional_ctor_base() = default;
|
| 283 |
+
optional_ctor_base(const optional_ctor_base&) = delete;
|
| 284 |
+
optional_ctor_base(optional_ctor_base&&) = delete;
|
| 285 |
+
optional_ctor_base& operator=(const optional_ctor_base&) = default;
|
| 286 |
+
optional_ctor_base& operator=(optional_ctor_base&&) = default;
|
| 287 |
+
};
|
| 288 |
+
|
| 289 |
+
// Base class for enabling/disabling copy/move assignment.
|
| 290 |
+
template <copy_traits>
|
| 291 |
+
class optional_assign_base;
|
| 292 |
+
|
| 293 |
+
template <>
|
| 294 |
+
class optional_assign_base<copy_traits::copyable> {
|
| 295 |
+
public:
|
| 296 |
+
constexpr optional_assign_base() = default;
|
| 297 |
+
optional_assign_base(const optional_assign_base&) = default;
|
| 298 |
+
optional_assign_base(optional_assign_base&&) = default;
|
| 299 |
+
optional_assign_base& operator=(const optional_assign_base&) = default;
|
| 300 |
+
optional_assign_base& operator=(optional_assign_base&&) = default;
|
| 301 |
+
};
|
| 302 |
+
|
| 303 |
+
template <>
|
| 304 |
+
class optional_assign_base<copy_traits::movable> {
|
| 305 |
+
public:
|
| 306 |
+
constexpr optional_assign_base() = default;
|
| 307 |
+
optional_assign_base(const optional_assign_base&) = default;
|
| 308 |
+
optional_assign_base(optional_assign_base&&) = default;
|
| 309 |
+
optional_assign_base& operator=(const optional_assign_base&) = delete;
|
| 310 |
+
optional_assign_base& operator=(optional_assign_base&&) = default;
|
| 311 |
+
};
|
| 312 |
+
|
| 313 |
+
template <>
|
| 314 |
+
class optional_assign_base<copy_traits::non_movable> {
|
| 315 |
+
public:
|
| 316 |
+
constexpr optional_assign_base() = default;
|
| 317 |
+
optional_assign_base(const optional_assign_base&) = default;
|
| 318 |
+
optional_assign_base(optional_assign_base&&) = default;
|
| 319 |
+
optional_assign_base& operator=(const optional_assign_base&) = delete;
|
| 320 |
+
optional_assign_base& operator=(optional_assign_base&&) = delete;
|
| 321 |
+
};
|
| 322 |
+
|
| 323 |
+
template <typename T>
|
| 324 |
+
struct ctor_copy_traits {
|
| 325 |
+
static constexpr copy_traits traits =
|
| 326 |
+
std::is_copy_constructible<T>::value
|
| 327 |
+
? copy_traits::copyable
|
| 328 |
+
: std::is_move_constructible<T>::value ? copy_traits::movable
|
| 329 |
+
: copy_traits::non_movable;
|
| 330 |
+
};
|
| 331 |
+
|
| 332 |
+
template <typename T>
|
| 333 |
+
struct assign_copy_traits {
|
| 334 |
+
static constexpr copy_traits traits =
|
| 335 |
+
absl::is_copy_assignable<T>::value && std::is_copy_constructible<T>::value
|
| 336 |
+
? copy_traits::copyable
|
| 337 |
+
: absl::is_move_assignable<T>::value &&
|
| 338 |
+
std::is_move_constructible<T>::value
|
| 339 |
+
? copy_traits::movable
|
| 340 |
+
: copy_traits::non_movable;
|
| 341 |
+
};
|
| 342 |
+
|
| 343 |
+
// Whether T is constructible or convertible from optional<U>.
|
| 344 |
+
template <typename T, typename U>
|
| 345 |
+
struct is_constructible_convertible_from_optional
|
| 346 |
+
: std::integral_constant<
|
| 347 |
+
bool, std::is_constructible<T, optional<U>&>::value ||
|
| 348 |
+
std::is_constructible<T, optional<U>&&>::value ||
|
| 349 |
+
std::is_constructible<T, const optional<U>&>::value ||
|
| 350 |
+
std::is_constructible<T, const optional<U>&&>::value ||
|
| 351 |
+
std::is_convertible<optional<U>&, T>::value ||
|
| 352 |
+
std::is_convertible<optional<U>&&, T>::value ||
|
| 353 |
+
std::is_convertible<const optional<U>&, T>::value ||
|
| 354 |
+
std::is_convertible<const optional<U>&&, T>::value> {};
|
| 355 |
+
|
| 356 |
+
// Whether T is constructible or convertible or assignable from optional<U>.
|
| 357 |
+
template <typename T, typename U>
|
| 358 |
+
struct is_constructible_convertible_assignable_from_optional
|
| 359 |
+
: std::integral_constant<
|
| 360 |
+
bool, is_constructible_convertible_from_optional<T, U>::value ||
|
| 361 |
+
std::is_assignable<T&, optional<U>&>::value ||
|
| 362 |
+
std::is_assignable<T&, optional<U>&&>::value ||
|
| 363 |
+
std::is_assignable<T&, const optional<U>&>::value ||
|
| 364 |
+
std::is_assignable<T&, const optional<U>&&>::value> {};
|
| 365 |
+
|
| 366 |
+
// Helper function used by [optional.relops], [optional.comp_with_t],
|
| 367 |
+
// for checking whether an expression is convertible to bool.
|
| 368 |
+
bool convertible_to_bool(bool);
|
| 369 |
+
|
| 370 |
+
// Base class for std::hash<absl::optional<T>>:
|
| 371 |
+
// If std::hash<std::remove_const_t<T>> is enabled, it provides operator() to
|
| 372 |
+
// compute the hash; Otherwise, it is disabled.
|
| 373 |
+
// Reference N4659 23.14.15 [unord.hash].
|
| 374 |
+
template <typename T, typename = size_t>
|
| 375 |
+
struct optional_hash_base {
|
| 376 |
+
optional_hash_base() = delete;
|
| 377 |
+
optional_hash_base(const optional_hash_base&) = delete;
|
| 378 |
+
optional_hash_base(optional_hash_base&&) = delete;
|
| 379 |
+
optional_hash_base& operator=(const optional_hash_base&) = delete;
|
| 380 |
+
optional_hash_base& operator=(optional_hash_base&&) = delete;
|
| 381 |
+
};
|
| 382 |
+
|
| 383 |
+
template <typename T>
|
| 384 |
+
struct optional_hash_base<T, decltype(std::hash<absl::remove_const_t<T> >()(
|
| 385 |
+
std::declval<absl::remove_const_t<T> >()))> {
|
| 386 |
+
using argument_type = absl::optional<T>;
|
| 387 |
+
using result_type = size_t;
|
| 388 |
+
size_t operator()(const absl::optional<T>& opt) const {
|
| 389 |
+
absl::type_traits_internal::AssertHashEnabled<absl::remove_const_t<T>>();
|
| 390 |
+
if (opt) {
|
| 391 |
+
return std::hash<absl::remove_const_t<T> >()(*opt);
|
| 392 |
+
} else {
|
| 393 |
+
return static_cast<size_t>(0x297814aaad196e6dULL);
|
| 394 |
+
}
|
| 395 |
+
}
|
| 396 |
+
};
|
| 397 |
+
|
| 398 |
+
} // namespace optional_internal
|
| 399 |
+
ABSL_NAMESPACE_END
|
| 400 |
+
} // namespace absl
|
| 401 |
+
|
| 402 |
+
#undef ABSL_OPTIONAL_USE_INHERITING_CONSTRUCTORS
|
| 403 |
+
|
| 404 |
+
#endif // ABSL_TYPES_INTERNAL_OPTIONAL_H_
|
miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/absl/types/internal/span.h
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//
|
| 2 |
+
// Copyright 2019 The Abseil Authors.
|
| 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 |
+
// https://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 |
+
#ifndef ABSL_TYPES_INTERNAL_SPAN_H_
|
| 17 |
+
#define ABSL_TYPES_INTERNAL_SPAN_H_
|
| 18 |
+
|
| 19 |
+
#include <algorithm>
|
| 20 |
+
#include <cstddef>
|
| 21 |
+
#include <string>
|
| 22 |
+
#include <type_traits>
|
| 23 |
+
|
| 24 |
+
#include "absl/algorithm/algorithm.h"
|
| 25 |
+
#include "absl/base/internal/throw_delegate.h"
|
| 26 |
+
#include "absl/meta/type_traits.h"
|
| 27 |
+
|
| 28 |
+
namespace absl {
|
| 29 |
+
ABSL_NAMESPACE_BEGIN
|
| 30 |
+
|
| 31 |
+
template <typename T>
|
| 32 |
+
class Span;
|
| 33 |
+
|
| 34 |
+
namespace span_internal {
|
| 35 |
+
// Wrappers for access to container data pointers.
|
| 36 |
+
template <typename C>
|
| 37 |
+
constexpr auto GetDataImpl(C& c, char) noexcept // NOLINT(runtime/references)
|
| 38 |
+
-> decltype(c.data()) {
|
| 39 |
+
return c.data();
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
// Before C++17, std::string::data returns a const char* in all cases.
|
| 43 |
+
inline char* GetDataImpl(std::string& s, // NOLINT(runtime/references)
|
| 44 |
+
int) noexcept {
|
| 45 |
+
return &s[0];
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
template <typename C>
|
| 49 |
+
constexpr auto GetData(C& c) noexcept // NOLINT(runtime/references)
|
| 50 |
+
-> decltype(GetDataImpl(c, 0)) {
|
| 51 |
+
return GetDataImpl(c, 0);
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
// Detection idioms for size() and data().
|
| 55 |
+
template <typename C>
|
| 56 |
+
using HasSize =
|
| 57 |
+
std::is_integral<absl::decay_t<decltype(std::declval<C&>().size())>>;
|
| 58 |
+
|
| 59 |
+
// We want to enable conversion from vector<T*> to Span<const T* const> but
|
| 60 |
+
// disable conversion from vector<Derived> to Span<Base>. Here we use
|
| 61 |
+
// the fact that U** is convertible to Q* const* if and only if Q is the same
|
| 62 |
+
// type or a more cv-qualified version of U. We also decay the result type of
|
| 63 |
+
// data() to avoid problems with classes which have a member function data()
|
| 64 |
+
// which returns a reference.
|
| 65 |
+
template <typename T, typename C>
|
| 66 |
+
using HasData =
|
| 67 |
+
std::is_convertible<absl::decay_t<decltype(GetData(std::declval<C&>()))>*,
|
| 68 |
+
T* const*>;
|
| 69 |
+
|
| 70 |
+
// Extracts value type from a Container
|
| 71 |
+
template <typename C>
|
| 72 |
+
struct ElementType {
|
| 73 |
+
using type = typename absl::remove_reference_t<C>::value_type;
|
| 74 |
+
};
|
| 75 |
+
|
| 76 |
+
template <typename T, size_t N>
|
| 77 |
+
struct ElementType<T (&)[N]> {
|
| 78 |
+
using type = T;
|
| 79 |
+
};
|
| 80 |
+
|
| 81 |
+
template <typename C>
|
| 82 |
+
using ElementT = typename ElementType<C>::type;
|
| 83 |
+
|
| 84 |
+
template <typename T>
|
| 85 |
+
using EnableIfMutable =
|
| 86 |
+
typename std::enable_if<!std::is_const<T>::value, int>::type;
|
| 87 |
+
|
| 88 |
+
template <template <typename> class SpanT, typename T>
|
| 89 |
+
bool EqualImpl(SpanT<T> a, SpanT<T> b) {
|
| 90 |
+
static_assert(std::is_const<T>::value, "");
|
| 91 |
+
return absl::equal(a.begin(), a.end(), b.begin(), b.end());
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
template <template <typename> class SpanT, typename T>
|
| 95 |
+
bool LessThanImpl(SpanT<T> a, SpanT<T> b) {
|
| 96 |
+
// We can't use value_type since that is remove_cv_t<T>, so we go the long way
|
| 97 |
+
// around.
|
| 98 |
+
static_assert(std::is_const<T>::value, "");
|
| 99 |
+
return std::lexicographical_compare(a.begin(), a.end(), b.begin(), b.end());
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
template <typename From, typename To>
|
| 103 |
+
using EnableIfConvertibleTo =
|
| 104 |
+
typename std::enable_if<std::is_convertible<From, To>::value>::type;
|
| 105 |
+
|
| 106 |
+
// IsView is true for types where the return type of .data() is the same for
|
| 107 |
+
// mutable and const instances. This isn't foolproof, but it's only used to
|
| 108 |
+
// enable a compiler warning.
|
| 109 |
+
template <typename T, typename = void, typename = void>
|
| 110 |
+
struct IsView {
|
| 111 |
+
static constexpr bool value = false;
|
| 112 |
+
};
|
| 113 |
+
|
| 114 |
+
template <typename T>
|
| 115 |
+
struct IsView<
|
| 116 |
+
T, absl::void_t<decltype(span_internal::GetData(std::declval<const T&>()))>,
|
| 117 |
+
absl::void_t<decltype(span_internal::GetData(std::declval<T&>()))>> {
|
| 118 |
+
private:
|
| 119 |
+
using Container = std::remove_const_t<T>;
|
| 120 |
+
using ConstData =
|
| 121 |
+
decltype(span_internal::GetData(std::declval<const Container&>()));
|
| 122 |
+
using MutData = decltype(span_internal::GetData(std::declval<Container&>()));
|
| 123 |
+
public:
|
| 124 |
+
static constexpr bool value = std::is_same<ConstData, MutData>::value;
|
| 125 |
+
};
|
| 126 |
+
|
| 127 |
+
// These enablers result in 'int' so they can be used as typenames or defaults
|
| 128 |
+
// in template paramters lists.
|
| 129 |
+
template <typename T>
|
| 130 |
+
using EnableIfIsView = std::enable_if_t<IsView<T>::value, int>;
|
| 131 |
+
|
| 132 |
+
template <typename T>
|
| 133 |
+
using EnableIfNotIsView = std::enable_if_t<!IsView<T>::value, int>;
|
| 134 |
+
|
| 135 |
+
} // namespace span_internal
|
| 136 |
+
ABSL_NAMESPACE_END
|
| 137 |
+
} // namespace absl
|
| 138 |
+
|
| 139 |
+
#endif // ABSL_TYPES_INTERNAL_SPAN_H_
|
miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/absl/types/internal/variant.h
ADDED
|
@@ -0,0 +1,1634 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2018 The Abseil Authors.
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// https://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
//
|
| 15 |
+
// Implementation details of absl/types/variant.h, pulled into a
|
| 16 |
+
// separate file to avoid cluttering the top of the API header with
|
| 17 |
+
// implementation details.
|
| 18 |
+
|
| 19 |
+
#ifndef ABSL_TYPES_INTERNAL_VARIANT_H_
|
| 20 |
+
#define ABSL_TYPES_INTERNAL_VARIANT_H_
|
| 21 |
+
|
| 22 |
+
#include <cassert>
|
| 23 |
+
#include <cstddef>
|
| 24 |
+
#include <cstdlib>
|
| 25 |
+
#include <memory>
|
| 26 |
+
#include <stdexcept>
|
| 27 |
+
#include <tuple>
|
| 28 |
+
#include <type_traits>
|
| 29 |
+
|
| 30 |
+
#include "absl/base/config.h"
|
| 31 |
+
#include "absl/base/internal/identity.h"
|
| 32 |
+
#include "absl/base/internal/inline_variable.h"
|
| 33 |
+
#include "absl/base/internal/invoke.h"
|
| 34 |
+
#include "absl/base/macros.h"
|
| 35 |
+
#include "absl/base/optimization.h"
|
| 36 |
+
#include "absl/meta/type_traits.h"
|
| 37 |
+
#include "absl/types/bad_variant_access.h"
|
| 38 |
+
#include "absl/utility/utility.h"
|
| 39 |
+
|
| 40 |
+
#if !defined(ABSL_USES_STD_VARIANT)
|
| 41 |
+
|
| 42 |
+
namespace absl {
|
| 43 |
+
ABSL_NAMESPACE_BEGIN
|
| 44 |
+
|
| 45 |
+
template <class... Types>
|
| 46 |
+
class variant;
|
| 47 |
+
|
| 48 |
+
ABSL_INTERNAL_INLINE_CONSTEXPR(size_t, variant_npos, static_cast<size_t>(-1));
|
| 49 |
+
|
| 50 |
+
template <class T>
|
| 51 |
+
struct variant_size;
|
| 52 |
+
|
| 53 |
+
template <std::size_t I, class T>
|
| 54 |
+
struct variant_alternative;
|
| 55 |
+
|
| 56 |
+
namespace variant_internal {
|
| 57 |
+
|
| 58 |
+
// NOTE: See specializations below for details.
|
| 59 |
+
template <std::size_t I, class T>
|
| 60 |
+
struct VariantAlternativeSfinae {};
|
| 61 |
+
|
| 62 |
+
// Requires: I < variant_size_v<T>.
|
| 63 |
+
//
|
| 64 |
+
// Value: The Ith type of Types...
|
| 65 |
+
template <std::size_t I, class T0, class... Tn>
|
| 66 |
+
struct VariantAlternativeSfinae<I, variant<T0, Tn...>>
|
| 67 |
+
: VariantAlternativeSfinae<I - 1, variant<Tn...>> {};
|
| 68 |
+
|
| 69 |
+
// Value: T0
|
| 70 |
+
template <class T0, class... Ts>
|
| 71 |
+
struct VariantAlternativeSfinae<0, variant<T0, Ts...>> {
|
| 72 |
+
using type = T0;
|
| 73 |
+
};
|
| 74 |
+
|
| 75 |
+
template <std::size_t I, class T>
|
| 76 |
+
using VariantAlternativeSfinaeT = typename VariantAlternativeSfinae<I, T>::type;
|
| 77 |
+
|
| 78 |
+
// NOTE: Requires T to be a reference type.
|
| 79 |
+
template <class T, class U>
|
| 80 |
+
struct GiveQualsTo;
|
| 81 |
+
|
| 82 |
+
template <class T, class U>
|
| 83 |
+
struct GiveQualsTo<T&, U> {
|
| 84 |
+
using type = U&;
|
| 85 |
+
};
|
| 86 |
+
|
| 87 |
+
template <class T, class U>
|
| 88 |
+
struct GiveQualsTo<T&&, U> {
|
| 89 |
+
using type = U&&;
|
| 90 |
+
};
|
| 91 |
+
|
| 92 |
+
template <class T, class U>
|
| 93 |
+
struct GiveQualsTo<const T&, U> {
|
| 94 |
+
using type = const U&;
|
| 95 |
+
};
|
| 96 |
+
|
| 97 |
+
template <class T, class U>
|
| 98 |
+
struct GiveQualsTo<const T&&, U> {
|
| 99 |
+
using type = const U&&;
|
| 100 |
+
};
|
| 101 |
+
|
| 102 |
+
template <class T, class U>
|
| 103 |
+
struct GiveQualsTo<volatile T&, U> {
|
| 104 |
+
using type = volatile U&;
|
| 105 |
+
};
|
| 106 |
+
|
| 107 |
+
template <class T, class U>
|
| 108 |
+
struct GiveQualsTo<volatile T&&, U> {
|
| 109 |
+
using type = volatile U&&;
|
| 110 |
+
};
|
| 111 |
+
|
| 112 |
+
template <class T, class U>
|
| 113 |
+
struct GiveQualsTo<volatile const T&, U> {
|
| 114 |
+
using type = volatile const U&;
|
| 115 |
+
};
|
| 116 |
+
|
| 117 |
+
template <class T, class U>
|
| 118 |
+
struct GiveQualsTo<volatile const T&&, U> {
|
| 119 |
+
using type = volatile const U&&;
|
| 120 |
+
};
|
| 121 |
+
|
| 122 |
+
template <class T, class U>
|
| 123 |
+
using GiveQualsToT = typename GiveQualsTo<T, U>::type;
|
| 124 |
+
|
| 125 |
+
// Convenience alias, since size_t integral_constant is used a lot in this file.
|
| 126 |
+
template <std::size_t I>
|
| 127 |
+
using SizeT = std::integral_constant<std::size_t, I>;
|
| 128 |
+
|
| 129 |
+
using NPos = SizeT<variant_npos>;
|
| 130 |
+
|
| 131 |
+
template <class Variant, class T, class = void>
|
| 132 |
+
struct IndexOfConstructedType {};
|
| 133 |
+
|
| 134 |
+
template <std::size_t I, class Variant>
|
| 135 |
+
struct VariantAccessResultImpl;
|
| 136 |
+
|
| 137 |
+
template <std::size_t I, template <class...> class Variantemplate, class... T>
|
| 138 |
+
struct VariantAccessResultImpl<I, Variantemplate<T...>&> {
|
| 139 |
+
using type = typename absl::variant_alternative<I, variant<T...>>::type&;
|
| 140 |
+
};
|
| 141 |
+
|
| 142 |
+
template <std::size_t I, template <class...> class Variantemplate, class... T>
|
| 143 |
+
struct VariantAccessResultImpl<I, const Variantemplate<T...>&> {
|
| 144 |
+
using type =
|
| 145 |
+
const typename absl::variant_alternative<I, variant<T...>>::type&;
|
| 146 |
+
};
|
| 147 |
+
|
| 148 |
+
template <std::size_t I, template <class...> class Variantemplate, class... T>
|
| 149 |
+
struct VariantAccessResultImpl<I, Variantemplate<T...>&&> {
|
| 150 |
+
using type = typename absl::variant_alternative<I, variant<T...>>::type&&;
|
| 151 |
+
};
|
| 152 |
+
|
| 153 |
+
template <std::size_t I, template <class...> class Variantemplate, class... T>
|
| 154 |
+
struct VariantAccessResultImpl<I, const Variantemplate<T...>&&> {
|
| 155 |
+
using type =
|
| 156 |
+
const typename absl::variant_alternative<I, variant<T...>>::type&&;
|
| 157 |
+
};
|
| 158 |
+
|
| 159 |
+
template <std::size_t I, class Variant>
|
| 160 |
+
using VariantAccessResult =
|
| 161 |
+
typename VariantAccessResultImpl<I, Variant&&>::type;
|
| 162 |
+
|
| 163 |
+
// NOTE: This is used instead of std::array to reduce instantiation overhead.
|
| 164 |
+
template <class T, std::size_t Size>
|
| 165 |
+
struct SimpleArray {
|
| 166 |
+
static_assert(Size != 0, "");
|
| 167 |
+
T value[Size];
|
| 168 |
+
};
|
| 169 |
+
|
| 170 |
+
template <class T>
|
| 171 |
+
struct AccessedType {
|
| 172 |
+
using type = T;
|
| 173 |
+
};
|
| 174 |
+
|
| 175 |
+
template <class T>
|
| 176 |
+
using AccessedTypeT = typename AccessedType<T>::type;
|
| 177 |
+
|
| 178 |
+
template <class T, std::size_t Size>
|
| 179 |
+
struct AccessedType<SimpleArray<T, Size>> {
|
| 180 |
+
using type = AccessedTypeT<T>;
|
| 181 |
+
};
|
| 182 |
+
|
| 183 |
+
template <class T>
|
| 184 |
+
constexpr T AccessSimpleArray(const T& value) {
|
| 185 |
+
return value;
|
| 186 |
+
}
|
| 187 |
+
|
| 188 |
+
template <class T, std::size_t Size, class... SizeT>
|
| 189 |
+
constexpr AccessedTypeT<T> AccessSimpleArray(const SimpleArray<T, Size>& table,
|
| 190 |
+
std::size_t head_index,
|
| 191 |
+
SizeT... tail_indices) {
|
| 192 |
+
return AccessSimpleArray(table.value[head_index], tail_indices...);
|
| 193 |
+
}
|
| 194 |
+
|
| 195 |
+
// Note: Intentionally is an alias.
|
| 196 |
+
template <class T>
|
| 197 |
+
using AlwaysZero = SizeT<0>;
|
| 198 |
+
|
| 199 |
+
template <class Op, class... Vs>
|
| 200 |
+
struct VisitIndicesResultImpl {
|
| 201 |
+
using type = absl::result_of_t<Op(AlwaysZero<Vs>...)>;
|
| 202 |
+
};
|
| 203 |
+
|
| 204 |
+
template <class Op, class... Vs>
|
| 205 |
+
using VisitIndicesResultT = typename VisitIndicesResultImpl<Op, Vs...>::type;
|
| 206 |
+
|
| 207 |
+
template <class ReturnType, class FunctionObject, class EndIndices,
|
| 208 |
+
class BoundIndices>
|
| 209 |
+
struct MakeVisitationMatrix;
|
| 210 |
+
|
| 211 |
+
template <class ReturnType, class FunctionObject, std::size_t... Indices>
|
| 212 |
+
constexpr ReturnType call_with_indices(FunctionObject&& function) {
|
| 213 |
+
static_assert(
|
| 214 |
+
std::is_same<ReturnType, decltype(std::declval<FunctionObject>()(
|
| 215 |
+
SizeT<Indices>()...))>::value,
|
| 216 |
+
"Not all visitation overloads have the same return type.");
|
| 217 |
+
return absl::forward<FunctionObject>(function)(SizeT<Indices>()...);
|
| 218 |
+
}
|
| 219 |
+
|
| 220 |
+
template <class ReturnType, class FunctionObject, std::size_t... BoundIndices>
|
| 221 |
+
struct MakeVisitationMatrix<ReturnType, FunctionObject, index_sequence<>,
|
| 222 |
+
index_sequence<BoundIndices...>> {
|
| 223 |
+
using ResultType = ReturnType (*)(FunctionObject&&);
|
| 224 |
+
static constexpr ResultType Run() {
|
| 225 |
+
return &call_with_indices<ReturnType, FunctionObject,
|
| 226 |
+
(BoundIndices - 1)...>;
|
| 227 |
+
}
|
| 228 |
+
};
|
| 229 |
+
|
| 230 |
+
template <typename Is, std::size_t J>
|
| 231 |
+
struct AppendToIndexSequence;
|
| 232 |
+
|
| 233 |
+
template <typename Is, std::size_t J>
|
| 234 |
+
using AppendToIndexSequenceT = typename AppendToIndexSequence<Is, J>::type;
|
| 235 |
+
|
| 236 |
+
template <std::size_t... Is, std::size_t J>
|
| 237 |
+
struct AppendToIndexSequence<index_sequence<Is...>, J> {
|
| 238 |
+
using type = index_sequence<Is..., J>;
|
| 239 |
+
};
|
| 240 |
+
|
| 241 |
+
template <class ReturnType, class FunctionObject, class EndIndices,
|
| 242 |
+
class CurrIndices, class BoundIndices>
|
| 243 |
+
struct MakeVisitationMatrixImpl;
|
| 244 |
+
|
| 245 |
+
template <class ReturnType, class FunctionObject, class EndIndices,
|
| 246 |
+
std::size_t... CurrIndices, class BoundIndices>
|
| 247 |
+
struct MakeVisitationMatrixImpl<ReturnType, FunctionObject, EndIndices,
|
| 248 |
+
index_sequence<CurrIndices...>, BoundIndices> {
|
| 249 |
+
using ResultType = SimpleArray<
|
| 250 |
+
typename MakeVisitationMatrix<ReturnType, FunctionObject, EndIndices,
|
| 251 |
+
index_sequence<>>::ResultType,
|
| 252 |
+
sizeof...(CurrIndices)>;
|
| 253 |
+
|
| 254 |
+
static constexpr ResultType Run() {
|
| 255 |
+
return {{MakeVisitationMatrix<
|
| 256 |
+
ReturnType, FunctionObject, EndIndices,
|
| 257 |
+
AppendToIndexSequenceT<BoundIndices, CurrIndices>>::Run()...}};
|
| 258 |
+
}
|
| 259 |
+
};
|
| 260 |
+
|
| 261 |
+
template <class ReturnType, class FunctionObject, std::size_t HeadEndIndex,
|
| 262 |
+
std::size_t... TailEndIndices, std::size_t... BoundIndices>
|
| 263 |
+
struct MakeVisitationMatrix<ReturnType, FunctionObject,
|
| 264 |
+
index_sequence<HeadEndIndex, TailEndIndices...>,
|
| 265 |
+
index_sequence<BoundIndices...>>
|
| 266 |
+
: MakeVisitationMatrixImpl<ReturnType, FunctionObject,
|
| 267 |
+
index_sequence<TailEndIndices...>,
|
| 268 |
+
absl::make_index_sequence<HeadEndIndex>,
|
| 269 |
+
index_sequence<BoundIndices...>> {};
|
| 270 |
+
|
| 271 |
+
struct UnreachableSwitchCase {
|
| 272 |
+
template <class Op>
|
| 273 |
+
[[noreturn]] static VisitIndicesResultT<Op, std::size_t> Run(
|
| 274 |
+
Op&& /*ignored*/) {
|
| 275 |
+
#if ABSL_HAVE_BUILTIN(__builtin_unreachable) || \
|
| 276 |
+
(defined(__GNUC__) && !defined(__clang__))
|
| 277 |
+
__builtin_unreachable();
|
| 278 |
+
#elif defined(_MSC_VER)
|
| 279 |
+
__assume(false);
|
| 280 |
+
#else
|
| 281 |
+
// Try to use assert of false being identified as an unreachable intrinsic.
|
| 282 |
+
// NOTE: We use assert directly to increase chances of exploiting an assume
|
| 283 |
+
// intrinsic.
|
| 284 |
+
assert(false); // NOLINT
|
| 285 |
+
|
| 286 |
+
// Hack to silence potential no return warning -- cause an infinite loop.
|
| 287 |
+
return Run(absl::forward<Op>(op));
|
| 288 |
+
#endif // Checks for __builtin_unreachable
|
| 289 |
+
}
|
| 290 |
+
};
|
| 291 |
+
|
| 292 |
+
template <class Op, std::size_t I>
|
| 293 |
+
struct ReachableSwitchCase {
|
| 294 |
+
static VisitIndicesResultT<Op, std::size_t> Run(Op&& op) {
|
| 295 |
+
return absl::base_internal::invoke(absl::forward<Op>(op), SizeT<I>());
|
| 296 |
+
}
|
| 297 |
+
};
|
| 298 |
+
|
| 299 |
+
// The number 33 is just a guess at a reasonable maximum to our switch. It is
|
| 300 |
+
// not based on any analysis. The reason it is a power of 2 plus 1 instead of a
|
| 301 |
+
// power of 2 is because the number was picked to correspond to a power of 2
|
| 302 |
+
// amount of "normal" alternatives, plus one for the possibility of the user
|
| 303 |
+
// providing "monostate" in addition to the more natural alternatives.
|
| 304 |
+
ABSL_INTERNAL_INLINE_CONSTEXPR(std::size_t, MaxUnrolledVisitCases, 33);
|
| 305 |
+
|
| 306 |
+
// Note: The default-definition is for unreachable cases.
|
| 307 |
+
template <bool IsReachable>
|
| 308 |
+
struct PickCaseImpl {
|
| 309 |
+
template <class Op, std::size_t I>
|
| 310 |
+
using Apply = UnreachableSwitchCase;
|
| 311 |
+
};
|
| 312 |
+
|
| 313 |
+
template <>
|
| 314 |
+
struct PickCaseImpl</*IsReachable =*/true> {
|
| 315 |
+
template <class Op, std::size_t I>
|
| 316 |
+
using Apply = ReachableSwitchCase<Op, I>;
|
| 317 |
+
};
|
| 318 |
+
|
| 319 |
+
// Note: This form of dance with template aliases is to make sure that we
|
| 320 |
+
// instantiate a number of templates proportional to the number of variant
|
| 321 |
+
// alternatives rather than a number of templates proportional to our
|
| 322 |
+
// maximum unrolled amount of visitation cases (aliases are effectively
|
| 323 |
+
// "free" whereas other template instantiations are costly).
|
| 324 |
+
template <class Op, std::size_t I, std::size_t EndIndex>
|
| 325 |
+
using PickCase = typename PickCaseImpl<(I < EndIndex)>::template Apply<Op, I>;
|
| 326 |
+
|
| 327 |
+
template <class ReturnType>
|
| 328 |
+
[[noreturn]] ReturnType TypedThrowBadVariantAccess() {
|
| 329 |
+
absl::variant_internal::ThrowBadVariantAccess();
|
| 330 |
+
}
|
| 331 |
+
|
| 332 |
+
// Given N variant sizes, determine the number of cases there would need to be
|
| 333 |
+
// in a single switch-statement that would cover every possibility in the
|
| 334 |
+
// corresponding N-ary visit operation.
|
| 335 |
+
template <std::size_t... NumAlternatives>
|
| 336 |
+
struct NumCasesOfSwitch;
|
| 337 |
+
|
| 338 |
+
template <std::size_t HeadNumAlternatives, std::size_t... TailNumAlternatives>
|
| 339 |
+
struct NumCasesOfSwitch<HeadNumAlternatives, TailNumAlternatives...> {
|
| 340 |
+
static constexpr std::size_t value =
|
| 341 |
+
(HeadNumAlternatives + 1) *
|
| 342 |
+
NumCasesOfSwitch<TailNumAlternatives...>::value;
|
| 343 |
+
};
|
| 344 |
+
|
| 345 |
+
template <>
|
| 346 |
+
struct NumCasesOfSwitch<> {
|
| 347 |
+
static constexpr std::size_t value = 1;
|
| 348 |
+
};
|
| 349 |
+
|
| 350 |
+
// A switch statement optimizes better than the table of function pointers.
|
| 351 |
+
template <std::size_t EndIndex>
|
| 352 |
+
struct VisitIndicesSwitch {
|
| 353 |
+
static_assert(EndIndex <= MaxUnrolledVisitCases,
|
| 354 |
+
"Maximum unrolled switch size exceeded.");
|
| 355 |
+
|
| 356 |
+
template <class Op>
|
| 357 |
+
static VisitIndicesResultT<Op, std::size_t> Run(Op&& op, std::size_t i) {
|
| 358 |
+
switch (i) {
|
| 359 |
+
case 0:
|
| 360 |
+
return PickCase<Op, 0, EndIndex>::Run(absl::forward<Op>(op));
|
| 361 |
+
case 1:
|
| 362 |
+
return PickCase<Op, 1, EndIndex>::Run(absl::forward<Op>(op));
|
| 363 |
+
case 2:
|
| 364 |
+
return PickCase<Op, 2, EndIndex>::Run(absl::forward<Op>(op));
|
| 365 |
+
case 3:
|
| 366 |
+
return PickCase<Op, 3, EndIndex>::Run(absl::forward<Op>(op));
|
| 367 |
+
case 4:
|
| 368 |
+
return PickCase<Op, 4, EndIndex>::Run(absl::forward<Op>(op));
|
| 369 |
+
case 5:
|
| 370 |
+
return PickCase<Op, 5, EndIndex>::Run(absl::forward<Op>(op));
|
| 371 |
+
case 6:
|
| 372 |
+
return PickCase<Op, 6, EndIndex>::Run(absl::forward<Op>(op));
|
| 373 |
+
case 7:
|
| 374 |
+
return PickCase<Op, 7, EndIndex>::Run(absl::forward<Op>(op));
|
| 375 |
+
case 8:
|
| 376 |
+
return PickCase<Op, 8, EndIndex>::Run(absl::forward<Op>(op));
|
| 377 |
+
case 9:
|
| 378 |
+
return PickCase<Op, 9, EndIndex>::Run(absl::forward<Op>(op));
|
| 379 |
+
case 10:
|
| 380 |
+
return PickCase<Op, 10, EndIndex>::Run(absl::forward<Op>(op));
|
| 381 |
+
case 11:
|
| 382 |
+
return PickCase<Op, 11, EndIndex>::Run(absl::forward<Op>(op));
|
| 383 |
+
case 12:
|
| 384 |
+
return PickCase<Op, 12, EndIndex>::Run(absl::forward<Op>(op));
|
| 385 |
+
case 13:
|
| 386 |
+
return PickCase<Op, 13, EndIndex>::Run(absl::forward<Op>(op));
|
| 387 |
+
case 14:
|
| 388 |
+
return PickCase<Op, 14, EndIndex>::Run(absl::forward<Op>(op));
|
| 389 |
+
case 15:
|
| 390 |
+
return PickCase<Op, 15, EndIndex>::Run(absl::forward<Op>(op));
|
| 391 |
+
case 16:
|
| 392 |
+
return PickCase<Op, 16, EndIndex>::Run(absl::forward<Op>(op));
|
| 393 |
+
case 17:
|
| 394 |
+
return PickCase<Op, 17, EndIndex>::Run(absl::forward<Op>(op));
|
| 395 |
+
case 18:
|
| 396 |
+
return PickCase<Op, 18, EndIndex>::Run(absl::forward<Op>(op));
|
| 397 |
+
case 19:
|
| 398 |
+
return PickCase<Op, 19, EndIndex>::Run(absl::forward<Op>(op));
|
| 399 |
+
case 20:
|
| 400 |
+
return PickCase<Op, 20, EndIndex>::Run(absl::forward<Op>(op));
|
| 401 |
+
case 21:
|
| 402 |
+
return PickCase<Op, 21, EndIndex>::Run(absl::forward<Op>(op));
|
| 403 |
+
case 22:
|
| 404 |
+
return PickCase<Op, 22, EndIndex>::Run(absl::forward<Op>(op));
|
| 405 |
+
case 23:
|
| 406 |
+
return PickCase<Op, 23, EndIndex>::Run(absl::forward<Op>(op));
|
| 407 |
+
case 24:
|
| 408 |
+
return PickCase<Op, 24, EndIndex>::Run(absl::forward<Op>(op));
|
| 409 |
+
case 25:
|
| 410 |
+
return PickCase<Op, 25, EndIndex>::Run(absl::forward<Op>(op));
|
| 411 |
+
case 26:
|
| 412 |
+
return PickCase<Op, 26, EndIndex>::Run(absl::forward<Op>(op));
|
| 413 |
+
case 27:
|
| 414 |
+
return PickCase<Op, 27, EndIndex>::Run(absl::forward<Op>(op));
|
| 415 |
+
case 28:
|
| 416 |
+
return PickCase<Op, 28, EndIndex>::Run(absl::forward<Op>(op));
|
| 417 |
+
case 29:
|
| 418 |
+
return PickCase<Op, 29, EndIndex>::Run(absl::forward<Op>(op));
|
| 419 |
+
case 30:
|
| 420 |
+
return PickCase<Op, 30, EndIndex>::Run(absl::forward<Op>(op));
|
| 421 |
+
case 31:
|
| 422 |
+
return PickCase<Op, 31, EndIndex>::Run(absl::forward<Op>(op));
|
| 423 |
+
case 32:
|
| 424 |
+
return PickCase<Op, 32, EndIndex>::Run(absl::forward<Op>(op));
|
| 425 |
+
default:
|
| 426 |
+
ABSL_ASSERT(i == variant_npos);
|
| 427 |
+
return absl::base_internal::invoke(absl::forward<Op>(op), NPos());
|
| 428 |
+
}
|
| 429 |
+
}
|
| 430 |
+
};
|
| 431 |
+
|
| 432 |
+
template <std::size_t... EndIndices>
|
| 433 |
+
struct VisitIndicesFallback {
|
| 434 |
+
template <class Op, class... SizeT>
|
| 435 |
+
static VisitIndicesResultT<Op, SizeT...> Run(Op&& op, SizeT... indices) {
|
| 436 |
+
return AccessSimpleArray(
|
| 437 |
+
MakeVisitationMatrix<VisitIndicesResultT<Op, SizeT...>, Op,
|
| 438 |
+
index_sequence<(EndIndices + 1)...>,
|
| 439 |
+
index_sequence<>>::Run(),
|
| 440 |
+
(indices + 1)...)(absl::forward<Op>(op));
|
| 441 |
+
}
|
| 442 |
+
};
|
| 443 |
+
|
| 444 |
+
// Take an N-dimensional series of indices and convert them into a single index
|
| 445 |
+
// without loss of information. The purpose of this is to be able to convert an
|
| 446 |
+
// N-ary visit operation into a single switch statement.
|
| 447 |
+
template <std::size_t...>
|
| 448 |
+
struct FlattenIndices;
|
| 449 |
+
|
| 450 |
+
template <std::size_t HeadSize, std::size_t... TailSize>
|
| 451 |
+
struct FlattenIndices<HeadSize, TailSize...> {
|
| 452 |
+
template <class... SizeType>
|
| 453 |
+
static constexpr std::size_t Run(std::size_t head, SizeType... tail) {
|
| 454 |
+
return head + HeadSize * FlattenIndices<TailSize...>::Run(tail...);
|
| 455 |
+
}
|
| 456 |
+
};
|
| 457 |
+
|
| 458 |
+
template <>
|
| 459 |
+
struct FlattenIndices<> {
|
| 460 |
+
static constexpr std::size_t Run() { return 0; }
|
| 461 |
+
};
|
| 462 |
+
|
| 463 |
+
// Take a single "flattened" index (flattened by FlattenIndices) and determine
|
| 464 |
+
// the value of the index of one of the logically represented dimensions.
|
| 465 |
+
template <std::size_t I, std::size_t IndexToGet, std::size_t HeadSize,
|
| 466 |
+
std::size_t... TailSize>
|
| 467 |
+
struct UnflattenIndex {
|
| 468 |
+
static constexpr std::size_t value =
|
| 469 |
+
UnflattenIndex<I / HeadSize, IndexToGet - 1, TailSize...>::value;
|
| 470 |
+
};
|
| 471 |
+
|
| 472 |
+
template <std::size_t I, std::size_t HeadSize, std::size_t... TailSize>
|
| 473 |
+
struct UnflattenIndex<I, 0, HeadSize, TailSize...> {
|
| 474 |
+
static constexpr std::size_t value = (I % HeadSize);
|
| 475 |
+
};
|
| 476 |
+
|
| 477 |
+
// The backend for converting an N-ary visit operation into a unary visit.
|
| 478 |
+
template <class IndexSequence, std::size_t... EndIndices>
|
| 479 |
+
struct VisitIndicesVariadicImpl;
|
| 480 |
+
|
| 481 |
+
template <std::size_t... N, std::size_t... EndIndices>
|
| 482 |
+
struct VisitIndicesVariadicImpl<absl::index_sequence<N...>, EndIndices...> {
|
| 483 |
+
// A type that can take an N-ary function object and converts it to a unary
|
| 484 |
+
// function object that takes a single, flattened index, and "unflattens" it
|
| 485 |
+
// into its individual dimensions when forwarding to the wrapped object.
|
| 486 |
+
template <class Op>
|
| 487 |
+
struct FlattenedOp {
|
| 488 |
+
template <std::size_t I>
|
| 489 |
+
VisitIndicesResultT<Op, decltype(EndIndices)...> operator()(
|
| 490 |
+
SizeT<I> /*index*/) && {
|
| 491 |
+
return base_internal::invoke(
|
| 492 |
+
absl::forward<Op>(op),
|
| 493 |
+
SizeT<UnflattenIndex<I, N, (EndIndices + 1)...>::value -
|
| 494 |
+
std::size_t{1}>()...);
|
| 495 |
+
}
|
| 496 |
+
|
| 497 |
+
Op&& op;
|
| 498 |
+
};
|
| 499 |
+
|
| 500 |
+
template <class Op, class... SizeType>
|
| 501 |
+
static VisitIndicesResultT<Op, decltype(EndIndices)...> Run(Op&& op,
|
| 502 |
+
SizeType... i) {
|
| 503 |
+
return VisitIndicesSwitch<NumCasesOfSwitch<EndIndices...>::value>::Run(
|
| 504 |
+
FlattenedOp<Op>{absl::forward<Op>(op)},
|
| 505 |
+
FlattenIndices<(EndIndices + std::size_t{1})...>::Run(
|
| 506 |
+
(i + std::size_t{1})...));
|
| 507 |
+
}
|
| 508 |
+
};
|
| 509 |
+
|
| 510 |
+
template <std::size_t... EndIndices>
|
| 511 |
+
struct VisitIndicesVariadic
|
| 512 |
+
: VisitIndicesVariadicImpl<absl::make_index_sequence<sizeof...(EndIndices)>,
|
| 513 |
+
EndIndices...> {};
|
| 514 |
+
|
| 515 |
+
// This implementation will flatten N-ary visit operations into a single switch
|
| 516 |
+
// statement when the number of cases would be less than our maximum specified
|
| 517 |
+
// switch-statement size.
|
| 518 |
+
// TODO(calabrese)
|
| 519 |
+
// Based on benchmarks, determine whether the function table approach actually
|
| 520 |
+
// does optimize better than a chain of switch statements and possibly update
|
| 521 |
+
// the implementation accordingly. Also consider increasing the maximum switch
|
| 522 |
+
// size.
|
| 523 |
+
template <std::size_t... EndIndices>
|
| 524 |
+
struct VisitIndices
|
| 525 |
+
: absl::conditional_t<(NumCasesOfSwitch<EndIndices...>::value <=
|
| 526 |
+
MaxUnrolledVisitCases),
|
| 527 |
+
VisitIndicesVariadic<EndIndices...>,
|
| 528 |
+
VisitIndicesFallback<EndIndices...>> {};
|
| 529 |
+
|
| 530 |
+
template <std::size_t EndIndex>
|
| 531 |
+
struct VisitIndices<EndIndex>
|
| 532 |
+
: absl::conditional_t<(EndIndex <= MaxUnrolledVisitCases),
|
| 533 |
+
VisitIndicesSwitch<EndIndex>,
|
| 534 |
+
VisitIndicesFallback<EndIndex>> {};
|
| 535 |
+
|
| 536 |
+
// Suppress bogus warning on MSVC: MSVC complains that the `reinterpret_cast`
|
| 537 |
+
// below is returning the address of a temporary or local object.
|
| 538 |
+
#ifdef _MSC_VER
|
| 539 |
+
#pragma warning(push)
|
| 540 |
+
#pragma warning(disable : 4172)
|
| 541 |
+
#endif // _MSC_VER
|
| 542 |
+
|
| 543 |
+
// TODO(calabrese) std::launder
|
| 544 |
+
// TODO(calabrese) constexpr
|
| 545 |
+
// NOTE: DO NOT REMOVE the `inline` keyword as it is necessary to work around a
|
| 546 |
+
// MSVC bug. See https://github.com/abseil/abseil-cpp/issues/129 for details.
|
| 547 |
+
template <class Self, std::size_t I>
|
| 548 |
+
inline VariantAccessResult<I, Self> AccessUnion(Self&& self, SizeT<I> /*i*/) {
|
| 549 |
+
return reinterpret_cast<VariantAccessResult<I, Self>>(self);
|
| 550 |
+
}
|
| 551 |
+
|
| 552 |
+
#ifdef _MSC_VER
|
| 553 |
+
#pragma warning(pop)
|
| 554 |
+
#endif // _MSC_VER
|
| 555 |
+
|
| 556 |
+
template <class T>
|
| 557 |
+
void DeducedDestroy(T& self) { // NOLINT
|
| 558 |
+
self.~T();
|
| 559 |
+
}
|
| 560 |
+
|
| 561 |
+
// NOTE: This type exists as a single entity for variant and its bases to
|
| 562 |
+
// befriend. It contains helper functionality that manipulates the state of the
|
| 563 |
+
// variant, such as the implementation of things like assignment and emplace
|
| 564 |
+
// operations.
|
| 565 |
+
struct VariantCoreAccess {
|
| 566 |
+
template <class VariantType>
|
| 567 |
+
static typename VariantType::Variant& Derived(VariantType& self) { // NOLINT
|
| 568 |
+
return static_cast<typename VariantType::Variant&>(self);
|
| 569 |
+
}
|
| 570 |
+
|
| 571 |
+
template <class VariantType>
|
| 572 |
+
static const typename VariantType::Variant& Derived(
|
| 573 |
+
const VariantType& self) { // NOLINT
|
| 574 |
+
return static_cast<const typename VariantType::Variant&>(self);
|
| 575 |
+
}
|
| 576 |
+
|
| 577 |
+
template <class VariantType>
|
| 578 |
+
static void Destroy(VariantType& self) { // NOLINT
|
| 579 |
+
Derived(self).destroy();
|
| 580 |
+
self.index_ = absl::variant_npos;
|
| 581 |
+
}
|
| 582 |
+
|
| 583 |
+
template <class Variant>
|
| 584 |
+
static void SetIndex(Variant& self, std::size_t i) { // NOLINT
|
| 585 |
+
self.index_ = i;
|
| 586 |
+
}
|
| 587 |
+
|
| 588 |
+
template <class Variant>
|
| 589 |
+
static void InitFrom(Variant& self, Variant&& other) { // NOLINT
|
| 590 |
+
VisitIndices<absl::variant_size<Variant>::value>::Run(
|
| 591 |
+
InitFromVisitor<Variant, Variant&&>{&self,
|
| 592 |
+
std::forward<Variant>(other)},
|
| 593 |
+
other.index());
|
| 594 |
+
self.index_ = other.index();
|
| 595 |
+
}
|
| 596 |
+
|
| 597 |
+
// Access a variant alternative, assuming the index is correct.
|
| 598 |
+
template <std::size_t I, class Variant>
|
| 599 |
+
static VariantAccessResult<I, Variant> Access(Variant&& self) {
|
| 600 |
+
// This cast instead of invocation of AccessUnion with an rvalue is a
|
| 601 |
+
// workaround for msvc. Without this there is a runtime failure when dealing
|
| 602 |
+
// with rvalues.
|
| 603 |
+
// TODO(calabrese) Reduce test case and find a simpler workaround.
|
| 604 |
+
return static_cast<VariantAccessResult<I, Variant>>(
|
| 605 |
+
variant_internal::AccessUnion(self.state_, SizeT<I>()));
|
| 606 |
+
}
|
| 607 |
+
|
| 608 |
+
// Access a variant alternative, throwing if the index is incorrect.
|
| 609 |
+
template <std::size_t I, class Variant>
|
| 610 |
+
static VariantAccessResult<I, Variant> CheckedAccess(Variant&& self) {
|
| 611 |
+
if (ABSL_PREDICT_FALSE(self.index_ != I)) {
|
| 612 |
+
TypedThrowBadVariantAccess<VariantAccessResult<I, Variant>>();
|
| 613 |
+
}
|
| 614 |
+
|
| 615 |
+
return Access<I>(absl::forward<Variant>(self));
|
| 616 |
+
}
|
| 617 |
+
|
| 618 |
+
// The implementation of the move-assignment operation for a variant.
|
| 619 |
+
template <class VType>
|
| 620 |
+
struct MoveAssignVisitor {
|
| 621 |
+
using DerivedType = typename VType::Variant;
|
| 622 |
+
template <std::size_t NewIndex>
|
| 623 |
+
void operator()(SizeT<NewIndex> /*new_i*/) const {
|
| 624 |
+
if (left->index_ == NewIndex) {
|
| 625 |
+
Access<NewIndex>(*left) = std::move(Access<NewIndex>(*right));
|
| 626 |
+
} else {
|
| 627 |
+
Derived(*left).template emplace<NewIndex>(
|
| 628 |
+
std::move(Access<NewIndex>(*right)));
|
| 629 |
+
}
|
| 630 |
+
}
|
| 631 |
+
|
| 632 |
+
void operator()(SizeT<absl::variant_npos> /*new_i*/) const {
|
| 633 |
+
Destroy(*left);
|
| 634 |
+
}
|
| 635 |
+
|
| 636 |
+
VType* left;
|
| 637 |
+
VType* right;
|
| 638 |
+
};
|
| 639 |
+
|
| 640 |
+
template <class VType>
|
| 641 |
+
static MoveAssignVisitor<VType> MakeMoveAssignVisitor(VType* left,
|
| 642 |
+
VType* other) {
|
| 643 |
+
return {left, other};
|
| 644 |
+
}
|
| 645 |
+
|
| 646 |
+
// The implementation of the assignment operation for a variant.
|
| 647 |
+
template <class VType>
|
| 648 |
+
struct CopyAssignVisitor {
|
| 649 |
+
using DerivedType = typename VType::Variant;
|
| 650 |
+
template <std::size_t NewIndex>
|
| 651 |
+
void operator()(SizeT<NewIndex> /*new_i*/) const {
|
| 652 |
+
using New =
|
| 653 |
+
typename absl::variant_alternative<NewIndex, DerivedType>::type;
|
| 654 |
+
|
| 655 |
+
if (left->index_ == NewIndex) {
|
| 656 |
+
Access<NewIndex>(*left) = Access<NewIndex>(*right);
|
| 657 |
+
} else if (std::is_nothrow_copy_constructible<New>::value ||
|
| 658 |
+
!std::is_nothrow_move_constructible<New>::value) {
|
| 659 |
+
Derived(*left).template emplace<NewIndex>(Access<NewIndex>(*right));
|
| 660 |
+
} else {
|
| 661 |
+
Derived(*left) = DerivedType(Derived(*right));
|
| 662 |
+
}
|
| 663 |
+
}
|
| 664 |
+
|
| 665 |
+
void operator()(SizeT<absl::variant_npos> /*new_i*/) const {
|
| 666 |
+
Destroy(*left);
|
| 667 |
+
}
|
| 668 |
+
|
| 669 |
+
VType* left;
|
| 670 |
+
const VType* right;
|
| 671 |
+
};
|
| 672 |
+
|
| 673 |
+
template <class VType>
|
| 674 |
+
static CopyAssignVisitor<VType> MakeCopyAssignVisitor(VType* left,
|
| 675 |
+
const VType& other) {
|
| 676 |
+
return {left, &other};
|
| 677 |
+
}
|
| 678 |
+
|
| 679 |
+
// The implementation of conversion-assignment operations for variant.
|
| 680 |
+
template <class Left, class QualifiedNew>
|
| 681 |
+
struct ConversionAssignVisitor {
|
| 682 |
+
using NewIndex =
|
| 683 |
+
variant_internal::IndexOfConstructedType<Left, QualifiedNew>;
|
| 684 |
+
|
| 685 |
+
void operator()(SizeT<NewIndex::value> /*old_i*/
|
| 686 |
+
) const {
|
| 687 |
+
Access<NewIndex::value>(*left) = absl::forward<QualifiedNew>(other);
|
| 688 |
+
}
|
| 689 |
+
|
| 690 |
+
template <std::size_t OldIndex>
|
| 691 |
+
void operator()(SizeT<OldIndex> /*old_i*/
|
| 692 |
+
) const {
|
| 693 |
+
using New =
|
| 694 |
+
typename absl::variant_alternative<NewIndex::value, Left>::type;
|
| 695 |
+
if (std::is_nothrow_constructible<New, QualifiedNew>::value ||
|
| 696 |
+
!std::is_nothrow_move_constructible<New>::value) {
|
| 697 |
+
left->template emplace<NewIndex::value>(
|
| 698 |
+
absl::forward<QualifiedNew>(other));
|
| 699 |
+
} else {
|
| 700 |
+
// the standard says "equivalent to
|
| 701 |
+
// operator=(variant(std::forward<T>(t)))", but we use `emplace` here
|
| 702 |
+
// because the variant's move assignment operator could be deleted.
|
| 703 |
+
left->template emplace<NewIndex::value>(
|
| 704 |
+
New(absl::forward<QualifiedNew>(other)));
|
| 705 |
+
}
|
| 706 |
+
}
|
| 707 |
+
|
| 708 |
+
Left* left;
|
| 709 |
+
QualifiedNew&& other;
|
| 710 |
+
};
|
| 711 |
+
|
| 712 |
+
template <class Left, class QualifiedNew>
|
| 713 |
+
static ConversionAssignVisitor<Left, QualifiedNew>
|
| 714 |
+
MakeConversionAssignVisitor(Left* left, QualifiedNew&& qual) {
|
| 715 |
+
return {left, absl::forward<QualifiedNew>(qual)};
|
| 716 |
+
}
|
| 717 |
+
|
| 718 |
+
// Backend for operations for `emplace()` which destructs `*self` then
|
| 719 |
+
// construct a new alternative with `Args...`.
|
| 720 |
+
template <std::size_t NewIndex, class Self, class... Args>
|
| 721 |
+
static typename absl::variant_alternative<NewIndex, Self>::type& Replace(
|
| 722 |
+
Self* self, Args&&... args) {
|
| 723 |
+
Destroy(*self);
|
| 724 |
+
using New = typename absl::variant_alternative<NewIndex, Self>::type;
|
| 725 |
+
New* const result = ::new (static_cast<void*>(&self->state_))
|
| 726 |
+
New(absl::forward<Args>(args)...);
|
| 727 |
+
self->index_ = NewIndex;
|
| 728 |
+
return *result;
|
| 729 |
+
}
|
| 730 |
+
|
| 731 |
+
template <class LeftVariant, class QualifiedRightVariant>
|
| 732 |
+
struct InitFromVisitor {
|
| 733 |
+
template <std::size_t NewIndex>
|
| 734 |
+
void operator()(SizeT<NewIndex> /*new_i*/) const {
|
| 735 |
+
using Alternative =
|
| 736 |
+
typename variant_alternative<NewIndex, LeftVariant>::type;
|
| 737 |
+
::new (static_cast<void*>(&left->state_)) Alternative(
|
| 738 |
+
Access<NewIndex>(std::forward<QualifiedRightVariant>(right)));
|
| 739 |
+
}
|
| 740 |
+
|
| 741 |
+
void operator()(SizeT<absl::variant_npos> /*new_i*/) const {
|
| 742 |
+
// This space intentionally left blank.
|
| 743 |
+
}
|
| 744 |
+
LeftVariant* left;
|
| 745 |
+
QualifiedRightVariant&& right;
|
| 746 |
+
};
|
| 747 |
+
};
|
| 748 |
+
|
| 749 |
+
template <class Expected, class... T>
|
| 750 |
+
struct IndexOfImpl;
|
| 751 |
+
|
| 752 |
+
template <class Expected>
|
| 753 |
+
struct IndexOfImpl<Expected> {
|
| 754 |
+
using IndexFromEnd = SizeT<0>;
|
| 755 |
+
using MatchedIndexFromEnd = IndexFromEnd;
|
| 756 |
+
using MultipleMatches = std::false_type;
|
| 757 |
+
};
|
| 758 |
+
|
| 759 |
+
template <class Expected, class Head, class... Tail>
|
| 760 |
+
struct IndexOfImpl<Expected, Head, Tail...> : IndexOfImpl<Expected, Tail...> {
|
| 761 |
+
using IndexFromEnd =
|
| 762 |
+
SizeT<IndexOfImpl<Expected, Tail...>::IndexFromEnd::value + 1>;
|
| 763 |
+
};
|
| 764 |
+
|
| 765 |
+
template <class Expected, class... Tail>
|
| 766 |
+
struct IndexOfImpl<Expected, Expected, Tail...>
|
| 767 |
+
: IndexOfImpl<Expected, Tail...> {
|
| 768 |
+
using IndexFromEnd =
|
| 769 |
+
SizeT<IndexOfImpl<Expected, Tail...>::IndexFromEnd::value + 1>;
|
| 770 |
+
using MatchedIndexFromEnd = IndexFromEnd;
|
| 771 |
+
using MultipleMatches = std::integral_constant<
|
| 772 |
+
bool, IndexOfImpl<Expected, Tail...>::MatchedIndexFromEnd::value != 0>;
|
| 773 |
+
};
|
| 774 |
+
|
| 775 |
+
template <class Expected, class... Types>
|
| 776 |
+
struct IndexOfMeta {
|
| 777 |
+
using Results = IndexOfImpl<Expected, Types...>;
|
| 778 |
+
static_assert(!Results::MultipleMatches::value,
|
| 779 |
+
"Attempted to access a variant by specifying a type that "
|
| 780 |
+
"matches more than one alternative.");
|
| 781 |
+
static_assert(Results::MatchedIndexFromEnd::value != 0,
|
| 782 |
+
"Attempted to access a variant by specifying a type that does "
|
| 783 |
+
"not match any alternative.");
|
| 784 |
+
using type = SizeT<sizeof...(Types) - Results::MatchedIndexFromEnd::value>;
|
| 785 |
+
};
|
| 786 |
+
|
| 787 |
+
template <class Expected, class... Types>
|
| 788 |
+
using IndexOf = typename IndexOfMeta<Expected, Types...>::type;
|
| 789 |
+
|
| 790 |
+
template <class Variant, class T, std::size_t CurrIndex>
|
| 791 |
+
struct UnambiguousIndexOfImpl;
|
| 792 |
+
|
| 793 |
+
// Terminating case encountered once we've checked all of the alternatives
|
| 794 |
+
template <class T, std::size_t CurrIndex>
|
| 795 |
+
struct UnambiguousIndexOfImpl<variant<>, T, CurrIndex> : SizeT<CurrIndex> {};
|
| 796 |
+
|
| 797 |
+
// Case where T is not Head
|
| 798 |
+
template <class Head, class... Tail, class T, std::size_t CurrIndex>
|
| 799 |
+
struct UnambiguousIndexOfImpl<variant<Head, Tail...>, T, CurrIndex>
|
| 800 |
+
: UnambiguousIndexOfImpl<variant<Tail...>, T, CurrIndex + 1>::type {};
|
| 801 |
+
|
| 802 |
+
// Case where T is Head
|
| 803 |
+
template <class Head, class... Tail, std::size_t CurrIndex>
|
| 804 |
+
struct UnambiguousIndexOfImpl<variant<Head, Tail...>, Head, CurrIndex>
|
| 805 |
+
: SizeT<UnambiguousIndexOfImpl<variant<Tail...>, Head, 0>::value ==
|
| 806 |
+
sizeof...(Tail)
|
| 807 |
+
? CurrIndex
|
| 808 |
+
: CurrIndex + sizeof...(Tail) + 1> {};
|
| 809 |
+
|
| 810 |
+
template <class Variant, class T>
|
| 811 |
+
struct UnambiguousIndexOf;
|
| 812 |
+
|
| 813 |
+
struct NoMatch {
|
| 814 |
+
struct type {};
|
| 815 |
+
};
|
| 816 |
+
|
| 817 |
+
template <class... Alts, class T>
|
| 818 |
+
struct UnambiguousIndexOf<variant<Alts...>, T>
|
| 819 |
+
: std::conditional<UnambiguousIndexOfImpl<variant<Alts...>, T, 0>::value !=
|
| 820 |
+
sizeof...(Alts),
|
| 821 |
+
UnambiguousIndexOfImpl<variant<Alts...>, T, 0>,
|
| 822 |
+
NoMatch>::type::type {};
|
| 823 |
+
|
| 824 |
+
template <class T, std::size_t /*Dummy*/>
|
| 825 |
+
using UnambiguousTypeOfImpl = T;
|
| 826 |
+
|
| 827 |
+
template <class Variant, class T>
|
| 828 |
+
using UnambiguousTypeOfT =
|
| 829 |
+
UnambiguousTypeOfImpl<T, UnambiguousIndexOf<Variant, T>::value>;
|
| 830 |
+
|
| 831 |
+
template <class H, class... T>
|
| 832 |
+
class VariantStateBase;
|
| 833 |
+
|
| 834 |
+
// This is an implementation of the "imaginary function" that is described in
|
| 835 |
+
// [variant.ctor]
|
| 836 |
+
// It is used in order to determine which alternative to construct during
|
| 837 |
+
// initialization from some type T.
|
| 838 |
+
template <class Variant, std::size_t I = 0>
|
| 839 |
+
struct ImaginaryFun;
|
| 840 |
+
|
| 841 |
+
template <std::size_t I>
|
| 842 |
+
struct ImaginaryFun<variant<>, I> {
|
| 843 |
+
static void Run() = delete;
|
| 844 |
+
};
|
| 845 |
+
|
| 846 |
+
template <class H, class... T, std::size_t I>
|
| 847 |
+
struct ImaginaryFun<variant<H, T...>, I> : ImaginaryFun<variant<T...>, I + 1> {
|
| 848 |
+
using ImaginaryFun<variant<T...>, I + 1>::Run;
|
| 849 |
+
|
| 850 |
+
// NOTE: const& and && are used instead of by-value due to lack of guaranteed
|
| 851 |
+
// move elision of C++17. This may have other minor differences, but tests
|
| 852 |
+
// pass.
|
| 853 |
+
static SizeT<I> Run(const H&, SizeT<I>);
|
| 854 |
+
static SizeT<I> Run(H&&, SizeT<I>);
|
| 855 |
+
};
|
| 856 |
+
|
| 857 |
+
// The following metafunctions are used in constructor and assignment
|
| 858 |
+
// constraints.
|
| 859 |
+
template <class Self, class T>
|
| 860 |
+
struct IsNeitherSelfNorInPlace : std::true_type {};
|
| 861 |
+
|
| 862 |
+
template <class Self>
|
| 863 |
+
struct IsNeitherSelfNorInPlace<Self, Self> : std::false_type {};
|
| 864 |
+
|
| 865 |
+
template <class Self, class T>
|
| 866 |
+
struct IsNeitherSelfNorInPlace<Self, in_place_type_t<T>> : std::false_type {};
|
| 867 |
+
|
| 868 |
+
template <class Self, std::size_t I>
|
| 869 |
+
struct IsNeitherSelfNorInPlace<Self, in_place_index_t<I>> : std::false_type {};
|
| 870 |
+
|
| 871 |
+
template <class Variant, class T>
|
| 872 |
+
struct IndexOfConstructedType<
|
| 873 |
+
Variant, T,
|
| 874 |
+
void_t<decltype(ImaginaryFun<Variant>::Run(std::declval<T>(), {}))>>
|
| 875 |
+
: decltype(ImaginaryFun<Variant>::Run(std::declval<T>(), {})) {};
|
| 876 |
+
|
| 877 |
+
template <std::size_t... Is>
|
| 878 |
+
struct ContainsVariantNPos
|
| 879 |
+
: absl::negation<std::is_same< // NOLINT
|
| 880 |
+
absl::integer_sequence<bool, 0 <= Is...>,
|
| 881 |
+
absl::integer_sequence<bool, Is != absl::variant_npos...>>> {};
|
| 882 |
+
|
| 883 |
+
template <class Op, class... QualifiedVariants>
|
| 884 |
+
using RawVisitResult =
|
| 885 |
+
absl::result_of_t<Op(VariantAccessResult<0, QualifiedVariants>...)>;
|
| 886 |
+
|
| 887 |
+
// NOTE: The spec requires that all return-paths yield the same type and is not
|
| 888 |
+
// SFINAE-friendly, so we can deduce the return type by examining the first
|
| 889 |
+
// result. If it's not callable, then we get an error, but are compliant and
|
| 890 |
+
// fast to compile.
|
| 891 |
+
// TODO(calabrese) Possibly rewrite in a way that yields better compile errors
|
| 892 |
+
// at the cost of longer compile-times.
|
| 893 |
+
template <class Op, class... QualifiedVariants>
|
| 894 |
+
struct VisitResultImpl {
|
| 895 |
+
using type =
|
| 896 |
+
absl::result_of_t<Op(VariantAccessResult<0, QualifiedVariants>...)>;
|
| 897 |
+
};
|
| 898 |
+
|
| 899 |
+
// Done in two steps intentionally so that we don't cause substitution to fail.
|
| 900 |
+
template <class Op, class... QualifiedVariants>
|
| 901 |
+
using VisitResult = typename VisitResultImpl<Op, QualifiedVariants...>::type;
|
| 902 |
+
|
| 903 |
+
template <class Op, class... QualifiedVariants>
|
| 904 |
+
struct PerformVisitation {
|
| 905 |
+
using ReturnType = VisitResult<Op, QualifiedVariants...>;
|
| 906 |
+
|
| 907 |
+
template <std::size_t... Is>
|
| 908 |
+
constexpr ReturnType operator()(SizeT<Is>... indices) const {
|
| 909 |
+
return Run(typename ContainsVariantNPos<Is...>::type{},
|
| 910 |
+
absl::index_sequence_for<QualifiedVariants...>(), indices...);
|
| 911 |
+
}
|
| 912 |
+
|
| 913 |
+
template <std::size_t... TupIs, std::size_t... Is>
|
| 914 |
+
constexpr ReturnType Run(std::false_type /*has_valueless*/,
|
| 915 |
+
index_sequence<TupIs...>, SizeT<Is>...) const {
|
| 916 |
+
static_assert(
|
| 917 |
+
std::is_same<ReturnType,
|
| 918 |
+
absl::result_of_t<Op(VariantAccessResult<
|
| 919 |
+
Is, QualifiedVariants>...)>>::value,
|
| 920 |
+
"All visitation overloads must have the same return type.");
|
| 921 |
+
return absl::base_internal::invoke(
|
| 922 |
+
absl::forward<Op>(op),
|
| 923 |
+
VariantCoreAccess::Access<Is>(
|
| 924 |
+
absl::forward<QualifiedVariants>(std::get<TupIs>(variant_tup)))...);
|
| 925 |
+
}
|
| 926 |
+
|
| 927 |
+
template <std::size_t... TupIs, std::size_t... Is>
|
| 928 |
+
[[noreturn]] ReturnType Run(std::true_type /*has_valueless*/,
|
| 929 |
+
index_sequence<TupIs...>, SizeT<Is>...) const {
|
| 930 |
+
absl::variant_internal::ThrowBadVariantAccess();
|
| 931 |
+
}
|
| 932 |
+
|
| 933 |
+
// TODO(calabrese) Avoid using a tuple, which causes lots of instantiations
|
| 934 |
+
// Attempts using lambda variadic captures fail on current GCC.
|
| 935 |
+
std::tuple<QualifiedVariants&&...> variant_tup;
|
| 936 |
+
Op&& op;
|
| 937 |
+
};
|
| 938 |
+
|
| 939 |
+
template <class... T>
|
| 940 |
+
union Union;
|
| 941 |
+
|
| 942 |
+
// We want to allow for variant<> to be trivial. For that, we need the default
|
| 943 |
+
// constructor to be trivial, which means we can't define it ourselves.
|
| 944 |
+
// Instead, we use a non-default constructor that takes NoopConstructorTag
|
| 945 |
+
// that doesn't affect the triviality of the types.
|
| 946 |
+
struct NoopConstructorTag {};
|
| 947 |
+
|
| 948 |
+
template <std::size_t I>
|
| 949 |
+
struct EmplaceTag {};
|
| 950 |
+
|
| 951 |
+
template <>
|
| 952 |
+
union Union<> {
|
| 953 |
+
constexpr explicit Union(NoopConstructorTag) noexcept {}
|
| 954 |
+
};
|
| 955 |
+
|
| 956 |
+
// Suppress bogus warning on MSVC: MSVC complains that Union<T...> has a defined
|
| 957 |
+
// deleted destructor from the `std::is_destructible` check below.
|
| 958 |
+
#ifdef _MSC_VER
|
| 959 |
+
#pragma warning(push)
|
| 960 |
+
#pragma warning(disable : 4624)
|
| 961 |
+
#endif // _MSC_VER
|
| 962 |
+
|
| 963 |
+
template <class Head, class... Tail>
|
| 964 |
+
union Union<Head, Tail...> {
|
| 965 |
+
using TailUnion = Union<Tail...>;
|
| 966 |
+
|
| 967 |
+
explicit constexpr Union(NoopConstructorTag /*tag*/) noexcept
|
| 968 |
+
: tail(NoopConstructorTag()) {}
|
| 969 |
+
|
| 970 |
+
template <class... P>
|
| 971 |
+
explicit constexpr Union(EmplaceTag<0>, P&&... args)
|
| 972 |
+
: head(absl::forward<P>(args)...) {}
|
| 973 |
+
|
| 974 |
+
template <std::size_t I, class... P>
|
| 975 |
+
explicit constexpr Union(EmplaceTag<I>, P&&... args)
|
| 976 |
+
: tail(EmplaceTag<I - 1>{}, absl::forward<P>(args)...) {}
|
| 977 |
+
|
| 978 |
+
Head head;
|
| 979 |
+
TailUnion tail;
|
| 980 |
+
};
|
| 981 |
+
|
| 982 |
+
#ifdef _MSC_VER
|
| 983 |
+
#pragma warning(pop)
|
| 984 |
+
#endif // _MSC_VER
|
| 985 |
+
|
| 986 |
+
// TODO(calabrese) Just contain a Union in this union (certain configs fail).
|
| 987 |
+
template <class... T>
|
| 988 |
+
union DestructibleUnionImpl;
|
| 989 |
+
|
| 990 |
+
template <>
|
| 991 |
+
union DestructibleUnionImpl<> {
|
| 992 |
+
constexpr explicit DestructibleUnionImpl(NoopConstructorTag) noexcept {}
|
| 993 |
+
};
|
| 994 |
+
|
| 995 |
+
template <class Head, class... Tail>
|
| 996 |
+
union DestructibleUnionImpl<Head, Tail...> {
|
| 997 |
+
using TailUnion = DestructibleUnionImpl<Tail...>;
|
| 998 |
+
|
| 999 |
+
explicit constexpr DestructibleUnionImpl(NoopConstructorTag /*tag*/) noexcept
|
| 1000 |
+
: tail(NoopConstructorTag()) {}
|
| 1001 |
+
|
| 1002 |
+
template <class... P>
|
| 1003 |
+
explicit constexpr DestructibleUnionImpl(EmplaceTag<0>, P&&... args)
|
| 1004 |
+
: head(absl::forward<P>(args)...) {}
|
| 1005 |
+
|
| 1006 |
+
template <std::size_t I, class... P>
|
| 1007 |
+
explicit constexpr DestructibleUnionImpl(EmplaceTag<I>, P&&... args)
|
| 1008 |
+
: tail(EmplaceTag<I - 1>{}, absl::forward<P>(args)...) {}
|
| 1009 |
+
|
| 1010 |
+
~DestructibleUnionImpl() {}
|
| 1011 |
+
|
| 1012 |
+
Head head;
|
| 1013 |
+
TailUnion tail;
|
| 1014 |
+
};
|
| 1015 |
+
|
| 1016 |
+
// This union type is destructible even if one or more T are not trivially
|
| 1017 |
+
// destructible. In the case that all T are trivially destructible, then so is
|
| 1018 |
+
// this resultant type.
|
| 1019 |
+
template <class... T>
|
| 1020 |
+
using DestructibleUnion =
|
| 1021 |
+
absl::conditional_t<std::is_destructible<Union<T...>>::value, Union<T...>,
|
| 1022 |
+
DestructibleUnionImpl<T...>>;
|
| 1023 |
+
|
| 1024 |
+
// Deepest base, containing the actual union and the discriminator
|
| 1025 |
+
template <class H, class... T>
|
| 1026 |
+
class VariantStateBase {
|
| 1027 |
+
protected:
|
| 1028 |
+
using Variant = variant<H, T...>;
|
| 1029 |
+
|
| 1030 |
+
template <class LazyH = H,
|
| 1031 |
+
class ConstructibleH = absl::enable_if_t<
|
| 1032 |
+
std::is_default_constructible<LazyH>::value, LazyH>>
|
| 1033 |
+
constexpr VariantStateBase() noexcept(
|
| 1034 |
+
std::is_nothrow_default_constructible<ConstructibleH>::value)
|
| 1035 |
+
: state_(EmplaceTag<0>()), index_(0) {}
|
| 1036 |
+
|
| 1037 |
+
template <std::size_t I, class... P>
|
| 1038 |
+
explicit constexpr VariantStateBase(EmplaceTag<I> tag, P&&... args)
|
| 1039 |
+
: state_(tag, absl::forward<P>(args)...), index_(I) {}
|
| 1040 |
+
|
| 1041 |
+
explicit constexpr VariantStateBase(NoopConstructorTag)
|
| 1042 |
+
: state_(NoopConstructorTag()), index_(variant_npos) {}
|
| 1043 |
+
|
| 1044 |
+
void destroy() {} // Does nothing (shadowed in child if non-trivial)
|
| 1045 |
+
|
| 1046 |
+
DestructibleUnion<H, T...> state_;
|
| 1047 |
+
std::size_t index_;
|
| 1048 |
+
};
|
| 1049 |
+
|
| 1050 |
+
using absl::internal::identity;
|
| 1051 |
+
|
| 1052 |
+
// OverloadSet::Overload() is a unary function which is overloaded to
|
| 1053 |
+
// take any of the element types of the variant, by reference-to-const.
|
| 1054 |
+
// The return type of the overload on T is identity<T>, so that you
|
| 1055 |
+
// can statically determine which overload was called.
|
| 1056 |
+
//
|
| 1057 |
+
// Overload() is not defined, so it can only be called in unevaluated
|
| 1058 |
+
// contexts.
|
| 1059 |
+
template <typename... Ts>
|
| 1060 |
+
struct OverloadSet;
|
| 1061 |
+
|
| 1062 |
+
template <typename T, typename... Ts>
|
| 1063 |
+
struct OverloadSet<T, Ts...> : OverloadSet<Ts...> {
|
| 1064 |
+
using Base = OverloadSet<Ts...>;
|
| 1065 |
+
static identity<T> Overload(const T&);
|
| 1066 |
+
using Base::Overload;
|
| 1067 |
+
};
|
| 1068 |
+
|
| 1069 |
+
template <>
|
| 1070 |
+
struct OverloadSet<> {
|
| 1071 |
+
// For any case not handled above.
|
| 1072 |
+
static void Overload(...);
|
| 1073 |
+
};
|
| 1074 |
+
|
| 1075 |
+
template <class T>
|
| 1076 |
+
using LessThanResult = decltype(std::declval<T>() < std::declval<T>());
|
| 1077 |
+
|
| 1078 |
+
template <class T>
|
| 1079 |
+
using GreaterThanResult = decltype(std::declval<T>() > std::declval<T>());
|
| 1080 |
+
|
| 1081 |
+
template <class T>
|
| 1082 |
+
using LessThanOrEqualResult = decltype(std::declval<T>() <= std::declval<T>());
|
| 1083 |
+
|
| 1084 |
+
template <class T>
|
| 1085 |
+
using GreaterThanOrEqualResult =
|
| 1086 |
+
decltype(std::declval<T>() >= std::declval<T>());
|
| 1087 |
+
|
| 1088 |
+
template <class T>
|
| 1089 |
+
using EqualResult = decltype(std::declval<T>() == std::declval<T>());
|
| 1090 |
+
|
| 1091 |
+
template <class T>
|
| 1092 |
+
using NotEqualResult = decltype(std::declval<T>() != std::declval<T>());
|
| 1093 |
+
|
| 1094 |
+
using type_traits_internal::is_detected_convertible;
|
| 1095 |
+
|
| 1096 |
+
template <class... T>
|
| 1097 |
+
using RequireAllHaveEqualT = absl::enable_if_t<
|
| 1098 |
+
absl::conjunction<is_detected_convertible<bool, EqualResult, T>...>::value,
|
| 1099 |
+
bool>;
|
| 1100 |
+
|
| 1101 |
+
template <class... T>
|
| 1102 |
+
using RequireAllHaveNotEqualT =
|
| 1103 |
+
absl::enable_if_t<absl::conjunction<is_detected_convertible<
|
| 1104 |
+
bool, NotEqualResult, T>...>::value,
|
| 1105 |
+
bool>;
|
| 1106 |
+
|
| 1107 |
+
template <class... T>
|
| 1108 |
+
using RequireAllHaveLessThanT =
|
| 1109 |
+
absl::enable_if_t<absl::conjunction<is_detected_convertible<
|
| 1110 |
+
bool, LessThanResult, T>...>::value,
|
| 1111 |
+
bool>;
|
| 1112 |
+
|
| 1113 |
+
template <class... T>
|
| 1114 |
+
using RequireAllHaveLessThanOrEqualT =
|
| 1115 |
+
absl::enable_if_t<absl::conjunction<is_detected_convertible<
|
| 1116 |
+
bool, LessThanOrEqualResult, T>...>::value,
|
| 1117 |
+
bool>;
|
| 1118 |
+
|
| 1119 |
+
template <class... T>
|
| 1120 |
+
using RequireAllHaveGreaterThanOrEqualT =
|
| 1121 |
+
absl::enable_if_t<absl::conjunction<is_detected_convertible<
|
| 1122 |
+
bool, GreaterThanOrEqualResult, T>...>::value,
|
| 1123 |
+
bool>;
|
| 1124 |
+
|
| 1125 |
+
template <class... T>
|
| 1126 |
+
using RequireAllHaveGreaterThanT =
|
| 1127 |
+
absl::enable_if_t<absl::conjunction<is_detected_convertible<
|
| 1128 |
+
bool, GreaterThanResult, T>...>::value,
|
| 1129 |
+
bool>;
|
| 1130 |
+
|
| 1131 |
+
// Helper template containing implementations details of variant that can't go
|
| 1132 |
+
// in the private section. For convenience, this takes the variant type as a
|
| 1133 |
+
// single template parameter.
|
| 1134 |
+
template <typename T>
|
| 1135 |
+
struct VariantHelper;
|
| 1136 |
+
|
| 1137 |
+
template <typename... Ts>
|
| 1138 |
+
struct VariantHelper<variant<Ts...>> {
|
| 1139 |
+
// Type metafunction which returns the element type selected if
|
| 1140 |
+
// OverloadSet::Overload() is well-formed when called with argument type U.
|
| 1141 |
+
template <typename U>
|
| 1142 |
+
using BestMatch = decltype(variant_internal::OverloadSet<Ts...>::Overload(
|
| 1143 |
+
std::declval<U>()));
|
| 1144 |
+
|
| 1145 |
+
// Type metafunction which returns true if OverloadSet::Overload() is
|
| 1146 |
+
// well-formed when called with argument type U.
|
| 1147 |
+
// CanAccept can't be just an alias because there is a MSVC bug on parameter
|
| 1148 |
+
// pack expansion involving decltype.
|
| 1149 |
+
template <typename U>
|
| 1150 |
+
struct CanAccept
|
| 1151 |
+
: std::integral_constant<bool, !std::is_void<BestMatch<U>>::value> {};
|
| 1152 |
+
|
| 1153 |
+
// Type metafunction which returns true if Other is an instantiation of
|
| 1154 |
+
// variant, and variants's converting constructor from Other will be
|
| 1155 |
+
// well-formed. We will use this to remove constructors that would be
|
| 1156 |
+
// ill-formed from the overload set.
|
| 1157 |
+
template <typename Other>
|
| 1158 |
+
struct CanConvertFrom;
|
| 1159 |
+
|
| 1160 |
+
template <typename... Us>
|
| 1161 |
+
struct CanConvertFrom<variant<Us...>>
|
| 1162 |
+
: public absl::conjunction<CanAccept<Us>...> {};
|
| 1163 |
+
};
|
| 1164 |
+
|
| 1165 |
+
// A type with nontrivial copy ctor and trivial move ctor.
|
| 1166 |
+
struct TrivialMoveOnly {
|
| 1167 |
+
TrivialMoveOnly(TrivialMoveOnly&&) = default;
|
| 1168 |
+
};
|
| 1169 |
+
|
| 1170 |
+
// Trait class to detect whether a type is trivially move constructible.
|
| 1171 |
+
// A union's defaulted copy/move constructor is deleted if any variant member's
|
| 1172 |
+
// copy/move constructor is nontrivial.
|
| 1173 |
+
template <typename T>
|
| 1174 |
+
struct IsTriviallyMoveConstructible
|
| 1175 |
+
: std::is_move_constructible<Union<T, TrivialMoveOnly>> {};
|
| 1176 |
+
|
| 1177 |
+
// To guarantee triviality of all special-member functions that can be trivial,
|
| 1178 |
+
// we use a chain of conditional bases for each one.
|
| 1179 |
+
// The order of inheritance of bases from child to base are logically:
|
| 1180 |
+
//
|
| 1181 |
+
// variant
|
| 1182 |
+
// VariantCopyAssignBase
|
| 1183 |
+
// VariantMoveAssignBase
|
| 1184 |
+
// VariantCopyBase
|
| 1185 |
+
// VariantMoveBase
|
| 1186 |
+
// VariantStateBaseDestructor
|
| 1187 |
+
// VariantStateBase
|
| 1188 |
+
//
|
| 1189 |
+
// Note that there is a separate branch at each base that is dependent on
|
| 1190 |
+
// whether or not that corresponding special-member-function can be trivial in
|
| 1191 |
+
// the resultant variant type.
|
| 1192 |
+
|
| 1193 |
+
template <class... T>
|
| 1194 |
+
class VariantStateBaseDestructorNontrivial;
|
| 1195 |
+
|
| 1196 |
+
template <class... T>
|
| 1197 |
+
class VariantMoveBaseNontrivial;
|
| 1198 |
+
|
| 1199 |
+
template <class... T>
|
| 1200 |
+
class VariantCopyBaseNontrivial;
|
| 1201 |
+
|
| 1202 |
+
template <class... T>
|
| 1203 |
+
class VariantMoveAssignBaseNontrivial;
|
| 1204 |
+
|
| 1205 |
+
template <class... T>
|
| 1206 |
+
class VariantCopyAssignBaseNontrivial;
|
| 1207 |
+
|
| 1208 |
+
// Base that is dependent on whether or not the destructor can be trivial.
|
| 1209 |
+
template <class... T>
|
| 1210 |
+
using VariantStateBaseDestructor =
|
| 1211 |
+
absl::conditional_t<std::is_destructible<Union<T...>>::value,
|
| 1212 |
+
VariantStateBase<T...>,
|
| 1213 |
+
VariantStateBaseDestructorNontrivial<T...>>;
|
| 1214 |
+
|
| 1215 |
+
// Base that is dependent on whether or not the move-constructor can be
|
| 1216 |
+
// implicitly generated by the compiler (trivial or deleted).
|
| 1217 |
+
// Previously we were using `std::is_move_constructible<Union<T...>>` to check
|
| 1218 |
+
// whether all Ts have trivial move constructor, but it ran into a GCC bug:
|
| 1219 |
+
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84866
|
| 1220 |
+
// So we have to use a different approach (i.e. `HasTrivialMoveConstructor`) to
|
| 1221 |
+
// work around the bug.
|
| 1222 |
+
template <class... T>
|
| 1223 |
+
using VariantMoveBase = absl::conditional_t<
|
| 1224 |
+
absl::disjunction<
|
| 1225 |
+
absl::negation<absl::conjunction<std::is_move_constructible<T>...>>,
|
| 1226 |
+
absl::conjunction<IsTriviallyMoveConstructible<T>...>>::value,
|
| 1227 |
+
VariantStateBaseDestructor<T...>, VariantMoveBaseNontrivial<T...>>;
|
| 1228 |
+
|
| 1229 |
+
// Base that is dependent on whether or not the copy-constructor can be trivial.
|
| 1230 |
+
template <class... T>
|
| 1231 |
+
using VariantCopyBase = absl::conditional_t<
|
| 1232 |
+
absl::disjunction<
|
| 1233 |
+
absl::negation<absl::conjunction<std::is_copy_constructible<T>...>>,
|
| 1234 |
+
std::is_copy_constructible<Union<T...>>>::value,
|
| 1235 |
+
VariantMoveBase<T...>, VariantCopyBaseNontrivial<T...>>;
|
| 1236 |
+
|
| 1237 |
+
// Base that is dependent on whether or not the move-assign can be trivial.
|
| 1238 |
+
template <class... T>
|
| 1239 |
+
using VariantMoveAssignBase = absl::conditional_t<
|
| 1240 |
+
absl::disjunction<
|
| 1241 |
+
absl::conjunction<absl::is_move_assignable<Union<T...>>,
|
| 1242 |
+
std::is_move_constructible<Union<T...>>,
|
| 1243 |
+
std::is_destructible<Union<T...>>>,
|
| 1244 |
+
absl::negation<absl::conjunction<std::is_move_constructible<T>...,
|
| 1245 |
+
// Note: We're not qualifying this with
|
| 1246 |
+
// absl:: because it doesn't compile
|
| 1247 |
+
// under MSVC.
|
| 1248 |
+
is_move_assignable<T>...>>>::value,
|
| 1249 |
+
VariantCopyBase<T...>, VariantMoveAssignBaseNontrivial<T...>>;
|
| 1250 |
+
|
| 1251 |
+
// Base that is dependent on whether or not the copy-assign can be trivial.
|
| 1252 |
+
template <class... T>
|
| 1253 |
+
using VariantCopyAssignBase = absl::conditional_t<
|
| 1254 |
+
absl::disjunction<
|
| 1255 |
+
absl::conjunction<absl::is_copy_assignable<Union<T...>>,
|
| 1256 |
+
std::is_copy_constructible<Union<T...>>,
|
| 1257 |
+
std::is_destructible<Union<T...>>>,
|
| 1258 |
+
absl::negation<absl::conjunction<std::is_copy_constructible<T>...,
|
| 1259 |
+
// Note: We're not qualifying this with
|
| 1260 |
+
// absl:: because it doesn't compile
|
| 1261 |
+
// under MSVC.
|
| 1262 |
+
is_copy_assignable<T>...>>>::value,
|
| 1263 |
+
VariantMoveAssignBase<T...>, VariantCopyAssignBaseNontrivial<T...>>;
|
| 1264 |
+
|
| 1265 |
+
template <class... T>
|
| 1266 |
+
using VariantBase = VariantCopyAssignBase<T...>;
|
| 1267 |
+
|
| 1268 |
+
template <class... T>
|
| 1269 |
+
class VariantStateBaseDestructorNontrivial : protected VariantStateBase<T...> {
|
| 1270 |
+
private:
|
| 1271 |
+
using Base = VariantStateBase<T...>;
|
| 1272 |
+
|
| 1273 |
+
protected:
|
| 1274 |
+
using Base::Base;
|
| 1275 |
+
|
| 1276 |
+
VariantStateBaseDestructorNontrivial() = default;
|
| 1277 |
+
VariantStateBaseDestructorNontrivial(VariantStateBaseDestructorNontrivial&&) =
|
| 1278 |
+
default;
|
| 1279 |
+
VariantStateBaseDestructorNontrivial(
|
| 1280 |
+
const VariantStateBaseDestructorNontrivial&) = default;
|
| 1281 |
+
VariantStateBaseDestructorNontrivial& operator=(
|
| 1282 |
+
VariantStateBaseDestructorNontrivial&&) = default;
|
| 1283 |
+
VariantStateBaseDestructorNontrivial& operator=(
|
| 1284 |
+
const VariantStateBaseDestructorNontrivial&) = default;
|
| 1285 |
+
|
| 1286 |
+
struct Destroyer {
|
| 1287 |
+
template <std::size_t I>
|
| 1288 |
+
void operator()(SizeT<I> i) const {
|
| 1289 |
+
using Alternative =
|
| 1290 |
+
typename absl::variant_alternative<I, variant<T...>>::type;
|
| 1291 |
+
variant_internal::AccessUnion(self->state_, i).~Alternative();
|
| 1292 |
+
}
|
| 1293 |
+
|
| 1294 |
+
void operator()(SizeT<absl::variant_npos> /*i*/) const {
|
| 1295 |
+
// This space intentionally left blank
|
| 1296 |
+
}
|
| 1297 |
+
|
| 1298 |
+
VariantStateBaseDestructorNontrivial* self;
|
| 1299 |
+
};
|
| 1300 |
+
|
| 1301 |
+
void destroy() { VisitIndices<sizeof...(T)>::Run(Destroyer{this}, index_); }
|
| 1302 |
+
|
| 1303 |
+
~VariantStateBaseDestructorNontrivial() { destroy(); }
|
| 1304 |
+
|
| 1305 |
+
protected:
|
| 1306 |
+
using Base::index_;
|
| 1307 |
+
using Base::state_;
|
| 1308 |
+
};
|
| 1309 |
+
|
| 1310 |
+
template <class... T>
|
| 1311 |
+
class VariantMoveBaseNontrivial : protected VariantStateBaseDestructor<T...> {
|
| 1312 |
+
private:
|
| 1313 |
+
using Base = VariantStateBaseDestructor<T...>;
|
| 1314 |
+
|
| 1315 |
+
protected:
|
| 1316 |
+
using Base::Base;
|
| 1317 |
+
|
| 1318 |
+
struct Construct {
|
| 1319 |
+
template <std::size_t I>
|
| 1320 |
+
void operator()(SizeT<I> i) const {
|
| 1321 |
+
using Alternative =
|
| 1322 |
+
typename absl::variant_alternative<I, variant<T...>>::type;
|
| 1323 |
+
::new (static_cast<void*>(&self->state_)) Alternative(
|
| 1324 |
+
variant_internal::AccessUnion(absl::move(other->state_), i));
|
| 1325 |
+
}
|
| 1326 |
+
|
| 1327 |
+
void operator()(SizeT<absl::variant_npos> /*i*/) const {}
|
| 1328 |
+
|
| 1329 |
+
VariantMoveBaseNontrivial* self;
|
| 1330 |
+
VariantMoveBaseNontrivial* other;
|
| 1331 |
+
};
|
| 1332 |
+
|
| 1333 |
+
VariantMoveBaseNontrivial() = default;
|
| 1334 |
+
VariantMoveBaseNontrivial(VariantMoveBaseNontrivial&& other) noexcept(
|
| 1335 |
+
absl::conjunction<std::is_nothrow_move_constructible<T>...>::value)
|
| 1336 |
+
: Base(NoopConstructorTag()) {
|
| 1337 |
+
VisitIndices<sizeof...(T)>::Run(Construct{this, &other}, other.index_);
|
| 1338 |
+
index_ = other.index_;
|
| 1339 |
+
}
|
| 1340 |
+
|
| 1341 |
+
VariantMoveBaseNontrivial(VariantMoveBaseNontrivial const&) = default;
|
| 1342 |
+
|
| 1343 |
+
VariantMoveBaseNontrivial& operator=(VariantMoveBaseNontrivial&&) = default;
|
| 1344 |
+
VariantMoveBaseNontrivial& operator=(VariantMoveBaseNontrivial const&) =
|
| 1345 |
+
default;
|
| 1346 |
+
|
| 1347 |
+
protected:
|
| 1348 |
+
using Base::index_;
|
| 1349 |
+
using Base::state_;
|
| 1350 |
+
};
|
| 1351 |
+
|
| 1352 |
+
template <class... T>
|
| 1353 |
+
class VariantCopyBaseNontrivial : protected VariantMoveBase<T...> {
|
| 1354 |
+
private:
|
| 1355 |
+
using Base = VariantMoveBase<T...>;
|
| 1356 |
+
|
| 1357 |
+
protected:
|
| 1358 |
+
using Base::Base;
|
| 1359 |
+
|
| 1360 |
+
VariantCopyBaseNontrivial() = default;
|
| 1361 |
+
VariantCopyBaseNontrivial(VariantCopyBaseNontrivial&&) = default;
|
| 1362 |
+
|
| 1363 |
+
struct Construct {
|
| 1364 |
+
template <std::size_t I>
|
| 1365 |
+
void operator()(SizeT<I> i) const {
|
| 1366 |
+
using Alternative =
|
| 1367 |
+
typename absl::variant_alternative<I, variant<T...>>::type;
|
| 1368 |
+
::new (static_cast<void*>(&self->state_))
|
| 1369 |
+
Alternative(variant_internal::AccessUnion(other->state_, i));
|
| 1370 |
+
}
|
| 1371 |
+
|
| 1372 |
+
void operator()(SizeT<absl::variant_npos> /*i*/) const {}
|
| 1373 |
+
|
| 1374 |
+
VariantCopyBaseNontrivial* self;
|
| 1375 |
+
const VariantCopyBaseNontrivial* other;
|
| 1376 |
+
};
|
| 1377 |
+
|
| 1378 |
+
VariantCopyBaseNontrivial(VariantCopyBaseNontrivial const& other)
|
| 1379 |
+
: Base(NoopConstructorTag()) {
|
| 1380 |
+
VisitIndices<sizeof...(T)>::Run(Construct{this, &other}, other.index_);
|
| 1381 |
+
index_ = other.index_;
|
| 1382 |
+
}
|
| 1383 |
+
|
| 1384 |
+
VariantCopyBaseNontrivial& operator=(VariantCopyBaseNontrivial&&) = default;
|
| 1385 |
+
VariantCopyBaseNontrivial& operator=(VariantCopyBaseNontrivial const&) =
|
| 1386 |
+
default;
|
| 1387 |
+
|
| 1388 |
+
protected:
|
| 1389 |
+
using Base::index_;
|
| 1390 |
+
using Base::state_;
|
| 1391 |
+
};
|
| 1392 |
+
|
| 1393 |
+
template <class... T>
|
| 1394 |
+
class VariantMoveAssignBaseNontrivial : protected VariantCopyBase<T...> {
|
| 1395 |
+
friend struct VariantCoreAccess;
|
| 1396 |
+
|
| 1397 |
+
private:
|
| 1398 |
+
using Base = VariantCopyBase<T...>;
|
| 1399 |
+
|
| 1400 |
+
protected:
|
| 1401 |
+
using Base::Base;
|
| 1402 |
+
|
| 1403 |
+
VariantMoveAssignBaseNontrivial() = default;
|
| 1404 |
+
VariantMoveAssignBaseNontrivial(VariantMoveAssignBaseNontrivial&&) = default;
|
| 1405 |
+
VariantMoveAssignBaseNontrivial(const VariantMoveAssignBaseNontrivial&) =
|
| 1406 |
+
default;
|
| 1407 |
+
VariantMoveAssignBaseNontrivial& operator=(
|
| 1408 |
+
VariantMoveAssignBaseNontrivial const&) = default;
|
| 1409 |
+
|
| 1410 |
+
VariantMoveAssignBaseNontrivial&
|
| 1411 |
+
operator=(VariantMoveAssignBaseNontrivial&& other) noexcept(
|
| 1412 |
+
absl::conjunction<std::is_nothrow_move_constructible<T>...,
|
| 1413 |
+
std::is_nothrow_move_assignable<T>...>::value) {
|
| 1414 |
+
VisitIndices<sizeof...(T)>::Run(
|
| 1415 |
+
VariantCoreAccess::MakeMoveAssignVisitor(this, &other), other.index_);
|
| 1416 |
+
return *this;
|
| 1417 |
+
}
|
| 1418 |
+
|
| 1419 |
+
protected:
|
| 1420 |
+
using Base::index_;
|
| 1421 |
+
using Base::state_;
|
| 1422 |
+
};
|
| 1423 |
+
|
| 1424 |
+
template <class... T>
|
| 1425 |
+
class VariantCopyAssignBaseNontrivial : protected VariantMoveAssignBase<T...> {
|
| 1426 |
+
friend struct VariantCoreAccess;
|
| 1427 |
+
|
| 1428 |
+
private:
|
| 1429 |
+
using Base = VariantMoveAssignBase<T...>;
|
| 1430 |
+
|
| 1431 |
+
protected:
|
| 1432 |
+
using Base::Base;
|
| 1433 |
+
|
| 1434 |
+
VariantCopyAssignBaseNontrivial() = default;
|
| 1435 |
+
VariantCopyAssignBaseNontrivial(VariantCopyAssignBaseNontrivial&&) = default;
|
| 1436 |
+
VariantCopyAssignBaseNontrivial(const VariantCopyAssignBaseNontrivial&) =
|
| 1437 |
+
default;
|
| 1438 |
+
VariantCopyAssignBaseNontrivial& operator=(
|
| 1439 |
+
VariantCopyAssignBaseNontrivial&&) = default;
|
| 1440 |
+
|
| 1441 |
+
VariantCopyAssignBaseNontrivial& operator=(
|
| 1442 |
+
const VariantCopyAssignBaseNontrivial& other) {
|
| 1443 |
+
VisitIndices<sizeof...(T)>::Run(
|
| 1444 |
+
VariantCoreAccess::MakeCopyAssignVisitor(this, other), other.index_);
|
| 1445 |
+
return *this;
|
| 1446 |
+
}
|
| 1447 |
+
|
| 1448 |
+
protected:
|
| 1449 |
+
using Base::index_;
|
| 1450 |
+
using Base::state_;
|
| 1451 |
+
};
|
| 1452 |
+
|
| 1453 |
+
////////////////////////////////////////
|
| 1454 |
+
// Visitors for Comparison Operations //
|
| 1455 |
+
////////////////////////////////////////
|
| 1456 |
+
|
| 1457 |
+
template <class... Types>
|
| 1458 |
+
struct EqualsOp {
|
| 1459 |
+
const variant<Types...>* v;
|
| 1460 |
+
const variant<Types...>* w;
|
| 1461 |
+
|
| 1462 |
+
constexpr bool operator()(SizeT<absl::variant_npos> /*v_i*/) const {
|
| 1463 |
+
return true;
|
| 1464 |
+
}
|
| 1465 |
+
|
| 1466 |
+
template <std::size_t I>
|
| 1467 |
+
constexpr bool operator()(SizeT<I> /*v_i*/) const {
|
| 1468 |
+
return VariantCoreAccess::Access<I>(*v) == VariantCoreAccess::Access<I>(*w);
|
| 1469 |
+
}
|
| 1470 |
+
};
|
| 1471 |
+
|
| 1472 |
+
template <class... Types>
|
| 1473 |
+
struct NotEqualsOp {
|
| 1474 |
+
const variant<Types...>* v;
|
| 1475 |
+
const variant<Types...>* w;
|
| 1476 |
+
|
| 1477 |
+
constexpr bool operator()(SizeT<absl::variant_npos> /*v_i*/) const {
|
| 1478 |
+
return false;
|
| 1479 |
+
}
|
| 1480 |
+
|
| 1481 |
+
template <std::size_t I>
|
| 1482 |
+
constexpr bool operator()(SizeT<I> /*v_i*/) const {
|
| 1483 |
+
return VariantCoreAccess::Access<I>(*v) != VariantCoreAccess::Access<I>(*w);
|
| 1484 |
+
}
|
| 1485 |
+
};
|
| 1486 |
+
|
| 1487 |
+
template <class... Types>
|
| 1488 |
+
struct LessThanOp {
|
| 1489 |
+
const variant<Types...>* v;
|
| 1490 |
+
const variant<Types...>* w;
|
| 1491 |
+
|
| 1492 |
+
constexpr bool operator()(SizeT<absl::variant_npos> /*v_i*/) const {
|
| 1493 |
+
return false;
|
| 1494 |
+
}
|
| 1495 |
+
|
| 1496 |
+
template <std::size_t I>
|
| 1497 |
+
constexpr bool operator()(SizeT<I> /*v_i*/) const {
|
| 1498 |
+
return VariantCoreAccess::Access<I>(*v) < VariantCoreAccess::Access<I>(*w);
|
| 1499 |
+
}
|
| 1500 |
+
};
|
| 1501 |
+
|
| 1502 |
+
template <class... Types>
|
| 1503 |
+
struct GreaterThanOp {
|
| 1504 |
+
const variant<Types...>* v;
|
| 1505 |
+
const variant<Types...>* w;
|
| 1506 |
+
|
| 1507 |
+
constexpr bool operator()(SizeT<absl::variant_npos> /*v_i*/) const {
|
| 1508 |
+
return false;
|
| 1509 |
+
}
|
| 1510 |
+
|
| 1511 |
+
template <std::size_t I>
|
| 1512 |
+
constexpr bool operator()(SizeT<I> /*v_i*/) const {
|
| 1513 |
+
return VariantCoreAccess::Access<I>(*v) > VariantCoreAccess::Access<I>(*w);
|
| 1514 |
+
}
|
| 1515 |
+
};
|
| 1516 |
+
|
| 1517 |
+
template <class... Types>
|
| 1518 |
+
struct LessThanOrEqualsOp {
|
| 1519 |
+
const variant<Types...>* v;
|
| 1520 |
+
const variant<Types...>* w;
|
| 1521 |
+
|
| 1522 |
+
constexpr bool operator()(SizeT<absl::variant_npos> /*v_i*/) const {
|
| 1523 |
+
return true;
|
| 1524 |
+
}
|
| 1525 |
+
|
| 1526 |
+
template <std::size_t I>
|
| 1527 |
+
constexpr bool operator()(SizeT<I> /*v_i*/) const {
|
| 1528 |
+
return VariantCoreAccess::Access<I>(*v) <= VariantCoreAccess::Access<I>(*w);
|
| 1529 |
+
}
|
| 1530 |
+
};
|
| 1531 |
+
|
| 1532 |
+
template <class... Types>
|
| 1533 |
+
struct GreaterThanOrEqualsOp {
|
| 1534 |
+
const variant<Types...>* v;
|
| 1535 |
+
const variant<Types...>* w;
|
| 1536 |
+
|
| 1537 |
+
constexpr bool operator()(SizeT<absl::variant_npos> /*v_i*/) const {
|
| 1538 |
+
return true;
|
| 1539 |
+
}
|
| 1540 |
+
|
| 1541 |
+
template <std::size_t I>
|
| 1542 |
+
constexpr bool operator()(SizeT<I> /*v_i*/) const {
|
| 1543 |
+
return VariantCoreAccess::Access<I>(*v) >= VariantCoreAccess::Access<I>(*w);
|
| 1544 |
+
}
|
| 1545 |
+
};
|
| 1546 |
+
|
| 1547 |
+
// Precondition: v.index() == w.index();
|
| 1548 |
+
template <class... Types>
|
| 1549 |
+
struct SwapSameIndex {
|
| 1550 |
+
variant<Types...>* v;
|
| 1551 |
+
variant<Types...>* w;
|
| 1552 |
+
template <std::size_t I>
|
| 1553 |
+
void operator()(SizeT<I>) const {
|
| 1554 |
+
type_traits_internal::Swap(VariantCoreAccess::Access<I>(*v),
|
| 1555 |
+
VariantCoreAccess::Access<I>(*w));
|
| 1556 |
+
}
|
| 1557 |
+
|
| 1558 |
+
void operator()(SizeT<variant_npos>) const {}
|
| 1559 |
+
};
|
| 1560 |
+
|
| 1561 |
+
// TODO(calabrese) do this from a different namespace for proper adl usage
|
| 1562 |
+
template <class... Types>
|
| 1563 |
+
struct Swap {
|
| 1564 |
+
variant<Types...>* v;
|
| 1565 |
+
variant<Types...>* w;
|
| 1566 |
+
|
| 1567 |
+
void generic_swap() const {
|
| 1568 |
+
variant<Types...> tmp(std::move(*w));
|
| 1569 |
+
VariantCoreAccess::Destroy(*w);
|
| 1570 |
+
VariantCoreAccess::InitFrom(*w, std::move(*v));
|
| 1571 |
+
VariantCoreAccess::Destroy(*v);
|
| 1572 |
+
VariantCoreAccess::InitFrom(*v, std::move(tmp));
|
| 1573 |
+
}
|
| 1574 |
+
|
| 1575 |
+
void operator()(SizeT<absl::variant_npos> /*w_i*/) const {
|
| 1576 |
+
if (!v->valueless_by_exception()) {
|
| 1577 |
+
generic_swap();
|
| 1578 |
+
}
|
| 1579 |
+
}
|
| 1580 |
+
|
| 1581 |
+
template <std::size_t Wi>
|
| 1582 |
+
void operator()(SizeT<Wi> /*w_i*/) {
|
| 1583 |
+
if (v->index() == Wi) {
|
| 1584 |
+
VisitIndices<sizeof...(Types)>::Run(SwapSameIndex<Types...>{v, w}, Wi);
|
| 1585 |
+
} else {
|
| 1586 |
+
generic_swap();
|
| 1587 |
+
}
|
| 1588 |
+
}
|
| 1589 |
+
};
|
| 1590 |
+
|
| 1591 |
+
template <typename Variant, typename = void, typename... Ts>
|
| 1592 |
+
struct VariantHashBase {
|
| 1593 |
+
VariantHashBase() = delete;
|
| 1594 |
+
VariantHashBase(const VariantHashBase&) = delete;
|
| 1595 |
+
VariantHashBase(VariantHashBase&&) = delete;
|
| 1596 |
+
VariantHashBase& operator=(const VariantHashBase&) = delete;
|
| 1597 |
+
VariantHashBase& operator=(VariantHashBase&&) = delete;
|
| 1598 |
+
};
|
| 1599 |
+
|
| 1600 |
+
struct VariantHashVisitor {
|
| 1601 |
+
template <typename T>
|
| 1602 |
+
size_t operator()(const T& t) {
|
| 1603 |
+
return std::hash<T>{}(t);
|
| 1604 |
+
}
|
| 1605 |
+
};
|
| 1606 |
+
|
| 1607 |
+
template <typename Variant, typename... Ts>
|
| 1608 |
+
struct VariantHashBase<Variant,
|
| 1609 |
+
absl::enable_if_t<absl::conjunction<
|
| 1610 |
+
type_traits_internal::IsHashable<Ts>...>::value>,
|
| 1611 |
+
Ts...> {
|
| 1612 |
+
using argument_type = Variant;
|
| 1613 |
+
using result_type = size_t;
|
| 1614 |
+
size_t operator()(const Variant& var) const {
|
| 1615 |
+
type_traits_internal::AssertHashEnabled<Ts...>();
|
| 1616 |
+
if (var.valueless_by_exception()) {
|
| 1617 |
+
return 239799884;
|
| 1618 |
+
}
|
| 1619 |
+
size_t result = VisitIndices<variant_size<Variant>::value>::Run(
|
| 1620 |
+
PerformVisitation<VariantHashVisitor, const Variant&>{
|
| 1621 |
+
std::forward_as_tuple(var), VariantHashVisitor{}},
|
| 1622 |
+
var.index());
|
| 1623 |
+
// Combine the index and the hash result in order to distinguish
|
| 1624 |
+
// std::variant<int, int> holding the same value as different alternative.
|
| 1625 |
+
return result ^ var.index();
|
| 1626 |
+
}
|
| 1627 |
+
};
|
| 1628 |
+
|
| 1629 |
+
} // namespace variant_internal
|
| 1630 |
+
ABSL_NAMESPACE_END
|
| 1631 |
+
} // namespace absl
|
| 1632 |
+
|
| 1633 |
+
#endif // !defined(ABSL_USES_STD_VARIANT)
|
| 1634 |
+
#endif // ABSL_TYPES_INTERNAL_VARIANT_H_
|