bitunion.hh (10640:edbc52a43cd8) | bitunion.hh (11294:a368064a2ab5) |
---|---|
1/* 2 * Copyright (c) 2007-2008 The Regents of The University of Michigan 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer; --- 75 unchanged lines hidden (view full) --- 84 //who's msb is "first", and who's lsb is "last". 85 template<int first, int last=first> 86 class Bitfield : public BitfieldBase<Type> 87 { 88 static_assert(first >= last, 89 "Bitfield ranges must be specified as <msb, lsb>"); 90 91 public: | 1/* 2 * Copyright (c) 2007-2008 The Regents of The University of Michigan 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer; --- 75 unchanged lines hidden (view full) --- 84 //who's msb is "first", and who's lsb is "last". 85 template<int first, int last=first> 86 class Bitfield : public BitfieldBase<Type> 87 { 88 static_assert(first >= last, 89 "Bitfield ranges must be specified as <msb, lsb>"); 90 91 public: |
92 operator const uint64_t () const | 92 operator uint64_t () const |
93 { 94 return this->getBits(first, last); 95 } 96 97 uint64_t 98 operator=(const uint64_t _data) 99 { 100 this->setBits(first, last, _data); --- 23 unchanged lines hidden (view full) --- 124 operator=(const Bitfield<first, last>& other); 125 }; 126 127 //Similar to the above, but only allows writing. 128 template<int first, int last=first> 129 class BitfieldWO : public Bitfield<first, last> 130 { 131 private: | 93 { 94 return this->getBits(first, last); 95 } 96 97 uint64_t 98 operator=(const uint64_t _data) 99 { 100 this->setBits(first, last, _data); --- 23 unchanged lines hidden (view full) --- 124 operator=(const Bitfield<first, last>& other); 125 }; 126 127 //Similar to the above, but only allows writing. 128 template<int first, int last=first> 129 class BitfieldWO : public Bitfield<first, last> 130 { 131 private: |
132 operator const uint64_t () const; | 132 operator uint64_t () const; |
133 134 public: 135 using Bitfield<first, last>::operator=; 136 }; 137 }; 138 139 //This class contains all the "regular" bitfield classes. It is inherited 140 //by all BitUnions which give them access to those types. 141 template<class Type> 142 class SignedBitfieldTypes 143 { 144 protected: 145 //This class implements ordinary bitfields, that is a span of bits 146 //who's msb is "first", and who's lsb is "last". 147 template<int first, int last=first> 148 class SignedBitfield : public BitfieldBase<Type> 149 { 150 public: | 133 134 public: 135 using Bitfield<first, last>::operator=; 136 }; 137 }; 138 139 //This class contains all the "regular" bitfield classes. It is inherited 140 //by all BitUnions which give them access to those types. 141 template<class Type> 142 class SignedBitfieldTypes 143 { 144 protected: 145 //This class implements ordinary bitfields, that is a span of bits 146 //who's msb is "first", and who's lsb is "last". 147 template<int first, int last=first> 148 class SignedBitfield : public BitfieldBase<Type> 149 { 150 public: |
151 operator const int64_t () const | 151 operator int64_t () const |
152 { 153 return sext<first - last + 1>(this->getBits(first, last)); 154 } 155 156 int64_t 157 operator=(const int64_t _data) 158 { 159 this->setBits(first, last, _data); --- 23 unchanged lines hidden (view full) --- 183 operator=(const SignedBitfield<first, last>& other); 184 }; 185 186 //Similar to the above, but only allows writing. 187 template<int first, int last=first> 188 class SignedBitfieldWO : public SignedBitfield<first, last> 189 { 190 private: | 152 { 153 return sext<first - last + 1>(this->getBits(first, last)); 154 } 155 156 int64_t 157 operator=(const int64_t _data) 158 { 159 this->setBits(first, last, _data); --- 23 unchanged lines hidden (view full) --- 183 operator=(const SignedBitfield<first, last>& other); 184 }; 185 186 //Similar to the above, but only allows writing. 187 template<int first, int last=first> 188 class SignedBitfieldWO : public SignedBitfield<first, last> 189 { 190 private: |
191 operator const int64_t () const; | 191 operator int64_t () const; |
192 193 public: 194 using SignedBitfield<first, last>::operator=; 195 }; 196 }; 197 198 template<class Type> 199 class BitfieldTypes : public RegularBitfieldTypes<Type>, --- 99 unchanged lines hidden (view full) --- 299 300//This closes off the union created above and gives it a name. Unlike the top 301//level BitUnion, we're interested in creating an object instead of a type. 302//The operators are defined in the macro itself instead of a class for 303//technical reasons. If someone determines a way to move them to one, please 304//do so. 305#define EndSubBitUnion(name) \ 306 }; \ | 192 193 public: 194 using SignedBitfield<first, last>::operator=; 195 }; 196 }; 197 198 template<class Type> 199 class BitfieldTypes : public RegularBitfieldTypes<Type>, --- 99 unchanged lines hidden (view full) --- 299 300//This closes off the union created above and gives it a name. Unlike the top 301//level BitUnion, we're interested in creating an object instead of a type. 302//The operators are defined in the macro itself instead of a class for 303//technical reasons. If someone determines a way to move them to one, please 304//do so. 305#define EndSubBitUnion(name) \ 306 }; \ |
307 inline operator const __DataType () const \ | 307 inline operator __DataType () const \ |
308 { return __data; } \ 309 \ | 308 { return __data; } \ 309 \ |
310 inline const __DataType operator = (const __DataType & _data) \ | 310 inline __DataType operator = (const __DataType & _data) \ |
311 { return __data = _data;} \ 312 } name; 313 314//Regular bitfields 315//These define macros for read/write regular bitfield based subbitfields. 316#define SubBitUnion(name, first, last) \ 317 __SubBitUnion(Bitfield, first, last, name) 318 --- 15 unchanged lines hidden --- | 311 { return __data = _data;} \ 312 } name; 313 314//Regular bitfields 315//These define macros for read/write regular bitfield based subbitfields. 316#define SubBitUnion(name, first, last) \ 317 __SubBitUnion(Bitfield, first, last, name) 318 --- 15 unchanged lines hidden --- |