DynExp
Highly flexible laboratory automation for dynamically changing experiments.
Util.h File Reference

Provides general utilities within DynExp's Util namespace. More...

Go to the source code of this file.

Classes

class  Util::INonCopyable
 Interface to delete copy constructor and copy assignment operator and thus make derived classes non-copyable. More...
 
class  Util::INonMovable
 Interface to delete move constructor and move assignment operator and thus make derived classes non-movable. More...
 
class  Util::ILockable
 Interface to allow synchronizing the access to derived classes between different threads by providing a mutex and a method to lock that mutex. Recursive locking is not allowed. More...
 
class  Util::ISynchronizedPointerLockable
 Interface to allow synchronizing the access to derived classes between different threads by making the class lockable by SynchronizedPointer smart pointer objects. Recursive locking is allowed. More...
 
class  Util::SynchronizedPointer< T >
 Pointer to lock a class derived from ISynchronizedPointerLockable for synchronizing between threads. Instances of this class are not intended to be stored somewhere since they make other threads block. Only use as temporary objects. More...
 
class  Util::OneToOneNotifier
 Helper class to communicate flags between different threads based on a condition variable and a mutex. Two threads make use of the same instance of this class. One of the thread awaits a flag to be set by the other thread. More...
 
struct  Util::is_contained_in< T, ListTs >
 Checks whether a type T is contained in a template parameter pack of types ListTs. More...
 
struct  Util::member_fn_ptr_traits< ReturnT(ObjectT::*)(ArgumentTs...) const >
 Extracts the return value type, the class type the callable is member of, and the argument types of a callable type CallableT which is a member function of some class. The extracted types are stored using type aliases return_type and instance_type and an alias of a tuple of types argument_types. More...
 
struct  Util::member_fn_ptr_traits< ReturnT(ObjectT::*)(ArgumentTs...) noexcept >
 Extracts the return value type, the class type the callable is member of, and the argument types of a callable type CallableT which is a member function of some class. The extracted types are stored using type aliases return_type and instance_type and an alias of a tuple of types argument_types. More...
 
struct  Util::member_fn_ptr_traits< ReturnT(ObjectT::*)(ArgumentTs...) const noexcept >
 Extracts the return value type, the class type the callable is member of, and the argument types of a callable type CallableT which is a member function of some class. The extracted types are stored using type aliases return_type and instance_type and an alias of a tuple of types argument_types. More...
 
struct  Util::member_fn_ptr_traits< ReturnT(ObjectT::*)(ArgumentTs...)>
 Extracts the return value type, the class type the callable is member of, and the argument types of a callable type CallableT which is a member function of some class. The extracted types are stored using type aliases return_type and instance_type and an alias of a tuple of types argument_types. More...
 
struct  Util::remove_first_from_tuple< std::tuple< FirstElementT, ElementTs... > >
 Removes first type from a tuple of types TupleT. More...
 
struct  Util::OffsetIndexSequence< Offset, std::index_sequence< Indices... > >
 Holds an alias for a std::index_sequence where all indices are shifted by an offset. More...
 
struct  Util::RangeIndexSequence< From, To >
 Holds an alias for a std::index_sequence spanning a certain range. More...
 
class  Util::CallableMemberWrapper< ObjectT, CallableT >
 Wraps a member function of some object and stores its default arguments. Moving from CallableMemberWrapper does not work since this class holds const members and a reference to the object the member function is invoked on. Copy instead. More...
 
class  Util::OnDestruction< ObjectT, CallableT >
 Holds a CallableMemberWrapper and invokes its callable when being destroyed. More...
 
class  Util::BlobDataType
 Data type which manages a binary large object. The reserved memory is freed upon destruction. More...
 
class  Util::OptionalBool
 Data type which stores an optional bool value (unknown, false, true). The type evaluates to bool while an unknown value is considered false. More...
 
struct  Util::VersionType
 Data type describing DynExp's program version in the form Major.Minor.Patch. More...
 
class  Util::Warning
 Class to store information about warnings in a thread-safe manner (deriving from ILockable). All function calls are thread-safe. More...
 
struct  Util::Warning::WarningData
 Data associated with a warning. The class is convertible to bool (true if it describes an error/warning, false otherwise). More...
 
struct  Util::LogEntry
 Data type of a single entry in DynExp's log. More...
 
