mirror of
https://github.com/Xaymar/obs-StreamFX
synced 2024-11-10 22:05:06 +00:00
obs-source: Implement copy and move constructors and operators
There was no proper implementation for all copy and move constructors and operators before, which meant that occasionally the default behavior took over. This is not what we want, as the default behavior doesn't deal well with reference counted pointers. Related: #32, #33
This commit is contained in:
parent
f910312a2d
commit
9848c5aa28
2 changed files with 58 additions and 22 deletions
|
@ -456,29 +456,60 @@ obs::source::source(obs_source_t* source, bool track_ownership, bool add_referen
|
|||
connect_signals();
|
||||
}
|
||||
|
||||
obs::source& obs::source::operator=(const source& ref)
|
||||
obs::source::source(source const& other)
|
||||
{
|
||||
if (this != &ref) {
|
||||
if (self) {
|
||||
if (track_ownership) {
|
||||
obs_source_release(self);
|
||||
}
|
||||
}
|
||||
self = ref.self;
|
||||
track_ownership = ref.track_ownership;
|
||||
if (track_ownership) {
|
||||
obs_source_addref(self);
|
||||
}
|
||||
this->self = other.self;
|
||||
|
||||
this->track_ownership = other.track_ownership;
|
||||
if (this->track_ownership) {
|
||||
obs_source_addref(this->self);
|
||||
}
|
||||
}
|
||||
|
||||
obs::source& obs::source::operator=(source const& other)
|
||||
{
|
||||
if (this == &other) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Release previous source.
|
||||
if (this->self && this->track_ownership) {
|
||||
obs_source_release(this->self);
|
||||
}
|
||||
|
||||
this->self = other.self;
|
||||
this->track_ownership = other.track_ownership;
|
||||
if (this->track_ownership) {
|
||||
obs_source_addref(this->self);
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
obs::source& obs::source::operator=(source&& ref) noexcept
|
||||
obs::source::source(source&& other)
|
||||
{
|
||||
if (this != &ref) {
|
||||
self = ref.self;
|
||||
ref.self = nullptr;
|
||||
this->self = other.self;
|
||||
this->track_ownership = other.track_ownership;
|
||||
other.self = nullptr;
|
||||
other.track_ownership = false;
|
||||
}
|
||||
|
||||
obs::source& obs::source::operator=(source&& other)
|
||||
{
|
||||
if (this == &other) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Release previous source.
|
||||
if (this->self && this->track_ownership) {
|
||||
obs_source_release(this->self);
|
||||
}
|
||||
|
||||
this->self = other.self;
|
||||
this->track_ownership = other.track_ownership;
|
||||
other.self = nullptr;
|
||||
other.track_ownership = false;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
|
|
@ -77,10 +77,15 @@ namespace obs {
|
|||
|
||||
source(obs_source_t* source, bool track_ownership = true, bool add_reference = false);
|
||||
|
||||
source& operator=(const source& ref);
|
||||
public /*copy*/:
|
||||
source(source const& other);
|
||||
source& operator=(source const& other);
|
||||
|
||||
source& operator=(source&& ref) noexcept;
|
||||
public /*move*/:
|
||||
source(source&& other);
|
||||
source& operator=(source&& other);
|
||||
|
||||
public:
|
||||
obs_source_type type();
|
||||
|
||||
void* type_data();
|
||||
|
@ -108,17 +113,17 @@ namespace obs {
|
|||
|
||||
util::event<obs::source*, bool> enable;
|
||||
|
||||
util::event<obs::source*, bool> push_to_mute_changed;
|
||||
util::event<obs::source*, bool> push_to_mute_changed;
|
||||
util::event<obs::source*, long long> push_to_mute_delay;
|
||||
util::event<obs::source*, bool> push_to_talk_changed;
|
||||
util::event<obs::source*, bool> push_to_talk_changed;
|
||||
util::event<obs::source*, long long> push_to_talk_delay;
|
||||
|
||||
util::event<obs::source*, std::string, std::string> rename;
|
||||
|
||||
util::event<obs::source*> update_properties;
|
||||
util::event<obs::source*> update_properties;
|
||||
util::event<obs::source*, long long> update_flags;
|
||||
|
||||
util::event<obs::source*, bool> mute;
|
||||
util::event<obs::source*, bool> mute;
|
||||
util::event<obs::source*, double&> volume;
|
||||
util::event<obs::source*, long long&> audio_sync;
|
||||
util::event<obs::source*, long long&> audio_mixers;
|
||||
|
|
Loading…
Reference in a new issue