0% found this document useful (0 votes)
4 views

Mã Run.js

The document contains a C++ implementation of a SettingsManager class that manages application settings using a variant type for different data types. It includes methods for setting, getting, applying, and displaying settings, along with specific checks for integer, range, and boolean settings. The main function demonstrates how to use the SettingsManager to configure and apply settings.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Mã Run.js

The document contains a C++ implementation of a SettingsManager class that manages application settings using a variant type for different data types. It includes methods for setting, getting, applying, and displaying settings, along with specific checks for integer, range, and boolean settings. The main function demonstrates how to use the SettingsManager to configure and apply settings.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include <iostream>

#include <map>
#include <string>
#include <variant>
#include <optional>
#include <iomanip> // Thư viện cho định dạng xuất ra

class SettingsManager {
public:
using SettingValue = std::variant<int, bool, std::string>;

void setSetting(const std::string& key, SettingValue value) {


settings[key] = std::move(value);
}

std::optional<SettingValue> getSetting(const std::string& key) const {


auto it = settings.find(key);
if (it != settings.end()) {
return it->second;
}
return std::nullopt;
}

void applySettings() {
std::cout << "\033[1;36m*** Applying VIP Settings ***\033[0m" << std::endl;

checkAndApplySetting("com.act_conf_seclect_sync_setting", 100, "Sync


setting enabled with value 100.");

checkAndApplyRangeSetting("Key_act_allow.file_code_settinghexbase86_appmaneger_sysa
pp_com.dts.freefireth_auto_cws", 70, 100, "Auto CWS setting within range.");
checkAndApplyBooleanSetting("uncrack.strings", "Uncrack strings protection
is enabled.", "Uncrack strings protection is disabled.");
}

void displaySettings() const {


std::cout << "\033[1;32mCurrent VIP Settings:\033[0m" << std::endl;
for (const auto& [key, value] : settings) {
std::cout << "\033[1;35mKey: \033[0m" << key << " -> \033[1;33mValue: \
033[0m";
std::visit([](auto&& val) { std::cout << val << std::endl; }, value);
}
}

private:
std::map<std::string, SettingValue> settings;

void checkAndApplySetting(const std::string& key, int expectedValue, const


std::string& message) {
if (auto setting = getSetting(key)) {
if (std::get<int>(*setting) == expectedValue) {
std::cout << "\033[1;32m" << message << "\033[0m" << std::endl;
} else {
std::cout << "\033[1;31mError: Unexpected value for " << key << "\
033[0m" << std::endl;
}
}
}
void checkAndApplyRangeSetting(const std::string& key, int min, int max, const
std::string& message) {
if (auto setting = getSetting(key)) {
int value = std::get<int>(*setting);
if (value >= min && value <= max) {
std::cout << "\033[1;32m" << message << ": " << value << "\033[0m"
<< std::endl;
} else {
std::cout << "\033[1;31mError: Value out of range for " << key <<
"\033[0m" << std::endl;
}
}
}

void checkAndApplyBooleanSetting(const std::string& key, const std::string&


trueMessage, const std::string& falseMessage) {
if (auto setting = getSetting(key)) {
if (std::get<bool>(*setting)) {
std::cout << "\033[1;32m" << trueMessage << "\033[0m" << std::endl;
} else {
std::cout << "\033[1;31m" << falseMessage << "\033[0m" <<
std::endl;
}
}
}
};

int main() {
SettingsManager settingsManager;

// Cấu hình VIP


settingsManager.setSetting("com.act_conf_seclect_sync_setting", 100);

settingsManager.setSetting("Key_act_allow.file_code_settinghexbase86_appmaneger_sys
app_com.dts.freefireth_auto_cws", 85);
settingsManager.setSetting("uncrack.strings", true);

settingsManager.applySettings();
settingsManager.displaySettings();

return 0;
}

You might also like