Skip to content

Commit

Permalink
Merge pull request #1016 from lairworks/signalVector
Browse files Browse the repository at this point in the history
Use `std::vector` in `Signal`
  • Loading branch information
DanRStevens authored Dec 7, 2021
2 parents ba63889 + d54b61d commit d026af0
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions NAS2D/Signal/SignalSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
#pragma once

#include "Delegate.h"
#include <set>
#include <vector>
#include <algorithm>


namespace NAS2D
Expand All @@ -28,23 +29,37 @@ namespace NAS2D

void clear() { delegateList.clear(); }

void connect(DelegateType delegate) { delegateList.insert(delegate); }
void connect(DelegateType delegate)
{
const auto iterator = std::find(delegateList.begin(), delegateList.end(), delegate);
if (iterator == delegateList.end())
{
delegateList.push_back(delegate);
}
}

template <typename X, typename Y>
void connect(Y* obj, void (X::*func)(Params...)) { delegateList.insert(MakeDelegate(obj, func)); }
void connect(Y* obj, void (X::*func)(Params...)) { connect(MakeDelegate(obj, func)); }

template <typename X, typename Y>
void connect(Y* obj, void (X::*func)(Params...) const) { delegateList.insert(MakeDelegate(obj, func)); }
void connect(Y* obj, void (X::*func)(Params...) const) { connect(MakeDelegate(obj, func)); }

void disconnect(DelegateType delegate) { delegateList.erase(delegate); }
void disconnect(DelegateType delegate)
{
const auto iterator = std::find(delegateList.begin(), delegateList.end(), delegate);
if (iterator != delegateList.end())
{
delegateList.erase(iterator);
}
}

template <typename X, typename Y>
void disconnect(Y* obj, void (X::*func)(Params...)) { delegateList.erase(MakeDelegate(obj, func)); }
void disconnect(Y* obj, void (X::*func)(Params...)) { disconnect(MakeDelegate(obj, func)); }

template <typename X, typename Y>
void disconnect(Y* obj, void (X::*func)(Params...) const) { delegateList.erase(MakeDelegate(obj, func)); }
void disconnect(Y* obj, void (X::*func)(Params...) const) { disconnect(MakeDelegate(obj, func)); }

protected:
std::set<DelegateType> delegateList{};
std::vector<DelegateType> delegateList;
};
} // namespace

0 comments on commit d026af0

Please sign in to comment.