llvm.org GIT mirror llvm / a655710
Support: Functions for writing endian specific data to streams. This adds a new header, EndianStream.h, which supplies an adaptor for writing endian specific data to a raw_ostream. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@205032 91177308-0d34-0410-b5e6-96231b3b80d8 Justin Bogner 6 years ago
1 changed file(s) with 39 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
0 //===- EndianStream.h - Stream ops with endian specific data ----*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines utilities for operating on streams that have endian
10 // specific data.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef _LLVM_SUPPORT_ENDIAN_STREAM_H_
15 #define _LLVM_SUPPORT_ENDIAN_STREAM_H_
16
17 #include
18 #include
19
20 namespace llvm {
21 namespace support {
22
23 namespace endian {
24 /// Adapter to write values to a stream in a particular byte order.
25 template struct Writer {
26 raw_ostream &OS;
27 Writer(raw_ostream &OS) : OS(OS) {}
28 template void write(value_type Val) {
29 Val = byte_swap(Val);
30 OS.write((const char *)&Val, sizeof(value_type));
31 }
32 };
33 } // end namespace endian
34
35 } // end namespace support
36 } // end namespace llvm
37
38 #endif // _LLVM_SUPPORT_ENDIAN_STREAM_H_