DUDS
Distributed Update of Data from Something
duds::general Namespace Reference

General use library code that isn't actually specific to the DUDS family of libraries, but were developed along with DUDS. More...

Classes

class  BitFlags
 A type-safe bit flag storage class. More...
 
struct  ChecksumError
 A bad checksum value was found. More...
 
struct  CrcError
 An incorrect cyclic redundancy code (CRC) value was found. More...
 
class  DataSize
 A class to assist with specifiying the sizes of data with scaling units, much like std::chrono::duration does with time. More...
 
struct  DataSizeConversionError
 Used to report a failure to make an exact conversion of a size represented by a DataSize object. More...
 
struct  DimensionMismatchError
 A specified position has a different number of dimensions than the array. More...
 
struct  EmptyDimensionError
 A specified dimension is zero. More...
 
struct  FileIoError
 An I/O error involving a file. More...
 
class  IntegerBiDirIterator
 A bidirectional iterator intended to work with sequential integers. More...
 
struct  IoError
 A general I/O error. More...
 
struct  LanguageTaggedString
 Holds a string and its associated language. More...
 
class  NddArray
 N-Dimensional Dynamic Array. More...
 
struct  NddArrayError
 Base class for exceptions thrown by NddArray. More...
 
struct  ObjectDestructedError
 An error indicating an attempt to use an already destructed object. More...
 
struct  OutOfRangeError
 A specified dimension is beyond the range of the array. More...
 
class  Spinlock
 A simple spinlock following the lockable and timed lockable concepts so that it can be used with std::lock_guard, std::unique_lock, and std::lock. More...
 
class  SpinlockYieldingWrapper
 A simple wrapper around a Spinlock object that implements the timed lockable concept such that attempts to lock an already locked Spinlock will always yield before trying again. More...
 
struct  UnimplementedError
 Indicates that the requested operation or called function is not implemented. More...
 
struct  ZeroSizeError
 An empty array, one with zero dimensions, cannot be indexed. More...
 

Typedefs

typedef DataSize< 1 > Bits
 DataSize type for a size in bits. More...
 
typedef DataSize< 8 > Bytes
 DataSize type for a size in bytes. More...
 
typedef boost::error_info< struct Info_DataSizeBlocks, std::size_t > DataSizeBlocks
 The number of blocks from a DataSize object that cannot be converted. More...
 
typedef 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. More...
 
typedef 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. More...
 
typedef DataSize< 1000000000 > Gigabits
 DataSize type for a size in gigabits. More...
 
typedef DataSize< 1000 > Kilobits
 DataSize type for a size in kilobits. More...
 
typedef DataSize< 1024 *8 > Kilobytes
 DataSize type for a size in kilobytes. More...
 
typedef std::map< std::string, std::string > LanguageTaggedStringMap
 
typedef DataSize< 1000000 > Megabits
 DataSize type for a size in megabits. More...
 
typedef DataSize< 1024 *1024 *8 > Megabytes
 DataSize type for a size in megabytes. More...
 
typedef DataSize< 4 > Nibbles
 DataSize type for a size in nibbles. More...
 
typedef std::lock_guard< duds::general::SpinlockSpinLockGuard
 A convenience typedef for a std::lock_guard using the Spinlock object. More...
 
typedef boost::error_info< struct Info_Stacktrace, boost::stacktrace::stacktrace > StackTrace
 Includes stack trace information in an exception. More...
 
typedef std::unique_lock< duds::general::SpinlockUniqueSpinLock
 A convenience typedef for a std::unique_lock using the Spinlock object. More...
 
typedef std::unique_lock< duds::general::SpinlockYieldingWrapperUniqueYieldingSpinLock
 A convenience typedef for a std::unique_lock using the Spinlock yielding wrapper. More...
 
typedef std::lock_guard< duds::general::SpinlockYieldingWrapperYieldingSpinLockGuard
 A convenience typedef for a std::lock_guard using the Spinlock yielding wrapper. More...
 

Functions

template<class T , class B >
std::size_t hash_value (const duds::general::BitFlags< T, B > &bf)
 Generates a hash value for use with Boost containers, like boost::multi_index::multi_index_container templates. More...
 
template<typename Integer >
constexpr bool IsPowerOf2 (Integer i)
 Returns true only if the given value is a power of 2. More...
 
template<typename Integer >
Integer ReverseBits (Integer i)
 Reverses the bits in a given value. More...
 
constexpr std::uint8_t ReverseBits (const std::uint8_t i)
 Reverse the bits of a given byte. More...
 
template<unsigned B, typename T >
std::make_signed< T >::type SignedMagnitudeToTwosComplement (const T x)
 Converts a signed magnitude value to two's complement. More...
 
template<unsigned B, typename T >
std::make_signed< T >::type SignExtend (const T x)
 Performs a sign extention operation. More...
 
