| Index: base/win/registry.h
|
| ===================================================================
|
| --- base/win/registry.h (revision 71761)
|
| +++ base/win/registry.h (working copy)
|
| @@ -11,63 +11,101 @@
|
|
|
| #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; }
|
| +};
|
| +
|
| +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 {
|
|
|
| // Utility class to read, write and manipulate the Windows Registry.
|
| // Registry vocabulary primer: a "key" is like a folder, in which there
|
| // are "values", which are <name, data> pairs, with an associated data type.
|
| +//
|
| +// Note:
|
| +// ReadValue family of functions guarantee that the return arguments
|
| +// are not touched in case of failure.
|
| class RegKey {
|
| public:
|
| RegKey();
|
| 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 +114,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_; }
|
|
|