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 StringParser inline template implementation */
17 //#include "StringParser.ih"
21 #define prefix_ inline
22 //-/////////////////////////////////////////////////////////////////////////////////////////////////
24 //-/////////////////////////////////////////////////////////////////////////////////////////////////
25 // senf::StringParser<LengthParser>
27 template <class LengthParser>
28 prefix_ senf::StringParser<LengthParser>::StringParser(data_iterator i, state_type s)
29 : PacketParserBase(i, s, init_bytes)
32 template <class LengthParser>
33 prefix_ typename senf::StringParser<LengthParser>::size_type senf::StringParser<LengthParser>::bytes()
36 return length_().value() + senf::bytes(length_());
39 template <class LengthParser>
40 prefix_ typename senf::StringParser<LengthParser>::value_type senf::StringParser<LengthParser>::value()
44 return std::string(i()+senf::bytes(length_()), i()+bytes());
47 template <class LengthParser>
48 prefix_ void senf::StringParser<LengthParser>::value(value_type v)
51 typename LengthParser::value_type sz (std::min<size_type>(v.size(), LengthParser::max_value+0));
52 resize(bytes(), sz+senf::bytes(length_()));
54 std::copy(v.begin(), boost::next(v.begin(),sz), i()+senf::bytes(length_()));
57 template <class LengthParser>
58 prefix_ senf::StringParser<LengthParser>::operator value_type()
64 template <class LengthParser>
65 prefix_ typename senf::StringParser<LengthParser> const & senf::StringParser<LengthParser>::operator=(value_type other)
71 template <class LengthParser>
72 prefix_ bool senf::StringParser<LengthParser>::empty()
78 template <class LengthParser>
79 prefix_ void senf::StringParser<LengthParser>::clear()
82 resize(bytes(), senf::bytes(length_()));
86 template <class LengthParser>
87 prefix_ bool senf::StringParser<LengthParser>::operator==(value_type const & other)
90 if (other.size() > length())
92 return std::equal(other.begin(), other.end(), i()+senf::bytes(length_()));
95 template <class LengthParser>
96 prefix_ std::ostream & senf::operator<<(std::ostream & os, StringParser<LengthParser> const & value)
102 //-/////////////////////////////////////////////////////////////////////////////////////////////////
103 // senf::FixedSizeStringParser<N>
105 template <std::string::size_type N>
106 prefix_ typename senf::FixedSizeStringParser<N>::value_type senf::FixedSizeStringParser<N>::value()
109 return std::string(i(), i()+fixed_bytes);
112 template <std::string::size_type N>
113 prefix_ void senf::FixedSizeStringParser<N>::value(value_type v)
115 std::copy(v.begin(), v.end(), i());
116 std::fill(i()+v.size(), i()+fixed_bytes, '\0');
119 template <std::string::size_type N>
120 prefix_ senf::FixedSizeStringParser<N>::operator value_type()
126 template <std::string::size_type N>
127 prefix_ typename senf::FixedSizeStringParser<N> const & senf::FixedSizeStringParser<N>::operator=(value_type other)
133 template <std::string::size_type N>
134 prefix_ bool senf::FixedSizeStringParser<N>::operator==(value_type const & other)
137 if (other.size() > N)
139 return std::equal(other.begin(), other.end(), i());
142 template <std::string::size_type N>
143 prefix_ std::ostream & senf::operator<<(std::ostream & os, FixedSizeStringParser<N> const & value)
149 //-/////////////////////////////////////////////////////////////////////////////////////////////////
156 // comment-column: 40
157 // c-file-style: "senf"
158 // indent-tabs-mode: nil
159 // ispell-local-dictionary: "american"
160 // compile-command: "scons -u test"