mirror of
https://github.com/cookiengineer/audacity
synced 2025-10-20 17:41:13 +02:00
Hide implicit conversions sampleCount <-> floating point, -> integer
This commit is contained in:
@@ -63,12 +63,24 @@ public:
|
|||||||
static_assert(sizeof(type) == 8, "Wrong width of sampleCount");
|
static_assert(sizeof(type) == 8, "Wrong width of sampleCount");
|
||||||
|
|
||||||
sampleCount () : value { 0 } {}
|
sampleCount () : value { 0 } {}
|
||||||
|
|
||||||
|
// Allow implicit conversion from integral types
|
||||||
sampleCount ( type v ) : value { v } {}
|
sampleCount ( type v ) : value { v } {}
|
||||||
|
sampleCount ( unsigned long long v ) : value ( v ) {}
|
||||||
|
sampleCount ( int v ) : value { v } {}
|
||||||
|
sampleCount ( unsigned v ) : value { v } {}
|
||||||
|
sampleCount ( long v ) : value { v } {}
|
||||||
|
sampleCount ( unsigned long v ) : value { v } {}
|
||||||
|
|
||||||
|
// Beware implicit conversions from floating point values!
|
||||||
|
// Otherwise the meaning of binary operators with sampleCount change
|
||||||
|
// their meaning when sampleCount is not an alias!
|
||||||
|
explicit sampleCount ( float f ) : value ( f ) {}
|
||||||
|
explicit sampleCount ( double d ) : value ( d ) {}
|
||||||
|
|
||||||
sampleCount ( const sampleCount& ) = default;
|
sampleCount ( const sampleCount& ) = default;
|
||||||
sampleCount &operator= ( const sampleCount& ) = default;
|
sampleCount &operator= ( const sampleCount& ) = default;
|
||||||
|
|
||||||
operator type () const { return value; }
|
|
||||||
|
|
||||||
float as_float() const { return value; }
|
float as_float() const { return value; }
|
||||||
double as_double() const { return value; }
|
double as_double() const { return value; }
|
||||||
|
|
||||||
@@ -86,6 +98,8 @@ public:
|
|||||||
sampleCount &operator /= (sampleCount b) { value /= b.value; return *this; }
|
sampleCount &operator /= (sampleCount b) { value /= b.value; return *this; }
|
||||||
sampleCount &operator %= (sampleCount b) { value %= b.value; return *this; }
|
sampleCount &operator %= (sampleCount b) { value %= b.value; return *this; }
|
||||||
|
|
||||||
|
sampleCount operator - () const { return -value; }
|
||||||
|
|
||||||
sampleCount &operator ++ () { ++value; return *this; }
|
sampleCount &operator ++ () { ++value; return *this; }
|
||||||
sampleCount operator ++ (int)
|
sampleCount operator ++ (int)
|
||||||
{ sampleCount result{ *this }; ++value; return result; }
|
{ sampleCount result{ *this }; ++value; return result; }
|
||||||
@@ -98,220 +112,60 @@ private:
|
|||||||
type value;
|
type value;
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace std
|
inline bool operator == (sampleCount a, sampleCount b)
|
||||||
{
|
{
|
||||||
inline sampleCount min (sampleCount a, sampleCount b)
|
return a.as_long_long() == b.as_long_long();
|
||||||
{
|
|
||||||
return a < b ? a : b;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline sampleCount max (sampleCount a, sampleCount b)
|
|
||||||
{
|
|
||||||
return a > b ? a : b;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline
|
inline bool operator != (sampleCount a, sampleCount b)
|
||||||
sampleCount operator + (sampleCount a, sampleCount b)
|
{
|
||||||
{ return (long long)a + (long long)b; }
|
return !(a == b);
|
||||||
|
}
|
||||||
|
|
||||||
inline
|
inline bool operator < (sampleCount a, sampleCount b)
|
||||||
sampleCount operator + (sampleCount a, size_t b)
|
{
|
||||||
{ return (long long)a + b; }
|
return a.as_long_long() < b.as_long_long();
|
||||||
|
}
|
||||||
|
|
||||||
inline
|
inline bool operator >= (sampleCount a, sampleCount b)
|
||||||
sampleCount operator + (size_t a, sampleCount b)
|
{
|
||||||
{ return a + (long long)b; }
|
return !(a < b);
|
||||||
|
}
|
||||||
|
|
||||||
inline
|
inline bool operator > (sampleCount a, sampleCount b)
|
||||||
sampleCount operator + (sampleCount a, int b)
|
{
|
||||||
{ return (long long)a + b; }
|
return b < a;
|
||||||
|
}
|
||||||
|
|
||||||
inline
|
inline bool operator <= (sampleCount a, sampleCount b)
|
||||||
sampleCount operator + (int a, sampleCount b)
|
{
|
||||||
{ return a + (long long)b; }
|
return !(b < a);
|
||||||
|
}
|
||||||
|
|
||||||
inline
|
inline sampleCount operator + (sampleCount a, sampleCount b)
|
||||||
sampleCount operator + (sampleCount a, long b)
|
{
|
||||||
{ return (long long)a + b; }
|
return sampleCount{ a } += b;
|
||||||
|
}
|
||||||
|
|
||||||
inline
|
inline sampleCount operator - (sampleCount a, sampleCount b)
|
||||||
sampleCount operator + (long a, sampleCount b)
|
{
|
||||||
{ return a + (long long)b; }
|
return sampleCount{ a } -= b;
|
||||||
|
}
|
||||||
|
|
||||||
inline
|
inline sampleCount operator * (sampleCount a, sampleCount b)
|
||||||
sampleCount operator + (sampleCount a, long long b)
|
{
|
||||||
{ return (long long)a + b; }
|
return sampleCount{ a } *= b;
|
||||||
|
}
|
||||||
|
|
||||||
inline
|
inline sampleCount operator / (sampleCount a, sampleCount b)
|
||||||
sampleCount operator + (long long a, sampleCount b)
|
{
|
||||||
{ return a + (long long)b; }
|
return sampleCount{ a } /= b;
|
||||||
|
}
|
||||||
|
|
||||||
inline
|
inline sampleCount operator % (sampleCount a, sampleCount b)
|
||||||
sampleCount operator + (sampleCount a, unsigned b)
|
{
|
||||||
{ return (long long)a + b; }
|
return sampleCount{ a } %= b;
|
||||||
|
}
|
||||||
inline
|
|
||||||
sampleCount operator + (unsigned a, sampleCount b)
|
|
||||||
{ return a + (long long)b; }
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
inline
|
|
||||||
sampleCount operator - (sampleCount a, sampleCount b)
|
|
||||||
{ return (long long)a - (long long)b; }
|
|
||||||
|
|
||||||
inline
|
|
||||||
sampleCount operator - (sampleCount a, size_t b)
|
|
||||||
{ return (long long)a - b; }
|
|
||||||
|
|
||||||
inline
|
|
||||||
sampleCount operator - (size_t a, sampleCount b)
|
|
||||||
{ return a - (long long)b; }
|
|
||||||
|
|
||||||
inline
|
|
||||||
sampleCount operator - (sampleCount a, int b)
|
|
||||||
{ return(long long) a - b; }
|
|
||||||
|
|
||||||
inline
|
|
||||||
sampleCount operator - (int a, sampleCount b)
|
|
||||||
{ return a - (long long)b; }
|
|
||||||
|
|
||||||
inline
|
|
||||||
sampleCount operator - (sampleCount a, long b)
|
|
||||||
{ return (long long)a - b; }
|
|
||||||
|
|
||||||
inline
|
|
||||||
sampleCount operator - (long a, sampleCount b)
|
|
||||||
{ return a - (long long)b; }
|
|
||||||
|
|
||||||
inline
|
|
||||||
sampleCount operator - (sampleCount a, long long b)
|
|
||||||
{ return (long long)a - b; }
|
|
||||||
|
|
||||||
inline
|
|
||||||
sampleCount operator - (long long a, sampleCount b)
|
|
||||||
{ return a - (long long)b; }
|
|
||||||
|
|
||||||
inline
|
|
||||||
sampleCount operator - (sampleCount a, unsigned b)
|
|
||||||
{ return (long long)a - b; }
|
|
||||||
|
|
||||||
inline
|
|
||||||
sampleCount operator - (unsigned a, sampleCount b)
|
|
||||||
{ return a - (long long)b; }
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
inline
|
|
||||||
sampleCount operator * (sampleCount a, sampleCount b)
|
|
||||||
{ return (long long)a * (long long)b; }
|
|
||||||
|
|
||||||
inline
|
|
||||||
sampleCount operator * (sampleCount a, int b)
|
|
||||||
{ return (long long)a * b; }
|
|
||||||
|
|
||||||
inline
|
|
||||||
sampleCount operator * (int a, sampleCount b)
|
|
||||||
{ return a * (long long)b; }
|
|
||||||
|
|
||||||
inline
|
|
||||||
sampleCount operator * (sampleCount a, unsigned b)
|
|
||||||
{ return (long long)a * b; }
|
|
||||||
|
|
||||||
inline
|
|
||||||
sampleCount operator * (unsigned a, sampleCount b)
|
|
||||||
{ return a * (long long)b; }
|
|
||||||
|
|
||||||
inline
|
|
||||||
sampleCount operator * (sampleCount a, long b)
|
|
||||||
{ return (long long)a * b; }
|
|
||||||
|
|
||||||
inline
|
|
||||||
sampleCount operator * (long a, sampleCount b)
|
|
||||||
{ return a * (long long)b; }
|
|
||||||
|
|
||||||
inline
|
|
||||||
sampleCount operator * (sampleCount a, unsigned long b)
|
|
||||||
{ return (long long)a * b; }
|
|
||||||
|
|
||||||
inline
|
|
||||||
sampleCount operator * (unsigned long a, sampleCount b)
|
|
||||||
{ return a * (long long)b; }
|
|
||||||
|
|
||||||
inline
|
|
||||||
sampleCount operator * (sampleCount a, long long b)
|
|
||||||
{ return (long long)a * b; }
|
|
||||||
|
|
||||||
inline
|
|
||||||
sampleCount operator * (long long a, sampleCount b)
|
|
||||||
{ return a * (long long)b; }
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
inline
|
|
||||||
sampleCount operator / (sampleCount a, sampleCount b)
|
|
||||||
{ return (long long)a / (long long)b; }
|
|
||||||
|
|
||||||
inline
|
|
||||||
sampleCount operator / (sampleCount a, int b)
|
|
||||||
{ return (long long)a / b; }
|
|
||||||
|
|
||||||
inline
|
|
||||||
sampleCount operator / (sampleCount a, size_t b)
|
|
||||||
{ return (long long)a / b; }
|
|
||||||
|
|
||||||
inline
|
|
||||||
double operator / (sampleCount a, double b)
|
|
||||||
{ return (long long)a / b; }
|
|
||||||
|
|
||||||
inline
|
|
||||||
float operator / (float a, sampleCount b)
|
|
||||||
{ return a / (long long)b; }
|
|
||||||
|
|
||||||
inline
|
|
||||||
double operator / (double a, sampleCount b)
|
|
||||||
{ return a / (long long)b; }
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
inline
|
|
||||||
double operator + (sampleCount a, double b)
|
|
||||||
{ return (long long)a + b; }
|
|
||||||
|
|
||||||
inline
|
|
||||||
double operator + (double a, sampleCount b)
|
|
||||||
{ return a + (long long)b; }
|
|
||||||
|
|
||||||
inline
|
|
||||||
double operator - (sampleCount a, double b)
|
|
||||||
{ return (long long)a - b; }
|
|
||||||
|
|
||||||
inline
|
|
||||||
double operator - (double a, sampleCount b)
|
|
||||||
{ return a - (long long)b; }
|
|
||||||
|
|
||||||
inline
|
|
||||||
double operator * (sampleCount a, double b)
|
|
||||||
{ return (long long)a * b; }
|
|
||||||
|
|
||||||
inline
|
|
||||||
double operator * (double a, sampleCount b)
|
|
||||||
{ return a * (long long)b; }
|
|
||||||
|
|
||||||
|
|
||||||
inline
|
|
||||||
float operator - (float a, sampleCount b)
|
|
||||||
{ return a - (long long)b; }
|
|
||||||
|
|
||||||
inline
|
|
||||||
float operator * (float a, sampleCount b)
|
|
||||||
{ return a * (long long)b; }
|
|
||||||
|
|
||||||
inline
|
|
||||||
float operator * (sampleCount a, float b)
|
|
||||||
{ return (long long)a * b; }
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// Function returning the minimum of a sampleCount and a size_t,
|
// Function returning the minimum of a sampleCount and a size_t,
|
||||||
@@ -320,9 +174,9 @@ float operator * (sampleCount a, float b)
|
|||||||
|
|
||||||
inline size_t limitSampleBufferSize( size_t bufferSize, sampleCount limit )
|
inline size_t limitSampleBufferSize( size_t bufferSize, sampleCount limit )
|
||||||
{
|
{
|
||||||
return static_cast<size_t> (
|
return
|
||||||
std::min( sampleCount( bufferSize ), std::max( sampleCount(0), limit ) )
|
std::min( sampleCount( bufferSize ), std::max( sampleCount(0), limit ) )
|
||||||
);
|
.as_size_t();
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
Reference in New Issue
Block a user