class  Util::EventLogger
 Logs events like errors and writes them immediately to a HTML file in a human-readable format. The logger also stores the events in an internal event log to be displayed within DynExp. The class is designed such that instances can be shared between different threads. Member function calls are synchronized. More...
 
class  Util::FeatureTester< EnumType, >
 Holds a bitset containing flags to indicate which features a certain instrument/ module etc. supports. More...
 
class  Util::StateMachineState< CallableT, >
 State machine state as used by class StateMachine. A state mainly wraps a state function of the member function pointer type CallableT to be invoked by the state machine. More...
 
class  Util::StateMachineContext< StateMachineStateT >
 State machine context as used by class StateMachine. A state machine context holds a map with keys and values of unique state identifiers of type StateEnumType (refer to class StateMachineState). Each map entry indicates a state (key) to be replaced by another state (value). StateMachine::Invoke checks the state identifiers returned by StateMachineState::Invoke and possibly replaces them according to the current context before setting the new state machine state. Contexts can be derived from base contexts unifying and including their replacement lists. More...
 
class  Util::StateMachine< StateMachineStateT >
 This class models a state machine. It keeps track of the current state and allows to invoke its associated state function. The return value of the state function determines the new state to transition into. Additionally, a context of type StateMachineContext can be assigned to the state machine. Contexts allow for replacing states with other states. This makes sense to write inner protocols BeginState -> StateA -> ... -> StateN -> EndState and to embed them into outer protocols. The outer protocol can transition into BeginState and take control back by replacing EndState with one of its own states by setting a respective context. All states (of type StateMachineState) have to be registered upon construction of the StateMachine instance. More...
 

Namespaces

 Util
 DynExp's Util namespace contains commonly used functions and templates as well as extensions to Qt and its widgets.
 

Typedefs

template<typename CallableT >
using Util::return_of_t = typename member_fn_ptr_traits< CallableT >::return_type
 Alias for the return type of a member function callable of type CallableT. More...
 
template<typename CallableT >
using Util::instance_of_t = typename member_fn_ptr_traits< CallableT >::instance_type
 Alias for the class type a member function callable of type CallableT is member of. More...
 
template<typename CallableT >
using Util::argument_of_t = typename member_fn_ptr_traits< CallableT >::argument_types
 Alias for a tuple of argument types the member function callable of type CallableT expects. More...
 
template<typename TupleT >
using Util::remove_first_from_tuple_t = typename remove_first_from_tuple< TupleT >::type
 Alias for a tuple of types where the first type of the input tuple TupleT is removed. More...
 
template<size_t Offset, typename IndexSequence >
using Util::OffsetIndexSequence_t = typename OffsetIndexSequence< Offset, IndexSequence >::type
 Alias for type contained in OffsetIndexSequence. More...
 
template<size_t From, size_t To>
using Util::RangeIndexSequence_t = typename RangeIndexSequence< From, To >::type
 Alias for type contained in RangeIndexSequence. More...
 

Functions

std::string Util::TrimTrailingZeros (const std::string &Str)
 Removes trailing zeros ('\0') from a string. More...
 
auto Util::CurrentTimeAndDateString ()
 Returns a human-readable string describing the current time and date in the current time zone. More...
 
auto Util::FilenameFromPath (std::string Path)
 Extracts the filename from a path. More...
 
auto Util::RemoveExtFromPath (std::string Path)
 Removes the filename's extension from a path. More...
 
std::strong_ordering Util::operator<=> (const VersionType &lhs, const VersionType &rhs)
 Compares two program version types with each other. More...
 
VersionType Util::VersionFromString (std::string_view Str)
 Extracts a program version from a string. More...
 
std::string Util::ToStr (const VersionType &Version)
 Converts a program version to a string in the form specified by VersionType. More...
 
template<typename... Ts>
std::vector< std::tuple< Ts... > > Util::ParseCSV (const std::string &CSVData, const char Delimiter=';', const size_t SkipLines=0)
 Parses a string containing comma-separated values (csv) and inserts each row as one tuple containing column data into a vector of tuples. More...
 
std::string Util::ExceptionToStr (const std::exception_ptr ExceptionPtr)
 Returns the what() information of an exception derived from std::exception and stored in an exception pointer. More...
 
std::string Util::ToLower (std::string_view Str)
 Transforms a string into lower case. More...
 
std::vector< std::complex< double > > Util::FFT (const std::vector< std::complex< double >> &Data, bool InverseTransform=false)
 Computes the Fast Fourier Transform (FFT) a vector of complex values. More...
 
