I am implementing an interface's method that receives a std::streambuf as argument using the boost::asio library and downcasting that std::streambuf to boost::asio::streambuf.
The objetive is implement a TCP/IP communication API abstrating the boost library, so enabling the possibility of changing it in the future, re-implementing the interface.
Below is the code:
class Interface {
[...]
virtual size_t readUntil(std::streambuf &streamBuffer,
const std::string &until) = 0;
[...]
}
class BoostImplementation : public Interface {
virtual size_t readUntil(std::streambuf &streamBuffer,
const std::string &until) {
[...]
size_t numBytes = boost::asio::read_until(
*m_socket,
dynamic_cast<boost::asio::streambuf&>(streamBuffer),
until);
[...]
}
}
Is the above dynamic_cast<boost::asio::streambuf&>(streamBuffer)
an anti-pattern? Is there any other way to do what I want?
Aucun commentaire:
Enregistrer un commentaire