quanta 0.1.0
Type-safe units for temperature, frequency, electrical and spatial quantities, modeled after std::chrono
Loading...
Searching...
No Matches
quanta::electro::level< Reference, Rep, Precision > Class Template Reference

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

#include <quanta/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
 
level & operator= (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 level & operator+= (const offset &o)
 
constexpr level & operator-= (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 quanta::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
dbm_level< int64_t > dbm
Power level in dBm, with 1 dB precision.
Definition decibel.hpp:625
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

template<typename Reference , typename Rep , typename Precision >
using quanta::electro::level< Reference, Rep, Precision >::offset = gain<Rep, Precision>

The gain type measuring the offset from the reference.

Definition at line 223 of file decibel.hpp.

◆ precision

template<typename Reference , typename Rep , typename Precision >
using quanta::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

template<typename Reference , typename Rep , typename Precision >
using quanta::electro::level< Reference, Rep, Precision >::reference = Reference

The reference tag type.

Definition at line 217 of file decibel.hpp.

◆ rep

template<typename Reference , typename Rep , typename Precision >
using quanta::electro::level< Reference, Rep, Precision >::rep = Rep

The representation type.

Definition at line 219 of file decibel.hpp.

Constructor & Destructor Documentation

◆ level() [1/6]

template<typename Reference , typename Rep , typename Precision >
constexpr quanta::electro::level< Reference, Rep, Precision >::level ( )
constexprdefault

◆ level() [2/6]

template<typename Reference , typename Rep , typename Precision >
quanta::electro::level< Reference, Rep, Precision >::level ( const level< Reference, Rep, Precision > &  )
default

◆ level() [3/6]

template<typename Reference , typename Rep , typename Precision >
template<typename Rep2 >
requires std::convertible_to<const Rep2&, rep> && (treat_as_inexact_v<rep> || !treat_as_inexact_v<Rep2>)
constexpr quanta::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]

template<typename Reference , typename Rep , typename Precision >
constexpr quanta::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 Reference , typename Rep , typename Precision >
template<typename Rep2 , typename Precision2 >
requires std::convertible_to<gain<Rep2, Precision2>, offset>
constexpr quanta::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 Reference , typename Rep , typename Precision >
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 quanta::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()

template<typename Reference , typename Rep , typename Precision >
quanta::electro::level< Reference, Rep, Precision >::~level ( )
default

Member Function Documentation

◆ count()

template<typename Reference , typename Rep , typename Precision >
constexpr rep quanta::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.

Referenced by quanta::electro::to_string(), and quanta::electro::to_string().

◆ max()

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

Returns the maximum representable level.

Definition at line 301 of file decibel.hpp.

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

◆ min()

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

Returns the minimum representable level.

Definition at line 298 of file decibel.hpp.

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

◆ offset_from_reference()

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

◆ operator+()

template<typename Reference , typename Rep , typename Precision >
constexpr level quanta::electro::level< Reference, Rep, Precision >::operator+ ( ) const
inlineconstexpr

Definition at line 282 of file decibel.hpp.

◆ operator+=()

template<typename Reference , typename Rep , typename Precision >
constexpr level & quanta::electro::level< Reference, Rep, Precision >::operator+= ( const offset &  o)
inlineconstexpr

Definition at line 284 of file decibel.hpp.

◆ operator-()

template<typename Reference , typename Rep , typename Precision >
constexpr level quanta::electro::level< Reference, Rep, Precision >::operator- ( ) const
inlineconstexpr

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 quanta::electro::level< Reference, Rep, Precision >::level().

◆ operator-=()

template<typename Reference , typename Rep , typename Precision >
constexpr level & quanta::electro::level< Reference, Rep, Precision >::operator-= ( const offset &  o)
inlineconstexpr

Definition at line 289 of file decibel.hpp.

◆ operator=()

template<typename Reference , typename Rep , typename Precision >
level & quanta::electro::level< Reference, Rep, Precision >::operator= ( const level< Reference, Rep, Precision > &  )
default

◆ reference_level()

template<typename Reference , typename Rep , typename Precision >
static constexpr level quanta::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 quanta::electro::level< Reference, Rep, Precision >::level().


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