Seregon/ShadPKG

A tool for deriving PKG packet encryption keys for ps4 written in c++

C++/47.3 KB/No license
common/fixed_value.h
ShadPKG / common / fixed_value.h
1// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
2// SPDX-License-Identifier: GPL-2.0-or-later
3 
4#pragma once
5 
6/**
7 * @brief A template class that encapsulates a fixed, compile-time constant value.
8 *
9 * @tparam T The type of the value.
10 * @tparam Value The fixed value of type T.
11 *
12 * This class provides a way to encapsulate a value that is constant and known at compile-time.
13 * The value is stored as a private member and cannot be changed. Any attempt to assign a new
14 * value to an object of this class will reset it to the fixed value.
15 */
16template <typename T, T Value>
17class FixedValue {
18 T m_value{Value};
19 
20public:
21 constexpr FixedValue() = default;
22 
23 constexpr explicit(false) operator T() const {
24 return m_value;
25 }
26 
27 FixedValue& operator=(const T&) {
28 m_value = Value;
29 return *this;
30 }
31 FixedValue& operator=(T&&) noexcept {
32 m_value = {Value};
33 return *this;
34 }
35};
36