sprint 1-alpha
|
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_CONFIGURATION_H 00023 #define _SPRINT_CONFIGURATION_H 00024 00029 #include <windows.h> 00030 #include <sprint/gtl/Registry.h> 00031 #include <string> 00032 00033 namespace sprint { 00034 namespace gtl { 00035 00037 class ReadConfiguration : public Registry { 00038 public: 00039 ReadConfiguration(const char *key) : Registry(HKEY_CURRENT_USER, key) { } 00040 ~ReadConfiguration() { } 00041 00043 inline bool reading() const { return true; } 00044 inline bool writing() const { return false; } 00045 00046 template<class T, class R> 00047 inline void operator() (LPCSTR path, T &value, R _default) { if(!Read(path, &value)) value = _default; } 00048 00049 template<class T> 00050 inline bool operator() (LPCSTR path, T &value) { return Read(path, &value); } 00051 00052 inline void str (LPCSTR path, char * buffer, int buflen, const char * _default) 00053 { 00054 if(!Read(path, buffer, buflen)) strcpy(buffer, _default); 00055 } 00056 00057 inline bool str (LPCSTR path, char * buffer, int buflen) 00058 { 00059 return Read(path, buffer, buflen); 00060 } 00061 00062 template<class T> 00063 inline bool data (LPCSTR path, T & dst) 00064 { 00065 return Read(path, (LPSTR) &dst, sizeof(T)); 00066 } 00067 00068 }; 00069 00071 class WriteConfiguration : public Registry { 00072 public: 00073 WriteConfiguration(const char *key) : Registry(HKEY_CURRENT_USER, key) { } 00074 ~WriteConfiguration() { } 00075 00077 inline bool reading() const { return false; } 00078 inline bool writing() const { return true; } 00079 00080 template<class T, class R> 00081 inline void operator() (LPCSTR path, T value, R _default) { Write(path, value); } 00082 00083 template<class T> 00084 inline bool operator() (LPCSTR path, T value) { Write(path, value); return true; } 00085 00086 inline void str (LPCSTR path, const char * buffer, int buflen, const char * _default) 00087 { 00088 Write(path, buffer); 00089 } 00090 00091 inline bool str (LPCSTR path, const char * buffer, int buflen) 00092 { 00093 Write(path, buffer); 00094 return true; 00095 } 00096 template<class T> 00097 inline bool data (LPCSTR path, const T & dst) 00098 { 00099 return RegSetValueExA ( 00100 hRegKey, 00101 path, 00102 0, 00103 REG_BINARY, 00104 (LPBYTE) &dst, 00105 sizeof(T) 00106 ); 00107 } 00108 00109 }; 00110 00111 } 00112 } 00113 00114 #endif // SPRINT_CONFIGURE_H