diff --git a/acn/pdu.h b/acn/pdu.h index 62008b8..4c94c5d 100644 --- a/acn/pdu.h +++ b/acn/pdu.h @@ -62,52 +62,65 @@ struct pdu_flags * @brief The pdu_header struct */ struct pdu_header : public pdu_stream_object {}; - +// C++20 +//template +//concept header = std::is_base_of::value; /** * @brief The pdu_data struct */ struct pdu_data : public pdu_stream_object {}; +// C++20 +//template +//concept data = std::is_base_of::value; +// C++20 +//template +//concept pdu = std::is_base_of::value; /** * @brief PDU::pdu_data subclass that encapsulates other PDU. * @tparam T PDU decendant subclass */ -template +//template // C++20 +template struct Block : public pdu_data { - std::shared_ptr>> pdu - = std::shared_ptr>> + Block() { + static_assert(std::is_base_of::value, + "type parameter of ACN::PDU::Block must derive from ACN::PDU::Pdu"); + } + std::shared_ptr>> pdu + = std::shared_ptr>> (new std::vector>); - void setParent(std::shared_ptr parent) { - for (auto p : *pdu) - p->setParent(parent); - } - size_t streamSize() const override { - size_t s = 0; - for (auto &child : *pdu) - s += child->streamSize(); - return s; - } - void iStream(Stream s) override { - while(s->good()) { - std::shared_ptr p(new T()); - p->iStream(s); - if (s->fail()) // stream failed during pdu read - break; - if (p->stream()->fail()) // pdu buffer failed - continue; - if (!pdu->empty()) // set inheritee - p->setInherit(pdu->back()); - pdu->push_back(p); // add to block - } - } - void oStream(Stream s) const override { - for ( const auto & child : *pdu ) - child->oStream(s); - }; + void setParent(std::shared_ptr parent) { + for (auto p : *pdu) + p->setParent(parent); + } + size_t streamSize() const override { + size_t s = 0; + for (auto &child : *pdu) + s += child->streamSize(); + return s; + } + void iStream(Stream s) override { + while(s->good()) { + std::shared_ptr p(new T()); + p->iStream(s); + if (s->fail()) // stream failed during pdu read + break; + if (p->stream()->fail()) // pdu buffer failed + continue; + if (!pdu->empty()) // set inheritee + p->setInherit(pdu->back()); + pdu->push_back(p); // add to block + } + } + void oStream(Stream s) const override { + for ( const auto & child : *pdu ) + child->oStream(s); + }; }; @@ -149,6 +162,7 @@ public: void setInherit(std::shared_ptr pdu) {inherit_ = pdu;} // protocol payloads +//template
// C++20 template void createHeader() { @@ -159,6 +173,8 @@ public: header_->iStream(stream_); } } + +//template // C++20 template void createData() { @@ -169,6 +185,7 @@ public: data_->iStream(stream_); } } +//template // C++20 template void createDataBlock() { auto block = new PDU::Block(); @@ -194,6 +211,7 @@ protected: * @brief Callback that understands how to proccess a PDU type. * @tparam T PDU decendant subclass */ +//template // C++20 template using Handler = std::function)>;