summaryrefslogtreecommitdiff
path: root/inputmethods/dasher/SettingsStore.cpp
blob: 7e0fa5833bf1dd404bcff6101297e90a0d4fbecb (plain)
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
// SettingsStore.cpp
//
/////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2002 Iain Murray
//
/////////////////////////////////////////////////////////////////////////////




#include "SettingsStore.h"

using namespace std;

/* TODO: Consider using Template functions to make this neater. */


CSettingsStore::~CSettingsStore()
{
}


bool CSettingsStore::GetBoolOption(const string& Key)
{
	if (BoolMap.find(Key)==BoolMap.end()) {
		bool Value = false;
		LoadSetting(Key, &Value);
		BoolMap[Key] = Value;
	}
	
	return BoolMap[Key];
}


long CSettingsStore::GetLongOption(const string& Key)
{
	if (LongMap.find(Key)==LongMap.end()) {
		long Value = 0l;
		LoadSetting(Key, &Value);
		LongMap[Key] = Value;
	}
	
	return LongMap[Key];
}


string& CSettingsStore::GetStringOption(const string& Key)
{
	if (StringMap.find(Key)==StringMap.end()) {
		string Value = "";
		LoadSetting(Key, &Value);
		StringMap[Key] = Value;
	}
	
	return StringMap[Key];
}


void CSettingsStore::SetBoolOption(const string& Key, bool Value)
{
	BoolMap[Key] = Value;
	SaveSetting(Key, Value);
}


void CSettingsStore::SetLongOption(const string& Key, long Value)
{
	LongMap[Key] = Value;
	SaveSetting(Key, Value);
}


void CSettingsStore::SetStringOption(const string& Key, const string& Value)
{
	StringMap[Key] = Value;
	SaveSetting(Key, Value);
}


void CSettingsStore::SetBoolDefault(const string& Key, bool Value)
{
	bool TmpValue;
	if ( (BoolMap.find(Key)==BoolMap.end()) && (!LoadSetting(Key, &TmpValue)) )
		SetBoolOption(Key, Value);
}


void CSettingsStore::SetLongDefault(const string& Key, long Value)
{
	long TmpValue;
	if ( (LongMap.find(Key)==LongMap.end()) && (!LoadSetting(Key, &TmpValue)) )
		SetLongOption(Key, Value);
}


void CSettingsStore::SetStringDefault(const string& Key, const string& Value)
{
	string TmpValue;
	if ( (StringMap.find(Key)==StringMap.end()) && (!LoadSetting(Key, &TmpValue)) )
		SetStringOption(Key, Value);
}


/* Private functions -- Settings are not saved between sessions unless these
functions are over-ridden.
--------------------------------------------------------------------------*/


bool CSettingsStore::LoadSetting(const string& , bool* )
{
	return false;
}


bool CSettingsStore::LoadSetting(const string& , long* )
{
	return false;
}


bool CSettingsStore::LoadSetting(const string& , string* )
{
	return false;
}


void CSettingsStore::SaveSetting(const string& , bool )
{
}


void CSettingsStore::SaveSetting(const string& , long )
{
}


void CSettingsStore::SaveSetting(const string& , const string& )
{
}