Loading...
Searching...
No Matches
decimal128.hpp
Go to the documentation of this file.
// Copyright 2009-present MongoDB, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once
#include <bsoncxx/v1/decimal128-fwd.hpp> // IWYU pragma: export
//
#include <bsoncxx/v1/detail/prelude.hpp>
#include <bsoncxx/v1/config/export.hpp>
#include <bsoncxx/v1/stdx/string_view.hpp>
#include <cstdint>
#include <string>
#include <system_error>
#include <type_traits>
namespace bsoncxx {
namespace v1 {
class decimal128 {
private:
std::uint64_t _high = 0u;
std::uint64_t _low = 0u;
public:
decimal128() = default;
decimal128(std::uint64_t high, std::uint64_t low) : _high{high}, _low{low} {}
explicit BSONCXX_ABI_EXPORT_CDECL() decimal128(v1::stdx::string_view str);
BSONCXX_ABI_EXPORT_CDECL(std::string) to_string() const;
std::uint64_t high() const {
return _high;
}
std::uint64_t low() const {
return _low;
}
friend bool operator==(decimal128 const& lhs, decimal128 const& rhs) {
return lhs._high == rhs._high && lhs._low == rhs._low;
}
friend bool operator!=(decimal128 const& lhs, decimal128 const& rhs) {
return !(lhs == rhs);
}
enum class errc {
zero,
empty_string,
invalid_string_length,
invalid_string_data,
};
static BSONCXX_ABI_EXPORT_CDECL(std::error_category const&) error_category();
friend std::error_code make_error_code(errc v) {
return {static_cast<int>(v), error_category()};
}
};
} // namespace v1
} // namespace bsoncxx
template <>
struct std::is_error_code_enum<bsoncxx::v1::decimal128::errc> : true_type {};
#include <bsoncxx/v1/detail/postlude.hpp>
export.hpp
Provides macros to control the set of symbols exported in the ABI.
BSONCXX_ABI_EXPORT_CDECL
#define BSONCXX_ABI_EXPORT_CDECL(...)
Equivalent to BSONCXX_ABI_EXPORT with BSONCXX_ABI_CDECL.
Definition export.hpp:52
postlude.hpp
The bsoncxx v1 macro guard postlude header.
prelude.hpp
The bsoncxx v1 macro guard prelude header.
bsoncxx::v1::decimal128::decimal128
decimal128(std::uint64_t high, std::uint64_t low)
Initialize with the given high and low byte representations.
Definition decimal128.hpp:53
bsoncxx::v1::decimal128::errc
errc
Errors codes which may be returned by bsoncxx::v1::decimal128.
Definition decimal128.hpp:102
bsoncxx::v1::decimal128::errc::invalid_string_data
@ invalid_string_data
String is not a valid Decimal128 representation.
Definition decimal128.hpp:106
bsoncxx::v1::decimal128::errc::invalid_string_length
@ invalid_string_length
Length of string is too long (exceeds INT_MAX).
Definition decimal128.hpp:105
bsoncxx::v1::decimal128::errc::empty_string
@ empty_string
String must not be empty.
Definition decimal128.hpp:104
bsoncxx::v1::decimal128::errc::zero
@ zero
Zero.
Definition decimal128.hpp:103
bsoncxx::v1::decimal128::operator!=
friend bool operator!=(decimal128 const &lhs, decimal128 const &rhs)
Compare equal when the byte representations compare equal.
Definition decimal128.hpp:93
bsoncxx::v1::decimal128::decimal128
decimal128()=default
Zero-initialize the byte representation.
bsoncxx::v1::decimal128::low
std::uint64_t low() const
Return the low-order bytes.
Definition decimal128.hpp:81
bsoncxx::v1::decimal128::make_error_code
friend std::error_code make_error_code(errc v)
Support implicit conversion to std::error_code.
Definition decimal128.hpp:117
bsoncxx::v1::decimal128::operator==
friend bool operator==(decimal128 const &lhs, decimal128 const &rhs)
Compare equal when the byte representations compare equal.
Definition decimal128.hpp:89
bsoncxx::v1::decimal128::error_category
static std::error_category const & error_category()
The error category for bsoncxx::v1::decimal128::errc.
bsoncxx::v1::decimal128::high
std::uint64_t high() const
Return the high-order bytes.
Definition decimal128.hpp:74
bsoncxx::v1::decimal128::to_string
std::string to_string() const
Return the string representation.
bsoncxx::v1::stdx
Declares C++17 standard library polyfills.
bsoncxx::v1
Declares entities whose ABI stability is guaranteed for documented symbols.
bsoncxx
The top-level namespace within which all bsoncxx library entities are declared.
decimal128-fwd.hpp
Declares bsoncxx::v1::decimal128.
string_view.hpp
Provides std::string_view-related polyfills for library API usage.