FREE Subscription to Dr. Dobb’s Digest: Same Great Content, New Digital Edition
Site Archive (Complete)
C++
Email
Print
Reprint

add to:
Del.icio.us
Digg
Google
Furl
Slashdot
Y! MyWeb
Blink
December 01, 2003
Static Packet Construction with C++ Templates

(Page 1 of 3)
Martin Casado
Martin uses C++ templates for static packet construction, and shows how you can use this technique to write generic routines in support of low-level networking primitives.
Static Packet Construction with C++ Templates

Listing 1: Class declaration for ipaddr.

struct ipaddr
{
    uint32_t addr;
    // --- Constructors ---
    ipaddr();
    ipaddr(const ipaddr&);
    ipaddr(const std::string&);
    // --- String Representation --
    char* toString() const;
    // --- Binary Operators ---
    ipaddr operator ~ () const;
    ipaddr operator & (const ipaddr&) const;
    ipaddr operator | (const ipaddr&) const;
    // --- Mathematical operators ---
    ipaddr operator ++ ();
    ipaddr operator -- ();
    // --- Assignment Operator ---
    ipaddr& operator = (const ipaddr&);
    ipaddr& operator = (const std::string &);
    // --- Comparison Operators ---
    bool operator == (const ipaddr&) const;
    bool operator != (const ipaddr&) const;
    bool operator <  (const ipaddr&) const;
    bool operator <= (const ipaddr&) const;
    bool operator >  (const ipaddr&) const;
    bool operator >= (const ipaddr&) const;
}; // -- struct ipaddr
1 | 2 | 3 Next Page
TOP 5 ARTICLES
No Top Articles.



MICROSITES
FEATURED TOPIC

ADDITIONAL TOPICS

INFO-LINK