From: Guilherme Maciel Ferreira Date: Fri, 4 Nov 2011 02:08:39 +0000 (-0200) Subject: Providing read() and write() methods, once operators >> and << does work properly... X-Git-Tag: v1.2~42 X-Git-Url: http://developer.intra2net.com/git/?a=commitdiff_plain;h=34a2dd333b605ce26fd2785a642c5fe02c1316ca;p=pingcheck Providing read() and write() methods, once operators >> and << does work properly with smart pointers --- diff --git a/src/icmp/icmppacket.h b/src/icmp/icmppacket.h index 7949198..a2c1084 100644 --- a/src/icmp/icmppacket.h +++ b/src/icmp/icmppacket.h @@ -23,10 +23,12 @@ #include +#include #include #include #include +#include //----------------------------------------------------------------------------- // IcmpPacket @@ -58,6 +60,15 @@ public: ) const = 0; virtual void print_destination_unreachable() const = 0; + virtual bool read( std::istream &is ) = 0; + virtual void write( std::ostream &os ) const = 0; + }; +//----------------------------------------------------------------------------- +// IcmpPacketItem +//----------------------------------------------------------------------------- + +typedef boost::shared_ptr IcmpPacketItem; + #endif // ICMP_PACKET_H diff --git a/src/icmp/icmpv4packet.cpp b/src/icmp/icmpv4packet.cpp index 65155e2..0a60aa8 100644 --- a/src/icmp/icmpv4packet.cpp +++ b/src/icmp/icmpv4packet.cpp @@ -202,6 +202,18 @@ void Icmpv4Packet::print_destination_unreachable() const << " Destination Net Unreachable" << endl; } +bool Icmpv4Packet::read( istream &is ) +{ + is >> *this; + + return is.fail(); +} + +void Icmpv4Packet::write( ostream &os ) const +{ + os << *this; +} + istream& operator>>( istream &is, Icmpv4Packet &packet diff --git a/src/icmp/icmpv4packet.h b/src/icmp/icmpv4packet.h index a2dc56d..51511a3 100644 --- a/src/icmp/icmpv4packet.h +++ b/src/icmp/icmpv4packet.h @@ -97,6 +97,9 @@ public: ) const; void print_destination_unreachable() const; + bool read( std::istream &is ); + void write( std::ostream &os ) const; + friend std::istream& operator>>( std::istream &is, Icmpv4Packet &packet diff --git a/src/icmp/icmpv6packet.cpp b/src/icmp/icmpv6packet.cpp index 0661c93..ecaff54 100644 --- a/src/icmp/icmpv6packet.cpp +++ b/src/icmp/icmpv6packet.cpp @@ -202,6 +202,18 @@ void Icmpv6Packet::print_destination_unreachable() const << " Destination Net Unreachable" << endl; } +bool Icmpv6Packet::read( istream &is ) +{ + is >> *this; + + return is.fail(); +} + +void Icmpv6Packet::write( ostream &os ) const +{ + os << *this; +} + istream& operator>>( istream &is, Icmpv6Packet &packet diff --git a/src/icmp/icmpv6packet.h b/src/icmp/icmpv6packet.h index d3923b4..4e88da8 100644 --- a/src/icmp/icmpv6packet.h +++ b/src/icmp/icmpv6packet.h @@ -111,6 +111,9 @@ public: ) const; void print_destination_unreachable() const; + bool read( std::istream &is ); + void write( std::ostream &os ) const; + friend std::istream& operator>>( std::istream &is, Icmpv6Packet &packet