obs.hpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /******************************************************************************
  2. Copyright (C) 2013 by Hugh Bailey <[email protected]>
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. ******************************************************************************/
  14. /* Useful C++ classes and bindings for base obs data */
  15. #pragma once
  16. #include <string.h>
  17. #include <stdarg.h>
  18. #include "obs.h"
  19. /* RAII wrappers */
  20. class OBSSource {
  21. obs_source_t source;
  22. OBSSource(OBSSource &&) = delete;
  23. OBSSource(OBSSource const&) = delete;
  24. OBSSource &operator=(OBSSource const&) = delete;
  25. public:
  26. inline OBSSource(obs_source_t source) : source(source) {}
  27. inline ~OBSSource() {obs_source_release(source);}
  28. inline OBSSource& operator=(obs_source_t p) {source = p; return *this;}
  29. inline operator obs_source_t() {return source;}
  30. inline bool operator==(obs_source_t p) const {return source == p;}
  31. inline bool operator!=(obs_source_t p) const {return source != p;}
  32. };
  33. class OBSSourceRef {
  34. obs_source_t source;
  35. public:
  36. inline OBSSourceRef(obs_source_t source) : source(source)
  37. {
  38. obs_source_addref(source);
  39. }
  40. inline OBSSourceRef(const OBSSourceRef &ref) : source(ref.source)
  41. {
  42. obs_source_addref(source);
  43. }
  44. inline OBSSourceRef(OBSSourceRef &&ref) : source(ref.source)
  45. {
  46. ref.source = NULL;
  47. }
  48. inline ~OBSSourceRef() {obs_source_release(source);}
  49. inline OBSSourceRef &operator=(obs_source_t sourceIn)
  50. {
  51. obs_source_addref(sourceIn);
  52. obs_source_release(source);
  53. source = sourceIn;
  54. return *this;
  55. }
  56. inline OBSSourceRef &operator=(const OBSSourceRef &ref)
  57. {
  58. obs_source_addref(ref.source);
  59. obs_source_release(source);
  60. source = ref.source;
  61. return *this;
  62. }
  63. inline OBSSourceRef &operator=(OBSSourceRef &&ref)
  64. {
  65. if (this != &ref) {
  66. source = ref.source;
  67. ref.source = NULL;
  68. }
  69. return *this;
  70. }
  71. inline operator obs_source_t() const {return source;}
  72. inline bool operator==(obs_source_t p) const {return source == p;}
  73. inline bool operator!=(obs_source_t p) const {return source != p;}
  74. };