Imported existing code

This commit is contained in:
Hazim Gazov
2010-04-02 02:48:44 -03:00
parent 48fbc5ae91
commit 7a86d01598
13996 changed files with 2468699 additions and 0 deletions

View File

@@ -0,0 +1,144 @@
// (C) Copyright 2008 CodeRage, LLC (turkanis at coderage dot com)
// (C) Copyright 2004-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.
#ifndef BOOST_IOSTREAMS_ARRAY_HPP_INCLUDED
#define BOOST_IOSTREAMS_ARRAY_HPP_INCLUDED
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
# pragma once
#endif
#include <boost/config.hpp> // BOOST_MSVC, make sure size_t is in std.
#include <boost/detail/workaround.hpp>
#include <cstddef> // std::size_t.
#include <utility> // pair.
#include <boost/iostreams/categories.hpp>
#include <boost/preprocessor/cat.hpp>
#include <boost/static_assert.hpp>
#include <boost/type_traits/is_convertible.hpp>
#include <boost/type_traits/is_same.hpp>
namespace boost { namespace iostreams {
namespace detail {
template<typename Mode, typename Ch>
class array_adapter {
public:
typedef Ch char_type;
typedef std::pair<char_type*, char_type*> pair_type;
struct category
: public Mode,
public device_tag,
public direct_tag
{ };
array_adapter(char_type* begin, char_type* end);
array_adapter(char_type* begin, std::size_t length);
array_adapter(const char_type* begin, const char_type* end);
array_adapter(const char_type* begin, std::size_t length);
#if !BOOST_WORKAROUND(BOOST_MSVC, < 1300)
template<int N>
array_adapter(char_type (&ar)[N])
: begin_(ar), end_(ar + N)
{ }
#endif
pair_type input_sequence();
pair_type output_sequence();
private:
char_type* begin_;
char_type* end_;
};
} // End namespace detail.
// Local macros, #undef'd below.
#if !BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
# define BOOST_IOSTREAMS_ARRAY_CTOR(name, ch) \
template<int N> \
BOOST_PP_CAT(basic_, name)(ch (&ar)[N]) \
: base_type(ar) { } \
/**/
#else
# define BOOST_IOSTREAMS_ARRAY_CTOR(name, ch)
#endif
#define BOOST_IOSTREAMS_ARRAY(name, mode) \
template<typename Ch> \
struct BOOST_PP_CAT(basic_, name) : detail::array_adapter<mode, Ch> { \
private: \
typedef detail::array_adapter<mode, Ch> base_type; \
public: \
typedef typename base_type::char_type char_type; \
typedef typename base_type::category category; \
BOOST_PP_CAT(basic_, name)(char_type* begin, char_type* end) \
: base_type(begin, end) { } \
BOOST_PP_CAT(basic_, name)(char_type* begin, std::size_t length) \
: base_type(begin, length) { } \
BOOST_PP_CAT(basic_, name)(const char_type* begin, const char_type* end) \
: base_type(begin, end) { } \
BOOST_PP_CAT(basic_, name)(const char_type* begin, std::size_t length) \
: base_type(begin, length) { } \
BOOST_IOSTREAMS_ARRAY_CTOR(name, Ch) \
}; \
typedef BOOST_PP_CAT(basic_, name)<char> name; \
typedef BOOST_PP_CAT(basic_, name)<wchar_t> BOOST_PP_CAT(w, name); \
/**/
BOOST_IOSTREAMS_ARRAY(array_source, input_seekable)
BOOST_IOSTREAMS_ARRAY(array_sink, output_seekable)
BOOST_IOSTREAMS_ARRAY(array, seekable)
#undef BOOST_IOSTREAMS_ARRAY_CTOR
#undef BOOST_IOSTREAMS_ARRAY
//------------------Implementation of array_adapter---------------------------//
namespace detail {
template<typename Mode, typename Ch>
array_adapter<Mode, Ch>::array_adapter
(char_type* begin, char_type* end)
: begin_(begin), end_(end)
{ }
template<typename Mode, typename Ch>
array_adapter<Mode, Ch>::array_adapter
(char_type* begin, std::size_t length)
: begin_(begin), end_(begin + length)
{ }
template<typename Mode, typename Ch>
array_adapter<Mode, Ch>::array_adapter
(const char_type* begin, const char_type* end)
: begin_(const_cast<char_type*>(begin)), // Treated as read-only.
end_(const_cast<char_type*>(end)) // Treated as read-only.
{ BOOST_STATIC_ASSERT((!is_convertible<Mode, output>::value)); }
template<typename Mode, typename Ch>
array_adapter<Mode, Ch>::array_adapter
(const char_type* begin, std::size_t length)
: begin_(const_cast<char_type*>(begin)), // Treated as read-only.
end_(const_cast<char_type*>(begin) + length) // Treated as read-only.
{ BOOST_STATIC_ASSERT((!is_convertible<Mode, output>::value)); }
template<typename Mode, typename Ch>
typename array_adapter<Mode, Ch>::pair_type
array_adapter<Mode, Ch>::input_sequence()
{ BOOST_STATIC_ASSERT((is_convertible<Mode, input>::value));
return pair_type(begin_, end_); }
template<typename Mode, typename Ch>
typename array_adapter<Mode, Ch>::pair_type
array_adapter<Mode, Ch>::output_sequence()
{ BOOST_STATIC_ASSERT((is_convertible<Mode, output>::value));
return pair_type(begin_, end_); }
} // End namespace detail.
//----------------------------------------------------------------------------//
} } // End namespaces iostreams, boost.
#endif // #ifndef BOOST_IOSTREAMS_ARRAY_HPP_INCLUDED

