r17903 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r17902‎ | r17903 | r17904 >
Date:06:43, 24 November 2006
Author:river
Status:old
Tags:
Comment:
document sockaddr_cast<>
Modified paths:
  • /trunk/willow/src/include/util.h (modified) (history)

Diff [purge]

Index: trunk/willow/src/include/util.h
@@ -89,6 +89,9 @@
9090 };
9191
9292 #ifdef WILLOW_DEBUG
 93+/*
 94+ * Helper classes for sockaddr_caster, see below.
 95+ */
9396 typedef mpl::map<
9497 mpl::pair<sockaddr_in, mpl::int_<AF_INET> >,
9598 mpl::pair<sockaddr_in6, mpl::int_<AF_INET6> >,
@@ -130,12 +133,33 @@
131134
132135 #endif
133136
 137+/**
 138+ * Cast from one sockaddr type to another. If the conversion can be proved
 139+ * invalid at compile time (e.g. the from type is not a sockaddr), a compile
 140+ * time error will be generated. Otherwise an assertion failure will be
 141+ * triggered at runtime if the sa_family of the type being cast does not match
 142+ * the destination type.
 143+ *
 144+ * Usage:
 145+ *
 146+ * \code
 147+ * void f(sockaddr *s) {
 148+ * sockaddr_in *sin = sockaddr_cast<sockaddr_in *>(s);
 149+ * ...
 150+ * }
 151+ * \endcode
 152+ *
 153+ * \param To sockaddr type to cast to
 154+ * \param From sockaddr type to cast from
 155+ * \param f sockaddr struct to cast
 156+ * \returns the result of the cast
 157+ */
134158 template<typename To, typename From>
135 -To sockaddr_cast(From from) {
 159+To sockaddr_cast(From f) {
136160 #ifdef WILLOW_DEBUG
137 - return sockaddr_caster<To, From>::cast(from);
 161+ return sockaddr_caster<To, From>::cast(f);
138162 #else
139 - return reinterpret_cast<To>(from);
 163+ return reinterpret_cast<To>(f);
140164 #endif
141165 }
142166