[PATCH] Add functions for writing endian specific data to streams
Michael Spencer
bigcheesegs at gmail.com
Thu Mar 27 14:07:14 PDT 2014
On Mon, Mar 24, 2014 at 3:34 PM, Rafael EspĂndola
<rafael.espindola at gmail.com> wrote:
> This is fine by me. Michael, what do you think?
>
> On 24 March 2014 17:08, Justin Bogner <mail at justinbogner.com> wrote:
>> This adds a new header, EndianStream.h, which supplies a single
>> templated function for writing endian specific data to a raw_ostream.
>>
>> The second patch is just a mechanical update of clang to use this rather
>> than rolling their own. I've included it to show what it looks like to
>> use this new API.
>>
I'm fine with this, but it does seem a bit verbose. It may be better
to add an adapter:
template <endianess e>
struct Writer {
raw_ostream &OS;
Writer(raw_ostream &os) : OS(os) {}
template <typename value_type>
void write(value_type Val) {
...
}
};
Then all the uses become:
Writer<little> W(Out);
W.write<uint32_t>(val);
...
...
Instead of repeating the endianess and raw_ostream each time.
Although the single use cases turn into:
endian::Writer<little>(Out).write<uint32_t>(val);
- Michael Spencer
More information about the llvm-commits
mailing list