1 /* 2 * Copyright (c) 2022 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 HIVIEW_BASE_EVENT_REPORT_PARAM_VALUE_H 17 #define HIVIEW_BASE_EVENT_REPORT_PARAM_VALUE_H 18 19 #include <string> 20 #include <variant> 21 #include <vector> 22 23 namespace OHOS { 24 namespace HiviewDFX { 25 constexpr uint8_t DEFAULT_UINT8 = 0; 26 constexpr uint16_t DEFAULT_UINT16 = 0; 27 constexpr uint32_t DEFAULT_UINT32 = 0; 28 constexpr uint64_t DEFAULT_UINT64 = 0; 29 const std::string DEFAULT_STRING = ""; 30 const std::vector<uint32_t> DEFAULT_UINT32_VEC = {}; 31 const std::vector<std::string> DEFAULT_STRING_VEC = {}; 32 33 class ParamValue { 34 public: 35 ParamValue(); 36 ParamValue(uint8_t value); 37 ParamValue(uint16_t value); 38 ParamValue(uint32_t value); 39 ParamValue(uint64_t value); 40 ParamValue(const std::string& value); 41 ParamValue(const std::vector<uint32_t>& value); 42 ParamValue(const std::vector<std::string>& value); 43 44 size_t GetType() const; 45 46 uint8_t GetUint8() const; 47 uint16_t GetUint16() const; 48 uint32_t GetUint32() const; 49 uint64_t GetUint64() const; 50 std::string GetString() const; 51 std::vector<uint32_t> GetUint32Vec() const; 52 std::vector<std::string> GetStringVec() const; 53 54 bool IsUint8() const; 55 bool IsUint16() const; 56 bool IsUint32() const; 57 bool IsUint64() const; 58 bool IsString() const; 59 bool IsUint32Vec() const; 60 bool IsStringVec() const; 61 62 private: 63 std::variant<uint8_t, uint16_t, uint32_t, uint64_t, std::string, 64 std::vector<uint32_t>, std::vector<std::string>> value_; 65 }; 66 } // namespace HiviewDFX 67 } // namespace OHOS 68 #endif // HIVIEW_BASE_EVENT_REPORT_PARAM_VALUE_H 69