View File

@@ -0,0 +1,41 @@
// (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.
#ifndef BOOST_IOSTREAMS_BACK_INSERTER_HPP_INCLUDED
#define BOOST_IOSTREAMS_BACK_INSERTER_HPP_INCLUDED
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
# pragma once
#endif
#include <boost/iostreams/detail/ios.hpp> // streamsize.
#include <boost/iostreams/categories.hpp>
namespace boost { namespace iostreams {
template<typename Container>
class back_insert_device {
public:
typedef typename Container::value_type char_type;
typedef sink_tag category;
back_insert_device(Container& cnt) : container(&cnt) { }
std::streamsize write(const char_type* s, std::streamsize n)
{
container->insert(container->end(), s, s + n);
return n;
}
protected:
Container* container;
};
template<typename Container>
back_insert_device<Container> back_inserter(Container& cnt)
{ return back_insert_device<Container>(cnt); }
} } // End namespaces iostreams, boost.
#endif // #ifndef BOOST_IOSTREAMS_BACK_INSERTER_HPP_INCLUDED

View File

@@ -0,0 +1,183 @@
// (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.
//
// Contains wrappers for standard file buffers, together
// with convenience typedefs:
// - basic_file_source
// - basic_file_sink
// - basic_file
//
#ifndef BOOST_IOSTREAMS_FILE_HPP_INCLUDED
#define BOOST_IOSTREAMS_FILE_HPP_INCLUDED
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
# pragma once
#endif
#include <boost/iostreams/detail/config/wide_streams.hpp>
#ifndef BOOST_IOSTREAMS_NO_LOCALE
# include <locale>
#endif
#include <string> // pathnames, char_traits.
#include <boost/iostreams/categories.hpp>
#include <boost/iostreams/detail/ios.hpp> // openmode, seekdir, int types.
#include <boost/iostreams/detail/fstream.hpp>
#include <boost/iostreams/operations.hpp> // seek.
#include <boost/shared_ptr.hpp>
// Must come last.
#include <boost/iostreams/detail/config/disable_warnings.hpp> // MSVC.
namespace boost { namespace iostreams {
template<typename Ch>
class basic_file {
public:
typedef Ch char_type;
struct category
: public seekable_device_tag,
public closable_tag,
public localizable_tag
{ };
basic_file( const std::string& path,
BOOST_IOS::openmode mode =
BOOST_IOS::in | BOOST_IOS::out,
BOOST_IOS::openmode base_mode =
BOOST_IOS::in | BOOST_IOS::out );
std::streamsize read(char_type* s, std::streamsize n);
std::streamsize write(const char_type* s, std::streamsize n);
std::streampos seek( stream_offset off, BOOST_IOS::seekdir way,
BOOST_IOS::openmode which =
BOOST_IOS::in | BOOST_IOS::out );
void open( const std::string& path,
BOOST_IOS::openmode mode =
BOOST_IOS::in | BOOST_IOS::out,
BOOST_IOS::openmode base_mode =
BOOST_IOS::in | BOOST_IOS::out );
bool is_open() const;
void close();
#ifndef BOOST_IOSTREAMS_NO_LOCALE
void imbue(const std::locale& loc) { pimpl_->file_.pubimbue(loc); }
#endif
private:
struct impl {
impl(const std::string& path, BOOST_IOS::openmode mode)
{ file_.open(path.c_str(), mode); }
~impl() { if (file_.is_open()) file_.close(); }
BOOST_IOSTREAMS_BASIC_FILEBUF(Ch) file_;
};
shared_ptr<impl> pimpl_;
};
typedef basic_file<char> file;
typedef basic_file<wchar_t> wfile;
template<typename Ch>
struct basic_file_source : private basic_file<Ch> {
typedef Ch char_type;
struct category
: input_seekable,
device_tag,
closable_tag
{ };
using basic_file<Ch>::read;
using basic_file<Ch>::seek;
using basic_file<Ch>::is_open;
using basic_file<Ch>::close;
basic_file_source( const std::string& path,
BOOST_IOS::openmode mode =
BOOST_IOS::in )
: basic_file<Ch>(path, mode & ~BOOST_IOS::out, BOOST_IOS::in)
{ }
void open( const std::string& path,
BOOST_IOS::openmode mode = BOOST_IOS::in )
{
basic_file<Ch>::open(path, mode & ~BOOST_IOS::out, BOOST_IOS::in);
}
};
typedef basic_file_source<char> file_source;
typedef basic_file_source<wchar_t> wfile_source;
template<typename Ch>
struct basic_file_sink : private basic_file<Ch> {
typedef Ch char_type;
struct category
: output_seekable,
device_tag,
closable_tag
{ };
using basic_file<Ch>::write;
using basic_file<Ch>::seek;
using basic_file<Ch>::is_open;
using basic_file<Ch>::close;
basic_file_sink( const std::string& path,
BOOST_IOS::openmode mode = BOOST_IOS::out )
: basic_file<Ch>(path, mode & ~BOOST_IOS::in, BOOST_IOS::out)
{ }
void open( const std::string& path,
BOOST_IOS::openmode mode = BOOST_IOS::out )
{
basic_file<Ch>::open(path, mode & ~BOOST_IOS::in, BOOST_IOS::out);
}
};
typedef basic_file_sink<char> file_sink;
typedef basic_file_sink<wchar_t> wfile_sink;
//------------------Implementation of basic_file------------------------------//
template<typename Ch>
basic_file<Ch>::basic_file
( const std::string& path, BOOST_IOS::openmode mode,
BOOST_IOS::openmode base_mode )
{
open(path, mode, base_mode);
}
template<typename Ch>
inline std::streamsize basic_file<Ch>::read
(char_type* s, std::streamsize n)
{
std::streamsize result = pimpl_->file_.sgetn(s, n);
return result != 0 ? result : -1;
}
template<typename Ch>
inline std::streamsize basic_file<Ch>::write
(const char_type* s, std::streamsize n)
{ return pimpl_->file_.sputn(s, n); }
template<typename Ch>
std::streampos basic_file<Ch>::seek
( stream_offset off, BOOST_IOS::seekdir way,
BOOST_IOS::openmode )
{ return iostreams::seek(pimpl_->file_, off, way); }
template<typename Ch>
void basic_file<Ch>::open
( const std::string& path, BOOST_IOS::openmode mode,
BOOST_IOS::openmode base_mode )
{
pimpl_.reset(new impl(path, mode | base_mode));
}
template<typename Ch>
bool basic_file<Ch>::is_open() const { return pimpl_->file_.is_open(); }
template<typename Ch>
void basic_file<Ch>::close() { pimpl_->file_.close(); }
//----------------------------------------------------------------------------//
} } // End namespaces iostreams, boost.
#include <boost/iostreams/detail/config/enable_warnings.hpp> // MSVC
#endif // #ifndef BOOST_IOSTREAMS_FILE_HPP_INCLUDED

