OSDN Git Service

change indent rule to hard tab with width 4 to adjust to default setting of VC++...
[yamy/yamy.git] / registry.h
1 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r
2 // registry.h\r
3 \r
4 \r
5 #ifndef _REGISTRY_H\r
6 #  define _REGISTRY_H\r
7 \r
8 #  include "stringtool.h"\r
9 #  include <list>\r
10 \r
11 \r
12 /// registry access class\r
13 class Registry\r
14 {\r
15         HKEY m_root;                                    /// registry root\r
16         tstring m_path;                         /// path from registry root\r
17 \r
18 public:\r
19         typedef std::list<tstring> tstrings;\r
20 \r
21 public:\r
22         ///\r
23         Registry() : m_root(NULL) {\r
24                 setRoot(NULL, _T(""));\r
25         }\r
26         ///\r
27         Registry(HKEY i_root, const tstring &i_path)\r
28                         : m_root(i_root), m_path(i_path) {\r
29                 setRoot(i_root, i_path);\r
30         }\r
31 \r
32         /// set registry root and path\r
33         void setRoot(HKEY i_root, const tstring &i_path) {\r
34                 m_root = i_root;\r
35                 m_path = i_path;\r
36                 _TCHAR exePath[GANA_MAX_PATH];\r
37                 _TCHAR exeDrive[GANA_MAX_PATH];\r
38                 _TCHAR exeDir[GANA_MAX_PATH];\r
39                 GetModuleFileName(NULL, exePath, GANA_MAX_PATH);\r
40                 _tsplitpath_s(exePath, exeDrive, GANA_MAX_PATH, exeDir, GANA_MAX_PATH, NULL, 0, NULL, 0);\r
41                 m_path = exeDrive;\r
42                 m_path += exeDir;\r
43                 m_path += _T("yamy.ini");\r
44         }\r
45 \r
46         /// remvoe\r
47         bool remove(const tstring &i_name = _T("")) const {\r
48                 return remove(m_root, m_path, i_name);\r
49         }\r
50 \r
51         /// does exist the key ?\r
52         bool doesExist() const {\r
53                 return doesExist(m_root, m_path);\r
54         }\r
55 \r
56         /// read DWORD\r
57         bool read(const tstring &i_name, int *o_value, int i_defaultValue = 0)\r
58         const {\r
59                 return read(m_root, m_path, i_name, o_value, i_defaultValue);\r
60         }\r
61         /// write DWORD\r
62         bool write(const tstring &i_name, int i_value) const {\r
63                 return write(m_root, m_path, i_name, i_value);\r
64         }\r
65 \r
66         /// read tstring\r
67         bool read(const tstring &i_name, tstring *o_value,\r
68                           const tstring &i_defaultValue = _T("")) const {\r
69                 return read(m_root, m_path, i_name, o_value, i_defaultValue);\r
70         }\r
71         /// write tstring\r
72         bool write(const tstring &i_name, const tstring &i_value) const {\r
73                 return write(m_root, m_path, i_name, i_value);\r
74         }\r
75 \r
76 #ifndef USE_INI\r
77         /// read list of tstring\r
78         bool read(const tstring &i_name, tstrings *o_value,\r
79                           const tstrings &i_defaultValue = tstrings()) const {\r
80                 return read(m_root, m_path, i_name, o_value, i_defaultValue);\r
81         }\r
82         /// write list of tstring\r
83         bool write(const tstring &i_name, const tstrings &i_value) const {\r
84                 return write(m_root, m_path, i_name, i_value);\r
85         }\r
86 \r
87         /// read binary data\r
88         bool read(const tstring &i_name, BYTE *o_value, DWORD i_valueSize,\r
89                           const BYTE *i_defaultValue = NULL, DWORD i_defaultValueSize = 0)\r
90         const {\r
91                 return read(m_root, m_path, i_name, o_value, i_valueSize, i_defaultValue,\r
92                                         i_defaultValueSize);\r
93         }\r
94         /// write binary data\r
95         bool write(const tstring &i_name, const BYTE *i_value,\r
96                            DWORD i_valueSize) const {\r
97                 return write(m_root, m_path, i_name, i_value, i_valueSize);\r
98         }\r
99 #endif //!USE_INI\r
100 \r
101 public:\r
102         /// remove\r
103         static bool remove(HKEY i_root, const tstring &i_path,\r
104                                            const tstring &i_name = _T(""));\r
105 \r
106         /// does exist the key ?\r
107         static bool doesExist(HKEY i_root, const tstring &i_path);\r
108 \r
109         /// read DWORD\r
110         static bool read(HKEY i_root, const tstring &i_path, const tstring &i_name,\r
111                                          int *o_value, int i_defaultValue = 0);\r
112         /// write DWORD\r
113         static bool write(HKEY i_root, const tstring &i_path, const tstring &i_name,\r
114                                           int i_value);\r
115 \r
116         /// read tstring\r
117         static bool read(HKEY i_root, const tstring &i_path, const tstring &i_name,\r
118                                          tstring *o_value, const tstring &i_defaultValue = _T(""));\r
119         /// write tstring\r
120         static bool write(HKEY i_root, const tstring &i_path, const tstring &i_name,\r
121                                           const tstring &i_value);\r
122 \r
123 #ifndef USE_INI\r
124         /// read list of tstring\r
125         static bool read(HKEY i_root, const tstring &i_path, const tstring &i_name,\r
126                                          tstrings *o_value, const tstrings &i_defaultValue = tstrings());\r
127         /// write list of tstring\r
128         static bool write(HKEY i_root, const tstring &i_path, const tstring &i_name,\r
129                                           const tstrings &i_value);\r
130 \r
131         /// read binary data\r
132         static bool read(HKEY i_root, const tstring &i_path, const tstring &i_name,\r
133                                          BYTE *o_value, DWORD i_valueSize,\r
134                                          const BYTE *i_defaultValue = NULL,\r
135                                          DWORD i_defaultValueSize = 0);\r
136         /// write binary data\r
137         static bool write(HKEY i_root, const tstring &i_path, const tstring &i_name,\r
138                                           const BYTE *i_value, DWORD i_valueSize);\r
139 #endif //!USE_INI\r
140         /// read LOGFONT\r
141         static bool read(HKEY i_root, const tstring &i_path, const tstring &i_name,\r
142                                          LOGFONT *o_value, const tstring &i_defaultStringValue);\r
143         /// write LOGFONT\r
144         static bool write(HKEY i_root, const tstring &i_path, const tstring &i_name,\r
145                                           const LOGFONT &i_value);\r
146 };\r
147 \r
148 \r
149 #endif // !_REGISTRY_H\r