electro 0.3.0
Type-safe electrical units library modeled after std::chrono
Loading...
Searching...
No Matches
electro::level< Reference, Rep, Precision > Class Template Reference

An absolute point on a logarithmic scale, relative to a reference. More...

#include <electro/decibel.hpp>

Public Types

using reference = Reference
 The reference tag type.
 
using rep = Rep
 The representation type.
 
using precision = typename Precision::type
 The offset precision, in dB, as a std::ratio.
 
using offset = gain< Rep, Precision >
 The gain type measuring the offset from the reference.
 

Public Member Functions

constexpr level ()=default
 Constructs a level at the reference point (0 dB offset).
 
 level (const level &)=default
 
template<typename Rep2 >
requires std::convertible_to<const Rep2&, rep> && (treat_as_inexact_v<rep> || !treat_as_inexact_v<Rep2>)
constexpr level (const Rep2 &r)
 Constructs from an offset count in dB.
 
constexpr level (const offset &o)
 Constructs from an offset relative to the reference.
 
template<typename Rep2 , typename Precision2 >
requires std::convertible_to<gain<Rep2, Precision2>, offset>
constexpr level (const level< Reference, Rep2, Precision2 > &l)
 Converts from a level with the same reference.
 
template<typename Rep2 , typename Precision2 >
requires (!std::is_same_v<level, level<Reference, Rep2, Precision2>>) && (!std::convertible_to<gain<Rep2, Precision2>, offset>) && std::constructible_from<offset, gain<Rep2, Precision2>>
constexpr level (const level< Reference, Rep2, Precision2 > &l)
 Explicit constructor for lossy precision conversions.
 
 ~level ()=default
 
leveloperator= (const level &)=default
 
constexpr offset offset_from_reference () const
 Returns the offset from the reference point.
 
constexpr rep count () const
 Returns the raw offset count, in units of Precision.
 
constexpr level operator- () const
 Reflects the level about its reference point.
 
constexpr level operator+ () const
 
constexpr leveloperator+= (const offset &o)
 
constexpr leveloperator-= (const offset &o)
 

Static Public Member Functions

static constexpr level reference_level () noexcept
 Returns the reference point itself (a 0 dB offset).
 
static constexpr level min () noexcept
 Returns the minimum representable level.
 
static constexpr level max () noexcept
 Returns the maximum representable level.
 

Detailed Description

template<typename Reference, typename Rep, typename Precision>
class electro::level< Reference, Rep, Precision >

An absolute point on a logarithmic scale, relative to a reference.

The time_point analog: a level plus or minus a gain is a level, and the difference of two levels is a gain. Adding two levels, or scaling a level by a scalar, is deliberately ill-formed.

dbm signal{-73}; // -73 dBm
auto amplified = signal + 20_dB; // -53 dBm
auto delta = amplified - signal; // 20 dB
An absolute point on a logarithmic scale, relative to a reference.
Definition decibel.hpp:212
constexpr bool treat_as_inexact_v
Definition electro.hpp:162
Template Parameters
ReferenceThe reference tag (milliwatt_reference, ...).
RepArithmetic type for the offset count.
PrecisionA std::ratio giving the offset precision, in dB.

Definition at line 212 of file decibel.hpp.

Member Typedef Documentation

◆ offset

The gain type measuring the offset from the reference.

Definition at line 223 of file decibel.hpp.

◆ precision

using electro::level< Reference, Rep, Precision >::precision = typename Precision::type

The offset precision, in dB, as a std::ratio.

Definition at line 221 of file decibel.hpp.

◆ reference

The reference tag type.

Definition at line 217 of file decibel.hpp.

◆ rep

The representation type.

Definition at line 219 of file decibel.hpp.

Constructor & Destructor Documentation

◆ level() [1/6]

◆ level() [2/6]

◆ level() [3/6]

template<typename Rep2 >
requires std::convertible_to<const Rep2&, rep> && (treat_as_inexact_v<rep> || !treat_as_inexact_v<Rep2>)
constexpr electro::level< Reference, Rep, Precision >::level ( const Rep2 r)
inlineexplicitconstexpr

Constructs from an offset count in dB.

Always explicit: a bare number is not a level.

Template Parameters
Rep2The source representation type.
Parameters
rThe offset from the reference, in units of Precision.

Definition at line 239 of file decibel.hpp.

◆ level() [4/6]

constexpr electro::level< Reference, Rep, Precision >::level ( const offset o)
inlineexplicitconstexpr

Constructs from an offset relative to the reference.

Definition at line 243 of file decibel.hpp.

◆ level() [5/6]

template<typename Rep2 , typename Precision2 >
requires std::convertible_to<gain<Rep2, Precision2>, offset>
constexpr electro::level< Reference, Rep, Precision >::level ( const level< Reference, Rep2, Precision2 > &  l)
inlineconstexpr

Converts from a level with the same reference.

Implicit when the conversion is lossless, mirroring quantity.

Definition at line 253 of file decibel.hpp.

◆ level() [6/6]

template<typename Rep2 , typename Precision2 >
requires (!std::is_same_v<level, level<Reference, Rep2, Precision2>>) && (!std::convertible_to<gain<Rep2, Precision2>, offset>) && std::constructible_from<offset, gain<Rep2, Precision2>>
constexpr electro::level< Reference, Rep, Precision >::level ( const level< Reference, Rep2, Precision2 > &  l)
inlineexplicitconstexpr

Explicit constructor for lossy precision conversions.

Definition at line 261 of file decibel.hpp.

◆ ~level()

Member Function Documentation

◆ count()

constexpr rep electro::level< Reference, Rep, Precision >::count ( ) const
inlineconstexpr

Returns the raw offset count, in units of Precision.

Definition at line 271 of file decibel.hpp.

References electro::quantity< Unit, Rep, Precision >::count().

◆ max()

static constexpr level electro::level< Reference, Rep, Precision >::max ( )
inlinestaticconstexprnoexcept

Returns the maximum representable level.

Definition at line 301 of file decibel.hpp.

References electro::level< Reference, Rep, Precision >::level(), and electro::quantity< Unit, Rep, Precision >::max().

◆ min()

static constexpr level electro::level< Reference, Rep, Precision >::min ( )
inlinestaticconstexprnoexcept

Returns the minimum representable level.

Definition at line 298 of file decibel.hpp.

References electro::level< Reference, Rep, Precision >::level(), and electro::quantity< Unit, Rep, Precision >::min().

◆ offset_from_reference()

constexpr offset electro::level< Reference, Rep, Precision >::offset_from_reference ( ) const
inlineconstexpr

Returns the offset from the reference point.

Definition at line 268 of file decibel.hpp.

◆ operator+()

Definition at line 282 of file decibel.hpp.

◆ operator+=()

Definition at line 284 of file decibel.hpp.

References electro::treat_as_inexact_v.

◆ operator-()

Reflects the level about its reference point.

Provided so that negative literals such as -73_dBm parse. Note that std::chrono::time_point offers no such operator; a level is an absolute point, and negating one is only meaningful as "the same magnitude of offset, on the other side of the reference".

Definition at line 281 of file decibel.hpp.

References electro::level< Reference, Rep, Precision >::level().

◆ operator-=()

Definition at line 289 of file decibel.hpp.

References electro::treat_as_inexact_v.

◆ operator=()

◆ reference_level()

static constexpr level electro::level< Reference, Rep, Precision >::reference_level ( )
inlinestaticconstexprnoexcept

Returns the reference point itself (a 0 dB offset).

Definition at line 295 of file decibel.hpp.

References electro::level< Reference, Rep, Precision >::level(), and electro::quantity< Unit, Rep, Precision >::zero().


The documentation for this class was generated from the following file: