YugabyteDB (2.13.0.0-b42, bfc6a6643e7399ac8a0e81d06a3ee6d6571b33ab)

Coverage Report

Created: 2022-03-09 17:30

/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
31
Result<Int> CheckedStoInt(Slice slice) {
26
31
  auto long_value = CheckedStoll(slice);
27
31
  RETURN_NOT_OK(long_value);
28
23
  auto result = static_cast<Int>(*long_value);
29
23
  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
20
  return result;
36
20
}
_ZN2yb13CheckedStoIntIiEENS_6ResultIT_EENS_5SliceE
Line
Count
Source
25
31
Result<Int> CheckedStoInt(Slice slice) {
26
31
  auto long_value = CheckedStoll(slice);
27
31
  RETURN_NOT_OK(long_value);
28
23
  auto result = static_cast<Int>(*long_value);
29
23
  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
20
  return result;
36
20
}
Unexecuted instantiation: _ZN2yb13CheckedStoIntIaEENS_6ResultIT_EENS_5SliceE
Unexecuted instantiation: _ZN2yb13CheckedStoIntIsEENS_6ResultIT_EENS_5SliceE
Unexecuted instantiation: _ZN2yb13CheckedStoIntIxEENS_6ResultIT_EENS_5SliceE
Unexecuted instantiation: _ZN2yb13CheckedStoIntItEENS_6ResultIT_EENS_5SliceE
37
38
30
inline Result<int32_t> CheckedStoi(Slice slice) {
39
30
  return CheckedStoInt<int32_t>(slice);
40
30
}
41
42
Result<long double> CheckedStold(Slice slice);
43
44
} // namespace yb
45
46
#endif // YB_UTIL_STOL_UTILS_H