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 HISYSEVENT_VALUE_H 17 #define HISYSEVENT_VALUE_H 18 19 #include <vector> 20 21 #include "json/json.h" 22 23 namespace OHOS { 24 namespace HiviewDFX { 25 class HiSysEventValue { 26 public: HiSysEventValue(std::string jsonStr)27 HiSysEventValue(std::string jsonStr) 28 { 29 ParseJsonStr(jsonStr); 30 } HiSysEventValue(Json::Value jsonVal)31 HiSysEventValue(Json::Value jsonVal): jsonVal_(jsonVal), hasInitialized_(true) {} ~HiSysEventValue()32 ~HiSysEventValue() {} 33 34 public: 35 bool HasInitialized() const; 36 bool IsArray() const; 37 bool IsMember(const std::string key) const; 38 bool IsInt64() const; 39 bool IsUInt64() const; 40 bool IsDouble() const; 41 bool IsString() const; 42 bool IsBool() const; 43 bool IsNull() const; 44 bool IsNumeric() const; 45 double AsDouble() const; 46 int64_t AsInt64() const; 47 uint64_t AsUInt64() const; 48 int Size() const; 49 std::string AsString() const; 50 Json::Value Index(const int index) const; 51 Json::Value GetParamValue(const std::string& key) const; 52 Json::ValueType Type() const; 53 void GetParamNames(std::vector<std::string>& params) const; 54 55 private: 56 void ParseJsonStr(const std::string jsonStr); 57 58 private: 59 Json::Value jsonVal_; 60 bool hasInitialized_ = false; 61 }; 62 } 63 } 64 65 #endif // HISYSEVENT_VALUE_H