Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 #ifndef __JAUS_BIT_PRESENCE_VECTOR_H
00042 #define __JAUS_BIT_PRESENCE_VECTOR_H
00043
00044 #include "jaus/core/types.h"
00045
00046 #ifdef __cplusplus
00047
00048 namespace JAUS
00049 {
00057 class JAUS_CORE_DLL BitVector
00058 {
00059 public:
00072 inline static int SetBit(Byte& pv, const unsigned int bit, const bool val = true)
00073 {
00074 if (bit < BYTE_BITS)
00075 {
00076 if (val)
00077 {
00078 pv |= (Byte)(0x01 << bit);
00079 }
00080 else
00081 {
00082 pv &= (Byte)(~(0x01 << bit));
00083 }
00084 return OK;
00085 }
00086 return FAILURE;
00087 }
00100 inline static int SetBit(UShort& pv, const unsigned int bit, const bool val = true)
00101 {
00102 if (bit < USHORT_BITS)
00103 {
00104 if (val)
00105 {
00106 pv |= (UShort)(0x01 << bit);
00107 }
00108 else
00109 {
00110 pv &= (UShort)(~(0x01 << bit));
00111 }
00112 return OK;
00113 }
00114 return FAILURE;
00115 }
00128 inline static int SetBit(UInt& pv, const unsigned int bit, const bool val = true)
00129 {
00130 if (bit < INT_BITS)
00131 {
00132 if (val)
00133 {
00134 pv |= (UInt)(0x01 << bit);
00135 }
00136 else
00137 {
00138 pv &= (UInt)(~(0x01 << bit));
00139 }
00140 return OK;
00141 }
00142 return FAILURE;
00143 }
00156 inline static int SetBit(ULong& pv, const unsigned int bit, const bool val = true)
00157 {
00158 if (bit < LONG_BITS)
00159 {
00160 if (val)
00161 {
00162 pv |= (ULong)(0x01) << bit;
00163 }
00164 else
00165 {
00166 pv &= (ULong)(~((ULong)(0x01) << bit));
00167 }
00168 return OK;
00169 }
00170 return FAILURE;
00171 }
00172
00184 inline static int ClearBit(Byte& pv, const unsigned int bit)
00185 {
00186 if (bit < BYTE_BITS)
00187 {
00188 pv &= (Byte)(~(0x01 << bit));
00189
00190 return OK;
00191 }
00192 return FAILURE;
00193 }
00205 inline static int ClearBit(UShort& pv, const unsigned int bit)
00206 {
00207 if (bit < USHORT_BITS)
00208 {
00209 pv &= (UShort)(~(0x01 << bit));
00210
00211 return OK;
00212 }
00213 return FAILURE;
00214 }
00226 inline static int ClearBit(UInt& pv, const unsigned int bit)
00227 {
00228 if (bit < INT_BITS)
00229 {
00230 pv &= (UInt)(~(0x01 << bit));
00231
00232 return OK;
00233 }
00234 return FAILURE;
00235 }
00247 inline static int ClearBit(ULong& pv, const unsigned int bit)
00248 {
00249 if (bit < LONG_BITS)
00250 {
00251 pv &= (ULong)(~(0x01 << bit));
00252
00253 return OK;
00254 }
00255 return FAILURE;
00256 }
00257
00268 inline static bool IsBitSet(const Byte pv, const unsigned int bit)
00269 {
00270 return (pv & (0x01 << bit)) > 0 ? true : false;
00271 }
00282 inline static bool IsBitSet(const UShort pv, const unsigned int bit)
00283 {
00284 return (pv & (0x01 << bit)) > 0 ? true : false;
00285 }
00296 inline static bool IsBitSet(const UInt pv, const unsigned int bit)
00297 {
00298 return (pv & (UInt)(0x01 << bit)) > 0 ? true : false;
00299 }
00310 inline static bool IsBitSet(const ULong pv, const unsigned int bit)
00311 {
00312 return (pv & ((ULong)(0x01) << bit)) > 0 ? true : false;
00313 }
00324 inline static bool GetBit(const Byte pv, const unsigned int bit)
00325 {
00326 return (pv & (Byte)(0x01 << bit)) > 0 ? true : false;
00327 }
00338 inline static bool GetBit(const UShort pv, const unsigned int bit)
00339 {
00340 return (pv & (0x01 << bit)) > 0 ? true : false;
00341 }
00352 inline static bool GetBit(const UInt pv, const unsigned int bit)
00353 {
00354 return (pv & (0x01 << bit)) > 0 ? true : false;
00355 }
00366 inline static bool GetBit(const ULong pv, const unsigned int bit)
00367 {
00368 return (pv & ((ULong)(0x01) << bit)) > 0 ? true : false;
00369 }
00384 inline static bool Supports(const Byte pv1, const Byte pv2)
00385 {
00386 return ((pv1 & pv2) == pv2) ? true : false;
00387 }
00402 inline static bool Supports(const UShort pv1, const UShort pv2)
00403 {
00404 return ((pv1 & pv2) == pv2) ? true : false;
00405 }
00420 inline static bool Supports(const UInt pv1, const UInt pv2)
00421 {
00422 return ((pv1 & pv2) == pv2) ? true : false;
00423 }
00438 inline static bool Supports(const ULong pv1, const ULong pv2)
00439 {
00440 return ((pv1 & pv2) == pv2) ? true : false;
00441 }
00442
00443 inline static void Clear(Byte& pv) { pv = 0; }
00444 inline static void Clear(UShort& pv) { pv = 0; }
00445 inline static void Clear(UInt& pv) { pv = 0; }
00446 inline static void Clear(ULong& pv) { pv = 0; }
00447 };
00448
00449 }
00450
00451 #endif
00452
00453 #endif
00454