1
0
mirror of https://github.com/sendyne/cppreg.git synced 2025-05-09 23:24:05 +00:00
cppreg/register/Traits.h
Nicolas Clauvelin c1081a114e Code maintenance
* Revise and simplify most enable_if statements in the project.
* Update code style in all files.
* Update copyright year.
* Add a dedicated Memory.h header with the memory device implementation.
* Update documentation.
* CMake cleanup.
2019-04-24 17:00:57 -04:00

70 lines
1.5 KiB
C++

//! Register traits implementation.
/**
* @file Traits.h
* @author Nicolas Clauvelin (nclauvelin@sendyne.com)
* @copyright Copyright 2010-2019 Sendyne Corp. All rights reserved.
*
* This header provides some traits for register type instantiation.
*/
#ifndef CPPREG_TRAITS_H
#define CPPREG_TRAITS_H
#include "cppreg_Defines.h"
namespace cppreg {
//! Register type traits based on size.
/**
* @tparam S Register size in bits.
*/
template <RegBitSize S>
struct TypeTraits {};
//!@{ TypeTraits specializations.
//! 8-bit specialization.
template <>
struct TypeTraits<RegBitSize::b8> {
using type = std::uint8_t;
constexpr static auto bit_size = std::uint8_t{8};
constexpr static auto byte_size = std::uint8_t{bit_size / 8};
};
//! 16-bit specialization.
template <>
struct TypeTraits<RegBitSize::b16> {
using type = std::uint16_t;
constexpr static auto bit_size = std::uint8_t{16};
constexpr static auto byte_size = std::uint8_t{bit_size / 8};
};
//! 32-bit specialization.
template <>
struct TypeTraits<RegBitSize::b32> {
using type = std::uint32_t;
constexpr static auto bit_size = std::uint8_t{32};
constexpr static auto byte_size = std::uint8_t{bit_size / 8};
};
//! 64-bit specialization.
template <>
struct TypeTraits<RegBitSize::b64> {
using type = std::uint64_t;
constexpr static auto bit_size = std::uint8_t{64};
constexpr static auto byte_size = std::uint8_t{bit_size / 8};
};
//!@}
} // namespace cppreg
#endif // CPPREG_TRAITS_H