EventLogger & Util::EventLog ()
 This function holds a static EventLogger instance and returns a reference to it. DynExp uses only one EventLogger instance to log events from any thread. A local static object instead of a global object is employed to avoid initialization order problems. More...
 

Variables

template<typename T , typename... ListTs>
constexpr bool Util::is_contained_in_v = is_contained_in<T, ListTs...>::value
 Value type of is_contained_in. More...
 

Conversion functions

These functions can be used to convert between different number and string types.

using Util::seconds = std::chrono::duration< double >
 Extends std::chrono by a duration data type for seconds capable of storing fractions of seconds. More...
 
using Util::picoseconds = std::chrono::duration< double, std::pico >
 Extends std::chrono by a duration data type for picoseconds. More...
 
template<typename T >
std::ostream & Util::operator<< (std::ostream &stream, const std::chrono::time_point< T > &TimePoint)
 Formats a time point to a human-readable string describing the time in the current time zone and writes the string to a stream. More...
 
template<typename T >
Util::StrToT (const std::string &String)
 Converts a std::string to a value of type T using operator<< of std::stringstream. More...
 
template<typename T >
std::string Util::ToStr (const T &Value, int Precision=-1)
 Converts a (numeric) value of type T to a std::string using operator<< of std::stringstream. More...
 
template<typename T >
std::string Util::ToStr (const std::chrono::time_point< T > &TimePoint)
 Converts a time point to a human-readable string describing the time in the current time zone. More...
 
std::string Util::ToStr (const char Value)
 Converts Value to a std::string using operator<< of std::stringstream. More...
 
std::string Util::ToStr (const uint8_t Value)
 Converts Value to a std::string using operator<< of std::stringstream. More...
 
std::string Util::ToStr (const QString &Str)
 Converts the Qt QString Str to a std::string. More...
 
template<typename ToT , typename FromT , std::enable_if_t< std::is_integral_v< ToT > &&std::is_integral_v< FromT > &&std::is_same_v< std::remove_cv_t< ToT >, std::remove_cv_t< FromT >>, int > = 0>
ToT Util::NumToT (const FromT Value)
 Converts a value of a numeric type to a value of another numeric type checking the conversion for its bounds. More...
 
template<typename ToT , std::enable_if_t< std::is_integral_v< ToT > &&!std::is_same_v< std::remove_cv_t< ToT >, double >, int > = 0>
ToT Util::NumToT (const double Value)
 Converts a value of a numeric type to a value of another numeric type checking the conversion for its bounds. More...
 
template<typename T >
std::string Util::ToUnitStr ()
 Returns a string describing the physical unit associated with type T. For example, if T is std::chrono::milliseconds, the function returns the string "ms". More...
 
template<>
std::string Util::ToUnitStr< std::chrono::seconds > ()
 Returns a string describing the physical unit associated with type T. For example, if T is std::chrono::milliseconds, the function returns the string "ms". More...
 
template<>
std::string Util::ToUnitStr< std::chrono::milliseconds > ()
 Returns a string describing the physical unit associated with type T. For example, if T is std::chrono::milliseconds, the function returns the string "ms". More...
 
template<>
std::string Util::ToUnitStr< std::chrono::microseconds > ()
 Returns a string describing the physical unit associated with type T. For example, if T is std::chrono::milliseconds, the function returns the string "ms". More...
 
template<>
std::string Util::ToUnitStr< std::chrono::nanoseconds > ()
 Returns a string describing the physical unit associated with type T. For example, if T is std::chrono::milliseconds, the function returns the string "ms". More...
 
template<>
std::string Util::ToUnitStr< seconds > ()
 Returns a string describing the physical unit associated with type T. For example, if T is std::chrono::milliseconds, the function returns the string "ms". More...
 
template<>
std::string Util::ToUnitStr< picoseconds > ()
 Returns a string describing the physical unit associated with type T. For example, if T is std::chrono::milliseconds, the function returns the string "ms". More...
 

Detailed Description

Provides general utilities within DynExp's Util namespace.

Definition in file Util.h.


Class Documentation

◆ Util::member_fn_ptr_traits< ReturnT(ObjectT::*)(ArgumentTs...) const >

struct Util::member_fn_ptr_traits< ReturnT(ObjectT::*)(ArgumentTs...) const >

