From 65512dc434d3d2b30915066fabddbf5a3d96a3ab Mon Sep 17 00:00:00 2001 From: Maxim Poliakovski Date: Tue, 19 Jul 2022 23:45:41 +0200 Subject: [PATCH] New property type: BinProperty. --- machines/machineproperties.cpp | 15 ++++++++++++++- machines/machineproperties.h | 30 +++++++++++++++++++++++++++++- 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/machines/machineproperties.cpp b/machines/machineproperties.cpp index 8139c65..c82cf42 100644 --- a/machines/machineproperties.cpp +++ b/machines/machineproperties.cpp @@ -1,6 +1,6 @@ /* DingusPPC - The Experimental PowerPC Macintosh emulator -Copyright (C) 2018-21 divingkatae and maximum +Copyright (C) 2018-22 divingkatae and maximum (theweirdo) spatium (Contact divingkatae#1017 or powermax#2286 on Discord for more info) @@ -131,3 +131,16 @@ bool IntProperty::check_val(uint32_t val) return true; } } + +void BinProperty::set_string(string val) +{ + if ((val.compare("ON") == 0) || (val.compare("on") == 0)) { + this->bin_val = 1; + this->val = val; + } else if ((val.compare("OFF") == 0) || (val.compare("off") == 0)) { + this->bin_val = 0; + this->val = val; + } else { + LOG_F(ERROR, "Invalid BinProperty value %s!", val.c_str()); + } +} diff --git a/machines/machineproperties.h b/machines/machineproperties.h index 1e1fa6a..87943f8 100644 --- a/machines/machineproperties.h +++ b/machines/machineproperties.h @@ -1,6 +1,6 @@ /* DingusPPC - The Experimental PowerPC Macintosh emulator -Copyright (C) 2018-21 divingkatae and maximum +Copyright (C) 2018-22 divingkatae and maximum (theweirdo) spatium (Contact divingkatae#1017 or powermax#2286 on Discord for more info) @@ -38,6 +38,7 @@ enum PropType : int { PROP_TYPE_UNKNOWN = 0, PROP_TYPE_STRING = 1, PROP_TYPE_INTEGER = 2, + PROP_TYPE_BINARY = 3, // binary aka on/off switch }; /** Check types for property values. */ @@ -164,6 +165,30 @@ private: vector vec; }; +/** Property class that holds a binary value. */ +class BinProperty : public BasicProperty { +public: + BinProperty(int val) + : BasicProperty(PROP_TYPE_BINARY, (val & 1) ? "on" : "off") + { + this->bin_val = val & 1; + }; + + BasicProperty* clone() const { return new BinProperty(*this); } + + // override BasicProperty::set_string() and perform checks + void set_string(string str); + + string get_valid_values_as_str() { + return string("on, off, ON, OFF"); + }; + + int get_val() { return this->bin_val; }; + +private: + int bin_val; +}; + /** Special map type for specifying machine presets. */ typedef map PropMap; @@ -177,4 +202,7 @@ extern map> gMachineSettings; #define GET_INT_PROP(name) \ dynamic_cast(gMachineSettings.at(name).get())->get_int() +#define GET_BIN_PROP(name) \ + dynamic_cast(gMachineSettings.at(name).get())->get_val() + #endif /* MACHINE_PROPERTIES_H */