Boost logo

Boost Users :

Subject: Re: [Boost-users] [Spirit][karma] Generating Pascal string like output
From: TONGARI (tongari95_at_[hidden])
Date: 2012-01-23 01:49:57


2012/1/23 Olaf Meeuwissen <olaf.meeuwissen_at_[hidden]>

> Hi all,
>
> While I had no trouble getting the parsing part for this to work, I'm
> stuck on the generator part. Specifically, I'm stuck on getting the
> size into the output.
>
> The goal is a rule that takes a std::vector<byte> and outputs it in such
> a way that it is preceded by its size (in a custom encoding) and padded
> by zeroes to align on a four byte boundary.
>
> I want to reuse this rule in several other rules and prefer to break it
> up into smaller pieces. A minimalistic example of what I have come up
> with so far is attached. What I can't seem figure out how to get at and
> store the vector's size in pascal_string_size_. There also seem to be
> problems with refering to the stored size_ in pascal_string_payload_ and
> pascal_string_padding_ that I don't understand.
>

o Use phoenix::size to extrac the size
o Use karma::embed(*) to feed in the size
o Use local variable to store the size
o Use inherited attribute to pass the size

Full code attached.

=footnotes=
(*) A component made by me, you can find it here:
https://github.com/jamboree/boost-jamboree-spirit. As an alternative, you
can search "no_attr" on Spirit ML.





Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net