diff options
| author | Matias Fontanini <matias.fontanini@gmail.com> | 2012-10-20 11:12:59 -0300 |
|---|---|---|
| committer | Matias Fontanini <matias.fontanini@gmail.com> | 2012-10-20 11:12:59 -0300 |
| commit | 5fd892c77e2744dd2a05e4f5d8b3224d70b83483 (patch) | |
| tree | 4e42bf75290fe68d790d3c8aa0bd6714fb67d873 /include/utils.h | |
| parent | abaa2bf9265eabd448e255410533f04186a3cb9e (diff) | |
Fixed some bugs. Added documentation.v0.2
Diffstat (limited to 'include/utils.h')
| -rw-r--r-- | include/utils.h | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/include/utils.h b/include/utils.h index b3a5fc9..ea81a21 100644 --- a/include/utils.h +++ b/include/utils.h @@ -228,9 +228,57 @@ namespace Tins { } #endif // WIN32 + /** + * \cond + */ namespace Internals { void skip_line(std::istream &input); bool from_hex(const std::string &str, uint32_t &result); + + template<bool, typename> + struct enable_if { + + }; + + template<typename T> + struct enable_if<true, T> { + typedef T type; + }; + } + /** + * \endcond + */ + + template <typename T> + struct is_pdu { + template <typename U> + static char test(typename U::PDUType*); + + template <typename U> + static long test(...); + + static const bool value = sizeof(test<T>(0)) == 1; + }; + + /** + * Returns the argument. + */ + inline PDU& dereference_until_pdu(PDU &pdu) { + return pdu; + } + + /** + * \brief Dereferences the parameter until a PDU is found. + * + * This function dereferences the parameter until a PDU object + * is found. When it's found, it is returned. + * + * \param value The parameter to be dereferenced. + */ + template<typename T> + inline typename Internals::enable_if<!is_pdu<T>::value, PDU&>::type + dereference_until_pdu(T &value) { + return dereference_until_pdu(*value); } } } |
