From: bangerth Date: Sat, 21 Dec 2013 17:03:28 +0000 (+0000) Subject: Add library subdirectory, but excluding all the documentation, build, test and exampl... X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=640bc8e5826153440a59e4b334e331756f419bfa;p=dealii-svn.git Add library subdirectory, but excluding all the documentation, build, test and example subdirectories. git-svn-id: https://svn.dealii.org/trunk@32086 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/bundled/boost-1.49.0/libs/iostreams/src/bzip2.cpp b/deal.II/bundled/boost-1.49.0/libs/iostreams/src/bzip2.cpp new file mode 100644 index 0000000000..7e4274919b --- /dev/null +++ b/deal.II/bundled/boost-1.49.0/libs/iostreams/src/bzip2.cpp @@ -0,0 +1,173 @@ +// (C) Copyright 2008 CodeRage, LLC (turkanis at coderage dot com) +// (C) Copyright 2003-2007 Jonathan Turkanis +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.) + +// See http://www.boost.org/libs/iostreams for documentation. + +// To configure Boost to work with libbz2, see the +// installation instructions here: +// http://boost.org/libs/iostreams/doc/index.html?path=7 + +// Define BOOST_IOSTREAMS_SOURCE so that +// knows that we are building the library (possibly exporting code), rather +// than using it (possibly importing code). +#define BOOST_IOSTREAMS_SOURCE + +#include +#include +#include +#include "bzlib.h" // Julian Seward's "bzip.h" header. + // To configure Boost to work with libbz2, see the + // installation instructions here: + // http://boost.org/libs/iostreams/doc/index.html?path=7 + +namespace boost { namespace iostreams { + +namespace bzip2 { + + // Status codes + +const int ok = BZ_OK; +const int run_ok = BZ_RUN_OK; +const int flush_ok = BZ_FLUSH_OK; +const int finish_ok = BZ_FINISH_OK; +const int stream_end = BZ_STREAM_END; +const int sequence_error = BZ_SEQUENCE_ERROR; +const int param_error = BZ_PARAM_ERROR; +const int mem_error = BZ_MEM_ERROR; +const int data_error = BZ_DATA_ERROR; +const int data_error_magic = BZ_DATA_ERROR_MAGIC; +const int io_error = BZ_IO_ERROR; +const int unexpected_eof = BZ_UNEXPECTED_EOF; +const int outbuff_full = BZ_OUTBUFF_FULL; +const int config_error = BZ_CONFIG_ERROR; + + // Action codes + +const int finish = BZ_FINISH; +const int run = BZ_RUN; + +} // End namespace bzip2. + +//------------------Implementation of bzip2_error-----------------------------// + +bzip2_error::bzip2_error(int error) + : BOOST_IOSTREAMS_FAILURE("bzip2 error"), error_(error) + { } + +void bzip2_error::check BOOST_PREVENT_MACRO_SUBSTITUTION(int error) +{ + switch (error) { + case BZ_OK: + case BZ_RUN_OK: + case BZ_FLUSH_OK: + case BZ_FINISH_OK: + case BZ_STREAM_END: + return; + case BZ_MEM_ERROR: + boost::throw_exception(std::bad_alloc()); + default: + boost::throw_exception(bzip2_error(error)); + } +} + +//------------------Implementation of bzip2_base------------------------------// + +namespace detail { + +bzip2_base::bzip2_base(const bzip2_params& params) + : params_(params), stream_(new bz_stream), ready_(false) + { } + +bzip2_base::~bzip2_base() { delete static_cast(stream_); } + +void bzip2_base::before( const char*& src_begin, const char* src_end, + char*& dest_begin, char* dest_end ) +{ + bz_stream* s = static_cast(stream_); + s->next_in = const_cast(src_begin); + s->avail_in = static_cast(src_end - src_begin); + s->next_out = reinterpret_cast(dest_begin); + s->avail_out= static_cast(dest_end - dest_begin); +} + +void bzip2_base::after(const char*& src_begin, char*& dest_begin) +{ + bz_stream* s = static_cast(stream_); + src_begin = const_cast(s->next_in); + dest_begin = s->next_out; +} + +int bzip2_base::check_end(const char* src_begin, const char* dest_begin) +{ + bz_stream* s = static_cast(stream_); + if( src_begin == s->next_in && + s->avail_in == 0 && + dest_begin == s->next_out) { + return bzip2::unexpected_eof; + } else { + return bzip2::ok; + } +} + +void bzip2_base::end(bool compress) +{ + if(!ready_) return; + ready_ = false; + bz_stream* s = static_cast(stream_); + bzip2_error::check BOOST_PREVENT_MACRO_SUBSTITUTION( + compress ? + BZ2_bzCompressEnd(s) : + BZ2_bzDecompressEnd(s) + ); +} + +int bzip2_base::compress(int action) +{ + return BZ2_bzCompress(static_cast(stream_), action); +} + +int bzip2_base::decompress() +{ + return BZ2_bzDecompress(static_cast(stream_)); +} + +void bzip2_base::do_init + ( bool compress, + #if !BOOST_WORKAROUND(BOOST_MSVC, < 1300) + bzip2::alloc_func /* alloc */, + bzip2::free_func /* free */, + #endif + void* derived ) +{ + bz_stream* s = static_cast(stream_); + + // Current interface for customizing memory management + // is non-conforming and has been disabled: + //#if !BOOST_WORKAROUND(BOOST_MSVC, < 1300) + // s->bzalloc = alloc; + // s->bzfree = free; + //#else + s->bzalloc = 0; + s->bzfree = 0; + //#endif + s->opaque = derived; + bzip2_error::check BOOST_PREVENT_MACRO_SUBSTITUTION( + compress ? + BZ2_bzCompressInit( s, + params_.block_size, + 0, + params_.work_factor ) : + BZ2_bzDecompressInit( s, + 0, + params_.small ) + ); + ready_ = true; +} + +} // End namespace detail. + +//----------------------------------------------------------------------------// + +} } // End namespaces iostreams, boost. diff --git a/deal.II/bundled/boost-1.49.0/libs/iostreams/src/file_descriptor.cpp b/deal.II/bundled/boost-1.49.0/libs/iostreams/src/file_descriptor.cpp new file mode 100644 index 0000000000..c1af69527a --- /dev/null +++ b/deal.II/bundled/boost-1.49.0/libs/iostreams/src/file_descriptor.cpp @@ -0,0 +1,593 @@ +// (C) Copyright 2008 CodeRage, LLC (turkanis at coderage dot com) +// (C) Copyright 2003-2007 Jonathan Turkanis +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.) + +// See http://www.boost.org/libs/iostreams for documentation. + +// Define BOOST_IOSTREAMS_SOURCE so that +// knows that we are building the library (possibly exporting code), rather +// than using it (possibly importing code). +#define BOOST_IOSTREAMS_SOURCE + +#include +#include +#include // SEEK_SET, etc. +#include // BOOST_JOIN +#include +#include +#include // BOOST_IOSTREAMS_FD_XXX +#include +#include +#include // openmodes, failure. +#include +#include +#include + + // OS-specific headers for low-level i/o. + +#include // file opening flags. +#include // file access permissions. +#ifdef BOOST_IOSTREAMS_WINDOWS +# include // low-level file i/o. +# define WINDOWS_LEAN_AND_MEAN +# include +# ifndef INVALID_SET_FILE_POINTER +# define INVALID_SET_FILE_POINTER ((DWORD)-1) +# endif +#else +# include // mode_t. +# include // low-level file i/o. +#endif + +namespace boost { namespace iostreams { + +//------------------Definition of file_descriptor_impl------------------------// + +namespace detail { + +// Contains the platform dependant implementation +struct file_descriptor_impl { + // Note: These need to match file_desciptor_flags + enum flags { + never_close = 0, + close_on_exit = 1, + close_on_close = 2, + close_always = 3 + }; + + file_descriptor_impl(); + ~file_descriptor_impl(); + void open(file_handle fd, flags); +#ifdef BOOST_IOSTREAMS_WINDOWS + void open(int fd, flags); +#endif + void open(const detail::path&, BOOST_IOS::openmode); + bool is_open() const; + void close(); + void close_impl(bool close_flag, bool throw_); + std::streamsize read(char* s, std::streamsize n); + std::streamsize write(const char* s, std::streamsize n); + std::streampos seek(stream_offset off, BOOST_IOS::seekdir way); + static file_handle invalid_handle(); + file_handle handle_; + int flags_; +}; + +//------------------Implementation of file_descriptor_impl--------------------// + +file_descriptor_impl::file_descriptor_impl() + : handle_(invalid_handle()), flags_(0) + { } + +file_descriptor_impl::~file_descriptor_impl() +{ + close_impl(flags_ & close_on_exit, false); +} + +void file_descriptor_impl::open(file_handle fd, flags f) +{ + // Using 'close' to close the existing handle so that it will throw an + // exception if it fails. + // + // Only closing after assigning the new handle, so that the class will + // take ownership of the handle regardless of whether close throws. + + file_descriptor_impl tmp; + tmp.handle_ = handle_; + tmp.flags_ = flags_ & close_on_exit ? close_on_close : never_close; + + handle_ = fd; + flags_ = f; + + tmp.close(); +} + +#ifdef BOOST_IOSTREAMS_WINDOWS //---------------------------------------------// + +void file_descriptor_impl::open(int fd, flags f) +{ open(reinterpret_cast(_get_osfhandle(fd)), f); } + +#endif // #ifdef BOOST_IOSTREAMS_WINDOWS //-----------------------------------// + +void file_descriptor_impl::open(const detail::path& p, BOOST_IOS::openmode mode) +{ + close_impl(flags_ & close_on_exit, true); + +#ifdef BOOST_IOSTREAMS_WINDOWS //---------------------------------------------// + DWORD dwDesiredAccess; + DWORD dwCreationDisposition; + if ( (mode & (BOOST_IOS::in | BOOST_IOS::out)) + == + (BOOST_IOS::in | BOOST_IOS::out) ) + { + if (mode & BOOST_IOS::app) + boost::throw_exception(BOOST_IOSTREAMS_FAILURE("bad open mode")); + dwDesiredAccess = GENERIC_READ | GENERIC_WRITE; + dwCreationDisposition = + (mode & BOOST_IOS::trunc) ? + CREATE_ALWAYS : + OPEN_EXISTING; + } else if (mode & BOOST_IOS::in) { + if (mode & (BOOST_IOS::app | BOOST_IOS::trunc)) + boost::throw_exception(BOOST_IOSTREAMS_FAILURE("bad open mode")); + dwDesiredAccess = GENERIC_READ; + dwCreationDisposition = OPEN_EXISTING; + } else if (mode & BOOST_IOS::out) { + if ( (mode & (BOOST_IOS::app | BOOST_IOS::trunc)) + == + (BOOST_IOS::app | BOOST_IOS::trunc) ) + boost::throw_exception(BOOST_IOSTREAMS_FAILURE("bad open mode")); + if (mode & BOOST_IOS::app) { + dwCreationDisposition = OPEN_ALWAYS; + dwDesiredAccess = + FILE_APPEND_DATA | + FILE_WRITE_ATTRIBUTES | + FILE_WRITE_EA | + STANDARD_RIGHTS_WRITE | + SYNCHRONIZE; + } else { + dwDesiredAccess = GENERIC_WRITE; + dwCreationDisposition = CREATE_ALWAYS; + } + } else { + boost::throw_exception(BOOST_IOSTREAMS_FAILURE("bad open mode")); + } + + HANDLE handle = p.is_wide() ? + ::CreateFileW( p.c_wstr(), + dwDesiredAccess, + FILE_SHARE_READ | FILE_SHARE_WRITE, + NULL, // lpSecurityAttributes + dwCreationDisposition, + FILE_ATTRIBUTE_NORMAL, + NULL ) : // hTemplateFile + ::CreateFileA( p.c_str(), + dwDesiredAccess, + FILE_SHARE_READ | FILE_SHARE_WRITE, + NULL, // lpSecurityAttributes + dwCreationDisposition, + FILE_ATTRIBUTE_NORMAL, + NULL ); // hTemplateFile + if (handle != INVALID_HANDLE_VALUE) { + handle_ = handle; + flags_ = close_always; + } else { + flags_ = 0; + throw_system_failure("failed opening file"); + } +#else // #ifdef BOOST_IOSTREAMS_WINDOWS //------------------------------------// + + // Calculate oflag argument to open. + + int oflag = 0; + if ( (mode & (BOOST_IOS::in | BOOST_IOS::out)) + == + (BOOST_IOS::in | BOOST_IOS::out) ) + { + if( mode & BOOST_IOS::app ) + boost::throw_exception(BOOST_IOSTREAMS_FAILURE("bad open mode")); + oflag |= O_RDWR; + if( mode & BOOST_IOS::trunc ) { + oflag |= O_TRUNC; + oflag |= O_CREAT; + } + } else if (mode & BOOST_IOS::in) { + if( mode & (BOOST_IOS::app | BOOST_IOS::trunc) ) + boost::throw_exception(BOOST_IOSTREAMS_FAILURE("bad open mode")); + oflag |= O_RDONLY; + } else if (mode & BOOST_IOS::out) { + if( (mode & (BOOST_IOS::app | BOOST_IOS::trunc)) + == + (BOOST_IOS::app | BOOST_IOS::trunc) ) + boost::throw_exception(BOOST_IOSTREAMS_FAILURE("bad open mode")); + oflag |= O_WRONLY; + if (mode & BOOST_IOS::app) + oflag |= O_APPEND; + else { + oflag |= O_CREAT; + oflag |= O_TRUNC; + } + } else { + boost::throw_exception(BOOST_IOSTREAMS_FAILURE("bad open mode")); + } + #ifdef _LARGEFILE64_SOURCE + oflag |= O_LARGEFILE; + #endif + + // Calculate pmode argument to open. + + mode_t pmode = S_IRUSR | S_IWUSR | + S_IRGRP | S_IWGRP | + S_IROTH | S_IWOTH; + + // Open file. + + int fd = BOOST_IOSTREAMS_FD_OPEN(p.c_str(), oflag, pmode); + if (fd == -1) { + boost::throw_exception(system_failure("failed opening file")); + } else { + handle_ = fd; + flags_ = close_always; + } +#endif // #ifndef BOOST_IOSTREAMS_WINDOWS //----------------------------------// +} + +bool file_descriptor_impl::is_open() const +{ return handle_ != invalid_handle(); } + +void file_descriptor_impl::close() +{ + close_impl(flags_ & close_on_close, true); +} + +void file_descriptor_impl::close_impl(bool close_flag, bool throw_) { + if (handle_ != invalid_handle()) { + if (close_flag) { + bool success = + #ifdef BOOST_IOSTREAMS_WINDOWS + ::CloseHandle(handle_) == 1; + #else + BOOST_IOSTREAMS_FD_CLOSE(handle_) != -1; + #endif + if (!success && throw_) + throw_system_failure("failed closing file"); + } + handle_ = invalid_handle(); + flags_ = 0; + } +} + +std::streamsize file_descriptor_impl::read(char* s, std::streamsize n) +{ +#ifdef BOOST_IOSTREAMS_WINDOWS + DWORD result; + if (!::ReadFile(handle_, s, n, &result, NULL)) + throw_system_failure("failed reading"); + return result == 0 ? -1 : static_cast(result); +#else // #ifdef BOOST_IOSTREAMS_WINDOWS + errno = 0; + std::streamsize result = BOOST_IOSTREAMS_FD_READ(handle_, s, n); + if (errno != 0) + throw_system_failure("failed reading"); + return result == 0 ? -1 : result; +#endif // #ifdef BOOST_IOSTREAMS_WINDOWS +} + +std::streamsize file_descriptor_impl::write(const char* s, std::streamsize n) +{ +#ifdef BOOST_IOSTREAMS_WINDOWS + DWORD ignore; + if (!::WriteFile(handle_, s, n, &ignore, NULL)) + throw_system_failure("failed writing"); + return n; +#else // #ifdef BOOST_IOSTREAMS_WINDOWS + int amt = BOOST_IOSTREAMS_FD_WRITE(handle_, s, n); + if (amt < n) // Handles blocking fd's only. + throw_system_failure("failed writing"); + return n; +#endif // #ifdef BOOST_IOSTREAMS_WINDOWS +} + +std::streampos file_descriptor_impl::seek + (stream_offset off, BOOST_IOS::seekdir way) +{ +#ifdef BOOST_IOSTREAMS_WINDOWS + LONG lDistanceToMove = static_cast(off & 0xffffffff); + LONG lDistanceToMoveHigh = static_cast(off >> 32); + DWORD dwResultLow = + ::SetFilePointer( handle_, + lDistanceToMove, + &lDistanceToMoveHigh, + way == BOOST_IOS::beg ? + FILE_BEGIN : + way == BOOST_IOS::cur ? + FILE_CURRENT : + FILE_END ); + if ( dwResultLow == INVALID_SET_FILE_POINTER && + ::GetLastError() != NO_ERROR ) + { + boost::throw_exception(system_failure("failed seeking")); + } else { + return offset_to_position( + (stream_offset(lDistanceToMoveHigh) << 32) + dwResultLow + ); + } +#else // #ifdef BOOST_IOSTREAMS_WINDOWS + if ( off > integer_traits::const_max || + off < integer_traits::const_min ) + { + boost::throw_exception(BOOST_IOSTREAMS_FAILURE("bad offset")); + } + stream_offset result = + BOOST_IOSTREAMS_FD_SEEK( + handle_, + static_cast(off), + ( way == BOOST_IOS::beg ? + SEEK_SET : + way == BOOST_IOS::cur ? + SEEK_CUR : + SEEK_END ) + ); + if (result == -1) + boost::throw_exception(system_failure("failed seeking")); + return offset_to_position(result); +#endif // #ifdef BOOST_IOSTREAMS_WINDOWS +} + +// Returns the value stored in a file_handle variable when no file is open +file_handle file_descriptor_impl::invalid_handle() +{ +#ifdef BOOST_IOSTREAMS_WINDOWS + return INVALID_HANDLE_VALUE; +#else + return -1; +#endif +} + +} // End namespace detail. + +//------------------Implementation of file_descriptor-------------------------// + +file_descriptor::file_descriptor() : pimpl_(new impl_type) { } + +file_descriptor::file_descriptor(handle_type fd, file_descriptor_flags f) + : pimpl_(new impl_type) +{ open(fd, f); } + +#if defined(BOOST_IOSTREAMS_USE_DEPRECATED) +file_descriptor::file_descriptor(handle_type fd, bool close_on_exit) + : pimpl_(new impl_type) +{ open(fd, close_on_exit); } +#endif + +#ifdef BOOST_IOSTREAMS_WINDOWS //---------------------------------------------// + +file_descriptor::file_descriptor(int fd, file_descriptor_flags f) + : pimpl_(new impl_type) +{ open(fd, f); } + +#if defined(BOOST_IOSTREAMS_USE_DEPRECATED) +file_descriptor::file_descriptor(int fd, bool close_on_exit) + : pimpl_(new impl_type) +{ open(fd, close_on_exit); } +#endif + +#endif // #ifdef BOOST_IOSTREAMS_WINDOWS //-----------------------------------// + +file_descriptor::file_descriptor( const std::string& path, + BOOST_IOS::openmode mode ) + : pimpl_(new impl_type) +{ open(path, mode); } + +file_descriptor::file_descriptor( const char* path, + BOOST_IOS::openmode mode ) + : pimpl_(new impl_type) +{ open(path, mode); } + +file_descriptor::file_descriptor(const file_descriptor& other) + : pimpl_(other.pimpl_) + { } + +void file_descriptor::open(handle_type fd, file_descriptor_flags f) +{ pimpl_->open(fd, static_cast(f)); } + +#if defined(BOOST_IOSTREAMS_USE_DEPRECATED) +void file_descriptor::open(handle_type fd, bool close_on_exit) +{ pimpl_->open(fd, close_on_exit ? + detail::file_descriptor_impl::close_always : + detail::file_descriptor_impl::close_on_close); } +#endif + +#ifdef BOOST_IOSTREAMS_WINDOWS //---------------------------------------------// + +void file_descriptor::open(int fd, file_descriptor_flags f) +{ pimpl_->open(fd, static_cast(f)); } + +#if defined(BOOST_IOSTREAMS_USE_DEPRECATED) +void file_descriptor::open(int fd, bool close_on_exit) +{ pimpl_->open(fd, close_on_exit ? + detail::file_descriptor_impl::close_always : + detail::file_descriptor_impl::close_on_close); } +#endif + +#endif // #ifdef BOOST_IOSTREAMS_WINDOWS //-----------------------------------// + +void file_descriptor::open(const std::string& path, BOOST_IOS::openmode mode) +{ open(detail::path(path), mode); } + +void file_descriptor::open(const char* path, BOOST_IOS::openmode mode) +{ open(detail::path(path), mode); } + +bool file_descriptor::is_open() const { return pimpl_->is_open(); } + +void file_descriptor::close() { pimpl_->close(); } + +std::streamsize file_descriptor::read(char_type* s, std::streamsize n) +{ return pimpl_->read(s, n); } + +std::streamsize file_descriptor::write(const char_type* s, std::streamsize n) +{ return pimpl_->write(s, n); } + +std::streampos file_descriptor::seek(stream_offset off, BOOST_IOS::seekdir way) +{ return pimpl_->seek(off, way); } + +detail::file_handle file_descriptor::handle() const { return pimpl_->handle_; } + +void file_descriptor::init() { pimpl_.reset(new impl_type); } + +void file_descriptor::open( + const detail::path& path, + BOOST_IOS::openmode mode, + BOOST_IOS::openmode base ) +{ + mode |= base; + pimpl_->open(path, mode); +} + +//------------------Implementation of file_descriptor_source------------------// + +file_descriptor_source::file_descriptor_source( + handle_type fd, file_descriptor_flags f) +{ open(fd, f); } + +#if defined(BOOST_IOSTREAMS_USE_DEPRECATED) +file_descriptor_source::file_descriptor_source( + handle_type fd, bool close_on_exit) +{ open(fd, close_on_exit); } +#endif + +#ifdef BOOST_IOSTREAMS_WINDOWS //---------------------------------------------// + +file_descriptor_source::file_descriptor_source(int fd, file_descriptor_flags f) +{ open(fd, f); } + +#if defined(BOOST_IOSTREAMS_USE_DEPRECATED) +file_descriptor_source::file_descriptor_source(int fd, bool close_on_exit) +{ open(fd, close_on_exit); } +#endif + +#endif // #ifdef BOOST_IOSTREAMS_WINDOWS //-----------------------------------// + +file_descriptor_source::file_descriptor_source( + const std::string& path, BOOST_IOS::openmode mode) +{ open(path, mode); } + +file_descriptor_source::file_descriptor_source( + const char* path, BOOST_IOS::openmode mode) +{ open(path, mode); } + +file_descriptor_source::file_descriptor_source( + const file_descriptor_source& other) + : file_descriptor(static_cast(other)) + { } + +void file_descriptor_source::open(handle_type fd, file_descriptor_flags f) +{ file_descriptor::open(fd, f); } + +#if defined(BOOST_IOSTREAMS_USE_DEPRECATED) +void file_descriptor_source::open(handle_type fd, bool close_on_exit) +{ file_descriptor::open(fd, close_on_exit); } +#endif + +#ifdef BOOST_IOSTREAMS_WINDOWS //---------------------------------------------// + +void file_descriptor_source::open(int fd, file_descriptor_flags f) +{ file_descriptor::open(fd, f); } + +#if defined(BOOST_IOSTREAMS_USE_DEPRECATED) +void file_descriptor_source::open(int fd, bool close_on_exit) +{ file_descriptor::open(fd, close_on_exit); } +#endif + +#endif // #ifdef BOOST_IOSTREAMS_WINDOWS //-----------------------------------// + +void file_descriptor_source::open( + const std::string& path, BOOST_IOS::openmode mode) +{ open(detail::path(path), mode); } + +void file_descriptor_source::open( + const char* path, BOOST_IOS::openmode mode) +{ open(detail::path(path), mode); } + +void file_descriptor_source::open( + const detail::path& path, BOOST_IOS::openmode mode) +{ + if (mode & (BOOST_IOS::out | BOOST_IOS::app | BOOST_IOS::trunc)) + boost::throw_exception(BOOST_IOSTREAMS_FAILURE("invalid mode")); + file_descriptor::open(path, mode, BOOST_IOS::in); +} + +//------------------Implementation of file_descriptor_sink--------------------// + +file_descriptor_sink::file_descriptor_sink( + handle_type fd, file_descriptor_flags f) +{ open(fd, f); } + +#if defined(BOOST_IOSTREAMS_USE_DEPRECATED) +file_descriptor_sink::file_descriptor_sink( + handle_type fd, bool close_on_exit) +{ open(fd, close_on_exit); } +#endif + +#ifdef BOOST_IOSTREAMS_WINDOWS //---------------------------------------------// + +file_descriptor_sink::file_descriptor_sink(int fd, file_descriptor_flags f) +{ open(fd, f); } + +#if defined(BOOST_IOSTREAMS_USE_DEPRECATED) +file_descriptor_sink::file_descriptor_sink(int fd, bool close_on_exit) +{ open(fd, close_on_exit); } +#endif + +#endif // #ifdef BOOST_IOSTREAMS_WINDOWS //-----------------------------------// + +file_descriptor_sink::file_descriptor_sink( + const std::string& path, BOOST_IOS::openmode mode) +{ open(path, mode); } + +file_descriptor_sink::file_descriptor_sink( + const char* path, BOOST_IOS::openmode mode) +{ open(path, mode); } + +file_descriptor_sink::file_descriptor_sink(const file_descriptor_sink& other) + : file_descriptor(static_cast(other)) + { } + +void file_descriptor_sink::open(handle_type fd, file_descriptor_flags f) +{ file_descriptor::open(fd, f); } + +#if defined(BOOST_IOSTREAMS_USE_DEPRECATED) +void file_descriptor_sink::open(handle_type fd, bool close_on_exit) +{ file_descriptor::open(fd, close_on_exit); } +#endif + +#ifdef BOOST_IOSTREAMS_WINDOWS //---------------------------------------------// + +void file_descriptor_sink::open(int fd, file_descriptor_flags f) +{ file_descriptor::open(fd, f); } + +#if defined(BOOST_IOSTREAMS_USE_DEPRECATED) +void file_descriptor_sink::open(int fd, bool close_on_exit) +{ file_descriptor::open(fd, close_on_exit); } +#endif + +#endif // #ifdef BOOST_IOSTREAMS_WINDOWS //-----------------------------------// + +void file_descriptor_sink::open( + const std::string& path, BOOST_IOS::openmode mode) +{ open(detail::path(path), mode); } + +void file_descriptor_sink::open( + const char* path, BOOST_IOS::openmode mode) +{ open(detail::path(path), mode); } + +void file_descriptor_sink::open( + const detail::path& path, BOOST_IOS::openmode mode) +{ + if (mode & BOOST_IOS::in) + boost::throw_exception(BOOST_IOSTREAMS_FAILURE("invalid mode")); + file_descriptor::open(path, mode, BOOST_IOS::out); +} + +} } // End namespaces iostreams, boost. diff --git a/deal.II/bundled/boost-1.49.0/libs/iostreams/src/gzip.cpp b/deal.II/bundled/boost-1.49.0/libs/iostreams/src/gzip.cpp new file mode 100644 index 0000000000..04cb71a54d --- /dev/null +++ b/deal.II/bundled/boost-1.49.0/libs/iostreams/src/gzip.cpp @@ -0,0 +1,174 @@ +// (C) Copyright 2008 CodeRage, LLC (turkanis at coderage dot com) +// (C) Copyright 2003-2007 Jonathan Turkanis +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.) + +// See http://www.boost.org/libs/iostreams for documentation. + +// To configure Boost to work with libbz2, see the +// installation instructions here: +// http://boost.org/libs/iostreams/doc/index.html?path=7 + +// Define BOOST_IOSTREAMS_SOURCE so that +// knows that we are building the library (possibly exporting code), rather +// than using it (possibly importing code). +#define BOOST_IOSTREAMS_SOURCE + +#include +#include +#include + +namespace boost { namespace iostreams { + +//------------------Implementation of gzip_header-----------------------------// + +namespace detail { + +void gzip_header::process(char c) +{ + uint8_t value = static_cast(c); + switch (state_) { + case s_id1: + if (value != gzip::magic::id1) + boost::throw_exception(gzip_error(gzip::bad_header)); + state_ = s_id2; + break; + case s_id2: + if (value != gzip::magic::id2) + boost::throw_exception(gzip_error(gzip::bad_header)); + state_ = s_cm; + break; + case s_cm: + if (value != gzip::method::deflate) + boost::throw_exception(gzip_error(gzip::bad_method)); + state_ = s_flg; + break; + case s_flg: + flags_ = value; + state_ = s_mtime; + break; + case s_mtime: + mtime_ += value << (offset_ * 8); + if (offset_ == 3) { + state_ = s_xfl; + offset_ = 0; + } else { + ++offset_; + } + break; + case s_xfl: + state_ = s_os; + break; + case s_os: + os_ = value; + if (flags_ & gzip::flags::extra) { + state_ = s_extra; + } else if (flags_ & gzip::flags::name) { + state_ = s_name; + } else if (flags_ & gzip::flags::comment) { + state_ = s_comment; + } else if (flags_ & gzip::flags::header_crc) { + state_ = s_hcrc; + } else { + state_ = s_done; + } + break; + case s_xlen: + xlen_ += value << (offset_ * 8); + if (offset_ == 1) { + state_ = s_extra; + offset_ = 0; + } else { + ++offset_; + } + break; + case s_extra: + if (--xlen_ == 0) { + if (flags_ & gzip::flags::name) { + state_ = s_name; + } else if (flags_ & gzip::flags::comment) { + state_ = s_comment; + } else if (flags_ & gzip::flags::header_crc) { + state_ = s_hcrc; + } else { + state_ = s_done; + } + } + break; + case s_name: + if (c != 0) { + file_name_ += c; + } else if (flags_ & gzip::flags::comment) { + state_ = s_comment; + } else if (flags_ & gzip::flags::header_crc) { + state_ = s_hcrc; + } else { + state_ = s_done; + } + break; + case s_comment: + if (c != 0) { + comment_ += c; + } else if (flags_ & gzip::flags::header_crc) { + state_ = s_hcrc; + } else { + state_ = s_done; + } + break; + case s_hcrc: + if (offset_ == 1) { + state_ = s_done; + offset_ = 0; + } else { + ++offset_; + } + break; + default: + BOOST_ASSERT(0); + } +} + +void gzip_header::reset() +{ + file_name_.clear(); + comment_.clear(); + os_ = flags_ = offset_ = xlen_ = 0; + mtime_ = 0; + state_ = s_id1; +} + +//------------------Implementation of gzip_footer-----------------------------// + +void gzip_footer::process(char c) +{ + uint8_t value = static_cast(c); + if (state_ == s_crc) { + crc_ += value << (offset_ * 8); + if (offset_ == 3) { + state_ = s_isize; + offset_ = 0; + } else { + ++offset_; + } + } else if (state_ == s_isize) { + isize_ += value << (offset_ * 8); + if (offset_ == 3) { + state_ = s_done; + offset_ = 0; + } else { + ++offset_; + } + } else { + BOOST_ASSERT(0); + } +} + +void gzip_footer::reset() +{ + crc_ = isize_ = offset_ = 0; + state_ = s_crc; +} + +} // End namespace boost::iostreams::detail. + +} } // End namespaces iostreams, boost. diff --git a/deal.II/bundled/boost-1.49.0/libs/iostreams/src/mapped_file.cpp b/deal.II/bundled/boost-1.49.0/libs/iostreams/src/mapped_file.cpp new file mode 100644 index 0000000000..59a942e9e5 --- /dev/null +++ b/deal.II/bundled/boost-1.49.0/libs/iostreams/src/mapped_file.cpp @@ -0,0 +1,496 @@ +// (C) Copyright Craig Henderson 2002 'boost/memmap.hpp' from sandbox +// (C) Copyright Jonathan Turkanis 2004. +// (C) Copyright Jonathan Graehl 2004. +// (C) Copyright Jorge Lodos 2008. +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.) + +// Define BOOST_IOSTREAMS_SOURCE so that +// knows that we are building the library (possibly exporting code), rather +// than using it (possibly importing code). +#define BOOST_IOSTREAMS_SOURCE + +#include +#include +#include +#include +#include +#include +#include + +#ifdef BOOST_IOSTREAMS_WINDOWS +# define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers +# include +#else +# include +# include +# include // mmap, munmap. +# include +# include // struct stat. +# include // sysconf. +#endif + +namespace boost { namespace iostreams { + +namespace detail { + +// Class containing the platform-sepecific implementation +// Invariant: The members params_, data_, size_, handle_ (and mapped_handle_ +// on Windows) either +// - all have default values (or INVALID_HANDLE_VALUE for +// Windows handles), or +// - all have values reflecting a successful mapping. +// In the first case, error_ may be true, reflecting a recent unsuccessful +// open or close attempt; in the second case, error_ is always false. +class mapped_file_impl { +public: + typedef mapped_file_source::size_type size_type; + typedef mapped_file_source::param_type param_type; + typedef mapped_file_source::mapmode mapmode; + BOOST_STATIC_CONSTANT( + size_type, max_length = mapped_file_source::max_length); + mapped_file_impl(); + ~mapped_file_impl(); + void open(param_type p); + bool is_open() const { return data_ != 0; } + void close(); + bool error() const { return error_; } + mapmode flags() const { return params_.flags; } + std::size_t size() const { return size_; } + char* data() const { return data_; } + void resize(stream_offset new_size); + static int alignment(); +private: + void open_file(param_type p); + void try_map_file(param_type p); + void map_file(param_type& p); + bool unmap_file(); + void clear(bool error); + void cleanup_and_throw(const char* msg); + param_type params_; + char* data_; + stream_offset size_; + file_handle handle_; +#ifdef BOOST_IOSTREAMS_WINDOWS + file_handle mapped_handle_; +#endif + bool error_; +}; + +mapped_file_impl::mapped_file_impl() { clear(false); } + +mapped_file_impl::~mapped_file_impl() +{ try { close(); } catch (...) { } } + +void mapped_file_impl::open(param_type p) +{ + if (is_open()) + boost::throw_exception(BOOST_IOSTREAMS_FAILURE("file already open")); + p.normalize(); + open_file(p); + map_file(p); // May modify p.hint + params_ = p; +} + +void mapped_file_impl::close() +{ + if (data_ == 0) + return; + bool error = false; + error = !unmap_file() || error; + error = + #ifdef BOOST_IOSTREAMS_WINDOWS + !::CloseHandle(handle_) + #else + ::close(handle_) != 0 + #endif + || error; + clear(error); + if (error) + throw_system_failure("failed closing mapped file"); +} + +void mapped_file_impl::resize(stream_offset new_size) +{ + if (!is_open()) + boost::throw_exception(BOOST_IOSTREAMS_FAILURE("file is closed")); + if (flags() & mapped_file::priv) + boost::throw_exception( + BOOST_IOSTREAMS_FAILURE("can't resize private mapped file") + ); + if (!(flags() & mapped_file::readwrite)) + boost::throw_exception( + BOOST_IOSTREAMS_FAILURE("can't resize readonly mapped file") + ); + if (params_.offset >= new_size) + boost::throw_exception( + BOOST_IOSTREAMS_FAILURE("can't resize below mapped offset") + ); + if (!unmap_file()) + cleanup_and_throw("failed unmapping file"); +#ifdef BOOST_IOSTREAMS_WINDOWS + stream_offset offset = ::SetFilePointer(handle_, 0, NULL, FILE_CURRENT); + if (offset == INVALID_SET_FILE_POINTER && ::GetLastError() != NO_ERROR) + cleanup_and_throw("failed querying file pointer"); + LONG sizehigh = (new_size >> (sizeof(LONG) * 8)); + LONG sizelow = (new_size & 0xffffffff); + DWORD result = ::SetFilePointer(handle_, sizelow, &sizehigh, FILE_BEGIN); + if ((result == INVALID_SET_FILE_POINTER && ::GetLastError() != NO_ERROR) + || !::SetEndOfFile(handle_)) + cleanup_and_throw("failed resizing mapped file"); + sizehigh = (offset >> (sizeof(LONG) * 8)); + sizelow = (offset & 0xffffffff); + ::SetFilePointer(handle_, sizelow, &sizehigh, FILE_BEGIN); +#else + if (BOOST_IOSTREAMS_FD_TRUNCATE(handle_, new_size) == -1) + cleanup_and_throw("failed resizing mapped file"); +#endif + size_ = new_size; + param_type p(params_); + map_file(p); // May modify p.hint + params_ = p; +} + +int mapped_file_impl::alignment() +{ +#ifdef BOOST_IOSTREAMS_WINDOWS + SYSTEM_INFO info; + ::GetSystemInfo(&info); + return static_cast(info.dwAllocationGranularity); +#else + return static_cast(sysconf(_SC_PAGESIZE)); +#endif +} + +void mapped_file_impl::open_file(param_type p) +{ + bool readonly = p.flags != mapped_file::readwrite; +#ifdef BOOST_IOSTREAMS_WINDOWS + + // Open file + DWORD dwDesiredAccess = + readonly ? + GENERIC_READ : + (GENERIC_READ | GENERIC_WRITE); + DWORD dwCreationDisposition = (p.new_file_size != 0 && !readonly) ? + CREATE_ALWAYS : + OPEN_EXISTING; + DWORD dwFlagsandAttributes = + readonly ? + FILE_ATTRIBUTE_READONLY : + FILE_ATTRIBUTE_TEMPORARY; + handle_ = p.path.is_wide() ? + ::CreateFileW( + p.path.c_wstr(), + dwDesiredAccess, + FILE_SHARE_READ, + NULL, + dwCreationDisposition, + dwFlagsandAttributes, + NULL ) : + ::CreateFileA( + p.path.c_str(), + dwDesiredAccess, + FILE_SHARE_READ, + NULL, + dwCreationDisposition, + dwFlagsandAttributes, + NULL ); + if (handle_ == INVALID_HANDLE_VALUE) + cleanup_and_throw("failed opening file"); + + // Set file size + if (p.new_file_size != 0 && !readonly) { + LONG sizehigh = (p.new_file_size >> (sizeof(LONG) * 8)); + LONG sizelow = (p.new_file_size & 0xffffffff); + DWORD result = ::SetFilePointer(handle_, sizelow, &sizehigh, FILE_BEGIN); + if ((result == INVALID_SET_FILE_POINTER && ::GetLastError() != NO_ERROR) + || !::SetEndOfFile(handle_)) + cleanup_and_throw("failed setting file size"); + } + + // Determine file size. Dynamically locate GetFileSizeEx for compatibility + // with old Platform SDK (thanks to Pavel Vozenilik). + typedef BOOL (WINAPI *func)(HANDLE, PLARGE_INTEGER); + HMODULE hmod = ::GetModuleHandleA("kernel32.dll"); + func get_size = + reinterpret_cast(::GetProcAddress(hmod, "GetFileSizeEx")); + if (get_size) { + LARGE_INTEGER info; + if (get_size(handle_, &info)) { + boost::intmax_t size = + ( (static_cast(info.HighPart) << 32) | + info.LowPart ); + size_ = + static_cast( + p.length != max_length ? + std::min(p.length, size) : + size + ); + } else { + cleanup_and_throw("failed querying file size"); + return; + } + } else { + DWORD hi; + DWORD low; + if ( (low = ::GetFileSize(handle_, &hi)) + != + INVALID_FILE_SIZE ) + { + boost::intmax_t size = + (static_cast(hi) << 32) | low; + size_ = + static_cast( + p.length != max_length ? + std::min(p.length, size) : + size + ); + } else { + cleanup_and_throw("failed querying file size"); + return; + } + } +#else // #ifdef BOOST_IOSTREAMS_WINDOWS + + // Open file + int flags = (readonly ? O_RDONLY : O_RDWR); + if (p.new_file_size != 0 && !readonly) + flags |= (O_CREAT | O_TRUNC); + #ifdef _LARGEFILE64_SOURCE + flags |= O_LARGEFILE; + #endif + errno = 0; + handle_ = ::open(p.path.c_str(), flags, S_IRWXU); + if (errno != 0) + cleanup_and_throw("failed opening file"); + + //--------------Set file size---------------------------------------------// + + if (p.new_file_size != 0 && !readonly) + if (BOOST_IOSTREAMS_FD_TRUNCATE(handle_, p.new_file_size) == -1) + cleanup_and_throw("failed setting file size"); + + //--------------Determine file size---------------------------------------// + + bool success = true; + if (p.length != max_length) { + size_ = p.length; + } else { + struct BOOST_IOSTREAMS_FD_STAT info; + success = ::BOOST_IOSTREAMS_FD_FSTAT(handle_, &info) != -1; + size_ = info.st_size; + } + if (!success) + cleanup_and_throw("failed querying file size"); +#endif // #ifdef BOOST_IOSTREAMS_WINDOWS +} + +void mapped_file_impl::try_map_file(param_type p) +{ + bool priv = p.flags == mapped_file::priv; + bool readonly = p.flags == mapped_file::readonly; +#ifdef BOOST_IOSTREAMS_WINDOWS + + // Create mapping + DWORD protect = priv ? + PAGE_WRITECOPY : + readonly ? + PAGE_READONLY : + PAGE_READWRITE; + mapped_handle_ = + ::CreateFileMappingA( + handle_, + NULL, + protect, + 0, + 0, + NULL ); + if (mapped_handle_ == NULL) + cleanup_and_throw("failed create mapping"); + + // Access data + DWORD access = priv ? + FILE_MAP_COPY : + readonly ? + FILE_MAP_READ : + FILE_MAP_WRITE; + void* data = + ::MapViewOfFileEx( + mapped_handle_, + access, + (DWORD) (p.offset >> 32), + (DWORD) (p.offset & 0xffffffff), + size_ != max_length ? size_ : 0, + (LPVOID) p.hint ); + if (!data) + cleanup_and_throw("failed mapping view"); +#else + void* data = + ::BOOST_IOSTREAMS_FD_MMAP( + const_cast(p.hint), + size_, + readonly ? PROT_READ : (PROT_READ | PROT_WRITE), + priv ? MAP_PRIVATE : MAP_SHARED, + handle_, + p.offset ); + if (data == MAP_FAILED) + cleanup_and_throw("failed mapping file"); +#endif + data_ = static_cast(data); +} + +void mapped_file_impl::map_file(param_type& p) +{ + try { + try_map_file(p); + } catch (const std::exception& e) { + if (p.hint) { + p.hint = 0; + try_map_file(p); + } else { + boost::throw_exception(e); + } + } +} + +bool mapped_file_impl::unmap_file() +{ +#ifdef BOOST_IOSTREAMS_WINDOWS + bool error = false; + error = !::UnmapViewOfFile(data_) || error; + error = !::CloseHandle(mapped_handle_) || error; + mapped_handle_ = NULL; + return !error; +#else + return ::munmap(data_, size_) == 0; +#endif +} + +void mapped_file_impl::clear(bool error) +{ + params_ = param_type(); + data_ = 0; + size_ = 0; +#ifdef BOOST_IOSTREAMS_WINDOWS + handle_ = INVALID_HANDLE_VALUE; + mapped_handle_ = NULL; +#else + handle_ = 0; +#endif + error_ = error; +} + +// Called when an error is encountered during the execution of open_file or +// map_file +void mapped_file_impl::cleanup_and_throw(const char* msg) +{ +#ifdef BOOST_IOSTREAMS_WINDOWS + DWORD error = GetLastError(); + if (mapped_handle_ != NULL) + ::CloseHandle(mapped_handle_); + if (handle_ != INVALID_HANDLE_VALUE) + ::CloseHandle(handle_); + SetLastError(error); +#else + int error = errno; + if (handle_ != 0) + ::close(handle_); + errno = error; +#endif + clear(true); + boost::iostreams::detail::throw_system_failure(msg); +} + +//------------------Implementation of mapped_file_params_base-----------------// + +void mapped_file_params_base::normalize() +{ + if (mode && flags) + boost::throw_exception(BOOST_IOSTREAMS_FAILURE( + "at most one of 'mode' and 'flags' may be specified" + )); + if (flags) { + switch (flags) { + case mapped_file::readonly: + case mapped_file::readwrite: + case mapped_file::priv: + break; + default: + boost::throw_exception(BOOST_IOSTREAMS_FAILURE("invalid flags")); + } + } else { + flags = (mode & BOOST_IOS::out) ? + mapped_file::readwrite : + mapped_file::readonly; + mode = BOOST_IOS::openmode(); + } + if (offset < 0) + boost::throw_exception(BOOST_IOSTREAMS_FAILURE("invalid offset")); + if (new_file_size < 0) + boost::throw_exception( + BOOST_IOSTREAMS_FAILURE("invalid new file size") + ); +} + +} // End namespace detail. + +//------------------Implementation of mapped_file_source----------------------// + +mapped_file_source::mapped_file_source() + : pimpl_(new impl_type) + { } + +mapped_file_source::mapped_file_source(const mapped_file_source& other) + : pimpl_(other.pimpl_) + { } + +bool mapped_file_source::is_open() const +{ return pimpl_->is_open(); } + +void mapped_file_source::close() { pimpl_->close(); } + +// safe_bool is explicitly qualified below to please msvc 7.1 +mapped_file_source::operator mapped_file_source::safe_bool() const +{ return pimpl_->error() ? &safe_bool_helper::x : 0; } + +bool mapped_file_source::operator!() const +{ return pimpl_->error(); } + +mapped_file_source::mapmode mapped_file_source::flags() const +{ return pimpl_->flags(); } + +mapped_file_source::size_type mapped_file_source::size() const +{ return pimpl_->size(); } + +const char* mapped_file_source::data() const { return pimpl_->data(); } + +const char* mapped_file_source::begin() const { return data(); } + +const char* mapped_file_source::end() const { return data() + size(); } +int mapped_file_source::alignment() +{ return detail::mapped_file_impl::alignment(); } + +void mapped_file_source::init() { pimpl_.reset(new impl_type); } + +void mapped_file_source::open_impl(const param_type& p) +{ pimpl_->open(p); } + +//------------------Implementation of mapped_file-----------------------------// + +mapped_file::mapped_file(const mapped_file& other) + : delegate_(other.delegate_) + { } + +void mapped_file::resize(stream_offset new_size) +{ delegate_.pimpl_->resize(new_size); } + +//------------------Implementation of mapped_file_sink------------------------// + +mapped_file_sink::mapped_file_sink(const mapped_file_sink& other) + : mapped_file(static_cast(other)) + { } + +//----------------------------------------------------------------------------// + +} } // End namespaces iostreams, boost. diff --git a/deal.II/bundled/boost-1.49.0/libs/iostreams/src/zlib.cpp b/deal.II/bundled/boost-1.49.0/libs/iostreams/src/zlib.cpp new file mode 100644 index 0000000000..d765e855df --- /dev/null +++ b/deal.II/bundled/boost-1.49.0/libs/iostreams/src/zlib.cpp @@ -0,0 +1,193 @@ +// (C) Copyright 2008 CodeRage, LLC (turkanis at coderage dot com) +// (C) Copyright 2003-2007 Jonathan Turkanis +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.) + +// See http://www.boost.org/libs/iostreams for documentation. + +// To configure Boost to work with zlib, see the +// installation instructions here: +// http://boost.org/libs/iostreams/doc/index.html?path=7 + +// Define BOOST_IOSTREAMS_SOURCE so that +// knows that we are building the library (possibly exporting code), rather +// than using it (possibly importing code). +#define BOOST_IOSTREAMS_SOURCE + +#include +#include +#include +#include "zlib.h" // Jean-loup Gailly's and Mark Adler's "zlib.h" header. + // To configure Boost to work with zlib, see the + // installation instructions here: + // http://boost.org/libs/iostreams/doc/index.html?path=7 + +namespace boost { namespace iostreams { + +namespace zlib { + + // Compression levels + +const int no_compression = Z_NO_COMPRESSION; +const int best_speed = Z_BEST_SPEED; +const int best_compression = Z_BEST_COMPRESSION; +const int default_compression = Z_DEFAULT_COMPRESSION; + + // Compression methods + +const int deflated = Z_DEFLATED; + + // Compression strategies + +const int default_strategy = Z_DEFAULT_STRATEGY; +const int filtered = Z_FILTERED; +const int huffman_only = Z_HUFFMAN_ONLY; + + // Status codes + +const int okay = Z_OK; +const int stream_end = Z_STREAM_END; +const int stream_error = Z_STREAM_ERROR; +const int version_error = Z_VERSION_ERROR; +const int data_error = Z_DATA_ERROR; +const int mem_error = Z_MEM_ERROR; +const int buf_error = Z_BUF_ERROR; + + // Flush codes + +const int finish = Z_FINISH; +const int no_flush = Z_NO_FLUSH; +const int sync_flush = Z_SYNC_FLUSH; + + // Code for current OS + +//const int os_code = OS_CODE; + +} // End namespace zlib. + +//------------------Implementation of zlib_error------------------------------// + +zlib_error::zlib_error(int error) + : BOOST_IOSTREAMS_FAILURE("zlib error"), error_(error) + { } + +void zlib_error::check BOOST_PREVENT_MACRO_SUBSTITUTION(int error) +{ + switch (error) { + case Z_OK: + case Z_STREAM_END: + //case Z_BUF_ERROR: + return; + case Z_MEM_ERROR: + boost::throw_exception(std::bad_alloc()); + default: + boost::throw_exception(zlib_error(error)); + ; + } +} + +//------------------Implementation of zlib_base-------------------------------// + +namespace detail { + +zlib_base::zlib_base() + : stream_(new z_stream), calculate_crc_(false), crc_(0), crc_imp_(0) + { } + +zlib_base::~zlib_base() { delete static_cast(stream_); } + +void zlib_base::before( const char*& src_begin, const char* src_end, + char*& dest_begin, char* dest_end ) +{ + z_stream* s = static_cast(stream_); + s->next_in = reinterpret_cast(const_cast(src_begin)); + s->avail_in = static_cast(src_end - src_begin); + s->next_out = reinterpret_cast(dest_begin); + s->avail_out= static_cast(dest_end - dest_begin); +} + +void zlib_base::after(const char*& src_begin, char*& dest_begin, bool compress) +{ + z_stream* s = static_cast(stream_); + char* next_in = reinterpret_cast(s->next_in); + char* next_out = reinterpret_cast(s->next_out); + if (calculate_crc_) { + const zlib::byte* buf = compress ? + reinterpret_cast(src_begin) : + reinterpret_cast( + const_cast(dest_begin) + ); + zlib::uint length = compress ? + static_cast(next_in - src_begin) : + static_cast(next_out - dest_begin); + if (length > 0) + crc_ = crc_imp_ = crc32(crc_imp_, buf, length); + } + total_in_ = s->total_in; + total_out_ = s->total_out; + src_begin = const_cast(next_in); + dest_begin = next_out; +} + +int zlib_base::xdeflate(int flush) +{ + return ::deflate(static_cast(stream_), flush); +} + +int zlib_base::xinflate(int flush) +{ + return ::inflate(static_cast(stream_), flush); +} + +void zlib_base::reset(bool compress, bool realloc) +{ + z_stream* s = static_cast(stream_); + // Undiagnosed bug: + // deflateReset(), etc., return Z_DATA_ERROR + //zlib_error::check BOOST_PREVENT_MACRO_SUBSTITUTION( + realloc ? + (compress ? deflateReset(s) : inflateReset(s)) : + (compress ? deflateEnd(s) : inflateEnd(s)) + ; + //); + crc_imp_ = 0; +} + +void zlib_base::do_init + ( const zlib_params& p, bool compress, + #if !BOOST_WORKAROUND(BOOST_MSVC, < 1300) + zlib::xalloc_func /* alloc */, zlib::xfree_func /* free*/, + #endif + void* derived ) +{ + calculate_crc_ = p.calculate_crc; + z_stream* s = static_cast(stream_); + + // Current interface for customizing memory management + // is non-conforming and has been disabled: + //#if !BOOST_WORKAROUND(BOOST_MSVC, < 1300) + // s->zalloc = alloc; + // s->zfree = free; + //#else + s->zalloc = 0; + s->zfree = 0; + //#endif + s->opaque = derived; + int window_bits = p.noheader? -p.window_bits : p.window_bits; + zlib_error::check BOOST_PREVENT_MACRO_SUBSTITUTION( + compress ? + deflateInit2( s, + p.level, + p.method, + window_bits, + p.mem_level, + p.strategy ) : + inflateInit2(s, window_bits) + ); +} + +} // End namespace detail. + +//----------------------------------------------------------------------------// + +} } // End namespaces iostreams, boost.