/* This file is part of Mitsuba, a physically based rendering system. Copyright (c) 2007-2014 by Wenzel Jakob and others. Mitsuba is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License Version 3 as published by the Free Software Foundation. Mitsuba is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include #include MTS_NAMESPACE_BEGIN static Stream::EByteOrder getByteOrder() { union { uint8_t charValue[2]; uint16_t shortValue; }; charValue[0] = 1; charValue[1] = 0; if (shortValue == 1) return Stream::ELittleEndian; else return Stream::EBigEndian; } Stream::EByteOrder Stream::m_hostByteOrder = mitsuba::getByteOrder(); Stream::Stream() : m_byteOrder(m_hostByteOrder) { } void Stream::setByteOrder(EByteOrder value) { m_byteOrder = value; } void Stream::skip(size_t amount) { seek(getPos() + amount); } void Stream::writeInt(int value) { if (m_byteOrder != m_hostByteOrder) value = endianness_swap(value); write(&value, sizeof(int)); } void Stream::writeIntArray(const int *data, size_t size) { if (m_byteOrder != m_hostByteOrder) { int *temp = new int[size]; for (size_t i=0; iwrite(data, blockSize); } } std::string Stream::toString() const { std::ostringstream oss; oss << "hostByteOrder=" << m_hostByteOrder << ", byteOrder=" << m_byteOrder; return oss.str(); } std::ostream &operator<<(std::ostream &os, const Stream::EByteOrder &value) { switch (value) { case Stream::ELittleEndian: os << "little-endian"; break; case Stream::EBigEndian: os << "big-endian"; break; default: os << "invalid"; break; } return os; } MTS_IMPLEMENT_CLASS(Stream, true, Object) MTS_NAMESPACE_END