2 // Copyright (c) 2020 Fraunhofer Institute for Applied Information Technology (FIT)
3 // Network Research Group (NET)
4 // Schloss Birlinghoven, 53754 Sankt Augustin, GERMANY
5 // Contact: support@wiback.org
7 // This file is part of the SENF code tree.
8 // It is licensed under the 3-clause BSD License (aka New BSD License).
9 // See LICENSE.txt in the top level directory for details or visit
10 // https://opensource.org/licenses/BSD-3-Clause
15 \brief PacketParser inline template implementation */
17 #include "PacketParser.ih"
21 #define prefix_ inline
22 //-/////////////////////////////////////////////////////////////////////////////////////////////////
25 template <class Parser>
26 prefix_ typename boost::enable_if_c<
27 boost::is_base_of<senf::PacketParserBase, Parser>::value && senf::is_fixed<Parser>::value, Parser >::type
28 senf::operator<<(Parser const & target, Parser const & source)
30 std::copy( source.i(), source.i(Parser::fixed_bytes), target.i());
35 //-/////////////////////////////////////////////////////////////////////////////////////////////////
36 // senf::PacketParserBase
38 template <class Parser>
39 prefix_ Parser senf::PacketParserBase::parse(data_iterator i)
42 return Parser(i,state());
45 template <class Parser, class Arg>
46 prefix_ Parser senf::PacketParserBase::parse(Arg const & arg, data_iterator i)
49 return Parser(arg, i, state());
52 template <class Parser>
53 prefix_ Parser senf::PacketParserBase::parse(size_type n)
56 return Parser(boost::next(i(),n),state());
59 template <class Parser, class Arg>
60 prefix_ Parser senf::PacketParserBase::parse(Arg const & arg, size_type n)
63 return Parser(arg, boost::next(i(),n), state());
66 //-/////////////////////////////////////////////////////////////////////////////////////////////////
69 template <class Parser>
70 prefix_ senf::PacketParserBase::size_type senf::bytes(Parser const & p)
72 return detail::packetParserSize(p, 0);
76 template <class Parser, class Value>
77 prefix_ typename boost::enable_if_c <
78 boost::is_base_of<senf::PacketParserBase, Parser>::value
79 && ! boost::is_base_of<senf::PacketParserBase, Value>::value,
80 Parser >::type senf::operator<<(Parser target, Value const & value)
86 template <class Parser, class Value>
87 prefix_ Parser senf::operator<<(Parser target, Value const & value)
92 template <class Parser, class Value>
93 prefix_ typename boost::enable_if_c <
94 boost::is_base_of<senf::PacketParserBase, Parser>::value
95 && ! boost::is_base_of<senf::PacketParserBase, Value>::value,
96 Parser >::type senf::operator<<(Parser target, boost::optional<Value> const & value)
103 template <class Parser, class Value>
104 prefix_ Parser senf::operator<<(Parser target, Value const & value)
108 template <class Parser>
109 prefix_ senf::PacketParserBase::size_type
110 senf::detail::packetParserSize(Parser const & p, int, senf::mpl::take_uint<Parser::init_bytes> *)
115 //-/////////////////////////////////////////////////////////////////////////////////////////////////
116 // senf::ArrayValueParserBase<Parser, ValueType, FixedBytes>
118 template <class Parser, typename ValueType>
119 prefix_ senf::ArrayValueParserBase<Parser, ValueType>::ArrayValueParserBase(data_iterator i, state_type s)
120 : PacketParserBase(i, s, fixed_bytes)
123 template <class Parser, typename ValueType>
124 prefix_ senf::ArrayValueParserBase<Parser, ValueType>::operator value_type ()
127 return static_cast<Parser const *>(this)->value();
130 template <class Parser, typename ValueType>
131 prefix_ senf::PacketParserBase::byte &
132 senf::ArrayValueParserBase<Parser, ValueType>::operator[](size_type index)
134 return *boost::next(i(), index);
137 template <class Parser, typename ValueType>
138 prefix_ senf::PacketParserBase::byte const &
139 senf::ArrayValueParserBase<Parser, ValueType>::operator[](size_type index)
142 return *boost::next(i(), index);
145 template <class Parser, typename ValueType>
146 prefix_ Parser const & senf::ArrayValueParserBase<Parser, ValueType>::operator= (value_type const & other)
148 static_cast<Parser*>(this)->value(other);
149 return *static_cast<Parser const *>(this);
152 template <class Parser, typename ValueType>
153 prefix_ bool senf::operator==(ArrayValueParserBase<Parser, ValueType> const & parser, ValueType const & value)
155 return std::equal(value.begin(), value.end(), parser.i());
158 template <class Parser, typename ValueType>
159 prefix_ bool senf::operator!=(ArrayValueParserBase<Parser, ValueType> const & parser, ValueType const & value)
161 return not std::equal(value.begin(), value.end(), parser.i());
164 template <class Parser, typename ValueType>
165 prefix_ bool senf::operator==(ValueType const & value, ArrayValueParserBase<Parser, ValueType> const & parser)
167 return std::equal(value.begin(), value.end(), parser.i());
170 template <class Parser, typename ValueType>
171 prefix_ bool senf::operator!=(ValueType const & value, ArrayValueParserBase<Parser, ValueType> const & parser)
173 return not std::equal(value.begin(), value.end(), parser.i());
176 template <class Parser, typename ValueType>
177 prefix_ bool senf::ArrayValueParserBase<Parser, ValueType>::operator==(Parser const & other)
180 return std::equal(i(), i(fixed_bytes), other.i());
183 //-/////////////////////////////////////////////////////////////////////////////////////////////////
190 // c-file-style: "senf"
191 // indent-tabs-mode: nil
192 // ispell-local-dictionary: "american"
193 // compile-command: "scons -u test"
194 // comment-column: 40