YugabyteDB (2.13.1.0-b60, 21121d69985fbf76aa6958d8f04a9bfa936293b5)

Coverage Report

Created: 2022-03-22 16:43

/Users/deen/code/yugabyte-db/src/yb/util/stol_utils.h
Line
Count
Source
1
// Copyright (c) YugaByte, Inc.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
4
// in compliance with the License.  You may obtain a copy of the License at
5
//
6
// http://www.apache.org/licenses/LICENSE-2.0
7
//
8
// Unless required by applicable law or agreed to in writing, software distributed under the License
9
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
10
// or implied.  See the License for the specific language governing permissions and limitations
11
// under the License.
12
//
13
14
#ifndef YB_UTIL_STOL_UTILS_H
15
#define YB_UTIL_STOL_UTILS_H
16
17
#include "yb/util/result.h"
18
#include "yb/util/status_format.h"
19
20
namespace yb {
21
22
Result<int64_t> CheckedStoll(Slice slice);
23
24
template <class Int>
25
41
Result<Int> CheckedStoInt(Slice slice) {
26
41
  auto long_value = CheckedStoll(slice);
27
41
  RETURN_NOT_OK(long_value);
28
32
  auto result = static_cast<Int>(*long_value);
29
32
  if (result != *long_value) {
30
3
    return STATUS_FORMAT(InvalidArgument,
31
3
                         "$0 is out of range: [$1; $2]",
32
3
                         std::numeric_limits<Int>::min(),
33
3
                         std::numeric_limits<Int>::max());
34
3
  }
35
29
  return result;
36
32
}
Unexecuted instantiation: yb::Result<signed char> yb::CheckedStoInt<signed char>(yb::Slice)
Unexecuted instantiation: yb::Result<short> yb::CheckedStoInt<short>(yb::Slice)
yb::Result<int> yb::CheckedStoInt<int>(yb::Slice)
Line
Count
Source
25
41
Result<Int> CheckedStoInt(Slice slice) {
26
41
  auto long_value = CheckedStoll(slice);
27
41
  RETURN_NOT_OK(long_value);
28
32
  auto result = static_cast<Int>(*long_value);
29
32
  if (result != *long_value) {
30
3
    return STATUS_FORMAT(InvalidArgument,
31
3
                         "$0 is out of range: [$1; $2]",
32
3
                         std::numeric_limits<Int>::min(),
33
3
                         std::numeric_limits<Int>::max());
34
3
  }
35
29
  return result;
36
32
}
Unexecuted instantiation: yb::Result<long long> yb::CheckedStoInt<long long>(yb::Slice)
Unexecuted instantiation: yb::Result<unsigned short> yb::CheckedStoInt<unsigned short>(yb::Slice)
37
38
40
inline Result<int32_t> CheckedStoi(Slice slice) {
39
40
  return CheckedStoInt<int32_t>(slice);
40
40
}
41
42
Result<long double> CheckedStold(Slice slice);
43
44
} // namespace yb
45
46
#endif // YB_UTIL_STOL_UTILS_H