diff options
author | Gabe Black <gabeblack@google.com> | 2018-01-07 18:38:04 -0800 |
---|---|---|
committer | Gabe Black <gabeblack@google.com> | 2018-01-20 07:29:56 +0000 |
commit | 0d56fdef7a60691c59e1782a5c5c0a532dcdeeea (patch) | |
tree | b78c0df7f4865944fe45d2120e4f3a5f66f0f501 /src/base/bitunion.hh | |
parent | cd9450c1d95d9494e2714ec84620c548b0eebbb1 (diff) | |
download | gem5-0d56fdef7a60691c59e1782a5c5c0a532dcdeeea.tar.xz |
base: Enable specializing templates on BitUnion types.
Previously these relied on reaching into private internal definitions
in the BitUnion types.
Change-Id: Ia6c94de92986b85ec9e5fcb197459d450111fb36
Reviewed-on: https://gem5-review.googlesource.com/7202
Reviewed-by: Jason Lowe-Power <jason@lowepower.com>
Maintainer: Gabe Black <gabeblack@google.com>
Diffstat (limited to 'src/base/bitunion.hh')
-rw-r--r-- | src/base/bitunion.hh | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/base/bitunion.hh b/src/base/bitunion.hh index 1715e34d6..718a06838 100644 --- a/src/base/bitunion.hh +++ b/src/base/bitunion.hh @@ -351,4 +351,41 @@ namespace BitfieldBackend #define BitUnion16(name) __BitUnion(uint16_t, name) #define BitUnion8(name) __BitUnion(uint8_t, name) + +//These templates make it possible to define other templates related to +//BitUnions without having to refer to internal typedefs or the BitfieldBackend +//namespace. + +//To build a template specialization which works for all BitUnions, accept a +//template argument T, and then use BitUnionType<T> as an argument in the +//template. To refer to the basic type the BitUnion wraps, use +//BitUnionBaseType<T>. + +//For example: +//template <typename T> +//void func(BitUnionType<T> u) { BitUnionBaseType<T> b = u; } + +//Also, BitUnionBaseType can be used on a BitUnion type directly. + +template <typename T> +using BitUnionType = BitfieldBackend::BitUnionOperators<T>; + +namespace BitfieldBackend +{ + template<typename T> + struct BitUnionBaseType + { + typedef typename BitUnionType<T>::__StorageType Type; + }; + + template<typename T> + struct BitUnionBaseType<BitUnionType<T> > + { + typedef typename BitUnionType<T>::__StorageType Type; + }; +} + +template <typename T> +using BitUnionBaseType = typename BitfieldBackend::BitUnionBaseType<T>::Type; + #endif // __BASE_BITUNION_HH__ |