X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Packets%2FParseArray.hh;h=ad10ccaee55a97e743f5d636aef96f764c50bbe8;hb=a3d3979b7daaf22ea63ca356edbfa8047dff7b78;hp=ee39b49ce75a9cbd6774e2594f331b07ad19d6bf;hpb=145f6a7d0f3a6aaa77b3625351c952d24cb0b8a1;p=senf.git diff --git a/Packets/ParseArray.hh b/Packets/ParseArray.hh index ee39b49..ad10cca 100644 --- a/Packets/ParseArray.hh +++ b/Packets/ParseArray.hh @@ -23,62 +23,81 @@ #ifndef HH_ParseArray_ #define HH_ParseArray_ 1 +/** \defgroup parsecollection Collection parsers + + Collection parsers are parsers which build collections from other parsers. Examples are a vector + of 16bit unsigned integers or a list of lists of 32bit numbers and so on. + + Collection parsers provide a (reduced) STL sequence like interface. It depends on the type of + collection parser, what kind of sequence is modelled (e.g. random access sequence, forward + sequence etc). Most collections will also provide a kind of container wrapper to allow extensive + manipulations of the collection contents. A container wrapper is initialized with the collection + parser and then provides a more complete sequence interface. Additionally, the collection + wrapper has a longer lifetime than an ordinary parser: While a parser will be invalidated + whenever the collection is changed, the container wrapper will stay valid as long as the + collection is changed through the wrapper (directly or indirectly, where indirectly means that a + sub-field or sub-collection of the collection is changed). Some collections may provide even + more lifetime guarantees but this guarantee should be met by all collection wrappers. + + \important Parser lifetime has to be tightly checked when working with collection parsers since + \e every change of the collections size will invalidate \e all parsers and iterators referencing + the \e complete packet chain. Collection wrappers do \e not invalidate if the change is \e after + the collection. + + \ingroup packetparser +*/ + // Custom includes -#include // for std::pair -#include "ParserBase.hh" +#include "PacketParser.hh" //#include "ParseArray.mpp" ///////////////////////////////hh.p//////////////////////////////////////// namespace senf { + namespace detail { template class Parse_Array_iterator; } + + /** \brief Fixed size collection of fixed size elements - namespace impl { template class Parse_Array_iterator; } + Parse_Array will parse a sequence of fixed size parsers. The number of array + elements is given by the \e elements template parameter and is fixed at compile time. + + Each element will be parsed by \a ElementParser, which can be any fixed size + parser. The array models an STL random-access sequence with the restriction that elements + cannot be added or removed since the size is fixed. - /* Parse_Array has the external interface of a container class + \ingroup parsecollection */ - template - struct Parse_Array : public ParserBase + template + struct Parse_Array : public PacketParserBase { - /////////////////////////////////////////////////////////////////////////// - // Parser interface + Parse_Array(data_iterator i, state_type s); - template - struct rebind { typedef Parse_Array parser; }; - typedef Iterator byte_iterator; + static size_type const fixed_bytes = elements*ElementParser::fixed_bytes; - Parse_Array(); - explicit Parse_Array(Iterator const & i); - - static unsigned bytes(); - bool check(Iterator const & e) const; void init() const; /////////////////////////////////////////////////////////////////////////// // Container interface - typedef typename Parser::template rebind::parser value_type; - typedef impl::Parse_Array_iterator iterator; - typedef unsigned size_type; - typedef int difference_type; - typedef std::pair range_type; + typedef ElementParser value_type; + typedef detail::Parse_Array_iterator iterator; + typedef iterator const_iterator; static size_type size(); iterator begin() const; iterator end() const; - range_type range() const; - iterator value() const; value_type operator[](difference_type i) const; - - template - Parse_Array const & operator= (InputIterator const & i); }; } ///////////////////////////////hh.e//////////////////////////////////////// +#endif +#if !defined(SENF_PACKETS_DECL_ONLY) && !defined(HH_ParseArray_i_) +#define HH_ParseArray_i_ //#include "ParseArray.cci" //#include "ParseArray.ct" #include "ParseArray.cti"