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 namespace OHOS {
19 namespace AAFwk {
20 IINTERFACE_IMPL_1(Short, Object, IShort);
21 
GetValue(short & value)22 ErrCode Short::GetValue(short &value) /* [out] */
23 {
24     VALIDATE_NOT_NULL(&value);
25 
26     value = value_;
27     return ERR_OK;
28 }
29 
Equals(IObject & other)30 bool Short::Equals(IObject &other) /* [in] */
31 {
32     Short *otherObj = static_cast<Short *>(IShort::Query(&other));
33     return otherObj != nullptr && otherObj->value_ == value_;
34 }
35 
ToString()36 std::string Short::ToString()
37 {
38     return std::to_string(value_);
39 }
40 
Box(short value)41 sptr<IShort> Short::Box(short value) /* [in] */
42 {
43     sptr<IShort> object = new Short(value);
44     return object;
45 }
46 
Unbox(IShort * object)47 short Short::Unbox(IShort *object) /* [in] */
48 {
49     short value;
50     object->GetValue(value);
51     return value;
52 }
53 
Parse(const std::string & str)54 sptr<IShort> Short::Parse(const std::string &str) /* [in] */
55 {
56     sptr<IShort> object;
57     std::size_t idx;
58     short value = (short)std::stoi(str, &idx);
59     if (idx != 0) {
60         object = new Short(value);
61     }
62     return object;
63 }
64 }  // namespace AAFwk
65 }  // namespace OHOS