1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-12-27 16:31:31 +00:00

Although duplicative, resolves function redefinition.

This commit is contained in:
Thomas Harte 2019-07-29 22:49:02 -04:00
parent eb3fb70ea1
commit bc25c52683

View File

@ -48,16 +48,6 @@
*/ */
namespace {
template <typename Source, typename Target> Target flush(int &value) {
const Target result = Source(value);
value = 0;
return result;
}
}
/*! /*!
Provides a class that wraps a plain int, providing most of the basic arithmetic and Provides a class that wraps a plain int, providing most of the basic arithmetic and
Boolean operators, but forcing callers and receivers to be explicit as to usage. Boolean operators, but forcing callers and receivers to be explicit as to usage.
@ -155,14 +145,6 @@ template <class T> class WrappedInt {
return result; return result;
} }
/*!
Flushes the value in @c this. The current value is returned, and the internal value
is reset to zero.
*/
template <typename Target> forceinline Target flush() {
return ::flush<T, Target>(length_);
}
// operator int() is deliberately not provided, to avoid accidental subtitution of // operator int() is deliberately not provided, to avoid accidental subtitution of
// classes that use this template. // classes that use this template.
@ -176,6 +158,16 @@ class Cycles: public WrappedInt<Cycles> {
forceinline constexpr Cycles(int l) noexcept : WrappedInt<Cycles>(l) {} forceinline constexpr Cycles(int l) noexcept : WrappedInt<Cycles>(l) {}
forceinline constexpr Cycles() noexcept : WrappedInt<Cycles>() {} forceinline constexpr Cycles() noexcept : WrappedInt<Cycles>() {}
forceinline constexpr Cycles(const Cycles &cycles) noexcept : WrappedInt<Cycles>(cycles.length_) {} forceinline constexpr Cycles(const Cycles &cycles) noexcept : WrappedInt<Cycles>(cycles.length_) {}
/*!
Flushes the value in @c this. The current value is returned, and the internal value
is reset to zero.
*/
template <typename T> T flush() {
const T result(*this);
length_ = 0;
return result;
}
}; };
/// Describes an integer number of half cycles: single clock signal transitions. /// Describes an integer number of half cycles: single clock signal transitions.
@ -192,6 +184,22 @@ class HalfCycles: public WrappedInt<HalfCycles> {
return Cycles(length_ >> 1); return Cycles(length_ >> 1);
} }
/*!
Flushes the value in @c this. The current value is returned, and the internal value
is reset to zero.
*/
template <typename T> T flush() {
const T result(*this);
length_ = 0;
return result;
}
template <> Cycles flush() {
const Cycles result(length_ >> 1);
length_ &= 1;
return result;
}
/*! /*!
Severs from @c this the effect of dividing by @c divisor; @c this will end up with Severs from @c this the effect of dividing by @c divisor; @c this will end up with
the value of @c this modulo @c divisor and @c divided by @c divisor is returned. the value of @c this modulo @c divisor and @c divided by @c divisor is returned.
@ -204,16 +212,6 @@ class HalfCycles: public WrappedInt<HalfCycles> {
} }
}; };
namespace {
template <> Cycles flush<HalfCycles, Cycles>(int &value) {
const Cycles result(value >> 1);
value &= 1;
return result;
}
}
// Create a specialisation of WrappedInt::flush for converting HalfCycles to Cycles // Create a specialisation of WrappedInt::flush for converting HalfCycles to Cycles
// without losing the fractional part. // without losing the fractional part.