Home | History | Annotate | Download | only in Support
      1 //===- EndianStream.h - Stream ops with endian specific data ----*- C++ -*-===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is distributed under the University of Illinois Open Source
      6 // License. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 //
     10 // This file defines utilities for operating on streams that have endian
     11 // specific data.
     12 //
     13 //===----------------------------------------------------------------------===//
     14 
     15 #ifndef _LLVM_SUPPORT_ENDIAN_STREAM_H_
     16 #define _LLVM_SUPPORT_ENDIAN_STREAM_H_
     17 
     18 #include <llvm/Support/Endian.h>
     19 #include <llvm/Support/raw_ostream.h>
     20 
     21 namespace llvm {
     22 namespace support {
     23 
     24 namespace endian {
     25 /// Adapter to write values to a stream in a particular byte order.
     26 template <endianness endian> struct Writer {
     27   raw_ostream &OS;
     28   Writer(raw_ostream &OS) : OS(OS) {}
     29   template <typename value_type> void write(value_type Val) {
     30     Val = byte_swap<value_type, endian>(Val);
     31     OS.write((const char *)&Val, sizeof(value_type));
     32   }
     33 };
     34 } // end namespace endian
     35 
     36 } // end namespace support
     37 } // end namespace llvm
     38 
     39 #endif // _LLVM_SUPPORT_ENDIAN_STREAM_H_
     40