summaryrefslogtreecommitdiffstats
path: root/src/SettingsRepositoryInterface.h
blob: 4547dfe19fb21b0b2db4b6e92dd4eb149eb91a70 (plain) (blame)
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
70
71
72
73

#pragma once

class cSettingsRepositoryInterface
{
  public:
	enum errors
	{
		noID = -1,
	};

	cSettingsRepositoryInterface() = default;
	virtual ~cSettingsRepositoryInterface() = default;
	DISALLOW_COPY_AND_ASSIGN(cSettingsRepositoryInterface);

	/** Returns true iff the specified key exists */
	virtual bool KeyExists(const AString keyname) const = 0;

	/** Returns true iff the specified value exists. */
	virtual bool HasValue(const AString & a_KeyName, const AString & a_ValueName) const = 0;

	/** Add a key name. Return value is not required to mean anything */
	virtual int AddKeyName(const AString & keyname) = 0;

	/** Add a key comment, will always fail if the repository does not support comments */
	virtual bool AddKeyComment(const AString & keyname, const AString & comment) = 0;

	/** Return a key comment, returns "" for repositories that do not return comments */
	virtual AString GetKeyComment(const AString & keyname, const int commentID) const = 0;

	/** Delete a key comment, will always fail if the repository does not support comments */
	virtual bool DeleteKeyComment(const AString & keyname, const int commentID) = 0;

	/** Adds a new value to the specified key.
	If a value of the same name already exists, creates another one */
	virtual void AddValue(const AString & a_KeyName, const AString & a_ValueName, const AString & a_Value) = 0;

	/** returns a vector containing a name, value pair for each value under the key */
	virtual std::vector<std::pair<AString, AString>> GetValues(AString a_keyName) = 0;

	/** Get the value at the specified key and value, returns defValue on failure */
	virtual AString GetValue(const AString & keyname, const AString & valuename, const AString & defValue = "")
		const = 0;

	/** Gets the value; if not found, write the default to the repository */
	virtual AString GetValueSet(const AString & keyname, const AString & valuename, const AString & defValue = "") = 0;
	virtual int GetValueSetI(const AString & keyname, const AString & valuename, const int defValue = 0) = 0;
	virtual Int64 GetValueSetI(const AString & keyname, const AString & valuename, const Int64 defValue = 0) = 0;
	virtual bool GetValueSetB(const AString & keyname, const AString & valuename, const bool defValue = false) = 0;

	/** Overwrites the value of the key, value pair
	Specify the optional parameter as false if you do not want the value created if it doesn't exist.
	Returns true if value set, false otherwise. */
	virtual bool SetValue(
		const AString & a_KeyName,
		const AString & a_ValueName,
		const AString & a_Value,
		const bool a_CreateIfNotExists = true
	) = 0;
	virtual bool SetValueI(
		const AString & a_KeyName,
		const AString & a_ValueName,
		const int a_Value,
		const bool a_CreateIfNotExists = true
	) = 0;

	/** Deletes the specified key, value pair */
	virtual bool DeleteValue(const AString & keyname, const AString & valuename) = 0;


	/** Writes the changes to the backing store, if the repository has one */
	virtual bool Flush() = 0;
};