Mesh Oriented datABase  (version 5.5.1)
An array-based unstructured mesh library
BitPage.cpp
Go to the documentation of this file.
1 #include "BitPage.hpp"
2 #include "moab/Range.hpp"
3 #include <cstdlib>
4 #include <cstring>
5 
6 namespace moab
7 {
8 
9 void BitPage::search( unsigned char value, int offset, int count, int per_ent, Range& results, EntityHandle start )
10  const
11 {
12  const int end = offset + count;
13  Range::iterator hint = results.begin();
14  while( offset != end )
15  {
16  if( get_bits( offset, per_ent ) == value ) hint = results.insert( hint, start );
17  ++offset;
18  ++start;
19  }
20 }
21 
22 BitPage::BitPage( int per_ent, unsigned char init_val )
23 {
24  unsigned char mask = (unsigned char)( 1 << per_ent ) - 1; // 2^per_ent - 1
25  init_val &= (unsigned char)mask;
26  switch( per_ent )
27  {
28  default:
29  assert( false );
30  abort();
31  break; // must be power of two
32 
33  // Note: fall through such that all bits in init_val are set, but with odd structure to avoid
34  // fall-through warnings
35  case 1:
36  init_val |= (unsigned char)( init_val << 1 );
37  // fall through
38  case 2:
39  init_val |= (unsigned char)( init_val << 2 );
40  // fall through
41  case 4:
42  init_val |= (unsigned char)( init_val << 4 );
43  // fall through
44  case 8:;
45  }
46  memset( byteArray, init_val, BitTag::PageSize );
47 }
48 
49 } // namespace moab