From a3e863942bca8607652e05e037b52fa55c22ef92 Mon Sep 17 00:00:00 2001 From: Matias Fontanini Date: Sun, 30 Apr 2017 09:36:50 -0700 Subject: [PATCH] Move type traits into a separate file --- include/tins/detail/type_traits.h | 83 +++++++++++++++++++++++++++++++ include/tins/internals.h | 36 +------------- include/tins/utils.h | 3 +- src/icmp.cpp | 1 + src/utils.cpp | 1 + 5 files changed, 88 insertions(+), 36 deletions(-) create mode 100644 include/tins/detail/type_traits.h diff --git a/include/tins/detail/type_traits.h b/include/tins/detail/type_traits.h new file mode 100644 index 0000000..c2bfb38 --- /dev/null +++ b/include/tins/detail/type_traits.h @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2017, Matias Fontanini + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef TINS_TYPE_TRAITS_H +#define TINS_TYPE_TRAITS_H + +#include + +namespace Tins { +namespace Internals { +/** + * \cond + */ + +template +struct enable_if { + typedef T type; +}; + +template +struct enable_if { + +}; + +template +struct is_unsigned_integral { + static const bool value = false; +}; + +template<> +struct is_unsigned_integral { + static const bool value = true; +}; + +template<> +struct is_unsigned_integral { + static const bool value = true; +}; + +template<> +struct is_unsigned_integral { + static const bool value = true; +}; + +template<> +struct is_unsigned_integral { + static const bool value = true; +}; + +/** + * \endcond + */ + +} // Internals +} // Tins + +#endif // TINS_TYPE_TRAITS_H diff --git a/include/tins/internals.h b/include/tins/internals.h index 17f4cc4..a4304e5 100644 --- a/include/tins/internals.h +++ b/include/tins/internals.h @@ -39,6 +39,7 @@ #include "pdu.h" #include "hw_address.h" #include "macros.h" +#include "detail/type_traits.h" /** * \cond @@ -109,16 +110,6 @@ void skip_line(std::istream& input); bool from_hex(const std::string& str, uint32_t& result); bool from_hex(const std::string& str, std::string& result); -template -struct enable_if { - typedef T type; -}; - -template -struct enable_if { - -}; - PDU* pdu_from_flag(Constants::Ethernet::e flag, const uint8_t* buffer, uint32_t size, bool rawpdu_on_no_match = true); PDU* pdu_from_flag(Constants::IP::e flag, const uint8_t* buffer, @@ -199,31 +190,6 @@ inline bool is_dot3(const uint8_t* ptr, size_t sz) { return (sz >= 13 && ptr[12] < 8); } -template -struct is_unsigned_integral { - static const bool value = false; -}; - -template<> -struct is_unsigned_integral { - static const bool value = true; -}; - -template<> -struct is_unsigned_integral { - static const bool value = true; -}; - -template<> -struct is_unsigned_integral { - static const bool value = true; -}; - -template<> -struct is_unsigned_integral { - static const bool value = true; -}; - #if TINS_IS_CXX11 && !defined(_MSC_VER) // Template metaprogramming trait to determine if a functor can accept another parameter as an argument diff --git a/include/tins/utils.h b/include/tins/utils.h index 1ac877d..0e9c341 100644 --- a/include/tins/utils.h +++ b/include/tins/utils.h @@ -37,7 +37,8 @@ #include #include "ip_address.h" #include "ipv6_address.h" -#include "internals.h" +#include "pdu.h" +#include "detail/type_traits.h" // Fix for Windows interface define on combaseapi.h #undef interface diff --git a/src/icmp.cpp b/src/icmp.cpp index 8695ccb..3404c77 100644 --- a/src/icmp.cpp +++ b/src/icmp.cpp @@ -36,6 +36,7 @@ #include "utils.h" #include "exceptions.h" #include "icmp.h" +#include "internals.h" #include "memory_helpers.h" using std::memset; diff --git a/src/utils.cpp b/src/utils.cpp index c849e17..3a6e0b9 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -68,6 +68,7 @@ #include "cxxstd.h" #include "hw_address.h" #include "memory_helpers.h" +#include "internals.h" #include "detail/smart_ptr.h" using std::string;