LLVM API Documentation

EndianStream.h
Go to the documentation of this file.
00001 //===- EndianStream.h - Stream ops with endian specific data ----*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file defines utilities for operating on streams that have endian
00011 // specific data.
00012 //
00013 //===----------------------------------------------------------------------===//
00014 
00015 #ifndef LLVM_SUPPORT_ENDIANSTREAM_H
00016 #define LLVM_SUPPORT_ENDIANSTREAM_H
00017 
00018 #include "llvm/Support/Endian.h"
00019 #include "llvm/Support/raw_ostream.h"
00020 
00021 namespace llvm {
00022 namespace support {
00023 
00024 namespace endian {
00025 /// Adapter to write values to a stream in a particular byte order.
00026 template <endianness endian> struct Writer {
00027   raw_ostream &OS;
00028   Writer(raw_ostream &OS) : OS(OS) {}
00029   template <typename value_type> void write(value_type Val) {
00030     Val = byte_swap<value_type, endian>(Val);
00031     OS.write((const char *)&Val, sizeof(value_type));
00032   }
00033 };
00034 } // end namespace endian
00035 
00036 } // end namespace support
00037 } // end namespace llvm
00038 
00039 #endif