template<class T >
void swap (NddArray< T > &one, NddArray< T > &two)
 Makes NddAray meet the requirements of Swappable to assist in using std::swap(). More...
 
template<class Duration >
void YieldingWait (Duration duration)
 Waits for a minumum period of time by calling std::this_thread::yield() in a loop. More...
 
void YieldingWait (int nano)
 Waits for a minumum period of time in nanoseconds by calling std::this_thread::yield() in a loop. More...
 

Detailed Description

General use library code that isn't actually specific to the DUDS family of libraries, but were developed along with DUDS.

The code in this namespace must not be specific to DUDS.

Typedef Documentation

◆ Bits

DataSize type for a size in bits.

Definition at line 374 of file DataSize.hpp.

◆ Bytes

DataSize type for a size in bytes.

Definition at line 384 of file DataSize.hpp.

◆ DataSizeBlocks

typedef boost::error_info<struct Info_DataSizeBlocks, std::size_t> duds::general::DataSizeBlocks

The number of blocks from a DataSize object that cannot be converted.

The represented size is the number of blocks multiplied by the bit size of the DataSize template parameter.

Definition at line 44 of file DataSize.hpp.

◆ DataSizeSourceUnit

typedef boost::error_info<struct Info_DataSizeSourceUnit, std::size_t> duds::general::DataSizeSourceUnit

The number of bits that make up the size unit of the source DataSize object.

Definition at line 30 of file DataSize.hpp.

◆ DataSizeTargetUnit

typedef boost::error_info<struct Info_DataSizeTargetUnit, std::size_t> duds::general::DataSizeTargetUnit

The number of bits that make up the size unit of the target DataSize object.

Definition at line 36 of file DataSize.hpp.

◆ Gigabits

typedef DataSize<1000000000> duds::general::Gigabits

DataSize type for a size in gigabits.

Definition at line 409 of file DataSize.hpp.

◆ Kilobits

DataSize type for a size in kilobits.

Definition at line 399 of file DataSize.hpp.

◆ Kilobytes

DataSize type for a size in kilobytes.

Definition at line 389 of file DataSize.hpp.

◆ LanguageTaggedStringMap

typedef std::map<std::string, std::string> duds::general::LanguageTaggedStringMap

Definition at line 69 of file LanguageTaggedString.hpp.

◆ Megabits

DataSize type for a size in megabits.

Definition at line 404 of file DataSize.hpp.

◆ Megabytes

typedef DataSize<1024*1024*8> duds::general::Megabytes

DataSize type for a size in megabytes.

Definition at line 394 of file DataSize.hpp.

◆ Nibbles

DataSize type for a size in nibbles.

Definition at line 379 of file DataSize.hpp.

◆ SpinLockGuard

A convenience typedef for a std::lock_guard using the Spinlock object.

Definition at line 216 of file Spinlock.hpp.

◆ StackTrace

typedef boost::error_info< struct Info_Stacktrace, boost::stacktrace::stacktrace> duds::general::StackTrace

Includes stack trace information in an exception.

This is included in exceptions that are thrown with DUDS_THROW_EXCEPTION when DUDS_ERRORS_VERBOSE is defined. The build normally defines DUDS_ERRORS_VERBOSE for debug builds when the required libraries are available and usable; see DUDS_THROW_EXCEPTION for more info.

Precondition
On Linux and similar systems, the dl library is required.
Bug:
The captured stack trace shows where this object is created rather than where the exception is thrown. The function throwing the exception may not be in the trace. However, the location of the throw is included in other exception information by DUDS_THROW_EXCEPTION and BOOST_THROW_EXCEPTION.

Definition at line 76 of file Errors.hpp.

◆ UniqueSpinLock

A convenience typedef for a std::unique_lock using the Spinlock object.

Definition at line 221 of file Spinlock.hpp.

◆ UniqueYieldingSpinLock

A convenience typedef for a std::unique_lock using the Spinlock yielding wrapper.

Definition at line 280 of file Spinlock.hpp.

◆ YieldingSpinLockGuard

A convenience typedef for a std::lock_guard using the Spinlock yielding wrapper.

Definition at line 273 of file Spinlock.hpp.

Function Documentation

◆ hash_value()

template<class T , class B >
std::size_t duds::general::hash_value ( const duds::general::BitFlags< T, B > &  bf)
inline

Generates a hash value for use with Boost containers, like boost::multi_index::multi_index_container templates.

These refuse to use std::hash as of Boost 1.65, so this implementation is required.

Definition at line 331 of file BitFlags.hpp.

◆ IsPowerOf2()

template<typename Integer >
constexpr bool duds::general::IsPowerOf2 ( Integer  i)
inline

Returns true only if the given value is a power of 2.

Template Parameters
IntegerThe integer type of the value.
Parameters
iThe integer value to check.

Definition at line 9 of file ReverseBits.hpp.

Referenced by ReverseBits().

◆ ReverseBits() [1/2]

