• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 Huawei Device Co., Ltd.
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  *     http://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 OHOS_VARIANT_UTIL_H
17 #define OHOS_VARIANT_UTIL_H
18 #include <cstdint>
19 #include <variant>
20 #include "global.h"
21 #include "input_client_info.h"
22 #include "input_method_utils.h"
23 namespace OHOS {
24 namespace MiscServices {
25 class VariantUtil {
26 public:
27     template<typename T>
GetValue(const std::variant<bool,uint32_t,ImeType,ClientState,TextTotalConfig,ClientType,pid_t> & input,T & output)28     static bool GetValue(
29         const std::variant<bool, uint32_t, ImeType, ClientState, TextTotalConfig, ClientType, pid_t> &input, T &output)
30     {
31         if (!std::holds_alternative<T>(input)) {
32             return false;
33         }
34         output = std::get<T>(input);
35         return true;
36     }
37 
38     template<typename T>
GetValue(const ResponseData & input,T & output)39     static bool GetValue(const ResponseData &input, T &output)
40     {
41         if (!std::holds_alternative<T>(input)) {
42             return false;
43         }
44         output = std::get<T>(input);
45         return true;
46     }
47 };
48 } // namespace MiscServices
49 } // namespace OHOS
50 #endif // OHOS_VARIANT_UTIL_H