template<typename ReturnT, typename ObjectT, typename... ArgumentTs>
struct Util::member_fn_ptr_traits< ReturnT(ObjectT::*)(ArgumentTs...) const >

Extracts the return value type, the class type the callable is member of, and the argument types of a callable type CallableT which is a member function of some class. The extracted types are stored using type aliases return_type and instance_type and an alias of a tuple of types argument_types.

Definition at line 318 of file Util.h.

Class Members
argument_types
typedef ObjectT instance_type
typedef ReturnT return_type

◆ Util::member_fn_ptr_traits< ReturnT(ObjectT::*)(ArgumentTs...) noexcept >

struct Util::member_fn_ptr_traits< ReturnT(ObjectT::*)(ArgumentTs...) noexcept >

template<typename ReturnT, typename ObjectT, typename... ArgumentTs>
struct Util::member_fn_ptr_traits< ReturnT(ObjectT::*)(ArgumentTs...) noexcept >

Extracts the return value type, the class type the callable is member of, and the argument types of a callable type CallableT which is a member function of some class. The extracted types are stored using type aliases return_type and instance_type and an alias of a tuple of types argument_types.

Definition at line 329 of file Util.h.

Class Members
argument_types
typedef ObjectT instance_type
typedef ReturnT return_type

◆ Util::member_fn_ptr_traits< ReturnT(ObjectT::*)(ArgumentTs...) const noexcept >

struct Util::member_fn_ptr_traits< ReturnT(ObjectT::*)(ArgumentTs...) const noexcept >

template<typename ReturnT, typename ObjectT, typename... ArgumentTs>
struct Util::member_fn_ptr_traits< ReturnT(ObjectT::*)(ArgumentTs...) const noexcept >

Extracts the return value type, the class type the callable is member of, and the argument types of a callable type CallableT which is a member function of some class. The extracted types are stored using type aliases return_type and instance_type and an alias of a tuple of types argument_types.

Definition at line 340 of file Util.h.

Class Members
argument_types
typedef ObjectT instance_type
typedef ReturnT return_type

◆ Util::member_fn_ptr_traits< ReturnT(ObjectT::*)(ArgumentTs...)>

struct Util::member_fn_ptr_traits< ReturnT(ObjectT::*)(ArgumentTs...)>

template<typename ReturnT, typename ObjectT, typename... ArgumentTs>
struct Util::member_fn_ptr_traits< ReturnT(ObjectT::*)(ArgumentTs...)>

Extracts the return value type, the class type the callable is member of, and the argument types of a callable type CallableT which is a member function of some class. The extracted types are stored using type aliases return_type and instance_type and an alias of a tuple of types argument_types.

Definition at line 351 of file Util.h.

Class Members
argument_types
typedef ObjectT instance_type
typedef ReturnT return_type

◆ Util::remove_first_from_tuple< std::tuple< FirstElementT, ElementTs... > >

struct Util::remove_first_from_tuple< std::tuple< FirstElementT, ElementTs... > >

template<typename FirstElementT, typename... ElementTs>
struct Util::remove_first_from_tuple< std::tuple< FirstElementT, ElementTs... > >

Removes first type from a tuple of types TupleT.

Definition at line 386 of file Util.h.

Class Members
type

◆ Util::OffsetIndexSequence< Offset, std::index_sequence< Indices... > >

struct Util::OffsetIndexSequence< Offset, std::index_sequence< Indices... > >

template<size_t Offset, size_t... Indices>
struct Util::OffsetIndexSequence< Offset, std::index_sequence< Indices... > >

Holds an alias for a std::index_sequence where all indices are shifted by an offset.

Template Parameters
IndexSequenceIndices passes as template arguments to std::index_sequence
OffsetOffset added to all indices

Definition at line 408 of file Util.h.

Class Members
type Alias for offset index sequence.

◆ Util::RangeIndexSequence

struct Util::RangeIndexSequence

template<size_t From, size_t To>
struct Util::RangeIndexSequence< From, To >

Holds an alias for a std::index_sequence spanning a certain range.

Template Parameters
FromStart value the index sequency begins with
ToLast value contained in the index sequence

Definition at line 428 of file Util.h.

Class Members
typedef OffsetIndexSequence_t< From, make_index_sequence< To - From > > type

◆ Util::VersionType

struct Util::VersionType

Data type describing DynExp's program version in the form Major.Minor.Patch.

Definition at line 858 of file Util.h.

Class Members
unsigned int Major
unsigned int Minor
unsigned int Patch