tesseract 4.1.1
Loading...
Searching...
No Matches
bits16.h
Go to the documentation of this file.
1/**********************************************************************
2 * File: bits16.h (Formerly bits8.h)
3 * Description: Code for 8 bit field class.
4 * Author: Phil Cheatle
5 *
6 * (C) Copyright 1991, Hewlett-Packard Ltd.
7 ** Licensed under the Apache License, Version 2.0 (the "License");
8 ** you may not use this file except in compliance with the License.
9 ** You may obtain a copy of the License at
10 ** http://www.apache.org/licenses/LICENSE-2.0
11 ** Unless required by applicable law or agreed to in writing, software
12 ** distributed under the License is distributed on an "AS IS" BASIS,
13 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 ** See the License for the specific language governing permissions and
15 ** limitations under the License.
16 *
17 **********************************************************************/
18
19#ifndef BITS16_H
20#define BITS16_H
21
22#include <cstdint> // for uint8_t, ...
23#include "platform.h" // for DLLSYM
24
26 public:
27 uint16_t val = 0;
28
29 BITS16() = default;
30 BITS16(uint16_t init) : val(init) {}
31
32 void turn_on_bit( // flip specified bit
33 uint8_t bit_num) { // bit to flip 0..7
34 val = static_cast<uint16_t>(val | 01 << bit_num);
35 }
36
37 void turn_off_bit( // flip specified bit
38 uint8_t bit_num) { // bit to flip 0..7
39 val = static_cast<uint16_t>(val & ~(01 << bit_num));
40 }
41
42 void set_bit( // flip specified bit
43 uint8_t bit_num, // bit to flip 0..7
44 bool value) { // value to flip to
45 if (value)
46 val = static_cast<uint16_t>(val | 01 << bit_num);
47 else
48 val = static_cast<uint16_t>(val & ~(01 << bit_num));
49 }
50
51 bool bit( // access bit
52 uint8_t bit_num) const { // bit to access
53 return (val >> bit_num) & 01;
54 }
55};
56
57#endif
#define DLLSYM
Definition: platform.h:21
Definition: bits16.h:25
void set_bit(uint8_t bit_num, bool value)
Definition: bits16.h:42
void turn_on_bit(uint8_t bit_num)
Definition: bits16.h:32
BITS16()=default
bool bit(uint8_t bit_num) const
Definition: bits16.h:51
void turn_off_bit(uint8_t bit_num)
Definition: bits16.h:37
BITS16(uint16_t init)
Definition: bits16.h:30