• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "param_value.h"
16 
17 namespace OHOS {
18 namespace HiviewDFX {
ParamValue()19 ParamValue::ParamValue()
20 {}
21 
ParamValue(uint8_t value)22 ParamValue::ParamValue(uint8_t value)
23 {
24     this->value_ = value;
25 }
26 
ParamValue(uint16_t value)27 ParamValue::ParamValue(uint16_t value)
28 {
29     this->value_ = value;
30 }
31 
ParamValue(uint32_t value)32 ParamValue::ParamValue(uint32_t value)
33 {
34     this->value_ = value;
35 }
36 
ParamValue(uint64_t value)37 ParamValue::ParamValue(uint64_t value)
38 {
39     this->value_ = value;
40 }
41 
ParamValue(const std::string & value)42 ParamValue::ParamValue(const std::string& value)
43 {
44     this->value_ = value;
45 }
46 
ParamValue(const std::vector<uint32_t> & value)47 ParamValue::ParamValue(const std::vector<uint32_t>& value)
48 {
49     this->value_ = value;
50 }
51 
ParamValue(const std::vector<std::string> & value)52 ParamValue::ParamValue(const std::vector<std::string>& value)
53 {
54     this->value_ = value;
55 }
56 
GetType() const57 size_t ParamValue::GetType() const
58 {
59     return this->value_.index();
60 }
61 
GetUint8() const62 uint8_t ParamValue::GetUint8() const
63 {
64     return IsUint8() ? std::get<uint8_t>(this->value_) : DEFAULT_UINT8;
65 }
66 
GetUint16() const67 uint16_t ParamValue::GetUint16() const
68 {
69     return IsUint16() ? std::get<uint16_t>(this->value_) : DEFAULT_UINT16;
70 }
71 
GetUint32() const72 uint32_t ParamValue::GetUint32() const
73 {
74     return IsUint32() ? std::get<uint32_t>(this->value_) : DEFAULT_UINT32;
75 }
76 
GetUint64() const77 uint64_t ParamValue::GetUint64() const
78 {
79     return IsUint64() ? std::get<uint64_t>(this->value_) : DEFAULT_UINT64;
80 }
81 
GetString() const82 std::string ParamValue::GetString() const
83 {
84     return IsString() ? std::get<std::string>(this->value_) : DEFAULT_STRING;
85 }
86 
GetUint32Vec() const87 std::vector<uint32_t> ParamValue::GetUint32Vec() const
88 {
89     return IsUint32Vec() ? std::get<std::vector<uint32_t>>(this->value_) : DEFAULT_UINT32_VEC;
90 }
91 
GetStringVec() const92 std::vector<std::string> ParamValue::GetStringVec() const
93 {
94     return IsStringVec() ? std::get<std::vector<std::string>>(this->value_) : DEFAULT_STRING_VEC;
95 }
96 
IsUint8() const97 bool ParamValue::IsUint8() const
98 {
99     return std::get_if<uint8_t>(&this->value_) != nullptr;
100 }
101 
IsUint16() const102 bool ParamValue::IsUint16() const
103 {
104     return std::get_if<uint16_t>(&this->value_) != nullptr;
105 }
106 
IsUint32() const107 bool ParamValue::IsUint32() const
108 {
109     return std::get_if<uint32_t>(&this->value_) != nullptr;
110 }
111 
IsUint64() const112 bool ParamValue::IsUint64() const
113 {
114     return std::get_if<uint64_t>(&this->value_) != nullptr;
115 }
116 
IsString() const117 bool ParamValue::IsString() const
118 {
119     return std::get_if<std::string>(&this->value_) != nullptr;
120 }
121 
IsUint32Vec() const122 bool ParamValue::IsUint32Vec() const
123 {
124     return std::get_if<std::vector<uint32_t>>(&this->value_) != nullptr;
125 }
126 
IsStringVec() const127 bool ParamValue::IsStringVec() const
128 {
129     return std::get_if<std::vector<std::string>>(&this->value_) != nullptr;
130 }
131 } // namespace HiviewDFX
132 } // namespace OHOS
133