obs-studio/libobs/obs.hpp

94 lines
2.6 KiB
C++
Raw Normal View History

2013-11-22 15:20:02 -08:00
/******************************************************************************
Copyright (C) 2013 by Hugh Bailey <obs.jim@gmail.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
2013-11-22 15:20:02 -08:00
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/
2013-12-22 16:42:02 -08:00
/* Useful C++ classes and bindings for base obs data */
2013-11-22 15:20:02 -08:00
#pragma once
2013-12-22 16:42:02 -08:00
#include "obs.h"
2013-11-22 19:57:24 -08:00
/* RAII wrappers */
template<class RefClass> class OBSRef {
typedef typename RefClass::type T;
T val;
2013-11-22 15:20:02 -08:00
public:
inline OBSRef() : val(nullptr) {}
inline OBSRef(T val_) : val(val_) {RefClass::AddRef(val);}
inline OBSRef(const OBSRef &ref) : val(ref.val) {RefClass::AddRef(val);}
inline OBSRef(OBSRef &&ref) : val(ref.val) {ref.val = nullptr;}
2013-11-22 15:20:02 -08:00
inline ~OBSRef() {RefClass::Release(val);}
2013-11-22 15:20:02 -08:00
inline OBSRef &operator=(T valIn)
2013-11-22 15:20:02 -08:00
{
RefClass::AddRef(valIn);
RefClass::Release(val);
val = valIn;
2013-11-22 15:20:02 -08:00
return *this;
}
inline OBSRef &operator=(const OBSRef &ref)
2013-11-22 15:20:02 -08:00
{
RefClass::AddRef(ref.val);
RefClass::Release(val);
val = ref.val;
2013-11-22 15:20:02 -08:00
return *this;
}
inline OBSRef &operator=(OBSRef &&ref)
2013-11-22 15:20:02 -08:00
{
if (this != &ref) {
val = ref.val;
ref.val = NULL;
2013-11-22 15:20:02 -08:00
}
return *this;
}
inline operator T() const {return val;}
2013-11-22 15:20:02 -08:00
inline bool operator==(T p) const {return val == p;}
inline bool operator!=(T p) const {return val != p;}
2013-11-22 15:20:02 -08:00
};
class OBSSourceRefClass {
public:
typedef obs_source_t type;
static inline void AddRef(type val) {obs_source_addref(val);}
static inline void Release(type val) {obs_source_release(val);}
};
class OBSSceneRefClass {
public:
typedef obs_scene_t type;
static inline void AddRef(type val) {obs_scene_addref(val);}
static inline void Release(type val) {obs_scene_release(val);}
};
class OBSSceneItemRefClass {
public:
typedef obs_sceneitem_t type;
static inline void AddRef(type val) {obs_sceneitem_addref(val);}
static inline void Release(type val) {obs_sceneitem_release(val);}
};
typedef OBSRef<OBSSourceRefClass> OBSSource;
typedef OBSRef<OBSSceneRefClass> OBSScene;
typedef OBSRef<OBSSceneItemRefClass> OBSSceneItem;