View File

@@ -0,0 +1,186 @@
// (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.
// Inspired by fdstream.hpp, (C) Copyright Nicolai M. Josuttis 2001,
// available at http://www.josuttis.com/cppcode/fdstream.html.
#ifndef BOOST_IOSTREAMS_FILE_DESCRIPTOR_HPP_INCLUDED
#define BOOST_IOSTREAMS_FILE_DESCRIPTOR_HPP_INCLUDED
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
# pragma once
#endif
#include <string> // file pathnames.
#include <boost/cstdint.hpp> // intmax_t.
#include <boost/iostreams/categories.hpp> // tags.
#include <boost/iostreams/detail/config/auto_link.hpp>
#include <boost/iostreams/detail/config/dyn_link.hpp>
#include <boost/iostreams/detail/config/windows_posix.hpp>
#include <boost/iostreams/detail/ios.hpp> // openmode, seekdir, int types.
#include <boost/iostreams/positioning.hpp>
#include <boost/shared_ptr.hpp>
// Must come last.
#include <boost/config/abi_prefix.hpp>
namespace boost { namespace iostreams {
class BOOST_IOSTREAMS_DECL file_descriptor {
public:
#ifdef BOOST_IOSTREAMS_WINDOWS
typedef void* handle_type; // A.k.a HANDLE
#else
typedef int handle_type;
#endif
typedef char char_type;
struct category
: seekable_device_tag,
closable_tag
{ };
file_descriptor();
explicit file_descriptor(handle_type fd, bool close_on_exit = false);
#ifdef BOOST_IOSTREAMS_WINDOWS
explicit file_descriptor(int fd, bool close_on_exit = false);
#endif
explicit file_descriptor( const std::string& path,
BOOST_IOS::openmode mode =
BOOST_IOS::in | BOOST_IOS::out,
BOOST_IOS::openmode base_mode =
BOOST_IOS::in | BOOST_IOS::out );
explicit file_descriptor( const char* path,
BOOST_IOS::openmode mode =
BOOST_IOS::in | BOOST_IOS::out,
BOOST_IOS::openmode base_mode =
BOOST_IOS::in | BOOST_IOS::out );
void open( const std::string& path,
BOOST_IOS::openmode =
BOOST_IOS::in | BOOST_IOS::out,
BOOST_IOS::openmode base_mode =
BOOST_IOS::in | BOOST_IOS::out );
void open( const char* path,
BOOST_IOS::openmode =
BOOST_IOS::in | BOOST_IOS::out,
BOOST_IOS::openmode base_mode =
BOOST_IOS::in | BOOST_IOS::out );
bool is_open() const { return pimpl_->flags_ != 0; }
std::streamsize read(char_type* s, std::streamsize n);
std::streamsize write(const char_type* s, std::streamsize n);
std::streampos seek(stream_offset off, BOOST_IOS::seekdir way);
void close();
handle_type handle() const { return pimpl_->handle_; }
private:
struct impl {
impl() :
#ifdef BOOST_IOSTREAMS_WINDOWS
handle_(reinterpret_cast<handle_type>(-1)),
#else
handle_(-1),
#endif
flags_(0)
{ }
impl(handle_type fd, bool close_on_exit)
: handle_(fd), flags_(0)
{ if (close_on_exit) flags_ |= impl::close_on_exit; }
~impl()
{ if (flags_ & close_on_exit) close_impl(*this); }
enum flags {
close_on_exit = 1,
append = 4
};
handle_type handle_;
int flags_;
};
friend struct impl;
static void close_impl(impl&);
#ifdef BOOST_IOSTREAMS_WINDOWS
static handle_type int_to_handle(int fd);
#endif
shared_ptr<impl> pimpl_;
};
struct file_descriptor_source : private file_descriptor {
#ifdef BOOST_IOSTREAMS_WINDOWS
typedef void* handle_type; // A.k.a HANDLE
#else
typedef int handle_type;
#endif
typedef char char_type;
struct category
: input_seekable,
device_tag,
closable_tag
{ };
using file_descriptor::read;
using file_descriptor::seek;
using file_descriptor::open;
using file_descriptor::is_open;
using file_descriptor::close;
using file_descriptor::handle;
file_descriptor_source() { }
explicit file_descriptor_source(handle_type fd, bool close_on_exit = false)
: file_descriptor(fd, close_on_exit)
{ }
#ifdef BOOST_IOSTREAMS_WINDOWS
explicit file_descriptor_source(int fd, bool close_on_exit = false)
: file_descriptor(fd, close_on_exit)
{ }
#endif
explicit file_descriptor_source( const std::string& path,
BOOST_IOS::openmode m = BOOST_IOS::in )
: file_descriptor(path, m & ~BOOST_IOS::out, BOOST_IOS::in)
{ }
explicit file_descriptor_source( const char* path,
BOOST_IOS::openmode m = BOOST_IOS::in )
: file_descriptor(path, m & ~BOOST_IOS::out, BOOST_IOS::in)
{ }
};
struct file_descriptor_sink : private file_descriptor {
#ifdef BOOST_IOSTREAMS_WINDOWS
typedef void* handle_type; // A.k.a HANDLE
#else
typedef int handle_type;
#endif
typedef char char_type;
struct category
: output_seekable,
device_tag,
closable_tag
{ };
using file_descriptor::write;
using file_descriptor::seek;
using file_descriptor::open;
using file_descriptor::is_open;
using file_descriptor::close;
using file_descriptor::handle;
file_descriptor_sink() { }
explicit file_descriptor_sink(handle_type fd, bool close_on_exit = false)
: file_descriptor(fd, close_on_exit)
{ }
#ifdef BOOST_IOSTREAMS_WINDOWS
explicit file_descriptor_sink(int fd, bool close_on_exit = false)
: file_descriptor(fd, close_on_exit)
{ }
#endif
explicit file_descriptor_sink( const std::string& path,
BOOST_IOS::openmode m = BOOST_IOS::out )
: file_descriptor(path, m & ~BOOST_IOS::in, BOOST_IOS::out)
{ }
explicit file_descriptor_sink( const char* path,
BOOST_IOS::openmode m = BOOST_IOS::out )
: file_descriptor(path, m & ~BOOST_IOS::in, BOOST_IOS::out)
{ }
};
} } // End namespaces iostreams, boost.
#include <boost/config/abi_suffix.hpp> // pops abi_suffix.hpp pragmas
#endif // #ifndef BOOST_IOSTREAMS_FILE_DESCRIPTOR_HPP_INCLUDED

