mirror of
https://github.com/sendyne/cppreg.git
synced 2025-05-09 15:14:05 +00:00
48 lines
1.0 KiB
C++
48 lines
1.0 KiB
C++
//! Overflow check implementation.
|
|
/**
|
|
* @file Overflow.h
|
|
* @author Nicolas Clauvelin (nclauvelin@sendyne.com)
|
|
* @copyright Copyright 2010-2018 Sendyne Corp. All rights reserved.
|
|
*/
|
|
|
|
|
|
#ifndef CPPREG_OVERFLOW_H
|
|
#define CPPREG_OVERFLOW_H
|
|
|
|
|
|
#include "Traits.h"
|
|
#include <type_traits>
|
|
|
|
|
|
//! cppreg::internals namespace.
|
|
namespace cppreg {
|
|
namespace internals {
|
|
|
|
|
|
//! Overflow check implementation.
|
|
/**
|
|
* @tparam W Width of the register or field type.
|
|
* @tparam value Value to check.
|
|
* @tparam limit Overflow limit value.
|
|
*
|
|
* This structure defines a type result set to std::true_type if there is
|
|
* no overflow and set to std::false_type if there is overflow.
|
|
* There is overflow if value if strictly larger than limit.
|
|
*/
|
|
template <
|
|
Width_t W,
|
|
typename RegisterType<W>::type value,
|
|
typename RegisterType<W>::type limit
|
|
>
|
|
struct check_overflow {
|
|
using result =
|
|
typename std::integral_constant<bool, value <= limit>::type;
|
|
};
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
#endif // CPPREG_OVERFLOW_H
|