From 55de2b2da30d63d106bded8949cd94fdf2a5696c Mon Sep 17 00:00:00 2001 From: Jonathan Turkanis Date: Thu, 26 May 2005 08:49:33 +0000 Subject: [PATCH] made ctors explicit; added mode check to mapped_file::data() [SVN r29214] --- .../boost/iostreams/device/mapped_file.hpp | 35 +++++++++++-------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/include/boost/iostreams/device/mapped_file.hpp b/include/boost/iostreams/device/mapped_file.hpp index fb096c7..0f239bd 100755 --- a/include/boost/iostreams/device/mapped_file.hpp +++ b/include/boost/iostreams/device/mapped_file.hpp @@ -97,10 +97,10 @@ public: BOOST_STATIC_CONSTANT(size_type, max_length = static_cast(-1)); mapped_file_source() { } - mapped_file_source(mapped_file_params); - mapped_file_source( const std::string& path, - size_type length = max_length, - boost::intmax_t offset = 0 ); + 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------------------------------------------// @@ -154,12 +154,12 @@ public: typedef const char* const_iterator; BOOST_STATIC_CONSTANT(size_type, max_length = delegate_type::max_length); mapped_file() { } - mapped_file(mapped_file_params p); - 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 ); + 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------------------------// @@ -183,7 +183,12 @@ public: //--------------Container interface---------------------------------------// size_type size() const { return delegate_.size(); } - char* data() const { return const_cast(delegate_.data()); } + char* data() const + { + return (mode() & BOOST_IOS::out) ? + const_cast(delegate_.data()) : + 0; + } const char* const_data() const { return delegate_.data(); } iterator begin() const { return data(); } const_iterator const_begin() const { return data(); } @@ -206,10 +211,10 @@ struct mapped_file_sink : private mapped_file { public closable_tag { }; using mapped_file::close; - mapped_file_sink(mapped_file_params p); - mapped_file_sink( const std::string& path, - size_type length = max_length, - boost::intmax_t offset = 0 ); + 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,