View File

@@ -0,0 +1,285 @@
// (C) Copyright 2008 CodeRage, LLC (turkanis at coderage dot com)
// (C) Copyright 2003-2007 Jonathan Turkanis
// (C) Copyright Craig Henderson 2002. 'boost/memmap.hpp' from sandbox
// 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.
//
// This header and its accompanying source file libs/iostreams/memmap.cpp are
// an adaptation of Craig Henderson's memmory mapped file library. The
// interface has been revised significantly, but the underlying OS-specific
// code is essentially the same, with some code from Boost.Filesystem
// mixed in. (See notations in source.)
//
// The following changes have been made:
//
// 1. OS-specific code put in a .cpp file.
// 2. Name of main class changed to mapped_file.
// 3. mapped_file given an interface similar to std::fstream (open(),
// is_open(), close()) and std::string (data(), size(), begin(), end()).
// 4. An additional class readonly_mapped_file has been provided as a
// convenience.
// 5. [Obsolete: Error states are reported using filesystem::error_code.]
// 6. Read-only or read-write states are specified using ios_base::openmode.
// 7. Access to the underlying file handles and to security parameters
// has been removed.
//
#ifndef BOOST_IOSTREAMS_MAPPED_FILE_HPP_INCLUDED
#define BOOST_IOSTREAMS_MAPPED_FILE_HPP_INCLUDED
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
# pragma once
#endif
#include <boost/config.hpp> // make sure size_t is in std.
#include <cstddef> // size_t.
#include <string> // pathnames.
#include <utility> // pair.
#include <boost/config.hpp> // BOOST_MSVC.
#include <boost/detail/workaround.hpp>
#include <boost/iostreams/close.hpp>
#include <boost/iostreams/concepts.hpp>
#include <boost/iostreams/detail/config/auto_link.hpp>
#include <boost/iostreams/detail/config/dyn_link.hpp>
#include <boost/iostreams/detail/ios.hpp> // openmode.
#include <boost/iostreams/operations_fwd.hpp>
#include <boost/iostreams/positioning.hpp>
#include <boost/shared_ptr.hpp>
// Must come last.
#include <boost/iostreams/detail/config/disable_warnings.hpp>
#include <boost/config/abi_prefix.hpp>
namespace boost { namespace iostreams {
namespace detail {
struct mapped_file_impl;
} // End namespace detail.
struct mapped_file_params {
explicit mapped_file_params()
#if BOOST_WORKAROUND(BOOST_MSVC, < 1400) && defined(BOOST_RWSTD_VER) || \
defined(__BORLANDC__) && defined(_CPPLIB_VER)
/**/
: mode(std::ios_base::openmode(0)),
#else
: mode(),
#endif
offset(0), length(static_cast<std::size_t>(-1)),
new_file_size(0), hint(0)
{ }
explicit mapped_file_params(const std::string& path)
: path(path),
#if BOOST_WORKAROUND(BOOST_MSVC, < 1400) && defined(BOOST_RWSTD_VER) || \
defined(__BORLANDC__) && defined(_CPPLIB_VER)
mode(std::ios_base::openmode(0)),
#else
mode(),
#endif
offset(0), length(static_cast<std::size_t>(-1)),
new_file_size(0), hint(0)
{ }
std::string path;
BOOST_IOS::openmode mode;
stream_offset offset;
std::size_t length;
stream_offset new_file_size;
const char* hint;
};
//------------------Definition of mapped_file_source--------------------------//
class BOOST_IOSTREAMS_DECL mapped_file_source {
private:
struct safe_bool_helper { int x; }; // From Bronek Kozicki.
typedef int safe_bool_helper::* safe_bool;
friend struct operations<mapped_file_source>;
public:
typedef char char_type;
struct category
: public source_tag,
public direct_tag,
public closable_tag
{ };
typedef std::size_t size_type;
typedef const char* iterator;
BOOST_STATIC_CONSTANT(size_type, max_length = static_cast<size_type>(-1));
mapped_file_source() { }
explicit mapped_file_source(mapped_file_params);
explicit mapped_file_source( const std::string& path,
size_type length = max_length,
boost::intmax_t offset = 0 );
//--------------Stream interface------------------------------------------//
void open(mapped_file_params params);
void open( const std::string& path,
size_type length = max_length,
boost::intmax_t offset = 0 );
bool is_open() const;
void close();
operator safe_bool() const;
bool operator!() const;
BOOST_IOS::openmode mode() const;
//--------------Container interface---------------------------------------//
size_type size() const;
const char* data() const;
iterator begin() const;
iterator end() const;
//--------------Query admissible offsets----------------------------------//
// Returns the allocation granularity for virtual memory. Values passed
// as offsets must be multiples of this value.
static int alignment();
private:
friend class mapped_file;
typedef detail::mapped_file_impl impl_type;
void open_impl(mapped_file_params);
boost::shared_ptr<impl_type> pimpl_;
};
//------------------Definition of mapped_file---------------------------------//
class BOOST_IOSTREAMS_DECL mapped_file {
private:
typedef mapped_file_source delegate_type;
delegate_type delegate_;
friend struct operations<mapped_file>;
public:
typedef char char_type;
struct category
: public seekable_device_tag,
public direct_tag,
public closable_tag
{ };
typedef mapped_file_source::size_type size_type;
typedef char* iterator;
typedef const char* const_iterator;
BOOST_STATIC_CONSTANT(size_type, max_length = delegate_type::max_length);
mapped_file() { }
explicit mapped_file(mapped_file_params p);
explicit mapped_file( const std::string& path,
BOOST_IOS::openmode mode =
BOOST_IOS::in | BOOST_IOS::out,
size_type length = max_length,
stream_offset offset = 0 );
//--------------Conversion to readonly_mapped_file------------------------//
operator mapped_file_source&() { return delegate_; }
operator const mapped_file_source&() const { return delegate_; }
//--------------Stream interface------------------------------------------//
void open(mapped_file_params p);
void open( const std::string& path,
BOOST_IOS::openmode mode =
BOOST_IOS::in | BOOST_IOS::out,
size_type length = max_length,
stream_offset offset = 0 );
bool is_open() const { return delegate_.is_open(); }
void close() { delegate_.close(); }
operator delegate_type::safe_bool() const { return delegate_; }
bool operator!() const { return !is_open(); }
BOOST_IOS::openmode mode() const { return delegate_.mode(); }
//--------------Container interface---------------------------------------//
size_type size() const { return delegate_.size(); }
char* data() const
{
return (mode() & BOOST_IOS::out) ?
const_cast<char*>(delegate_.data()) :
0;
}
const char* const_data() const { return delegate_.data(); }
iterator begin() const { return data(); }
const_iterator const_begin() const { return data(); }
iterator end() const { return data() + size(); }
const_iterator const_end() const { return data() + size(); }
//--------------Query admissible offsets----------------------------------//
// Returns the allocation granularity for virtual memory. Values passed
// as offsets must be multiples of this value.
static int alignment() { return mapped_file_source::alignment(); }
};
struct BOOST_IOSTREAMS_DECL mapped_file_sink : private mapped_file {
friend struct operations<mapped_file_sink>;
typedef char char_type;
struct category
: public sink_tag,
public direct_tag,
public closable_tag
{ };
using mapped_file::close;
using mapped_file::size;
explicit mapped_file_sink(mapped_file_params p);
explicit mapped_file_sink( const std::string& path,
size_type length = max_length,
boost::intmax_t offset = 0 );
void open(mapped_file_params p);
void open( const std::string& path,
size_type length = max_length,
boost::intmax_t offset = 0 );
};
//------------------Specialization of direct_impl-----------------------------//
template<>
struct operations<boost::iostreams::mapped_file_source>
: detail::close_impl<closable_tag>
{
static std::pair<char*, char*>
input_sequence(boost::iostreams::mapped_file_source& src)
{
return std::make_pair( const_cast<char*>(src.begin()),
const_cast<char*>(src.end()) );
}
};
template<>
struct operations<boost::iostreams::mapped_file_sink>
: detail::close_impl<closable_tag>
{
static std::pair<char*, char*>
output_sequence(boost::iostreams::mapped_file_sink& sink)
{
return std::make_pair(sink.begin(), sink.end());
}
};
template<>
struct operations<boost::iostreams::mapped_file>
: detail::close_impl<closable_tag>
{
static std::pair<char*, char*>
input_sequence(boost::iostreams::mapped_file& file)
{
return std::make_pair(file.begin(), file.end());
}
static std::pair<char*, char*>
output_sequence(boost::iostreams::mapped_file& file)
{
return std::make_pair(file.begin(), file.end());
}
};
} } // End namespaces iostreams, boost.
#include <boost/config/abi_suffix.hpp> // pops abi_suffix.hpp pragmas
#include <boost/iostreams/detail/config/enable_warnings.hpp> // MSVC.
#endif // #ifndef BOOST_IOSTREAMS_MAPPED_FILE_HPP_INCLUDED

