Chromium Code Reviews| Index: base/win/registry.h |
| =================================================================== |
| --- base/win/registry.h (revision 70917) |
| +++ base/win/registry.h (working copy) |
| @@ -11,6 +11,39 @@ |
| #include "base/basictypes.h" |
| +// Please ignore this part. This temporary hack exists |
| +// to detect if the return value is used as 'bool'. |
| +// Todo(amit): remove this before (or soon after) checkin. |
| +struct CatchBoolChecks { |
| + CatchBoolChecks(LONG l) : l_(l) {} |
| + LONG l_; |
| + operator LONG() { return l_; } |
| + LONG value() const { return l_; } |
| + bool operator == (LONG l) const { return l == l_; } |
| + bool operator != (LONG l) const { return l != l_; } |
| + private: |
| + // If you hit a compile error here, you most likely attempting to use the |
| + // return value of a RegKey helper as a bool. Please note that RegKey |
| + // methods return LONG now instead of bool. |
| + operator bool () {return false;} |
|
Sigurður Ásgeirsson
2011/01/12 14:04:19
nit: ws around {}
amit
2011/01/14 05:23:33
Done.
|
| +}; |
| + |
| +inline bool operator == (const LONG& l, const CatchBoolChecks& g) { |
| + return g.value() == l; |
| +} |
| + |
| +inline bool operator != (const LONG& l, const CatchBoolChecks& g) { |
| + return g.value() != l; |
| +} |
| + |
| +using std::ostream; |
| +inline ostream& operator <<(ostream &os, const CatchBoolChecks& g) { |
| + os << g.value(); |
| + return os; |
| +} |
| + |
| +typedef CatchBoolChecks GONG; |
| + |
| namespace base { |
| namespace win { |
| @@ -23,51 +56,52 @@ |
| RegKey(HKEY rootkey, const wchar_t* subkey, REGSAM access); |
| ~RegKey(); |
| - bool Create(HKEY rootkey, const wchar_t* subkey, REGSAM access); |
| + GONG Create(HKEY rootkey, const wchar_t* subkey, REGSAM access); |
| - bool CreateWithDisposition(HKEY rootkey, const wchar_t* subkey, |
| + GONG CreateWithDisposition(HKEY rootkey, const wchar_t* subkey, |
| DWORD* disposition, REGSAM access); |
| - bool Open(HKEY rootkey, const wchar_t* subkey, REGSAM access); |
| + GONG Open(HKEY rootkey, const wchar_t* subkey, REGSAM access); |
| // Creates a subkey or open it if it already exists. |
| - bool CreateKey(const wchar_t* name, REGSAM access); |
| + GONG CreateKey(const wchar_t* name, REGSAM access); |
| // Opens a subkey |
| - bool OpenKey(const wchar_t* name, REGSAM access); |
| + GONG OpenKey(const wchar_t* name, REGSAM access); |
| void Close(); |
| DWORD ValueCount() const; |
| // Determine the nth value's name. |
| - bool ReadName(int index, std::wstring* name) const; |
| + GONG ReadName(int index, std::wstring* name) const; |
| // True while the key is valid. |
| bool Valid() const { return key_ != NULL; } |
| // Kill a key and everything that live below it; please be careful when using |
| // it. |
| - bool DeleteKey(const wchar_t* name); |
| + GONG DeleteKey(const wchar_t* name); |
| // Deletes a single value within the key. |
| - bool DeleteValue(const wchar_t* name); |
| + GONG DeleteValue(const wchar_t* name); |
| - bool ValueExists(const wchar_t* name); |
| + bool ValueExists(const wchar_t* name) const; |
| - bool ReadValue(const wchar_t* name, void* data, DWORD* dsize, |
| + GONG ReadValue(const wchar_t* name, void* data, DWORD* dsize, |
| DWORD* dtype) const; |
| - bool ReadValue(const wchar_t* name, std::wstring* value) const; |
| - bool ReadValueDW(const wchar_t* name, DWORD* value) const; |
| + GONG ReadValue(const wchar_t* name, std::wstring* value) const; |
| + GONG ReadValueDW(const wchar_t* name, DWORD* value) const; |
| + GONG ReadInt64(const wchar_t* name, int64* value) const; |
| - bool WriteValue(const wchar_t* name, const void* data, DWORD dsize, |
| + GONG WriteValue(const wchar_t* name, const void* data, DWORD dsize, |
| DWORD dtype); |
| - bool WriteValue(const wchar_t* name, const wchar_t* value); |
| - bool WriteValue(const wchar_t* name, DWORD value); |
| + GONG WriteValue(const wchar_t* name, const wchar_t* value); |
| + GONG WriteValue(const wchar_t* name, DWORD value); |
| // Starts watching the key to see if any of its values have changed. |
| // The key must have been opened with the KEY_NOTIFY access privilege. |
| - bool StartWatching(); |
| + GONG StartWatching(); |
| // If StartWatching hasn't been called, always returns false. |
| // Otherwise, returns true if anything under the key has changed. |
| @@ -76,7 +110,7 @@ |
| // Will automatically be called by destructor if not manually called |
| // beforehand. Returns true if it was watching, false otherwise. |
| - bool StopWatching(); |
| + GONG StopWatching(); |
| inline bool IsWatching() const { return watch_event_ != 0; } |
| HANDLE watch_event() const { return watch_event_; } |