File: OptionsManager.h

package info (click to toggle)
freespace2 24.2.0%2Brepack-1
  • links: PTS, VCS
  • area: non-free
  • in suites: forky, sid
  • size: 43,716 kB
  • sloc: cpp: 595,001; ansic: 21,741; python: 1,174; sh: 457; makefile: 248; xml: 181
file content (69 lines) | stat: -rw-r--r-- 1,988 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#pragma once

#include "globalincs/pstypes.h"
#include "libs/jansson.h"
#include <memory>
#include <tl/optional.hpp>

namespace options {

// Forward declaration
class OptionBase;

class OptionsManager {
	OptionsManager();

	SCP_unordered_map<SCP_string, std::unique_ptr<json_t>> _config_overrides;

	SCP_unordered_map<SCP_string, std::unique_ptr<json_t>> _changed_values;

	SCP_unordered_map<SCP_string, const OptionBase*> _optionsMapping;

	SCP_vector<std::shared_ptr<const OptionBase>> _options;
	bool _optionsSorted = false;

  public:
	static OptionsManager* instance();

	~OptionsManager();

	tl::optional<std::unique_ptr<json_t>> getValueFromConfig(const SCP_string& key) const;

	void setConfigValue(const SCP_string& key, std::unique_ptr<json_t>&& value);

	void setOverride(const SCP_string& key, const SCP_string& json);

	const OptionBase* addOption(std::shared_ptr<const OptionBase>&& option);

	void removeOption(const std::shared_ptr<const OptionBase>& option);

	const OptionBase* getOptionByKey(SCP_string name);

	const SCP_vector<std::shared_ptr<const options::OptionBase>>& getOptions();

	bool persistOptionChanges(const options::OptionBase* option);

	/**
	 * @brief Persists changes to the disk
	 *
	 * This writes all the outstanding changes to the config file and returns a vector of all the options that indicated
	 * that they could not change the value. If the return value is empty then all changes were applied but if it is not
	 * empty then a restart is required for all the options to take effect.
	 *
	 * @return A vector of options that did not support changing the value
	 */
	SCP_vector<const options::OptionBase*> persistChanges();

	void discardChanges();

	void loadInitialValues();

	void printValues();

	void set_ingame_binary_option(SCP_string key, bool value);
	void set_ingame_multi_option(SCP_string key, int value);
	void set_ingame_range_option(SCP_string key, int value);
	void set_ingame_range_option(SCP_string key, float value);
};

}