1 //
2 // Copyright 2020 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_PRIVATE_HANDLE_ACCESSOR_H_
17 #define ABSL_FLAGS_INTERNAL_PRIVATE_HANDLE_ACCESSOR_H_
18 
19 #include <memory>
20 #include <string>
21 
22 #include "absl/base/config.h"
23 #include "absl/flags/commandlineflag.h"
24 #include "absl/flags/internal/commandlineflag.h"
25 #include "absl/strings/string_view.h"
26 
27 namespace absl {
28 ABSL_NAMESPACE_BEGIN
29 namespace flags_internal {
30 
31 // This class serves as a trampoline to access private methods of
32 // CommandLineFlag. This class is intended for use exclusively internally inside
33 // of the Abseil Flags implementation.
34 class PrivateHandleAccessor {
35  public:
36   // Access to CommandLineFlag::TypeId.
37   static FlagFastTypeId TypeId(const CommandLineFlag& flag);
38 
39   // Access to CommandLineFlag::SaveState.
40   static std::unique_ptr<FlagStateInterface> SaveState(CommandLineFlag& flag);
41 
42   // Access to CommandLineFlag::IsSpecifiedOnCommandLine.
43   static bool IsSpecifiedOnCommandLine(const CommandLineFlag& flag);
44 
45   // Access to CommandLineFlag::ValidateInputValue.
46   static bool ValidateInputValue(const CommandLineFlag& flag,
47                                  absl::string_view value);
48 
49   // Access to CommandLineFlag::CheckDefaultValueParsingRoundtrip.
50   static void CheckDefaultValueParsingRoundtrip(const CommandLineFlag& flag);
51 
52   static bool ParseFrom(CommandLineFlag& flag, absl::string_view value,
53                         flags_internal::FlagSettingMode set_mode,
54                         flags_internal::ValueSource source, std::string& error);
55 };
56 
57 }  // namespace flags_internal
58 ABSL_NAMESPACE_END
59 }  // namespace absl
60 
61 #endif  // ABSL_FLAGS_INTERNAL_PRIVATE_HANDLE_ACCESSOR_H_
62