scoped_hstring.h 980 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // Copyright (c) 2015 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE-CHROMIUM file.
  4. #ifndef BRIGHTRAY_BROWSER_WIN_SCOPED_HSTRING_H_
  5. #define BRIGHTRAY_BROWSER_WIN_SCOPED_HSTRING_H_
  6. #include <hstring.h>
  7. #include <windows.h>
  8. #include <string>
  9. #include "base/macros.h"
  10. class ScopedHString {
  11. public:
  12. // Copy from |source|.
  13. explicit ScopedHString(const wchar_t* source);
  14. explicit ScopedHString(const std::wstring& source);
  15. // Create empty string.
  16. ScopedHString();
  17. ~ScopedHString();
  18. // Sets to |source|.
  19. void Reset();
  20. void Reset(const wchar_t* source);
  21. void Reset(const std::wstring& source);
  22. // Returns string.
  23. operator HSTRING() const { return str_; }
  24. // Whether there is a string created.
  25. bool success() const { return str_; }
  26. private:
  27. HSTRING str_;
  28. DISALLOW_COPY_AND_ASSIGN(ScopedHString);
  29. };
  30. #endif // BRIGHTRAY_BROWSER_WIN_SCOPED_HSTRING_H_