template<typename Integer >
Integer duds::general::ReverseBits ( Integer  i)
inline

Reverses the bits in a given value.

From http://graphics.stanford.edu/~seander/bithacks.html#ReverseParallel, with some reformatting and changed to a C++ template. The code is in the public domain.

Template Parameters
IntegerThe integer type of the value.
Parameters
iThe integer value to reverse.
Returns
The integer with the bits in reverse order.
Author
Ken Raeburn
Jeff Jackowski (changed to template, power of 2 check)
License^^ Public domain

Definition at line 26 of file ReverseBits.hpp.

Referenced by duds::hardware::devices::displays::HD44780::setGlyph(), and duds::hardware::devices::displays::ST7920::writeBlock().

◆ ReverseBits() [2/2]

constexpr std::uint8_t duds::general::ReverseBits ( const std::uint8_t  i)
inline

Reverse the bits of a given byte.

From http://graphics.stanford.edu/~seander/bithacks.html#ReverseByteWith64BitsDiv, with some reformatting into a constexpr function. The code is in the public domain.

Parameters
iThe integer value to reverse.
Returns
The integer with the bits in reverse order.
Author
Rich Schroeppel
Jeff Jackowski (changed to constexpr function)
License^^ Public domain

Definition at line 52 of file ReverseBits.hpp.

◆ SignedMagnitudeToTwosComplement()

template<unsigned B, typename T >
std::make_signed<T>::type duds::general::SignedMagnitudeToTwosComplement ( const T  x)
inline

Converts a signed magnitude value to two's complement.

Also has the effect of a sign extention on the input value.

Template Parameters
BThe number of bits used in the input. The value of x must be positioned (shifted) such that a positive value is already correct. The sign bit will be the MSb indicated by this value (1 << B). More significant bits than B bits are ignored.
TThe supplied integer type. A negative value will be properly represented in the signed variation of the type in the returned value. T may be signed or unsigned.
Parameters
xA signed magnitude value from a potentially limited number of bits that may not fill T.
Returns
The two's complement version of x that fills T. Negative zero is reported as zero. The type is always signed.
Author
Jeff Jackowski
Sean Eron Anderson (SignExtend() was used as starting point)
License^^ Public domain

Definition at line 24 of file SignedMagnitudeToTwosComplement.hpp.

◆ SignExtend()

template<unsigned B, typename T >
std::make_signed<T>::type duds::general::SignExtend ( const T  x)
inline

Performs a sign extention operation.

From http://graphics.stanford.edu/~seander/bithacks.html#FixedSignExtend, with some reformatting, a swap of the template parameters, and an update to take advantage of C++11. The code is in the public domain.

Template Parameters
BThe number of bits used in the input. The value of x must be positioned (shifted) such that a positive value is already correct.
TThe supplied integer type. A negative value will be properly represented in the signed variation of the type in the returned value. T may be signed or unsigned.
Parameters
xA signed value from a limited number of bits that does not fill T.
Returns
A sign extended version of x. The type is always signed.
Author
Sean Eron Anderson
Jeff Jackowski (used std::make_signed so T can be unsigned)
License^^ Public domain

Definition at line 24 of file SignExtend.hpp.

◆ swap()

template<class T >
void duds::general::swap ( NddArray< T > &  one,
NddArray< T > &  two 
)

Makes NddAray meet the requirements of Swappable to assist in using std::swap().

Definition at line 1211 of file NddArray.hpp.

Referenced by duds::ui::graphics::BppImage::swap(), and duds::general::NddArray< double >::swap().

◆ YieldingWait() [1/2]

template<class Duration >
void duds::general::YieldingWait ( Duration  duration)

Waits for a minumum period of time by calling std::this_thread::yield() in a loop.

This can be closer to the requested time for periods under a millisecond than calling std::this_thread::sleep_for() with the same duration when running on Linux, even on a fast computer. Calling yield prevents the wait from monopolizing a processor.

Template Parameters
DurationThe type used for the duration. It must be a variation of std::chrono::duration.
Parameters
durationThe minimum time to wait.
Author
Jeff Jackowski

Definition at line 28 of file YieldingWait.hpp.

Referenced by duds::hardware::devices::displays::HD44780::sendByte(), duds::hardware::devices::displays::ST7920::sendByte(), duds::hardware::devices::displays::HD44780::wait(), duds::hardware::devices::displays::ST7920::wait(), and YieldingWait().

◆ YieldingWait() [2/2]

void duds::general::YieldingWait ( int  nano)
inline

Waits for a minumum period of time in nanoseconds by calling std::this_thread::yield() in a loop.

This can be closer to the requested time for periods under a millisecond than calling std::this_thread::sleep_for() with the same duration when running on Linux, even on a fast computer. Calling yield prevents the wait from monopolizing a processor.

Parameters
nanoThe minimum time to wait in nanoseconds.
Author
Jeff Jackowski

Definition at line 45 of file YieldingWait.hpp.