jak-project/game/sound/common/bitfield.h
Tyler Wilding 60db0e5ef9
deps: update fmt to latest version (#3403)
This updates `fmt` to the latest version and moves to just being a copy
of their repo to make updating easier (no editing their cmake / figuring
out which files to minimally include).

The motivation for this is now that we switched to C++ 20, there were a
ton of deprecated function usages that is going away in future compiler
versions. This gets rid of all those warnings.
2024-03-05 22:11:52 -05:00

22 lines
599 B
C++

// Copyright: 2021 - 2024, Ziemas
// SPDX-License-Identifier: ISC
#pragma once
/* Bitfield convenience class for use with unions
* should be allowed as per common initial subsequence rule regarding unions */
template <typename sourcetype, typename type, int pos, int width>
class bitfield {
public:
constexpr type get() { return static_cast<type>((underlying >> pos) & mask()); };
constexpr void set(type value) {
underlying &= ~(mask() << pos);
underlying |= (value & mask()) << pos;
};
private:
sourcetype underlying;
constexpr int mask() { return (1 << width) - 1; };
};