1 /* 2 * Copyright (c) 2021-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 #include "bool_wrapper.h" 17 18 namespace OHOS { 19 namespace AAFwk { 20 IINTERFACE_IMPL_1(Boolean, Object, IBoolean); GetValue(bool & value)21ErrCode Boolean::GetValue(bool &value) /* [out] */ 22 { 23 VALIDATE_NOT_NULL(&value); 24 25 value = value_; 26 return ERR_OK; 27 } 28 Equals(IObject & other)29bool Boolean::Equals(IObject &other) /* [in] */ 30 { 31 Boolean *otherObj = static_cast<Boolean *>(IBoolean::Query(&other)); 32 return otherObj != nullptr && otherObj->value_ == value_; 33 } 34 ToString()35std::string Boolean::ToString() 36 { 37 return value_ ? "true" : "false"; 38 } 39 Box(bool value)40sptr<IBoolean> Boolean::Box(bool value) /* [in] */ 41 { 42 sptr<IBoolean> object = new Boolean(value); 43 return object; 44 } 45 Unbox(IBoolean * object)46bool Boolean::Unbox(IBoolean *object) /* [in] */ 47 { 48 bool value = false; 49 object->GetValue(value); 50 return value; 51 } 52 Parse(const std::string & str)53sptr<IBoolean> Boolean::Parse(const std::string &str) /* [in] */ 54 { 55 sptr<IBoolean> object; 56 if (str == "true") { 57 object = new Boolean(true); 58 } else if (str == "false") { 59 object = new Boolean(false); 60 } 61 return object; 62 } 63 } // namespace AAFwk 64 } // namespace OHOS