MongoDB C++ Driver  mongocxx-3.7.0
decimal128.hpp
1 // Copyright 2016 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 <cstdint>
18 #include <string>
19 
20 #include <bsoncxx/stdx/string_view.hpp>
21 
22 #include <bsoncxx/config/prelude.hpp>
23 
24 namespace bsoncxx {
25 BSONCXX_INLINE_NAMESPACE_BEGIN
26 
30 class BSONCXX_API decimal128 {
31  public:
35  decimal128() = default;
36 
45  decimal128(uint64_t high, uint64_t low) noexcept : _high(high), _low(low) {}
46 
56  explicit decimal128(stdx::string_view str);
57 
63  std::string to_string() const;
64 
72  friend BSONCXX_API bool BSONCXX_CALL operator==(const decimal128& lhs, const decimal128& rhs);
73  friend BSONCXX_API bool BSONCXX_CALL operator!=(const decimal128& lhs, const decimal128& rhs);
77 
81  BSONCXX_INLINE uint64_t high() const {
82  return _high;
83  }
84 
88  BSONCXX_INLINE uint64_t low() const {
89  return _low;
90  }
91 
92  private:
93  uint64_t _high = 0;
94  uint64_t _low = 0;
95 };
96 
97 BSONCXX_INLINE_NAMESPACE_END
98 } // namespace bsoncxx
99 
100 #include <bsoncxx/config/postlude.hpp>
bsoncxx
Top level namespace for MongoDB C++ BSON functionality.
Definition: element.hpp:24
bsoncxx::decimal128::high
uint64_t high() const
Accessor for high 64 bits.
Definition: decimal128.hpp:81
bsoncxx::decimal128::decimal128
decimal128(uint64_t high, uint64_t low) noexcept
Constructs a BSON Decimal128 from high and low 64-bit big-endian parts.
Definition: decimal128.hpp:45
bsoncxx::decimal128::low
uint64_t low() const
Accessor for low 64 bits.
Definition: decimal128.hpp:88
bsoncxx::decimal128
Represents an IEEE 754-2008 BSON Decimal128 value in a platform-independent way.
Definition: decimal128.hpp:30
bsoncxx::to_string
std::string to_string(type rhs)
Returns a stringification of the given type.