qt_interface.cc 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // Copyright 2022 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 file.
  4. #include "ui/qt/qt_interface.h"
  5. #include <cstdlib>
  6. #include <cstring>
  7. namespace qt {
  8. String::String() = default;
  9. String::String(const char* str) {
  10. if (str)
  11. str_ = strdup(str);
  12. }
  13. String::String(String&& other) {
  14. str_ = other.str_;
  15. other.str_ = nullptr;
  16. }
  17. String& String::operator=(String&& other) {
  18. free(str_);
  19. str_ = other.str_;
  20. other.str_ = nullptr;
  21. return *this;
  22. }
  23. String::~String() {
  24. free(str_);
  25. }
  26. Buffer::Buffer() = default;
  27. Buffer::Buffer(const uint8_t* data, size_t size)
  28. : data_(static_cast<uint8_t*>(malloc(size))), size_(size) {
  29. memcpy(data_, data, size);
  30. }
  31. Buffer::Buffer(Buffer&& other) {
  32. data_ = other.data_;
  33. size_ = other.size_;
  34. other.data_ = nullptr;
  35. other.size_ = 0;
  36. }
  37. Buffer& Buffer::operator=(Buffer&& other) {
  38. free(data_);
  39. data_ = other.data_;
  40. size_ = other.size_;
  41. other.data_ = nullptr;
  42. other.size_ = 0;
  43. return *this;
  44. }
  45. Buffer::~Buffer() {
  46. free(data_);
  47. }
  48. uint8_t* Buffer::Take() {
  49. uint8_t* data = data_;
  50. data_ = nullptr;
  51. size_ = 0;
  52. return data;
  53. }
  54. } // namespace qt