From 60b5f3e6e4bde9e81f45082c36c8209a706db4d6 Mon Sep 17 00:00:00 2001 From: Matias Fontanini Date: Sun, 30 Apr 2017 18:51:55 -0700 Subject: [PATCH] Remove inclusion of algorithm almost everywhere --- include/tins/ip.h | 10 +++++----- include/tins/pdu_option.h | 40 +++++++++++++++++++++++++------------ src/arp.cpp | 1 - src/dhcp.cpp | 8 ++------ src/dhcpv6.cpp | 9 ++------- src/dot11/dot11_base.cpp | 7 ++----- src/dot11/dot11_control.cpp | 3 +-- src/dot3.cpp | 12 +++++------ src/eapol.cpp | 24 ++++++++++------------ src/ethernetII.cpp | 8 ++------ src/icmp_extension.cpp | 1 - src/icmpv6.cpp | 15 +++++++------- src/ip.cpp | 30 +++++++++++++--------------- src/ipv6.cpp | 3 +-- src/ipv6_address.cpp | 8 ++++---- src/packet_sender.cpp | 4 +--- src/ppi.cpp | 1 - src/rawpdu.cpp | 1 - src/tcp.cpp | 12 ++++------- 19 files changed, 87 insertions(+), 110 deletions(-) diff --git a/include/tins/ip.h b/include/tins/ip.h index c2c06826..420f974c 100644 --- a/include/tins/ip.h +++ b/include/tins/ip.h @@ -410,7 +410,7 @@ class TINS_API IP : public PDU { * \return The stored options. */ const options_type& options() const { - return ip_options_; + return options_; } /* Setters */ @@ -525,7 +525,7 @@ class TINS_API IP : public PDU { */ void add_option(option &&opt) { internal_add_option(opt); - ip_options_.push_back(std::move(opt)); + options_.push_back(std::move(opt)); } /** @@ -538,8 +538,8 @@ class TINS_API IP : public PDU { */ template void add_option(Args&&... args) { - ip_options_.emplace_back(std::forward(args)...); - internal_add_option(ip_options_.back()); + options_.emplace_back(std::forward(args)...); + internal_add_option(options_.back()); } #endif @@ -770,7 +770,7 @@ class TINS_API IP : public PDU { ip_header header_; uint16_t options_size_, padded_options_size_; - options_type ip_options_; + options_type options_; }; } // Tins diff --git a/include/tins/pdu_option.h b/include/tins/pdu_option.h index efb45a68..6e950c9d 100644 --- a/include/tins/pdu_option.h +++ b/include/tins/pdu_option.h @@ -537,22 +537,36 @@ class PDUOption { }; namespace Internals { - /* - * \cond - */ - template - struct option_type_equality_comparator { - option_type_equality_comparator(typename Option::option_type type) : type(type) { } +/* + * \cond + */ - bool operator()(const Option& opt) const { - return opt.option() == type; +template +typename Container::iterator find_option(Container& cont, typename Option::option_type type) { + typename Container::iterator iter; + for (iter = cont.begin(); iter != cont.end(); ++iter) { + if (iter->option() == type) { + break; } + } + return iter; +} - typename Option::option_type type; - }; - /* - * \endcond - */ +template +typename Container::const_iterator find_option_const(const Container& cont, + typename Option::option_type type) { + typename Container::const_iterator iter; + for (iter = cont.begin(); iter != cont.end(); ++iter) { + if (iter->option() == type) { + break; + } + } + return iter; +} + +/* + * \endcond + */ } // Internals } // namespace Tins diff --git a/src/arp.cpp b/src/arp.cpp index f415d47c..06eb32d7 100644 --- a/src/arp.cpp +++ b/src/arp.cpp @@ -28,7 +28,6 @@ */ #include -#include #include "arp.h" #include "ethernetII.h" #include "rawpdu.h" diff --git a/src/dhcp.cpp b/src/dhcp.cpp index 0ab03ef4..2a862890 100644 --- a/src/dhcp.cpp +++ b/src/dhcp.cpp @@ -29,7 +29,6 @@ #include #include -#include #include "endianness.h" #include "dhcp.h" #include "exceptions.h" @@ -39,7 +38,6 @@ using std::string; using std::vector; using std::list; using std::runtime_error; -using std::find_if; using Tins::Memory::InputMemoryStream; using Tins::Memory::OutputMemoryStream; @@ -113,13 +111,11 @@ const DHCP::option* DHCP::search_option(OptionTypes opt) const { } DHCP::options_type::const_iterator DHCP::search_option_iterator(OptionTypes opt) const { - Internals::option_type_equality_comparator