1 /* |
|
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // specializations for getters |
|
20 // throwing versions |
|
21 template<> |
|
22 inline int CxeSettings::get<int>(const QString &key) const { |
|
23 QVariant v; |
|
24 getValue(key, v); |
|
25 return v.value<int>(); |
|
26 } |
|
27 |
|
28 template<> |
|
29 inline bool CxeSettings::get<bool>(const QString &key) const { |
|
30 QVariant v; |
|
31 getValue(key, v); |
|
32 return v.value<bool>(); |
|
33 } |
|
34 |
|
35 template<> |
|
36 inline qreal CxeSettings::get<qreal>(const QString &key) const { |
|
37 QVariant v; |
|
38 getValue(key, v); |
|
39 return v.value<qreal>(); |
|
40 } |
|
41 |
|
42 template<> |
|
43 inline QString CxeSettings::get<QString>(const QString &key) const { |
|
44 QVariant v; |
|
45 getValue(key, v); |
|
46 return v.value<QString>(); |
|
47 } |
|
48 |
|
49 template<> |
|
50 inline QVariantMap CxeSettings::get<QVariantMap>(const QString &key) const { |
|
51 QVariant v; |
|
52 getValue(key, v); |
|
53 return v.value<QVariantMap>(); |
|
54 } |
|
55 |
|
56 // non-throwing versions |
|
57 template<> |
|
58 inline int CxeSettings::get<int>(const QString &key, const int &defaultValue) const { |
|
59 try { |
|
60 return get<int>(key); |
|
61 } catch (CxeException &e) { |
|
62 return defaultValue; |
|
63 } |
|
64 } |
|
65 |
|
66 template<> |
|
67 inline bool CxeSettings::get<bool>(const QString &key, const bool &defaultValue) const { |
|
68 try { |
|
69 return get<bool>(key); |
|
70 } catch (CxeException &e) { |
|
71 return defaultValue; |
|
72 } |
|
73 } |
|
74 |
|
75 template<> |
|
76 inline qreal CxeSettings::get<qreal>(const QString &key, const qreal &defaultValue) const { |
|
77 try { |
|
78 return get<qreal>(key); |
|
79 } catch (CxeException &e) { |
|
80 return defaultValue; |
|
81 } |
|
82 } |
|
83 |
|
84 template<> |
|
85 inline QString CxeSettings::get<QString>(const QString &key, const QString &defaultValue) const { |
|
86 try { |
|
87 return get<QString>(key); |
|
88 } catch (CxeException &e) { |
|
89 return defaultValue; |
|
90 } |
|
91 } |
|
92 |
|
93 template<> |
|
94 inline QVariantMap CxeSettings::get<QVariantMap>(const QString &key, const QVariantMap &defaultValue) const { |
|
95 try { |
|
96 return get<QVariantMap>(key); |
|
97 } catch (CxeException &e) { |
|
98 return defaultValue; |
|
99 } |
|
100 } |
|
101 |
|
102 // specializations for setters |
|
103 template<> |
|
104 inline void CxeSettings::set<int>(const QString &key, const int &value) { |
|
105 QVariant v; |
|
106 v.setValue(value); |
|
107 setValue(key, v); |
|
108 } |
|
109 |
|
110 template<> |
|
111 inline void CxeSettings::set<bool>(const QString &key, const bool &value) { |
|
112 QVariant v; |
|
113 v.setValue(value); |
|
114 setValue(key, v); |
|
115 } |
|
116 |
|
117 template<> |
|
118 inline void CxeSettings::set<qreal>(const QString &key, const qreal &value) { |
|
119 QVariant v; |
|
120 v.setValue(value); |
|
121 setValue(key, v); |
|
122 } |
|
123 |
|
124 template<> |
|
125 inline void CxeSettings::set<QString>(const QString &key, const QString &value) { |
|
126 QVariant v; |
|
127 v.setValue(value); |
|
128 setValue(key, v); |
|
129 } |
|
130 |
|
131 template<> |
|
132 inline void CxeSettings::set<QVariantMap>(const QString &key, const QVariantMap &value) { |
|
133 QVariant v; |
|
134 v.setValue(value); |
|
135 setValue(key, v); |
|
136 } |
|