View File

@@ -0,0 +1,66 @@
// (C) Copyright 2008 CodeRage, LLC (turkanis at coderage dot com)
// (C) Copyright 2004-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.
// Inspired by Daryle Walker's nullbuf from his More I/O submission.
#ifndef BOOST_IOSTREAMS_NULL_HPP_INCLUDED
#define BOOST_IOSTREAMS_NULL_HPP_INCLUDED
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
# pragma once
#endif
#include <boost/iostreams/categories.hpp>
#include <boost/iostreams/detail/ios.hpp> // openmode, streamsize.
#include <boost/iostreams/positioning.hpp>
namespace boost { namespace iostreams {
template<typename Ch, typename Mode>
class basic_null_device {
public:
typedef Ch char_type;
struct category
: public Mode,
public device_tag,
public closable_tag
{ };
std::streamsize read(Ch*, std::streamsize) { return 0; }
std::streamsize write(const Ch*, std::streamsize n) { return n; }
std::streampos seek( stream_offset, BOOST_IOS::seekdir,
BOOST_IOS::openmode =
BOOST_IOS::in | BOOST_IOS::out )
{ return -1; }
void close() { }
void close(BOOST_IOS::openmode) { }
};
template<typename Ch>
struct basic_null_source : private basic_null_device<Ch, input> {
typedef Ch char_type;
typedef source_tag category;
using basic_null_device<Ch, input>::read;
using basic_null_device<Ch, input>::close;
};
typedef basic_null_source<char> null_source;
typedef basic_null_source<wchar_t> wnull_source;
template<typename Ch>
struct basic_null_sink : private basic_null_device<Ch, output> {
typedef Ch char_type;
typedef sink_tag category;
using basic_null_device<Ch, output>::write;
using basic_null_device<Ch, output>::close;
};
typedef basic_null_sink<char> null_sink;
typedef basic_null_sink<wchar_t> wnull_sink;
} } // End namespaces iostreams, boost.
#endif // #ifndef BOOST_IOSTREAMS_NULL_HPP_INCLUDED