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/decimal128-fwd.hpp> // IWYU pragma: export
18
19//
20
21#include <bsoncxx/v1/decimal128.hpp> // IWYU pragma: export
22#include <bsoncxx/v1/detail/type_traits.hpp> // IWYU pragma: keep: backward compatibility, to be removed.
23
24#include <cstdint>
25#include <string>
26
28
30
31namespace bsoncxx {
32namespace v_noabi {
33
46 private:
47 v1::decimal128 _d128;
48
49 public:
53 decimal128() = default;
54
58 /* explicit(false) */ decimal128(v1::decimal128 const& d128) noexcept : _d128{d128} {}
59
68 decimal128(std::uint64_t high, std::uint64_t low) : _d128{high, low} {}
69
79 explicit BSONCXX_ABI_EXPORT_CDECL() decimal128(v1::stdx::string_view str);
80
84 explicit operator v1::decimal128() const noexcept {
85 return _d128;
86 }
87
93 std::string to_string() const {
94 return _d128.to_string();
95 }
96
100 std::uint64_t high() const {
101 return _d128.high();
102 }
103
107 std::uint64_t low() const {
108 return _d128.low();
109 }
110
116 friend bool operator==(decimal128 const& lhs, decimal128 const& rhs) {
117 return lhs._d128 == rhs._d128;
118 }
119
125 friend bool operator!=(decimal128 const& lhs, decimal128 const& rhs) {
126 return lhs._d128 != rhs._d128;
127 }
128};
129
134 return {v};
135}
136
141 return v1::decimal128{v};
142}
143
144} // namespace v_noabi
145} // namespace bsoncxx
146
148
#define BSONCXX_ABI_EXPORT_CDECL(...)
Equivalent to BSONCXX_ABI_EXPORT with BSONCXX_ABI_CDECL.
Definition export.hpp:52
The bsoncxx v_noabi macro guard postlude header.
The bsoncxx v_noabi macro guard prelude header.
decimal128()=default
Constructs a BSON Decimal128 value representing zero.
A BSON Decimal128.
Definition decimal128.hpp:39
Represents a MongoDB BSON Decimal128.
Definition decimal128.hpp:45
decimal128(std::uint64_t high, std::uint64_t low)
Constructs a BSON Decimal128 from high and low 64-bit big-endian parts.
Definition decimal128.hpp:68
friend bool operator!=(decimal128 const &lhs, decimal128 const &rhs)
Equality comparison operator.
Definition decimal128.hpp:125
decimal128()=default
Constructs a BSON Decimal128 value representing zero.
decimal128(v1::decimal128 const &d128) noexcept
Construct with the bsoncxx::v1 equivalent.
Definition decimal128.hpp:58
std::string to_string() const
Converts this decimal128 value to a string representation.
Definition decimal128.hpp:93
friend bool operator==(decimal128 const &lhs, decimal128 const &rhs)
Equality comparison operator.
Definition decimal128.hpp:116
std::uint64_t low() const
Accessor for low 64 bits.
Definition decimal128.hpp:107
std::uint64_t high() const
Accessor for high 64 bits.
Definition decimal128.hpp:100
Declares entities whose ABI stability is guaranteed for documented symbols.
Declares C++17 standard library polyfills.
Declares entities whose ABI stability is NOT guaranteed.
v1::element::view to_v1(v_noabi::array::element const &v)
Convert to the bsoncxx::v1 equivalent of v.
Definition element.hpp:132
v_noabi::array::value from_v1(v1::array::value const &v)
Convert from the bsoncxx::v1 equivalent of v.
Definition value.hpp:267
The top-level namespace within which all bsoncxx library entities are declared.
Provides bsoncxx::v1::decimal128.
For internal use only!
Declares bsoncxx::v_noabi::decimal128.
Provides std::string_view-related polyfills for library API usage.