Add 'unflatten' to doxygen/dot processing
[senf.git] / Socket / Protocols / BSDSocketAddress.hh
index 5afd329..2040513 100644 (file)
@@ -27,6 +27,9 @@
 #define HH_SENF_Socket_Protocols_BSDSocketAddress_ 1
 
 // Custom includes
+#include <boost/type_traits/alignment_of.hpp>
+#include <boost/type_traits/type_with_alignment.hpp>
+#include <boost/operators.hpp>
 #include "../../Utils/safe_bool.hh"
 #include <sys/socket.h>
 #include <iostream>
@@ -71,14 +74,19 @@ namespace senf {
         \ingroup addr_group
       */
     class BSDSocketAddress
-        : public senf::comparable_safe_bool<BSDSocketAddress>
+        : public senf::comparable_safe_bool<BSDSocketAddress>,
+          public boost::less_than_comparable<BSDSocketAddress>,
+          public boost::equality_comparable<BSDSocketAddress>
     {
     public:
         bool operator==(BSDSocketAddress const & other) const; ///< Compare two arbitrary addresses
                                         /**< For addresses to be considered equal, they must have
                                              the same family, length and the data must be
                                              identical. */
-        bool operator!=(BSDSocketAddress const & other) const; ///< Inverse of operator==
+        bool operator<(BSDSocketAddress const & other) const; ///< Compare two arbitrary addresses
+                                        /**< Ordering is based on the in-memory representation.  It
+                                             is primarily useful to use addresses as keys in a map
+                                             or set. */
 
         bool boolean_test() const;      ///< Return \c true, if address is not empty
                                         /**< An address is considered empty if
@@ -112,8 +120,15 @@ namespace senf {
         void socklen(socklen_t len);
 
     private:
-
-        socklen_t len_;
+        // The following incantation is needed to fix the alignment of the sockaddr data members
+        // which will be added by the derived classes later: The alignment must be forced
+        // to coincide with the struct sockaddr_storage alignment (which must have the largest
+        // alignment of all sockaddr types).
+        union {
+            socklen_t len_;
+            boost::type_with_alignment<boost::alignment_of<struct sockaddr_storage>::value> a_;
+            char _b[boost::alignment_of<struct sockaddr_storage>::value];
+        };
     };
 
     /** \brief Safe socket address down-cast