1 /**
2  * Copyright (c) 2021-2024 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 #ifndef PANDA_RUNTIME_VALUE_INL_H_
16 #define PANDA_RUNTIME_VALUE_INL_H_
17 
18 #include "value.h"
19 
20 namespace ark {
21 
22 template <>
GetAs() const23 inline ObjectHeader *Value::GetAs() const
24 {
25     return IsReference() ? (std::get<1>(value_)) : nullptr;
26 }
27 
28 template <>
GetAs() const29 inline float Value::GetAs() const
30 {
31     return bit_cast<float>(GetAs<uint32_t>());
32 }
33 
34 template <>
GetAs() const35 inline double Value::GetAs() const
36 {
37     return bit_cast<double>(GetAs<uint64_t>());
38 }
39 
GetAsLong() const40 inline int64_t Value::GetAsLong() const
41 {
42     if (IsPrimitive()) {
43         return GetAs<int64_t>();
44     }
45     return reinterpret_cast<int64_t>(GetAs<ObjectHeader *>());
46 }
47 
48 }  // namespace ark
49 
50 #endif  // PANDA_RUNTIME_VALUE_INL_H_
51