sprint 1-alpha
sprint/gtl/Registry.h
Go to the documentation of this file.
00001 /******************************************************************************
00002  *  GTL: GUI Template Library 
00003  *    A Cross Platform C++ Wrapper for Win32 users
00004  *  Copyright (C) 2007-2011 Paolo Medici (www.pmx.it)
00005  *
00006  *  This library is free software; you can redistribute it and/or
00007  *  modify it under the terms of the GNU Lesser General Public
00008  *  License as published by the Free Software Foundation; either
00009  *  version 2.1 of the License, or (at your option) any later version.
00010  *
00011  *  This library is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  *  Lesser General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU Lesser General Public
00017  *  License along with this library; if not, write to the Free Software
00018  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00019  *
00020  *******************************************************************************/
00021 
00022 #ifndef _SPRINT_REGISTRY_H
00023 #define _SPRINT_REGISTRY_H
00024 
00025 #include <string>
00026 
00030 namespace sprint {
00031         namespace gtl {
00032 
00034 class Registry {
00035 protected:
00037         HKEY hRegKey;
00038         
00041         unsigned long result;
00042         
00043 public:
00045         Registry(HKEY hKey, LPCSTR lpSubKey)
00046         {
00047         RegCreateKeyEx(hKey, lpSubKey,
00048                         0, (CHAR *) "software", 0, KEY_ALL_ACCESS, NULL, &hRegKey, &result);
00049         }
00050         
00051         inline ~Registry()      {
00052         RegCloseKey(hRegKey);   
00053         }
00054 
00056         inline Registry * CreateKey(LPCSTR lpszSubKey) const
00057         {
00058                 return new Registry(hRegKey, lpszSubKey);
00059         }
00060 
00062 
00064 
00065 
00066 
00067 
00068         inline LONG Write(LPCTSTR  path, const BYTE *value, DWORD cbData)       const {
00069                 return RegSetValueExA (hRegKey, path, 0, REG_BINARY, value, cbData);
00070         }
00071 
00073         inline LONG Write(LPCSTR path, LPCSTR str) const
00074         {
00075         return RegSetValueExA (
00076     hRegKey,
00077     path,
00078     0,
00079     REG_SZ,
00080     (LPBYTE) str,
00081     strlen(str)+1);
00082         }
00083         
00085         inline LONG Write(LPCSTR path, const std::string & str) const
00086           {
00087     return RegSetValueExA (
00088       hRegKey,
00089       path,
00090       0,
00091       REG_SZ,
00092       (LPBYTE) str.c_str(),
00093       str.size()+1);
00094     }
00095         
00097         inline LONG Write(LPCSTR path, DWORD value) const       {
00098         return RegSetValueExA (
00099                 hRegKey,
00100                 path,
00101                 0,
00102                 REG_DWORD,
00103                 (LPBYTE) &value,
00104                 sizeof(DWORD));
00105         }
00106         
00108         inline LONG Write(LPCSTR path, unsigned int value) const        {
00109         return RegSetValueExA (
00110                 hRegKey,
00111                 path,
00112                 0,
00113                 REG_DWORD,
00114                 (LPBYTE) &value,
00115                 sizeof(unsigned int));
00116         }
00117 
00119         inline LONG Write(LPCSTR path, int value) const {
00120         return RegSetValueExA (
00121                 hRegKey,
00122                 path,
00123                 0,
00124                 REG_DWORD,
00125                 (LPBYTE) &value,
00126                 sizeof(int));
00127         }
00128 
00130         inline LONG Write(LPCSTR path, long int value) const    {
00131         return RegSetValueExA (
00132                 hRegKey,
00133                 path,
00134                 0,
00135                 REG_DWORD,
00136                 (LPBYTE) &value,
00137                 sizeof(long int));
00138         }
00139 
00141         inline LONG Write(LPCSTR path, bool value) const        {
00142                 DWORD dummy = value;
00143         return RegSetValueExA (
00144                 hRegKey,
00145                 path,
00146                 0,
00147                 REG_DWORD,
00148                 (LPBYTE) &dummy,
00149                 sizeof(DWORD));
00150         }
00151         
00152         LONG Write(LPCSTR path, float value) const;
00153         LONG Write(LPCSTR path, double value) const;
00154         
00157 
00158 
00160 
00161         bool Read(LPCSTR path, unsigned int *out) const;
00163         bool Read(LPCSTR path, int *out) const; 
00165         bool Read(LPCSTR path, unsigned long *out) const;
00167         bool Read(LPCSTR path, long *out) const;        
00168 
00170         bool Read(LPCSTR path, bool *out) const;                
00172         bool Read(LPCSTR path, char * str, unsigned int cbSize) const;
00174     bool Read(LPCSTR path, std::string & str) const;
00179         bool Read(LPCSTR path, LPBYTE out, LPDWORD lptype, LPDWORD lpsize) const;
00180 
00183 
00184 
00185 
00186 
00187         DWORD Read(LPCSTR path, DWORD def) const;
00189         bool Read(LPCSTR path, bool def) const;
00192         bool Read(LPCSTR path, float *value) const;
00193         bool Read(LPCSTR path, double *value) const;
00194 
00195 };
00196 
00197 }
00198 }
00199 
00200 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines