ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
ecvFlags.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #pragma once
9 
10 // System
11 #include <cstring>
12 
14 class ccFlags {
15 public:
17  void reset() { memset(table, 0, sizeof(bool) * 8); }
18 
20  void fromByte(unsigned char byte) {
21  unsigned char i, mask = 1;
22  for (i = 0; i < 8; ++i) {
23  table[i] = ((byte & mask) == mask);
24  mask <<= 1;
25  }
26  }
27 
29  unsigned char toByte() const {
30  unsigned char i, byte = 0, mask = 1;
31  for (i = 0; i < 8; ++i) {
32  if (table[i]) byte |= mask;
33  mask <<= 1;
34  }
35 
36  return byte;
37  }
38 
40  bool table[8];
41 };
Flags.
Definition: ecvFlags.h:14
bool table[8]
Table of 8 booleans (one per bit)
Definition: ecvFlags.h:40
void reset()
Sets all bits to 0.
Definition: ecvFlags.h:17
void fromByte(unsigned char byte)
Converts a byte to this structure.
Definition: ecvFlags.h:20
unsigned char toByte() const
Converts this structure to a byte.
Definition: ecvFlags.h:29