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 "short_wrapper.h" 17 18 #include "ability_base_log_wrapper.h" 19 20 namespace OHOS { 21 namespace AAFwk { 22 IINTERFACE_IMPL_1(Short, Object, IShort); 23 GetValue(short & value)24ErrCode Short::GetValue(short &value) /* [out] */ 25 { 26 VALIDATE_NOT_NULL(&value); 27 28 value = value_; 29 return ERR_OK; 30 } 31 Equals(IObject & other)32bool Short::Equals(IObject &other) /* [in] */ 33 { 34 Short *otherObj = static_cast<Short *>(IShort::Query(&other)); 35 return otherObj != nullptr && otherObj->value_ == value_; 36 } 37 ToString()38std::string Short::ToString() 39 { 40 return std::to_string(value_); 41 } 42 Box(short value)43sptr<IShort> Short::Box(short value) /* [in] */ 44 { 45 sptr<IShort> object = sptr<Short>::MakeSptr(value); 46 return object; 47 } 48 Unbox(IShort * object)49short Short::Unbox(IShort *object) /* [in] */ 50 { 51 short value; 52 object->GetValue(value); 53 return value; 54 } 55 Parse(const std::string & str)56sptr<IShort> Short::Parse(const std::string &str) /* [in] */ 57 { 58 sptr<IShort> object; 59 std::size_t idx; 60 try { 61 short value = (short)std::stoi(str, &idx); 62 if (idx != 0) { 63 object = sptr<Short>::MakeSptr(value); 64 } 65 } catch (...) { 66 ABILITYBASE_LOGE("failed to convert to short: %{public}s", str.c_str()); 67 } 68 return object; 69 } 70 } // namespace AAFwk 71 } // namespace OHOS 72