Files
AppleWin/source/Registry.h
T
Kelvin Lee 926c592f75 Replace some BOOL usages with proper bool (PR #1500)
1. Registry functions
   The set of functions are changed to consistently use bool arguments.
   The macros are changed to inline functions to improve type checking.
   RegSaveValue() are overloaded with help of templates to reduce
   typecasting at call sites. For instance, bool value would be converted
   consistently instead of relying on call sites to convert bool to int values.
2. Memory functions
   BOOL usages were unnecessary. Mostly internal usages which can simply be bool.
3. FrameBase
   Some member variables are changed to bool.
   BOOL was used because of those Registry functions.

Additional changes:
- Some expressions are forced to be bool when assigning to bool variables.
2026-06-06 14:12:42 +01:00

46 lines
2.1 KiB
C++

#pragma once
#include "Card.h"
#include "CopyProtectionDongles.h"
#include <string>
#include <type_traits>
bool RegLoadString (LPCTSTR section, LPCTSTR key, bool peruser, LPTSTR buffer, uint32_t chars);
bool RegLoadString (LPCTSTR section, LPCTSTR key, bool peruser, LPTSTR buffer, uint32_t chars, LPCTSTR defaultValue);
bool RegLoadValue (LPCTSTR section, LPCTSTR key, bool peruser, uint32_t* value);
bool RegLoadValue (LPCTSTR section, LPCTSTR key, bool peruser, uint32_t* value, uint32_t defaultValue);
inline bool REGLOAD(LPCTSTR a, uint32_t* b) {
return RegLoadValue(REG_CONFIG, a, true, b);
}
inline bool REGLOAD_DEFAULT(LPCTSTR a, uint32_t* b, uint32_t c) {
return RegLoadValue(REG_CONFIG, a, true, b, c);
}
void RegSaveString(LPCTSTR section, LPCTSTR key, bool peruser, const std::string & buffer);
template<typename V, typename std::enable_if_t<std::is_same_v<V, bool>, int> = 0>
void RegSaveValue(LPCTSTR section, LPCTSTR key, bool peruser, V value) {
RegSaveString(section, key, peruser, value ? "1" : "0");
}
template<typename V, typename std::enable_if_t<std::is_signed_v<V> && !std::is_same_v<V, bool>, int> = 0>
void RegSaveValue(LPCTSTR section, LPCTSTR key, bool peruser, V value) {
RegSaveString(section, key, peruser, std::to_string(value));
}
template<typename V, typename std::enable_if_t<std::is_unsigned_v<V> && !std::is_same_v<V, bool>, int> = 0>
void RegSaveValue(LPCTSTR section, LPCTSTR key, bool peruser, V value) {
RegSaveValue<typename std::make_signed_t<V>>(section, key, peruser, value);
}
template<typename V, typename std::enable_if_t<std::is_enum_v<V>, int> = 0>
void RegSaveValue(LPCTSTR section, LPCTSTR key, bool peruser, V value) {
RegSaveValue<typename std::underlying_type_t<V>>(section, key, peruser, value);
}
template<typename V>
inline void REGSAVE(LPCTSTR a, const V & b) {
RegSaveValue(REG_CONFIG, a, true, b);
}
std::string RegGetConfigSlotSection(UINT slot);
void RegDeleteConfigSlotSection(UINT slot);
void RegSetConfigSlotNewCardType(UINT slot, SS_CARDTYPE type);
void RegSetConfigGameIOConnectorNewDongleType(UINT slot, DONGLETYPE type);