/root/doris/be/src/common/cast_set.h
Line | Count | Source (jump to first uncovered line) |
1 | | |
2 | | // Licensed to the Apache Software Foundation (ASF) under one |
3 | | // or more contributor license agreements. See the NOTICE file |
4 | | // distributed with this work for additional information |
5 | | // regarding copyright ownership. The ASF licenses this file |
6 | | // to you under the Apache License, Version 2.0 (the |
7 | | // "License"); you may not use this file except in compliance |
8 | | // with the License. You may obtain a copy of the License at |
9 | | // |
10 | | // http://www.apache.org/licenses/LICENSE-2.0 |
11 | | // |
12 | | // Unless required by applicable law or agreed to in writing, |
13 | | // software distributed under the License is distributed on an |
14 | | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
15 | | // KIND, either express or implied. See the License for the |
16 | | // specific language governing permissions and limitations |
17 | | // under the License. |
18 | | |
19 | | #pragma once |
20 | | |
21 | | #include <limits> |
22 | | #include <type_traits> |
23 | | |
24 | | #include "common/exception.h" |
25 | | #include "common/status.h" |
26 | | |
27 | | namespace doris { |
28 | | |
29 | | template <typename T, typename U> |
30 | 12.7k | void check_cast_value(U b) { |
31 | 12.7k | if constexpr (std::is_unsigned_v<U>) { |
32 | 10.4k | if (b > std::numeric_limits<T>::max()) { |
33 | 0 | throw doris::Exception(ErrorCode::INVALID_ARGUMENT, |
34 | 0 | "value {} cast to type {} out of range [{},{}]", b, |
35 | 0 | typeid(T).name(), std::numeric_limits<T>::min(), |
36 | 0 | std::numeric_limits<T>::max()); |
37 | 0 | } |
38 | 10.4k | } else if constexpr (std::is_unsigned_v<T>) { |
39 | 10.2k | if (b < 0 || b > std::numeric_limits<T>::max()) { |
40 | 0 | throw doris::Exception(ErrorCode::INVALID_ARGUMENT, |
41 | 0 | "value {} cast to type {} out of range [{},{}]", b, |
42 | 0 | typeid(T).name(), std::numeric_limits<T>::min(), |
43 | 0 | std::numeric_limits<T>::max()); |
44 | 0 | } |
45 | 10.2k | } else { |
46 | 170 | if (b < std::numeric_limits<T>::min() || b > std::numeric_limits<T>::max()) { |
47 | 0 | throw doris::Exception(ErrorCode::INVALID_ARGUMENT, |
48 | 0 | "value {} cast to type {} out of range [{},{}]", b, |
49 | 0 | typeid(T).name(), std::numeric_limits<T>::min(), |
50 | 0 | std::numeric_limits<T>::max()); |
51 | 0 | } |
52 | 170 | } |
53 | 12.7k | } _ZN5doris16check_cast_valueIilEEvT0_ Line | Count | Source | 30 | 170 | void check_cast_value(U b) { | 31 | 170 | if constexpr (std::is_unsigned_v<U>) { | 32 | 170 | if (b > std::numeric_limits<T>::max()) { | 33 | 170 | throw doris::Exception(ErrorCode::INVALID_ARGUMENT, | 34 | 170 | "value {} cast to type {} out of range [{},{}]", b, | 35 | 170 | typeid(T).name(), std::numeric_limits<T>::min(), | 36 | 170 | std::numeric_limits<T>::max()); | 37 | 170 | } | 38 | 170 | } else if constexpr (std::is_unsigned_v<T>) { | 39 | 170 | if (b < 0 || b > std::numeric_limits<T>::max()) { | 40 | 170 | throw doris::Exception(ErrorCode::INVALID_ARGUMENT, | 41 | 170 | "value {} cast to type {} out of range [{},{}]", b, | 42 | 170 | typeid(T).name(), std::numeric_limits<T>::min(), | 43 | 170 | std::numeric_limits<T>::max()); | 44 | 170 | } | 45 | 170 | } else { | 46 | 170 | if (b < std::numeric_limits<T>::min() || b > std::numeric_limits<T>::max()) { | 47 | 0 | throw doris::Exception(ErrorCode::INVALID_ARGUMENT, | 48 | 0 | "value {} cast to type {} out of range [{},{}]", b, | 49 | 0 | typeid(T).name(), std::numeric_limits<T>::min(), | 50 | 0 | std::numeric_limits<T>::max()); | 51 | 0 | } | 52 | 170 | } | 53 | 170 | } |
_ZN5doris16check_cast_valueItiEEvT0_ Line | Count | Source | 30 | 10.2k | void check_cast_value(U b) { | 31 | 10.2k | if constexpr (std::is_unsigned_v<U>) { | 32 | 10.2k | if (b > std::numeric_limits<T>::max()) { | 33 | 10.2k | throw doris::Exception(ErrorCode::INVALID_ARGUMENT, | 34 | 10.2k | "value {} cast to type {} out of range [{},{}]", b, | 35 | 10.2k | typeid(T).name(), std::numeric_limits<T>::min(), | 36 | 10.2k | std::numeric_limits<T>::max()); | 37 | 10.2k | } | 38 | 10.2k | } else if constexpr (std::is_unsigned_v<T>) { | 39 | 10.2k | if (b < 0 || b > std::numeric_limits<T>::max()) { | 40 | 0 | throw doris::Exception(ErrorCode::INVALID_ARGUMENT, | 41 | 0 | "value {} cast to type {} out of range [{},{}]", b, | 42 | 0 | typeid(T).name(), std::numeric_limits<T>::min(), | 43 | 0 | std::numeric_limits<T>::max()); | 44 | 0 | } | 45 | 10.2k | } else { | 46 | 10.2k | if (b < std::numeric_limits<T>::min() || b > std::numeric_limits<T>::max()) { | 47 | 10.2k | throw doris::Exception(ErrorCode::INVALID_ARGUMENT, | 48 | 10.2k | "value {} cast to type {} out of range [{},{}]", b, | 49 | 10.2k | typeid(T).name(), std::numeric_limits<T>::min(), | 50 | 10.2k | std::numeric_limits<T>::max()); | 51 | 10.2k | } | 52 | 10.2k | } | 53 | 10.2k | } |
_ZN5doris16check_cast_valueIjmEEvT0_ Line | Count | Source | 30 | 1.72k | void check_cast_value(U b) { | 31 | 1.72k | if constexpr (std::is_unsigned_v<U>) { | 32 | 1.72k | if (b > std::numeric_limits<T>::max()) { | 33 | 0 | throw doris::Exception(ErrorCode::INVALID_ARGUMENT, | 34 | 0 | "value {} cast to type {} out of range [{},{}]", b, | 35 | 0 | typeid(T).name(), std::numeric_limits<T>::min(), | 36 | 0 | std::numeric_limits<T>::max()); | 37 | 0 | } | 38 | 1.72k | } else if constexpr (std::is_unsigned_v<T>) { | 39 | 1.72k | if (b < 0 || b > std::numeric_limits<T>::max()) { | 40 | 1.72k | throw doris::Exception(ErrorCode::INVALID_ARGUMENT, | 41 | 1.72k | "value {} cast to type {} out of range [{},{}]", b, | 42 | 1.72k | typeid(T).name(), std::numeric_limits<T>::min(), | 43 | 1.72k | std::numeric_limits<T>::max()); | 44 | 1.72k | } | 45 | 1.72k | } else { | 46 | 1.72k | if (b < std::numeric_limits<T>::min() || b > std::numeric_limits<T>::max()) { | 47 | 1.72k | throw doris::Exception(ErrorCode::INVALID_ARGUMENT, | 48 | 1.72k | "value {} cast to type {} out of range [{},{}]", b, | 49 | 1.72k | typeid(T).name(), std::numeric_limits<T>::min(), | 50 | 1.72k | std::numeric_limits<T>::max()); | 51 | 1.72k | } | 52 | 1.72k | } | 53 | 1.72k | } |
_ZN5doris16check_cast_valueIimEEvT0_ Line | Count | Source | 30 | 573 | void check_cast_value(U b) { | 31 | 573 | if constexpr (std::is_unsigned_v<U>) { | 32 | 573 | if (b > std::numeric_limits<T>::max()) { | 33 | 0 | throw doris::Exception(ErrorCode::INVALID_ARGUMENT, | 34 | 0 | "value {} cast to type {} out of range [{},{}]", b, | 35 | 0 | typeid(T).name(), std::numeric_limits<T>::min(), | 36 | 0 | std::numeric_limits<T>::max()); | 37 | 0 | } | 38 | 573 | } else if constexpr (std::is_unsigned_v<T>) { | 39 | 573 | if (b < 0 || b > std::numeric_limits<T>::max()) { | 40 | 573 | throw doris::Exception(ErrorCode::INVALID_ARGUMENT, | 41 | 573 | "value {} cast to type {} out of range [{},{}]", b, | 42 | 573 | typeid(T).name(), std::numeric_limits<T>::min(), | 43 | 573 | std::numeric_limits<T>::max()); | 44 | 573 | } | 45 | 573 | } else { | 46 | 573 | if (b < std::numeric_limits<T>::min() || b > std::numeric_limits<T>::max()) { | 47 | 573 | throw doris::Exception(ErrorCode::INVALID_ARGUMENT, | 48 | 573 | "value {} cast to type {} out of range [{},{}]", b, | 49 | 573 | typeid(T).name(), std::numeric_limits<T>::min(), | 50 | 573 | std::numeric_limits<T>::max()); | 51 | 573 | } | 52 | 573 | } | 53 | 573 | } |
Unexecuted instantiation: _ZN5doris16check_cast_valueImnEEvT0_ _ZN5doris16check_cast_valueIjlEEvT0_ Line | Count | Source | 30 | 9 | void check_cast_value(U b) { | 31 | 9 | if constexpr (std::is_unsigned_v<U>) { | 32 | 9 | if (b > std::numeric_limits<T>::max()) { | 33 | 9 | throw doris::Exception(ErrorCode::INVALID_ARGUMENT, | 34 | 9 | "value {} cast to type {} out of range [{},{}]", b, | 35 | 9 | typeid(T).name(), std::numeric_limits<T>::min(), | 36 | 9 | std::numeric_limits<T>::max()); | 37 | 9 | } | 38 | 9 | } else if constexpr (std::is_unsigned_v<T>) { | 39 | 9 | if (b < 0 || b > std::numeric_limits<T>::max()) { | 40 | 0 | throw doris::Exception(ErrorCode::INVALID_ARGUMENT, | 41 | 0 | "value {} cast to type {} out of range [{},{}]", b, | 42 | 0 | typeid(T).name(), std::numeric_limits<T>::min(), | 43 | 0 | std::numeric_limits<T>::max()); | 44 | 0 | } | 45 | 9 | } else { | 46 | 9 | if (b < std::numeric_limits<T>::min() || b > std::numeric_limits<T>::max()) { | 47 | 9 | throw doris::Exception(ErrorCode::INVALID_ARGUMENT, | 48 | 9 | "value {} cast to type {} out of range [{},{}]", b, | 49 | 9 | typeid(T).name(), std::numeric_limits<T>::min(), | 50 | 9 | std::numeric_limits<T>::max()); | 51 | 9 | } | 52 | 9 | } | 53 | 9 | } |
Unexecuted instantiation: _ZN5doris16check_cast_valueIhsEEvT0_ Unexecuted instantiation: _ZN5doris16check_cast_valueIhlEEvT0_ Unexecuted instantiation: _ZN5doris16check_cast_valueIjjEEvT0_ Unexecuted instantiation: _ZN5doris16check_cast_valueIijEEvT0_ |
54 | | |
55 | | template <typename T, typename U, bool need_check_value = true> |
56 | | requires std::is_integral_v<T> && std::is_integral_v<U> |
57 | 0 | void cast_set(T& a, U b) { |
58 | 0 | if constexpr (need_check_value) { |
59 | 0 | check_cast_value<T>(b); |
60 | 0 | } |
61 | 0 | a = static_cast<T>(b); |
62 | 0 | } |
63 | | |
64 | | template <typename T, typename U, bool need_check_value = true> |
65 | | requires std::is_integral_v<T> && std::is_integral_v<U> |
66 | 12.7k | T cast_set(U b) { |
67 | 12.7k | if constexpr (need_check_value) { |
68 | 12.7k | check_cast_value<T>(b); |
69 | 12.7k | } |
70 | 12.7k | return static_cast<T>(b); |
71 | 12.7k | } _ZN5doris8cast_setIciLb0EEET_T0_ Line | Count | Source | 66 | 20 | T cast_set(U b) { | 67 | 20 | if constexpr (need_check_value) { | 68 | 20 | check_cast_value<T>(b); | 69 | 20 | } | 70 | 20 | return static_cast<T>(b); | 71 | 20 | } |
_ZN5doris8cast_setIilLb1EEET_T0_ Line | Count | Source | 66 | 170 | T cast_set(U b) { | 67 | 170 | if constexpr (need_check_value) { | 68 | 170 | check_cast_value<T>(b); | 69 | 170 | } | 70 | 170 | return static_cast<T>(b); | 71 | 170 | } |
_ZN5doris8cast_setItiLb1EEET_T0_ Line | Count | Source | 66 | 10.2k | T cast_set(U b) { | 67 | 10.2k | if constexpr (need_check_value) { | 68 | 10.2k | check_cast_value<T>(b); | 69 | 10.2k | } | 70 | 10.2k | return static_cast<T>(b); | 71 | 10.2k | } |
Unexecuted instantiation: _ZN5doris8cast_setIimLb0EEET_T0_ _ZN5doris8cast_setIjmLb1EEET_T0_ Line | Count | Source | 66 | 1.72k | T cast_set(U b) { | 67 | 1.72k | if constexpr (need_check_value) { | 68 | 1.72k | check_cast_value<T>(b); | 69 | 1.72k | } | 70 | 1.72k | return static_cast<T>(b); | 71 | 1.72k | } |
_ZN5doris8cast_setIhjLb0EEET_T0_ Line | Count | Source | 66 | 4 | T cast_set(U b) { | 67 | 4 | if constexpr (need_check_value) { | 68 | 4 | check_cast_value<T>(b); | 69 | 4 | } | 70 | 4 | return static_cast<T>(b); | 71 | 4 | } |
Unexecuted instantiation: _ZN5doris8cast_setIaiLb0EEET_T0_ Unexecuted instantiation: _ZN5doris8cast_setIsiLb0EEET_T0_ _ZN5doris8cast_setIimLb1EEET_T0_ Line | Count | Source | 66 | 573 | T cast_set(U b) { | 67 | 573 | if constexpr (need_check_value) { | 68 | 573 | check_cast_value<T>(b); | 69 | 573 | } | 70 | 573 | return static_cast<T>(b); | 71 | 573 | } |
Unexecuted instantiation: _ZN5doris8cast_setItjLb0EEET_T0_ Unexecuted instantiation: _ZN5doris8cast_setIilLb0EEET_T0_ Unexecuted instantiation: _ZN5doris8cast_setImnLb1EEET_T0_ _ZN5doris8cast_setIjlLb1EEET_T0_ Line | Count | Source | 66 | 9 | T cast_set(U b) { | 67 | 9 | if constexpr (need_check_value) { | 68 | 9 | check_cast_value<T>(b); | 69 | 9 | } | 70 | 9 | return static_cast<T>(b); | 71 | 9 | } |
Unexecuted instantiation: _ZN5doris8cast_setIhsLb1EEET_T0_ Unexecuted instantiation: _ZN5doris8cast_setIhlLb1EEET_T0_ Unexecuted instantiation: _ZN5doris8cast_setIjjLb1EEET_T0_ Unexecuted instantiation: _ZN5doris8cast_setItmLb0EEET_T0_ Unexecuted instantiation: _ZN5doris8cast_setIijLb1EEET_T0_ |
72 | | |
73 | | } // namespace doris |