mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-28 03:13:35 +08:00
ReceivedDataStructure<> made noncopyable
This commit is contained in:
@@ -29,9 +29,14 @@ namespace uavcan
|
|||||||
* void first(const ReceivedDataStructure<Foo>& msg);
|
* void first(const ReceivedDataStructure<Foo>& msg);
|
||||||
* void second(const Foo& msg);
|
* void second(const Foo& msg);
|
||||||
* In the latter case, an implicit cast will happen before the callback is invoked.
|
* In the latter case, an implicit cast will happen before the callback is invoked.
|
||||||
|
*
|
||||||
|
* This class is not copyable because it holds a reference to a stack-allocated transfer descriptor object.
|
||||||
|
* You can slice cast it to the underlying data type though, which would be copyable:
|
||||||
|
* DataType dt = rds; // where rds is of type ReceivedDataStructure<DataType>
|
||||||
|
* // dt is now copyable
|
||||||
*/
|
*/
|
||||||
template <typename DataType_>
|
template <typename DataType_>
|
||||||
class UAVCAN_EXPORT ReceivedDataStructure : public DataType_
|
class UAVCAN_EXPORT ReceivedDataStructure : public DataType_, Noncopyable
|
||||||
{
|
{
|
||||||
const IncomingTransfer* const _transfer_; ///< Such weird name is necessary to avoid clashing with DataType fields
|
const IncomingTransfer* const _transfer_; ///< Such weird name is necessary to avoid clashing with DataType fields
|
||||||
|
|
||||||
|
|||||||
@@ -14,18 +14,16 @@
|
|||||||
template <typename DataType>
|
template <typename DataType>
|
||||||
class SubscriptionCollector : uavcan::Noncopyable
|
class SubscriptionCollector : uavcan::Noncopyable
|
||||||
{
|
{
|
||||||
typedef uavcan::ReceivedDataStructure<DataType> ReceivedDataStructType;
|
void handler(const DataType& msg)
|
||||||
|
|
||||||
void handler(const ReceivedDataStructType& msg)
|
|
||||||
{
|
{
|
||||||
this->msg.reset(new ReceivedDataStructType(msg));
|
this->msg.reset(new DataType(msg));
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
std::auto_ptr<ReceivedDataStructType> msg;
|
std::auto_ptr<DataType> msg;
|
||||||
|
|
||||||
typedef uavcan::MethodBinder<SubscriptionCollector*,
|
typedef uavcan::MethodBinder<SubscriptionCollector*,
|
||||||
void (SubscriptionCollector::*)(const ReceivedDataStructType&)> Binder;
|
void (SubscriptionCollector::*)(const DataType&)> Binder;
|
||||||
|
|
||||||
Binder bind() { return Binder(this, &SubscriptionCollector::handler); }
|
Binder bind() { return Binder(this, &SubscriptionCollector::handler); }
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user