type_erased.h
Go to the documentation of this file.
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_FLAGS_INTERNAL_TYPE_ERASED_H_
17 #define ABSL_FLAGS_INTERNAL_TYPE_ERASED_H_
18 
19 #include <string>
20 
23 
24 // --------------------------------------------------------------------
25 // Registry interfaces operating on type erased handles.
26 
27 namespace absl {
28 namespace flags_internal {
29 
30 // If a flag named "name" exists, store its current value in *OUTPUT
31 // and return true. Else return false without changing *OUTPUT.
32 // Thread-safe.
34 
35 // If a flag named "name" exists, store its information in *OUTPUT
36 // and return true. Else return false without changing *OUTPUT.
37 // Thread-safe.
39  CommandLineFlagInfo* OUTPUT);
40 
41 // Returns the CommandLineFlagInfo of the flagname. exit() with an
42 // error code if name not found.
43 // Thread-safe.
45 
46 // Set the value of the flag named "name" to value. If successful,
47 // returns true. If not successful (e.g., the flag was not found or
48 // the value is not a valid value), returns false.
49 // Thread-safe.
51 
54  FlagSettingMode set_mode);
55 
56 //-----------------------------------------------------------------------------
57 
58 // Returns true iff all of the following conditions are true:
59 // (a) "name" names a registered flag
60 // (b) "value" can be parsed succesfully according to the type of the flag
61 // (c) parsed value passes any validator associated with the flag
63 
64 //-----------------------------------------------------------------------------
65 
66 // Returns true iff a flag named "name" was specified on the command line
67 // (either directly, or via one of --flagfile or --fromenv or --tryfromenv).
68 //
69 // Any non-command-line modification of the flag does not affect the
70 // result of this function. So for example, if a flag was passed on
71 // the command line but then reset via SET_FLAGS_DEFAULT, this
72 // function will still return true.
74 
75 //-----------------------------------------------------------------------------
76 
77 // If a flag with specified "name" exists and has type T, store
78 // its current value in *dst and return true. Else return false
79 // without touching *dst. T must obey all of the requirements for
80 // types passed to DEFINE_FLAG.
81 template <typename T>
82 inline bool GetByName(absl::string_view name, T* dst) {
84  if (!flag) return false;
85 
86  if (auto val = flag->Get<T>()) {
87  *dst = *val;
88  return true;
89  }
90 
91  return false;
92 }
93 
94 } // namespace flags_internal
95 } // namespace absl
96 
97 #endif // ABSL_FLAGS_INTERNAL_TYPE_ERASED_H_
bool GetCommandLineOption(absl::string_view name, std::string *value)
Definition: type_erased.cc:26
bool SetCommandLineOption(absl::string_view name, absl::string_view value)
Definition: type_erased.cc:64
bool IsValidFlagValue(absl::string_view name, absl::string_view value)
Definition: type_erased.cc:89
bool GetByName(absl::string_view name, T *dst)
Definition: type_erased.h:82
Definition: algorithm.h:29
bool SetCommandLineOptionWithMode(absl::string_view name, absl::string_view value, FlagSettingMode set_mode)
Definition: type_erased.cc:69
bool GetCommandLineFlagInfo(absl::string_view name, CommandLineFlagInfo *OUTPUT)
Definition: type_erased.cc:40
CommandLineFlagInfo GetCommandLineFlagInfoOrDie(absl::string_view name)
Definition: type_erased.cc:54
size_t value
CommandLineFlag * FindCommandLineFlag(absl::string_view name)
Definition: registry.cc:427
char name[1]
Definition: mutex.cc:296
bool SpecifiedOnCommandLine(absl::string_view name)
Definition: type_erased.cc:111


abseil_cpp
Author(s):
autogenerated on Wed Jun 19 2019 19:19:58