SDRAngel  4.11.5
Developer docs for <a href="https://github.com/f4exb/sdrangel">SDRangel<\a>, an Open Source Qt5 / OpenGL 3.0+ SDR and signal analyzer frontend to various hardware.
bitfieldindex.h
Go to the documentation of this file.
1 // Copyright (C) 2015 F4EXB //
3 // written by Edouard Griffiths //
4 // //
5 // This program is free software; you can redistribute it and/or modify //
6 // it under the terms of the GNU General Public License as published by //
7 // the Free Software Foundation as version 3 of the License, or //
8 // (at your option) any later version. //
9 // //
10 // This program is distributed in the hope that it will be useful, //
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
13 // GNU General Public License V3 for more details. //
14 // //
15 // You should have received a copy of the GNU General Public License //
16 // along with this program. If not, see <http://www.gnu.org/licenses/>. //
18 
19 #ifndef _UTIL_BITFIELDINDEX_H_
20 #define _UTIL_BITFIELDINDEX_H_
21 
22 #include <stdint.h>
23 
24 template <unsigned int size>
26 {
27  uint32_t v : size;
28 
29  BitfieldIndex() : v(0) {}
30  BitfieldIndex(int i) { v = i; }
31 
32  BitfieldIndex& operator=(const BitfieldIndex& rhs) { v = rhs.v; return *this; }
33  BitfieldIndex& operator=(const int& rhi) { v = rhi; return *this; }
34  BitfieldIndex& operator++() { v++; return *this; }
35  BitfieldIndex operator++(int) { BitfieldIndex x(*this); ++(*this); return x; }
36  BitfieldIndex& operator+=(const BitfieldIndex& b) { v += b.v; return *this; }
37  BitfieldIndex& operator-=(const BitfieldIndex& b) { v -= b.v; return *this; }
38  BitfieldIndex& operator+=(int i) { v += i; return *this; }
39  BitfieldIndex& operator-=(int i) { v -= i; return *this; }
40  BitfieldIndex operator+(const BitfieldIndex& b) const { BitfieldIndex x(*this); x.v += b.v; return x; }
41  BitfieldIndex operator-(const BitfieldIndex& b) const { BitfieldIndex x(*this); x.v -= b.v; return x; }
42  BitfieldIndex operator+(int i) const { BitfieldIndex x(*this); x.v += i; return x; }
43  BitfieldIndex operator-(int i) const { BitfieldIndex x(*this); x.v -= i; return x; }
44 
45  operator int() const { return v; }
46 };
47 
48 template <unsigned int size>
50 {
52  x.v = a.v + b.v;
53  return x;
54 }
55 
56 template <unsigned int size>
58 {
60  x.v = a.v - b.v;
61  return x;
62 }
63 
64 #endif // _UTIL_BITFIELDINDEX_H_
BitfieldIndex & operator-=(const BitfieldIndex &b)
Definition: bitfieldindex.h:37
BitfieldIndex & operator+=(int i)
Definition: bitfieldindex.h:38
BitfieldIndex operator++(int)
Definition: bitfieldindex.h:35
BitfieldIndex operator+(const BitfieldIndex &b) const
Definition: bitfieldindex.h:40
BitfieldIndex & operator-=(int i)
Definition: bitfieldindex.h:39
BitfieldIndex & operator+=(const BitfieldIndex &b)
Definition: bitfieldindex.h:36
unsigned int uint32_t
Definition: rtptypes_win.h:46
BitfieldIndex operator-(const BitfieldIndex &b) const
Definition: bitfieldindex.h:41
int32_t i
Definition: decimators.h:244
BitfieldIndex & operator=(const BitfieldIndex &rhs)
Definition: bitfieldindex.h:32
BitfieldIndex & operator++()
Definition: bitfieldindex.h:34
BitfieldIndex & operator=(const int &rhi)
Definition: bitfieldindex.h:33
BitfieldIndex operator-(int i) const
Definition: bitfieldindex.h:43
BitfieldIndex operator+(int i) const
Definition: bitfieldindex.h:42
BitfieldIndex(int i)
Definition: bitfieldindex.h:30