[DEV] correct the copy of the connection
This commit is contained in:
parent
c4eb2635a3
commit
dd8296fd60
@ -24,12 +24,23 @@ namespace esignal {
|
|||||||
m_signalRefUnique(), m_uid(0) {
|
m_signalRefUnique(), m_uid(0) {
|
||||||
|
|
||||||
}
|
}
|
||||||
Connection(LockSharedPtrRef<Base> _ref, std::size_t _id):
|
Connection(const LockSharedPtrRef<Base>& _ref, std::size_t _id):
|
||||||
m_signalRefUnique(_ref), m_uid(_id) {
|
m_signalRefUnique(_ref),
|
||||||
|
m_uid(_id) {
|
||||||
|
|
||||||
}
|
}
|
||||||
Connection(Connection&&) = default; // movable
|
Connection(Connection&& _obj):
|
||||||
Connection& operator=(Connection&&) = default; // movable op
|
m_signalRefUnique(_obj.m_signalRefUnique),
|
||||||
|
m_uid(_obj.m_uid) {
|
||||||
|
_obj.m_uid = 0;
|
||||||
|
}
|
||||||
|
Connection& operator=(Connection&& _obj) {
|
||||||
|
disconnect();
|
||||||
|
m_signalRefUnique = _obj.m_signalRefUnique;
|
||||||
|
m_uid = _obj.m_uid;
|
||||||
|
_obj.m_uid = 0;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
Connection(const Connection&) = delete; // not copyable
|
Connection(const Connection&) = delete; // not copyable
|
||||||
Connection& operator=(const Connection&) = delete; // no copy operator
|
Connection& operator=(const Connection&) = delete; // no copy operator
|
||||||
/*
|
/*
|
||||||
|
@ -33,7 +33,7 @@ namespace esignal {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// copy constructor:
|
// copy constructor:
|
||||||
LockSharedPtrRef(const LockSharedPtrRef& _obj) :
|
LockSharedPtrRef(const LockSharedPtrRef<TYPE>& _obj) :
|
||||||
m_counter(_obj.m_counter) {
|
m_counter(_obj.m_counter) {
|
||||||
if (m_counter == nullptr) {
|
if (m_counter == nullptr) {
|
||||||
return;
|
return;
|
||||||
@ -41,8 +41,8 @@ namespace esignal {
|
|||||||
m_counter->inc();
|
m_counter->inc();
|
||||||
}
|
}
|
||||||
// copy operator:
|
// copy operator:
|
||||||
LockSharedPtrRef& operator=(LockSharedPtrRef) = delete;
|
//LockSharedPtrRef& operator=(LockSharedPtrRef<TYPE>) = delete;
|
||||||
LockSharedPtrRef& operator=(const LockSharedPtrRef& _obj) {
|
LockSharedPtrRef& operator=(const LockSharedPtrRef<TYPE>& _obj) {
|
||||||
if (&_obj == this) {
|
if (&_obj == this) {
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@ -52,20 +52,24 @@ namespace esignal {
|
|||||||
}
|
}
|
||||||
m_counter = _obj.m_counter;
|
m_counter = _obj.m_counter;
|
||||||
if (m_counter == nullptr) {
|
if (m_counter == nullptr) {
|
||||||
return;
|
return *this;
|
||||||
}
|
}
|
||||||
m_counter->inc();
|
m_counter->inc();
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
// Move constructor
|
// Move constructor
|
||||||
LockSharedPtrRef(LockSharedPtrRef&& _obj) :
|
LockSharedPtrRef(LockSharedPtrRef<TYPE>&& _obj) :
|
||||||
m_counter(std::move(_obj.m_counter)) {
|
m_counter(std::move(_obj.m_counter)) {
|
||||||
|
|
||||||
}
|
}
|
||||||
// Move operator
|
// Move operator
|
||||||
LockSharedPtrRef& operator=(LockSharedPtrRef&& _obj) {
|
#if 1
|
||||||
|
LockSharedPtrRef& operator=(LockSharedPtrRef<TYPE>&& _obj) = delete;
|
||||||
|
#else
|
||||||
|
LockSharedPtrRef& operator=(LockSharedPtrRef<TYPE>&& _obj) {
|
||||||
m_counter = std::move(_obj.m_counter);
|
m_counter = std::move(_obj.m_counter);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
~LockSharedPtrRef() {
|
~LockSharedPtrRef() {
|
||||||
int64_t count = m_counter->dec();
|
int64_t count = m_counter->dec();
|
||||||
if (count > 0) {
|
if (count > 0) {
|
||||||
|
@ -102,8 +102,8 @@ namespace esignal {
|
|||||||
};
|
};
|
||||||
public:
|
public:
|
||||||
template< class ObserverType >
|
template< class ObserverType >
|
||||||
Connection connect(ObserverType&& observer ) {
|
Connection connect(ObserverType&& _observer ) {
|
||||||
std::unique_ptr<Executor> executer(new Executor(std::forward<ObserverType>(observer)));
|
std::unique_ptr<Executor> executer(new Executor(std::forward<ObserverType>(_observer)));
|
||||||
std::size_t uid = executer->m_uid;
|
std::size_t uid = executer->m_uid;
|
||||||
m_executors.push_back(std::move(executer));
|
m_executors.push_back(std::move(executer));
|
||||||
return Connection(Base::m_shared, uid);
|
return Connection(Base::m_shared, uid);
|
||||||
|
@ -111,18 +111,18 @@ TEST(test_signal_arg, checkType) {
|
|||||||
EXPECT_EQ(connectedClass->m_valueInt32, 22);
|
EXPECT_EQ(connectedClass->m_valueInt32, 22);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#if 0
|
||||||
esignal::Signal<std::string> signal;
|
esignal::Signal<std::string> signal;
|
||||||
/*
|
/*
|
||||||
TestConnect connectedClass;
|
TestConnect connectedClass;
|
||||||
esignal::Connection h6564 = signal.connect(connectedClass, TestConnect::non_const);
|
esignal::Connection h6564 = signal.connect(&connectedClass, TestConnect::non_const);
|
||||||
esignal::Connection h6565 = signal.connect(connectedClass, TestConnect::is_const);
|
esignal::Connection h6565 = signal.connect(&connectedClass, TestConnect::is_const);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
std::shared_ptr<TestConnectShared> connectedClassShared = std::make_shared<TestConnectShared>();
|
std::shared_ptr<TestConnectShared> connectedClassShared = std::make_shared<TestConnectShared>();
|
||||||
signal.connect(connectedClassShared, &TestConnectShared::non_const);
|
signal.connect(connectedClassShared, &TestConnectShared::non_const);
|
||||||
signal.connect(connectedClassShared, &TestConnectShared::is_const);
|
signal.connect(connectedClassShared, &TestConnectShared::is_const);
|
||||||
|
#endif
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
esignal::Signal<int, float, char> signal;
|
esignal::Signal<int, float, char> signal;
|
||||||
@ -205,6 +205,13 @@ TEST(test_signal_arg, checkType) {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
esignal::Signal<std::string> signal;
|
||||||
|
|
||||||
|
TestConnect connectedClass;
|
||||||
|
esignal::Connection h6564 = signal.connect(&connectedClass, &TestConnect::non_const);
|
||||||
|
h6564.disconnect();
|
||||||
|
h6564 = signal.connect(&connectedClass, &TestConnect::is_const);
|
||||||
|
signal.emit("kljlkjlkjlkj");
|
||||||
|
|
||||||
std::cout << "========================================= " << std::endl;
|
std::cout << "========================================= " << std::endl;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user