16 namespace duds {
namespace general {
29 typedef boost::error_info<struct Info_DataSizeSourceUnit, std::size_t>
35 typedef boost::error_info<struct Info_DataSizeTargetUnit, std::size_t>
43 typedef boost::error_info<struct Info_DataSizeBlocks, std::size_t>
46 #if defined(DUDS_ERRORS_VERBOSE) || defined(DOXYGEN) 57 #define THROW_DATASIZE_CONVERSION_ERROR(bits, trgbits, blocks) \ 58 throw boost::enable_current_exception(DataSizeConversionError()) << \ 59 DataSizeSourceUnit(bits) << DataSizeTargetUnit(trgbits) << \ 60 DataSizeBlocks(blocks) << \ 61 boost::throw_function(BOOST_CURRENT_FUNCTION) << \ 62 boost::throw_file(__FILE__) << ::boost::throw_line((int)__LINE__) << \ 63 duds::general::StackTrace(boost::stacktrace::stacktrace()) 65 #define THROW_DATASIZE_CONVERSION_ERROR(bits, trgbits, blocks) \ 66 throw boost::enable_current_exception(DataSizeConversionError()) << \ 67 DataSizeSourceUnit(bits) << DataSizeTargetUnit(trgbits) << \ 68 DataSizeBlocks(blocks) << \ 69 boost::throw_function(BOOST_CURRENT_FUNCTION) << \ 70 boost::throw_file(__FILE__) << ::boost::throw_line((int)__LINE__) 105 template <std::
size_t Bits>
127 constexpr
DataSize(std::size_t blocks) : numblocks(blocks) { }
150 template <std::
size_t ConvBits>
170 constexpr std::uint64_t
bits()
const {
171 return (std::uint64_t)numblocks * (std::uint64_t)
Bits;
188 template <
class OtherDataSize>
189 constexpr OtherDataSize
size()
const {
192 return (bits() % OtherDataSize::blockSize()) ?
194 OtherDataSize(bits() / OtherDataSize::blockSize());
212 template <std::
size_t ConvBits>
214 return size<ConvBits>();
225 template <
class OtherDataSize>
227 return OtherDataSize(
228 (bits() / OtherDataSize::blockSize()) +
229 ((bits() % OtherDataSize::blockSize()) ? 1 : 0)
241 constexpr std::uint64_t
bytes()
const {
242 return size< DataSize<8> >().blocks();
250 return sizeRounded< DataSize<8> >().blocks();
256 template <std::
size_t OtherBits>
258 return bits() == op.
bits();
264 template <std::
size_t OtherBits>
266 return bits() != op.
bits();
272 template <std::
size_t OtherBits>
274 return bits() > op.
bits();
280 template <std::
size_t OtherBits>
281 constexpr
bool operator < (const DataSize<OtherBits> &op)
const {
282 return bits() < op.bits();
288 template <std::
size_t OtherBits>
290 return bits() >= op.
bits();
296 template <std::
size_t OtherBits>
297 constexpr
bool operator <= (const DataSize<OtherBits> &op)
const {
298 return bits() <= op.bits();
345 return DataSize(numblocks * scalar);
353 return DataSize(numblocks / scalar);
413 #endif // #ifndef DATASIZES_HPP DataSize< 1000 > Kilobits
DataSize type for a size in kilobits.
Used to report a failure to make an exact conversion of a size represented by a DataSize object...
static constexpr std::size_t blockSize()
Returns the number of bits in each unit for this type; same as Bits.
boost::error_info< struct Info_DataSizeBlocks, std::size_t > DataSizeBlocks
The number of blocks from a DataSize object that cannot be converted.
constexpr bool operator==(const DigitalPinCap &cap, const DigitalPinCap::Flags &flg)
constexpr std::uint64_t bytesRounded() const
Returns the size specified in bytes, rounded up.
constexpr std::uint64_t bits() const
Returns the size specified in bits.
boost::error_info< struct Info_DataSizeTargetUnit, std::size_t > DataSizeTargetUnit
The number of bits that make up the size unit of the target DataSize object.
DataSize< 1000000000 > Gigabits
DataSize type for a size in gigabits.
DataSize< 1024 *1024 *8 > Megabytes
DataSize type for a size in megabytes.
std::size_t numblocks
The indicated size stored as a multiple of Bits.
constexpr bool operator!=(const DigitalPinCap &cap, const DigitalPinCap::Flags &flg)
DataSize< 1 > Bits
DataSize type for a size in bits.
constexpr std::size_t blocks() const
Returns the size specified as a multuple of Bits.
constexpr OtherDataSize size() const
Returns a new DataSize object representing the same size, but with a multiple different from Bits...
constexpr OtherDataSize sizeRounded() const
Returns a new DataSize object representing a size with a multiple different from Bits that is as smal...
Quantity operator*(double s, const Quantity &q)
Multiplies a Quantity by a scalar.
constexpr std::uint64_t bytes() const
Returns the size specified in bytes, or fails if the size cannot be exactly represented as an integer...
A class to assist with specifiying the sizes of data with scaling units, much like std::chrono::durat...
DataSize< 1000000 > Megabits
DataSize type for a size in megabits.
DataSize< 1024 *8 > Kilobytes
DataSize type for a size in kilobytes.
constexpr DataSize(std::size_t blocks)
Initalizes the size to the indicated value.
boost::error_info< struct Info_DataSizeSourceUnit, std::size_t > DataSizeSourceUnit
The number of bits that make up the size unit of the source DataSize object.
constexpr DataSize(const DataSize< ConvBits > &ds)
Constructs a new DataSize object representing the same size as the given object, but with a multiple ...
DataSize< 4 > Nibbles
DataSize type for a size in nibbles.
#define THROW_DATASIZE_CONVERSION_ERROR(bits, trgbits, blocks)
Throws a DataSizeConversionError exception and adds in error metadata.
Quantity operator/(double s, const Quantity &q)
Divides a Quantity by a scalar.
DataSize< 8 > Bytes
DataSize type for a size in bytes.