• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 #ifndef PANDA_RUNTIME_INCLUDE_VALUE_INL_H_
17 #define PANDA_RUNTIME_INCLUDE_VALUE_INL_H_
18 
19 #include "value.h"
20 
21 namespace panda {
22 
23 template <>
GetAs()24 inline ObjectHeader *Value::GetAs() const
25 {
26     return IsReference() ? std::get<1>(value_) : nullptr;
27 }
28 
29 template <>
GetAs()30 inline float Value::GetAs() const
31 {
32     return bit_cast<float>(GetAs<uint32_t>());
33 }
34 
35 template <>
GetAs()36 inline double Value::GetAs() const
37 {
38     return bit_cast<double>(GetAs<uint64_t>());
39 }
40 
GetAsLong()41 inline int64_t Value::GetAsLong()
42 {
43     if (IsPrimitive()) {
44         return GetAs<int64_t>();
45     }
46     return reinterpret_cast<int64_t>(GetAs<ObjectHeader *>());
47 }
48 
49 }  // namespace panda
50 
51 #endif  // PANDA_RUNTIME_INCLUDE_VALUE_INL_H_
52