FastEngine 0.9.3
A multiplayer oriented 2D engine made with Vulkan.
Loading...
Searching...
No Matches
C_bitBank.hpp
1/*
2 * Copyright 2024 Guillaume Guillet
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef _FGE_C_BITBANK_HPP_INCLUDED
18#define _FGE_C_BITBANK_HPP_INCLUDED
19
20#include "FastEngine/network/C_packet.hpp"
21
22namespace fge
23{
24
32template<std::size_t TNbytes>
34{
35 static_assert(TNbytes > 0, "TNbytes must be greater than 0");
36
37public:
38 BitBank() = default;
39 ~BitBank() = default;
40
46 void clear();
47
56 void set(std::size_t index, bool flag);
65 [[nodiscard]] bool get(std::size_t index) const;
72 [[nodiscard]] uint8_t getByte(std::size_t index) const;
73
79 [[nodiscard]] std::size_t getSize() const;
80
86 void pack(fge::net::Packet& pck);
92 void unpack(fge::net::Packet& pck);
93
94private:
95 uint8_t g_data[TNbytes]{0};
96};
97
98} // namespace fge
99
100#include "C_bitBank.inl"
101
102#endif // _FGE_C_BITBANK_HPP_INCLUDED
A class to manage a group of bits.
Definition C_bitBank.hpp:34
bool get(std::size_t index) const
Get the value of a bit.
Definition C_bitBank.inl:38
void unpack(fge::net::Packet &pck)
Unpack the bank data from the packet.
Definition C_bitBank.inl:68
void pack(fge::net::Packet &pck)
Pack the bank data into the packet.
Definition C_bitBank.inl:63
std::size_t getSize() const
Get the number of bytes in the bank.
Definition C_bitBank.inl:57
void set(std::size_t index, bool flag)
Set a bit to 1 or 0.
Definition C_bitBank.inl:30
uint8_t getByte(std::size_t index) const
Get the specified byte.
Definition C_bitBank.inl:47
void clear()
Clear the bank.
Definition C_bitBank.inl:21
Definition C_packet.hpp:70