Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:31:43

0001 //
0002 // Copyright 2019 The Abseil Authors.
0003 //
0004 // Licensed under the Apache License, Version 2.0 (the "License");
0005 // you may not use this file except in compliance with the License.
0006 // You may obtain a copy of the License at
0007 //
0008 //      https://www.apache.org/licenses/LICENSE-2.0
0009 //
0010 // Unless required by applicable law or agreed to in writing, software
0011 // distributed under the License is distributed on an "AS IS" BASIS,
0012 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0013 // See the License for the specific language governing permissions and
0014 // limitations under the License.
0015 
0016 #ifndef ABSL_FLAGS_INTERNAL_REGISTRY_H_
0017 #define ABSL_FLAGS_INTERNAL_REGISTRY_H_
0018 
0019 #include <functional>
0020 
0021 #include "absl/base/config.h"
0022 #include "absl/flags/commandlineflag.h"
0023 #include "absl/flags/internal/commandlineflag.h"
0024 #include "absl/strings/string_view.h"
0025 
0026 // --------------------------------------------------------------------
0027 // Global flags registry API.
0028 
0029 namespace absl {
0030 ABSL_NAMESPACE_BEGIN
0031 namespace flags_internal {
0032 
0033 // Executes specified visitor for each non-retired flag in the registry. While
0034 // callback are executed, the registry is locked and can't be changed.
0035 void ForEachFlag(std::function<void(CommandLineFlag&)> visitor);
0036 
0037 //-----------------------------------------------------------------------------
0038 
0039 bool RegisterCommandLineFlag(CommandLineFlag&, const char* filename);
0040 
0041 void FinalizeRegistry();
0042 
0043 //-----------------------------------------------------------------------------
0044 // Retired registrations:
0045 //
0046 // Retired flag registrations are treated specially. A 'retired' flag is
0047 // provided only for compatibility with automated invocations that still
0048 // name it.  A 'retired' flag:
0049 //   - is not bound to a C++ FLAGS_ reference.
0050 //   - has a type and a value, but that value is intentionally inaccessible.
0051 //   - does not appear in --help messages.
0052 //   - is fully supported by _all_ flag parsing routines.
0053 //   - consumes args normally, and complains about type mismatches in its
0054 //     argument.
0055 //   - emits a complaint but does not die (e.g. LOG(ERROR)) if it is
0056 //     accessed by name through the flags API for parsing or otherwise.
0057 //
0058 // The registrations for a flag happen in an unspecified order as the
0059 // initializers for the namespace-scope objects of a program are run.
0060 // Any number of weak registrations for a flag can weakly define the flag.
0061 // One non-weak registration will upgrade the flag from weak to non-weak.
0062 // Further weak registrations of a non-weak flag are ignored.
0063 //
0064 // This mechanism is designed to support moving dead flags into a
0065 // 'graveyard' library.  An example migration:
0066 //
0067 //   0: Remove references to this FLAGS_flagname in the C++ codebase.
0068 //   1: Register as 'retired' in old_lib.
0069 //   2: Make old_lib depend on graveyard.
0070 //   3: Add a redundant 'retired' registration to graveyard.
0071 //   4: Remove the old_lib 'retired' registration.
0072 //   5: Eventually delete the graveyard registration entirely.
0073 //
0074 
0075 // Retire flag with name "name" and type indicated by ops.
0076 void Retire(const char* name, FlagFastTypeId type_id, char* buf);
0077 
0078 constexpr size_t kRetiredFlagObjSize = 3 * sizeof(void*);
0079 constexpr size_t kRetiredFlagObjAlignment = alignof(void*);
0080 
0081 // Registered a retired flag with name 'flag_name' and type 'T'.
0082 template <typename T>
0083 class RetiredFlag {
0084  public:
0085   void Retire(const char* flag_name) {
0086     flags_internal::Retire(flag_name, base_internal::FastTypeId<T>(), buf_);
0087   }
0088 
0089  private:
0090   alignas(kRetiredFlagObjAlignment) char buf_[kRetiredFlagObjSize];
0091 };
0092 
0093 }  // namespace flags_internal
0094 ABSL_NAMESPACE_END
0095 }  // namespace absl
0096 
0097 #endif  // ABSL_FLAGS_INTERNAL_REGISTRY_H_