|
DUDS
|
Distributed Update of Data from Something
|
A class to assist with specifiying the sizes of data with scaling units, much like std::chrono::duration does with time. More...
#include <DataSize.hpp>
Public Member Functions | |
| DataSize ()=default | |
| Trival constructor. More... | |
| constexpr | DataSize (std::size_t blocks) |
| Initalizes the size to the indicated value. More... | |
| template<std::size_t ConvBits> | |
| constexpr | DataSize (const DataSize< ConvBits > &ds) |
| Constructs a new DataSize object representing the same size as the given object, but with a multiple different from Bits. More... | |
| constexpr std::uint64_t | bits () const |
| Returns the size specified in bits. More... | |
| constexpr std::size_t | blocks () const |
| Returns the size specified as a multuple of Bits. More... | |
| constexpr std::uint64_t | bytes () const |
| Returns the size specified in bytes, or fails if the size cannot be exactly represented as an integer value of bytes. More... | |
| constexpr std::uint64_t | bytesRounded () const |
| Returns the size specified in bytes, rounded up. More... | |
| template<std::size_t ConvBits> | |
| constexpr | operator DataSize< ConvBits > () const |
| Implicit conversion of DataSize objects to other DataSize classes using a different size multiple. More... | |
| template<std::size_t OtherBits> | |
| constexpr bool | operator!= (const DataSize< OtherBits > &op) const |
| Checks inequality by comparing the number of bits so that any DataSize template types may be compared without a conversion. More... | |
| constexpr DataSize | operator* (int scalar) const |
| Muliplies the size by a scalar value. More... | |
| DataSize & | operator*= (int scalar) |
| Multiplies a DataSize object by a scalar and stores the result. More... | |
| constexpr DataSize | operator+ (const DataSize &op) const |
| Adds two sizes. More... | |
| DataSize & | operator+= (const DataSize &op) |
| Adds two DataSize objects and stores the result. More... | |
| constexpr DataSize | operator- (const DataSize &op) const |
| Subtracts two sizes. More... | |
| DataSize & | operator-= (const DataSize &op) |
| Subtracts two DataSize objects and stores the result. More... | |
| constexpr DataSize | operator/ (int scalar) const |
| Divides the size by a scalar value. More... | |
| DataSize & | operator/= (int scalar) |
| Divides a DataSize object by a scalar and stores the result. More... | |
| template<std::size_t OtherBits> | |
| constexpr bool | operator< (const DataSize< OtherBits > &op) const |
| Less-than comparison done by comparing the number of bits so that any DataSize template types may be compared without a conversion. More... | |
| template<std::size_t OtherBits> | |
| constexpr bool | operator<= (const DataSize< OtherBits > &op) const |
| Less-than-or-equal comparison done by comparing the number of bits so that any DataSize template types may be compared without a conversion. More... | |
| template<std::size_t OtherBits> | |
| constexpr bool | operator== (const DataSize< OtherBits > &op) const |
| Checks equality by comparing the number of bits so that any DataSize template types may be compared without a conversion. More... | |
| template<std::size_t OtherBits> | |
| constexpr bool | operator> (const DataSize< OtherBits > &op) const |
| Greater-than comparison done by comparing the number of bits so that any DataSize template types may be compared without a conversion. More... | |
| template<std::size_t OtherBits> | |
| constexpr bool | operator>= (const DataSize< OtherBits > &op) const |
| Greater-than-or-equal comparison done by comparing the number of bits so that any DataSize template types may be compared without a conversion. More... | |
| template<class OtherDataSize > | |
| constexpr OtherDataSize | size () const |
| Returns a new DataSize object representing the same size, but with a multiple different from Bits. More... | |
| template<class OtherDataSize > | |
| constexpr OtherDataSize | sizeRounded () const |
| Returns a new DataSize object representing a size with a multiple different from Bits that is as small as possible while representing at least as many bits as this object. More... | |
Static Public Member Functions | |
| static constexpr std::size_t | blockSize () |
| Returns the number of bits in each unit for this type; same as Bits. More... | |
Private Attributes | |
| std::size_t | numblocks |
| The indicated size stored as a multiple of Bits. More... | |
A class to assist with specifiying the sizes of data with scaling units, much like std::chrono::duration does with time.
The base unit used is the bit in order to work for any application, not just data storage on common computers. The template takes the number of bits for its scalar, and stores the multiple of those bits for its indicated size. Many of the functions are declared constexpr, and the class is trivially constructable and copyable.
DataSize objects are implicitly convertable to other DataSize template types, and will convert the stored size to match units. If such a conversion cannot represent the size exactly in an integer, the conversion will fail. If the conversion is in a constexpr expression, the failure is at compile time. Otherwise, it is at runtime with a DataSizeConversionError exception. There are conversion functions that end with "Rounded" that will round up when the size cannot be exactly represented so that the result will be at least as large as the input.
| Bits | The number of bits that make up one unit of data for this type. For example, 8 for a byte, and 1024 for a kilobyte. Several typedefs for common sizes exist, including Bytes and Kilobytes. |
Definition at line 106 of file DataSize.hpp.
|
default |
Trival constructor.
|
inline |
Initalizes the size to the indicated value.
The represented size will be blocks multiplied by Bits.
| blocks | The size specified as a multuple of Bits. |
Definition at line 127 of file DataSize.hpp.
|
inline |
Constructs a new DataSize object representing the same size as the given object, but with a multiple different from Bits.
| ConvBits | The number of bits in each unit of the converted result. This will need to be explicitly specified. |
| ds | The source DataSize object. |
| DataSizeConversionError | The size cannot be excactly represented by a DataSize<ConvBits> object. This will only be thrown from expressions that are not constexpr. |
Definition at line 151 of file DataSize.hpp.
|
inline |
Returns the size specified in bits.
Definition at line 170 of file DataSize.hpp.
Referenced by duds::general::DataSize< Bits >::operator!=(), duds::general::DataSize< Bits >::operator==(), duds::general::DataSize< Bits >::operator>(), and duds::general::DataSize< Bits >::operator>=().
|
inline |
Returns the size specified as a multuple of Bits.
Definition at line 162 of file DataSize.hpp.
Referenced by duds::hardware::interface::linux::SpiMasterSyncSerial::transfer().
|
inlinestatic |
Returns the number of bits in each unit for this type; same as Bits.
Definition at line 115 of file DataSize.hpp.
|
inline |
Returns the size specified in bytes, or fails if the size cannot be exactly represented as an integer value of bytes.
Definition at line 241 of file DataSize.hpp.
|
inline |
Returns the size specified in bytes, rounded up.
Definition at line 249 of file DataSize.hpp.
|
inline |
Implicit conversion of DataSize objects to other DataSize classes using a different size multiple.
The conversion will fail if the size cannot be exactly represented.
| ConvBits | The number of bits in each unit of the converted result. This will need to be explicitly specified. |
| DataSizeConversionError | The size cannot be excactly represented by a DataSize<ConvBits> object. This will only be thrown from expressions that are not constexpr. |
Definition at line 213 of file DataSize.hpp.
|
inline |
Checks inequality by comparing the number of bits so that any DataSize template types may be compared without a conversion.
Definition at line 265 of file DataSize.hpp.
|
inline |
Muliplies the size by a scalar value.
Multiplying two DataSize objects is not directly allowed since the result should be a value in square bits.
Definition at line 344 of file DataSize.hpp.
|
inline |
Multiplies a DataSize object by a scalar and stores the result.
Definition at line 358 of file DataSize.hpp.
|
inline |
Adds two sizes.
Differing DataSize templates may be used; this will cause an implicit conversion which will fail if the conversion cannot be exact. The result is that the DataSize template with the smaller uint (Bits) should generally be on the left side of the expression.
Definition at line 310 of file DataSize.hpp.
|
inline |
Adds two DataSize objects and stores the result.
Definition at line 329 of file DataSize.hpp.
|
inline |
Subtracts two sizes.
Differing DataSize templates may be used; this will cause an implicit conversion which will fail if the conversion cannot be exact. The result is that the DataSize template with the smaller uint (Bits) should generally be on the left side of the expression.
Definition at line 323 of file DataSize.hpp.
|
inline |
Subtracts two DataSize objects and stores the result.
Definition at line 336 of file DataSize.hpp.
|
inline |
Divides the size by a scalar value.
Dividing two DataSize objects is not directly allowed since the result would be unitless (not bits or anything else).
Definition at line 352 of file DataSize.hpp.
|
inline |
Divides a DataSize object by a scalar and stores the result.
Definition at line 365 of file DataSize.hpp.
|
inline |
Less-than comparison done by comparing the number of bits so that any DataSize template types may be compared without a conversion.
Definition at line 281 of file DataSize.hpp.
|
inline |
Less-than-or-equal comparison done by comparing the number of bits so that any DataSize template types may be compared without a conversion.
Definition at line 297 of file DataSize.hpp.
|
inline |
Checks equality by comparing the number of bits so that any DataSize template types may be compared without a conversion.
Definition at line 257 of file DataSize.hpp.
|
inline |
Greater-than comparison done by comparing the number of bits so that any DataSize template types may be compared without a conversion.
Definition at line 273 of file DataSize.hpp.
|
inline |
Greater-than-or-equal comparison done by comparing the number of bits so that any DataSize template types may be compared without a conversion.
Definition at line 289 of file DataSize.hpp.
|
inline |
Returns a new DataSize object representing the same size, but with a multiple different from Bits.
| OtherDataSize | The number of bits in each unit of the converted result. This will need to be explicitly specified. |
| DataSizeConversionError | The size cannot be excactly represented by a DataSize<OtherDataSize> object. This will only be thrown from expressions that are not constexpr. |
Definition at line 189 of file DataSize.hpp.
|
inline |
Returns a new DataSize object representing a size with a multiple different from Bits that is as small as possible while representing at least as many bits as this object.
| OtherDataSize | The number of bits in each unit of the converted result. This will need to be explicitly specified. |
Definition at line 226 of file DataSize.hpp.
|
private |
The indicated size stored as a multiple of Bits.
Definition at line 110 of file DataSize.hpp.
Referenced by duds::general::DataSize< Bits >::operator+(), duds::general::DataSize< Bits >::operator+=(), duds::general::DataSize< Bits >::operator-(), and duds::general::DataSize< Bits >::operator-=().