MongoDB C++ Driver 4.2.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
40 private:
41 std::uint64_t _high = 0u;
42 std::uint64_t _low = 0u;
43
44 public:
50 decimal128() = default;
51
55 decimal128(std::uint64_t high, std::uint64_t low) : _high{high}, _low{low} {}
56
66 explicit BSONCXX_ABI_EXPORT_CDECL() decimal128(v1::stdx::string_view str);
67
71 BSONCXX_ABI_EXPORT_CDECL(std::string) to_string() const;
72
76 std::uint64_t high() const {
77 return _high;
78 }
79
83 std::uint64_t low() const {
84 return _low;
85 }
86
91 friend bool operator==(decimal128 const& lhs, decimal128 const& rhs) {
92 return lhs._high == rhs._high && lhs._low == rhs._low;
93 }
94
95 friend bool operator!=(decimal128 const& lhs, decimal128 const& rhs) {
96 return !(lhs == rhs);
97 }
98
100
112
118 static BSONCXX_ABI_EXPORT_CDECL(std::error_category const&) error_category();
119
125 friend std::error_code make_error_code(errc v) {
126 return {static_cast<int>(v), error_category()};
127 }
128};
129
130} // namespace v1
131} // namespace bsoncxx
132
133template <>
134struct std::is_error_code_enum<bsoncxx::v1::decimal128::errc> : true_type {};
135
137
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:55
errc
Errors codes which may be returned by bsoncxx::v1::decimal128.
Definition decimal128.hpp:106
@ invalid_string_data
String is not a valid Decimal128 representation.
Definition decimal128.hpp:110
@ invalid_string_length
Length of string is too long (exceeds INT_MAX).
Definition decimal128.hpp:109
@ empty_string
String must not be empty.
Definition decimal128.hpp:108
@ zero
Zero.
Definition decimal128.hpp:107
friend bool operator!=(decimal128 const &lhs, decimal128 const &rhs)
Compare equal when the byte representations compare equal.
Definition decimal128.hpp:95
decimal128()=default
Zero-initialize the byte representation.
std::uint64_t low() const
Return the low-order bytes.
Definition decimal128.hpp:83
friend std::error_code make_error_code(errc v)
Support implicit conversion to std::error_code.
Definition decimal128.hpp:125
friend bool operator==(decimal128 const &lhs, decimal128 const &rhs)
Compare equal when the byte representations compare equal.
Definition decimal128.hpp:91
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:76
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.