This is Unofficial EPICS BASE Doxygen Site
bitSetUtil.cpp
Go to the documentation of this file.
1 /*bitSetUtil.cpp*/
2 /*
3  * Copyright information and license terms for this software can be
4  * found in the file LICENSE that is included with the distribution
5  */
9 #define epicsExportSharedSymbols
10 #include <pv/noDefaultMethods.h>
11 #include <pv/pvData.h>
12 #include <pv/bitSetUtil.h>
13 
14 namespace epics { namespace pvData {
15 
17 using std::size_t;
18 
19 static bool checkBitSetPVField(
20  PVFieldPtr const &pvField,BitSetPtr const &bitSet,int32 initialOffset)
21 {
22  int32 offset = initialOffset;
23  int32 nbits = static_cast<int32>(pvField->getNumberFields());
24  if(nbits==1) return bitSet->get(offset);
25  int32 nextSetBit = bitSet->nextSetBit(offset);
26  if(nextSetBit>=(offset+nbits)) return false;
27  if(nextSetBit<0) return false;
28  if(bitSet->get(offset)) {
29  if(nbits>1) {
30  for(int32 i=offset+1; i<offset+nbits; i++) bitSet->clear(i);
31  }
32  return true;
33  }
34 
35  bool atLeastOneBitSet = false;
36  bool allBitsSet = true;
37  PVStructurePtr pvStructure = static_pointer_cast<PVStructure>(pvField);
38  offset = static_cast<int32>(pvStructure->getFieldOffset()) + 1;
39  while(offset<initialOffset + nbits) {
40  PVFieldPtr pvSubField = pvStructure->getSubFieldT(offset);
41  int32 nbitsNow = static_cast<int32>(pvSubField->getNumberFields());
42  if(nbitsNow==1) {
43  if(bitSet->get(offset)) {
44  atLeastOneBitSet = true;
45  } else {
46  allBitsSet = false;
47  }
48  offset++;
49  } else {
50  bool result = checkBitSetPVField(pvSubField,bitSet,offset);
51  if(result) {
52  atLeastOneBitSet = true;
53  if(!bitSet->get(offset)) {
54  allBitsSet = false;
55  }
56  } else {
57  allBitsSet = false;
58  }
59  offset += static_cast<int32>(pvSubField->getNumberFields());
60  }
61  }
62  if(allBitsSet) {
63  if(nbits>1) {
64  for(int32 i=initialOffset+1; i<initialOffset+nbits; i++){
65  bitSet->clear(i);
66  }
67  }
68  bitSet->set(initialOffset);
69  }
70  return atLeastOneBitSet;
71 }
72 
73 bool BitSetUtil::compress(BitSetPtr const &bitSet,PVStructurePtr const &pvStructure)
74 {
75  return checkBitSetPVField(pvStructure,bitSet,0);
76 }
77 
78 }}
pvac::PutEvent result
Definition: clientSync.cpp:117
int i
Definition: scan.c:967
shared_ptr< T > static_pointer_cast(shared_ptr< U > const &r) BOOST_NOEXCEPT
Definition: shared_ptr.hpp:788
TODO only here because of the Lockable.
Definition: ntaggregate.cpp:16
static bool compress(BitSetPtr const &bitSet, PVStructurePtr const &pvStructure)
Definition: bitSetUtil.cpp:73
std::tr1::shared_ptr< PVStructure > PVStructurePtr
Definition: pvData.h:87
std::tr1::shared_ptr< PVField > PVFieldPtr
Definition: pvData.h:66
std::tr1::shared_ptr< BitSet > BitSetPtr
Definition: bitSet.h:26
int32_t int32
Definition: pvType.h:83