MongoDB C++ Driver 4.4.0
Loading...
Searching...
No Matches
decimal128.hpp
Go to the documentation of this file.
1// Copyright 2009-present MongoDB, Inc.
2//
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#pragma once
16
17#include <bsoncxx/v1/decimal128-fwd.hpp> // IWYU pragma: export
18
19//
20
22
25
26#include <cstdint>
27#include <string>
28#include <system_error>
29#include <type_traits>
30
31namespace bsoncxx {
32namespace v1 {
33
38 private:
39 std::uint64_t _high = 0u;
40 std::uint64_t _low = 0u;
41
42 public:
48 decimal128() = default;
49
53 decimal128(std::uint64_t high, std::uint64_t low) : _high{high}, _low{low} {}
54
64 explicit BSONCXX_ABI_EXPORT_CDECL() decimal128(v1::stdx::string_view str);
65
69 BSONCXX_ABI_EXPORT_CDECL(std::string) to_string() const;
70
74 std::uint64_t high() const {
75 return _high;
76 }
77
81 std::uint64_t low() const {
82 return _low;
83 }
84
89 friend bool operator==(decimal128 const& lhs, decimal128 const& rhs) {
90 return lhs._high == rhs._high && lhs._low == rhs._low;
91 }
92
93 friend bool operator!=(decimal128 const& lhs, decimal128 const& rhs) {
94 return !(lhs == rhs);
95 }
96
98
108
112 static BSONCXX_ABI_EXPORT_CDECL(std::error_category const&) error_category();
113
117 friend std::error_code make_error_code(errc v) {
118 return {static_cast<int>(v), error_category()};
119 }
120};
121
122} // namespace v1
123} // namespace bsoncxx
124
125template <>
126struct std::is_error_code_enum<bsoncxx::v1::decimal128::errc> : true_type {};
127
129
Provides macros to control the set of symbols exported in the ABI.
#define BSONCXX_ABI_EXPORT_CDECL(...)
Equivalent to BSONCXX_ABI_EXPORT with BSONCXX_ABI_CDECL.
Definition export.hpp:52
The bsoncxx v1 macro guard postlude header.
The bsoncxx v1 macro guard prelude header.
decimal128(std::uint64_t high, std::uint64_t low)
Initialize with the given high and low byte representations.
Definition decimal128.hpp:53
errc
Errors codes which may be returned by bsoncxx::v1::decimal128.
Definition decimal128.hpp:102
@ invalid_string_data
String is not a valid Decimal128 representation.
Definition decimal128.hpp:106
@ invalid_string_length
Length of string is too long (exceeds INT_MAX).
Definition decimal128.hpp:105
@ empty_string
String must not be empty.
Definition decimal128.hpp:104
@ zero
Zero.
Definition decimal128.hpp:103
friend bool operator!=(decimal128 const &lhs, decimal128 const &rhs)
Compare equal when the byte representations compare equal.
Definition decimal128.hpp:93
decimal128()=default
Zero-initialize the byte representation.
std::uint64_t low() const
Return the low-order bytes.
Definition decimal128.hpp:81
friend std::error_code make_error_code(errc v)
Support implicit conversion to std::error_code.
Definition decimal128.hpp:117
friend bool operator==(decimal128 const &lhs, decimal128 const &rhs)
Compare equal when the byte representations compare equal.
Definition decimal128.hpp:89
static std::error_category const & error_category()
The error category for bsoncxx::v1::decimal128::errc.
std::uint64_t high() const
Return the high-order bytes.
Definition decimal128.hpp:74
std::string to_string() const
Return the string representation.
Declares C++17 standard library polyfills.
Declares entities whose ABI stability is guaranteed for documented symbols.
The top-level namespace within which all bsoncxx library entities are declared.
Declares bsoncxx::v1::decimal128.
Provides std::string_view-related polyfills for library API usage.