annotate DEPENDENCIES/generic/include/boost/iostreams/device/mapped_file.hpp @ 125:34e428693f5d vext

Vext -> Repoint
author Chris Cannam
date Thu, 14 Jun 2018 11:15:39 +0100
parents 2665513ce2d3
children
rev   line source
Chris@16 1 // (C) Copyright Jorge Lodos 2008.
Chris@16 2 // (C) Copyright Jonathan Turkanis 2003.
Chris@16 3 // (C) Copyright Craig Henderson 2002. 'boost/memmap.hpp' from sandbox
Chris@16 4 // Distributed under the Boost Software License, Version 1.0. (See accompanying
Chris@16 5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.)
Chris@16 6
Chris@16 7 #ifndef BOOST_IOSTREAMS_MAPPED_FILE_HPP_INCLUDED
Chris@16 8 #define BOOST_IOSTREAMS_MAPPED_FILE_HPP_INCLUDED
Chris@16 9
Chris@16 10 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
Chris@16 11 # pragma once
Chris@16 12 #endif
Chris@16 13
Chris@16 14 #include <boost/config.hpp> // make sure size_t is in std.
Chris@16 15 #include <cstddef> // size_t.
Chris@16 16 #include <string> // pathnames.
Chris@16 17 #include <utility> // pair.
Chris@16 18 #include <boost/config.hpp> // BOOST_MSVC.
Chris@16 19 #include <boost/detail/workaround.hpp>
Chris@16 20 #include <boost/iostreams/close.hpp>
Chris@16 21 #include <boost/iostreams/concepts.hpp>
Chris@16 22 #include <boost/iostreams/detail/config/auto_link.hpp>
Chris@16 23 #include <boost/iostreams/detail/config/dyn_link.hpp>
Chris@16 24 #include <boost/iostreams/detail/config/wide_streams.hpp>
Chris@16 25 #include <boost/iostreams/detail/ios.hpp> // openmode, failure
Chris@16 26 #include <boost/iostreams/detail/path.hpp>
Chris@16 27 #include <boost/iostreams/operations_fwd.hpp>
Chris@16 28 #include <boost/iostreams/positioning.hpp>
Chris@16 29 #include <boost/shared_ptr.hpp>
Chris@16 30 #include <boost/static_assert.hpp>
Chris@16 31 #include <boost/throw_exception.hpp>
Chris@16 32 #include <boost/type_traits/is_same.hpp>
Chris@16 33
Chris@16 34 // Must come last.
Chris@16 35 #include <boost/config/abi_prefix.hpp>
Chris@16 36
Chris@16 37 namespace boost { namespace iostreams {
Chris@16 38
Chris@16 39 //------------------Definition of mapped_file_base and mapped_file_params-----//
Chris@16 40
Chris@16 41 // Forward declarations
Chris@16 42 class mapped_file_source;
Chris@16 43 class mapped_file_sink;
Chris@16 44 class mapped_file;
Chris@16 45 namespace detail { class mapped_file_impl; }
Chris@16 46
Chris@16 47 class mapped_file_base {
Chris@16 48 public:
Chris@16 49 enum mapmode {
Chris@16 50 readonly = 1,
Chris@16 51 readwrite = 2,
Chris@16 52 priv = 4
Chris@16 53 };
Chris@16 54 };
Chris@16 55
Chris@16 56 // Bitmask operations for mapped_file_base::mapmode
Chris@16 57 mapped_file_base::mapmode
Chris@16 58 operator|(mapped_file_base::mapmode a, mapped_file_base::mapmode b);
Chris@16 59
Chris@16 60 mapped_file_base::mapmode
Chris@16 61 operator&(mapped_file_base::mapmode a, mapped_file_base::mapmode b);
Chris@16 62
Chris@16 63 mapped_file_base::mapmode
Chris@16 64 operator^(mapped_file_base::mapmode a, mapped_file_base::mapmode b);
Chris@16 65
Chris@16 66 mapped_file_base::mapmode
Chris@16 67 operator~(mapped_file_base::mapmode a);
Chris@16 68
Chris@16 69 mapped_file_base::mapmode
Chris@16 70 operator|=(mapped_file_base::mapmode& a, mapped_file_base::mapmode b);
Chris@16 71
Chris@16 72 mapped_file_base::mapmode
Chris@16 73 operator&=(mapped_file_base::mapmode& a, mapped_file_base::mapmode b);
Chris@16 74
Chris@16 75 mapped_file_base::mapmode
Chris@16 76 operator^=(mapped_file_base::mapmode& a, mapped_file_base::mapmode b);
Chris@16 77
Chris@16 78 //------------------Definition of mapped_file_params--------------------------//
Chris@16 79
Chris@16 80 namespace detail {
Chris@16 81
Chris@16 82 struct mapped_file_params_base {
Chris@16 83 mapped_file_params_base()
Chris@16 84 : flags(static_cast<mapped_file_base::mapmode>(0)),
Chris@16 85 mode(), offset(0), length(static_cast<std::size_t>(-1)),
Chris@16 86 new_file_size(0), hint(0)
Chris@16 87 { }
Chris@16 88 private:
Chris@16 89 friend class mapped_file_impl;
Chris@16 90 void normalize();
Chris@16 91 public:
Chris@16 92 mapped_file_base::mapmode flags;
Chris@16 93 BOOST_IOS::openmode mode; // Deprecated
Chris@16 94 stream_offset offset;
Chris@16 95 std::size_t length;
Chris@16 96 stream_offset new_file_size;
Chris@16 97 const char* hint;
Chris@16 98 };
Chris@16 99
Chris@16 100 } // End namespace detail.
Chris@16 101
Chris@16 102 // This template allows Boost.Filesystem paths to be specified when creating or
Chris@16 103 // reopening a memory mapped file, without creating a dependence on
Chris@16 104 // Boost.Filesystem. Possible values of Path include std::string,
Chris@16 105 // boost::filesystem::path, boost::filesystem::wpath,
Chris@16 106 // and boost::iostreams::detail::path (used to store either a std::string or a
Chris@16 107 // std::wstring).
Chris@16 108 template<typename Path>
Chris@16 109 struct basic_mapped_file_params
Chris@16 110 : detail::mapped_file_params_base
Chris@16 111 {
Chris@16 112 typedef detail::mapped_file_params_base base_type;
Chris@16 113
Chris@16 114 // For wide paths, instantiate basic_mapped_file_params
Chris@16 115 // with boost::filesystem::wpath
Chris@16 116 #ifndef BOOST_IOSTREAMS_NO_WIDE_STREAMS
Chris@16 117 BOOST_STATIC_ASSERT((!is_same<Path, std::wstring>::value));
Chris@16 118 #endif
Chris@16 119
Chris@16 120 // Default constructor
Chris@16 121 basic_mapped_file_params() { }
Chris@16 122
Chris@16 123 // Construction from a Path
Chris@16 124 explicit basic_mapped_file_params(const Path& p) : path(p) { }
Chris@16 125
Chris@16 126 // Construction from a path of a different type
Chris@16 127 template<typename PathT>
Chris@16 128 explicit basic_mapped_file_params(const PathT& p) : path(p) { }
Chris@16 129
Chris@16 130 // Copy constructor
Chris@16 131 basic_mapped_file_params(const basic_mapped_file_params& other)
Chris@16 132 : base_type(other), path(other.path)
Chris@16 133 { }
Chris@16 134
Chris@16 135 // Templated copy constructor
Chris@16 136 template<typename PathT>
Chris@16 137 basic_mapped_file_params(const basic_mapped_file_params<PathT>& other)
Chris@16 138 : base_type(other), path(other.path)
Chris@16 139 { }
Chris@16 140
Chris@16 141 typedef Path path_type;
Chris@16 142 Path path;
Chris@16 143 };
Chris@16 144
Chris@16 145 typedef basic_mapped_file_params<std::string> mapped_file_params;
Chris@16 146
Chris@16 147 //------------------Definition of mapped_file_source--------------------------//
Chris@16 148
Chris@16 149 class BOOST_IOSTREAMS_DECL mapped_file_source : public mapped_file_base {
Chris@16 150 private:
Chris@16 151 struct safe_bool_helper { int x; };
Chris@16 152 typedef int safe_bool_helper::* safe_bool;
Chris@16 153 typedef detail::mapped_file_impl impl_type;
Chris@16 154 typedef basic_mapped_file_params<detail::path> param_type;
Chris@16 155 friend class mapped_file;
Chris@16 156 friend class detail::mapped_file_impl;
Chris@16 157 friend struct boost::iostreams::operations<mapped_file_source>;
Chris@16 158 public:
Chris@16 159 typedef char char_type;
Chris@16 160 struct category
Chris@16 161 : public source_tag,
Chris@16 162 public direct_tag,
Chris@16 163 public closable_tag
Chris@16 164 { };
Chris@16 165 typedef std::size_t size_type;
Chris@16 166 typedef const char* iterator;
Chris@16 167 BOOST_STATIC_CONSTANT(size_type, max_length = static_cast<size_type>(-1));
Chris@16 168
Chris@16 169 // Default constructor
Chris@16 170 mapped_file_source();
Chris@16 171
Chris@16 172 // Constructor taking a parameters object
Chris@16 173 template<typename Path>
Chris@16 174 explicit mapped_file_source(const basic_mapped_file_params<Path>& p);
Chris@16 175
Chris@16 176 // Constructor taking a list of parameters
Chris@16 177 template<typename Path>
Chris@16 178 explicit mapped_file_source( const Path& path,
Chris@16 179 size_type length = max_length,
Chris@16 180 boost::intmax_t offset = 0 );
Chris@16 181
Chris@16 182 // Copy Constructor
Chris@16 183 mapped_file_source(const mapped_file_source& other);
Chris@16 184
Chris@16 185 //--------------Stream interface------------------------------------------//
Chris@16 186
Chris@16 187 template<typename Path>
Chris@16 188 void open(const basic_mapped_file_params<Path>& p);
Chris@16 189
Chris@16 190 template<typename Path>
Chris@16 191 void open( const Path& path,
Chris@16 192 size_type length = max_length,
Chris@16 193 boost::intmax_t offset = 0 );
Chris@16 194
Chris@16 195 bool is_open() const;
Chris@16 196 void close();
Chris@16 197 operator safe_bool() const;
Chris@16 198 bool operator!() const;
Chris@16 199 mapmode flags() const;
Chris@16 200
Chris@16 201 //--------------Container interface---------------------------------------//
Chris@16 202
Chris@16 203 size_type size() const;
Chris@16 204 const char* data() const;
Chris@16 205 iterator begin() const;
Chris@16 206 iterator end() const;
Chris@16 207
Chris@16 208 //--------------Query admissible offsets----------------------------------//
Chris@16 209
Chris@16 210 // Returns the allocation granularity for virtual memory. Values passed
Chris@16 211 // as offsets must be multiples of this value.
Chris@16 212 static int alignment();
Chris@16 213
Chris@16 214 private:
Chris@16 215 void init();
Chris@16 216 void open_impl(const param_type& p);
Chris@16 217
Chris@16 218 boost::shared_ptr<impl_type> pimpl_;
Chris@16 219 };
Chris@16 220
Chris@16 221 //------------------Definition of mapped_file---------------------------------//
Chris@16 222
Chris@16 223 class BOOST_IOSTREAMS_DECL mapped_file : public mapped_file_base {
Chris@16 224 private:
Chris@16 225 typedef mapped_file_source delegate_type;
Chris@16 226 typedef delegate_type::safe_bool safe_bool;
Chris@16 227 typedef basic_mapped_file_params<detail::path> param_type;
Chris@16 228 friend struct boost::iostreams::operations<mapped_file >;
Chris@16 229 friend class mapped_file_sink;
Chris@16 230 public:
Chris@16 231 typedef char char_type;
Chris@16 232 struct category
Chris@16 233 : public seekable_device_tag,
Chris@16 234 public direct_tag,
Chris@16 235 public closable_tag
Chris@16 236 { };
Chris@16 237 typedef mapped_file_source::size_type size_type;
Chris@16 238 typedef char* iterator;
Chris@16 239 typedef const char* const_iterator;
Chris@16 240 BOOST_STATIC_CONSTANT(size_type, max_length = delegate_type::max_length);
Chris@16 241
Chris@16 242 // Default constructor
Chris@16 243 mapped_file() { }
Chris@16 244
Chris@16 245 // Construstor taking a parameters object
Chris@16 246 template<typename Path>
Chris@16 247 explicit mapped_file(const basic_mapped_file_params<Path>& p);
Chris@16 248
Chris@16 249 // Constructor taking a list of parameters
Chris@16 250 template<typename Path>
Chris@16 251 mapped_file( const Path& path,
Chris@16 252 mapmode flags,
Chris@16 253 size_type length = max_length,
Chris@16 254 stream_offset offset = 0 );
Chris@16 255
Chris@16 256 // Constructor taking a list of parameters, including a
Chris@16 257 // std::ios_base::openmode (deprecated)
Chris@16 258 template<typename Path>
Chris@16 259 explicit mapped_file( const Path& path,
Chris@16 260 BOOST_IOS::openmode mode =
Chris@16 261 BOOST_IOS::in | BOOST_IOS::out,
Chris@16 262 size_type length = max_length,
Chris@16 263 stream_offset offset = 0 );
Chris@16 264
Chris@16 265 // Copy Constructor
Chris@16 266 mapped_file(const mapped_file& other);
Chris@16 267
Chris@16 268 //--------------Conversion to mapped_file_source (deprecated)-------------//
Chris@16 269
Chris@16 270 operator mapped_file_source&() { return delegate_; }
Chris@16 271 operator const mapped_file_source&() const { return delegate_; }
Chris@16 272
Chris@16 273 //--------------Stream interface------------------------------------------//
Chris@16 274
Chris@16 275 // open overload taking a parameters object
Chris@16 276 template<typename Path>
Chris@16 277 void open(const basic_mapped_file_params<Path>& p);
Chris@16 278
Chris@16 279 // open overload taking a list of parameters
Chris@16 280 template<typename Path>
Chris@16 281 void open( const Path& path,
Chris@16 282 mapmode mode,
Chris@16 283 size_type length = max_length,
Chris@16 284 stream_offset offset = 0 );
Chris@16 285
Chris@16 286 // open overload taking a list of parameters, including a
Chris@16 287 // std::ios_base::openmode (deprecated)
Chris@16 288 template<typename Path>
Chris@16 289 void open( const Path& path,
Chris@16 290 BOOST_IOS::openmode mode =
Chris@16 291 BOOST_IOS::in | BOOST_IOS::out,
Chris@16 292 size_type length = max_length,
Chris@16 293 stream_offset offset = 0 );
Chris@16 294
Chris@16 295 bool is_open() const { return delegate_.is_open(); }
Chris@16 296 void close() { delegate_.close(); }
Chris@16 297 operator safe_bool() const { return delegate_; }
Chris@16 298 bool operator!() const { return !delegate_; }
Chris@16 299 mapmode flags() const { return delegate_.flags(); }
Chris@16 300
Chris@16 301 //--------------Container interface---------------------------------------//
Chris@16 302
Chris@16 303 size_type size() const { return delegate_.size(); }
Chris@16 304 char* data() const;
Chris@16 305 const char* const_data() const { return delegate_.data(); }
Chris@16 306 iterator begin() const { return data(); }
Chris@16 307 const_iterator const_begin() const { return const_data(); }
Chris@16 308 iterator end() const { return data() + size(); }
Chris@16 309 const_iterator const_end() const { return const_data() + size(); }
Chris@16 310
Chris@16 311 //--------------Query admissible offsets----------------------------------//
Chris@16 312
Chris@16 313 // Returns the allocation granularity for virtual memory. Values passed
Chris@16 314 // as offsets must be multiples of this value.
Chris@16 315 static int alignment() { return mapped_file_source::alignment(); }
Chris@16 316
Chris@16 317 //--------------File access----------------------------------------------//
Chris@16 318
Chris@16 319 void resize(stream_offset new_size);
Chris@16 320 private:
Chris@16 321 delegate_type delegate_;
Chris@16 322 };
Chris@16 323
Chris@16 324 //------------------Definition of mapped_file_sink----------------------------//
Chris@16 325
Chris@16 326 class BOOST_IOSTREAMS_DECL mapped_file_sink : private mapped_file {
Chris@16 327 public:
Chris@16 328 friend struct boost::iostreams::operations<mapped_file_sink>;
Chris@16 329 using mapped_file::mapmode;
Chris@16 330 using mapped_file::readonly;
Chris@16 331 using mapped_file::readwrite;
Chris@16 332 using mapped_file::priv;
Chris@16 333 using mapped_file::char_type;
Chris@16 334 struct category
Chris@16 335 : public sink_tag,
Chris@16 336 public direct_tag,
Chris@16 337 public closable_tag
Chris@16 338 { };
Chris@16 339 using mapped_file::size_type;
Chris@16 340 using mapped_file::iterator;
Chris@16 341 using mapped_file::max_length;
Chris@16 342 using mapped_file::is_open;
Chris@16 343 using mapped_file::close;
Chris@16 344 using mapped_file::operator safe_bool;
Chris@16 345 using mapped_file::operator !;
Chris@16 346 using mapped_file::flags;
Chris@16 347 using mapped_file::size;
Chris@16 348 using mapped_file::data;
Chris@16 349 using mapped_file::begin;
Chris@16 350 using mapped_file::end;
Chris@16 351 using mapped_file::alignment;
Chris@16 352 using mapped_file::resize;
Chris@16 353
Chris@16 354 // Default constructor
Chris@16 355 mapped_file_sink() { }
Chris@16 356
Chris@16 357 // Constructor taking a parameters object
Chris@16 358 template<typename Path>
Chris@16 359 explicit mapped_file_sink(const basic_mapped_file_params<Path>& p);
Chris@16 360
Chris@16 361 // Constructor taking a list of parameters
Chris@16 362 template<typename Path>
Chris@16 363 explicit mapped_file_sink( const Path& path,
Chris@16 364 size_type length = max_length,
Chris@16 365 boost::intmax_t offset = 0,
Chris@16 366 mapmode flags = readwrite );
Chris@16 367
Chris@16 368 // Copy Constructor
Chris@16 369 mapped_file_sink(const mapped_file_sink& other);
Chris@16 370
Chris@16 371 // open overload taking a parameters object
Chris@16 372 template<typename Path>
Chris@16 373 void open(const basic_mapped_file_params<Path>& p);
Chris@16 374
Chris@16 375 // open overload taking a list of parameters
Chris@16 376 template<typename Path>
Chris@16 377 void open( const Path& path,
Chris@16 378 size_type length = max_length,
Chris@16 379 boost::intmax_t offset = 0,
Chris@16 380 mapmode flags = readwrite );
Chris@16 381 };
Chris@16 382
Chris@16 383 //------------------Implementation of mapped_file_source----------------------//
Chris@16 384
Chris@16 385 template<typename Path>
Chris@16 386 mapped_file_source::mapped_file_source(const basic_mapped_file_params<Path>& p)
Chris@16 387 { init(); open(p); }
Chris@16 388
Chris@16 389 template<typename Path>
Chris@16 390 mapped_file_source::mapped_file_source(
Chris@16 391 const Path& path, size_type length, boost::intmax_t offset)
Chris@16 392 { init(); open(path, length, offset); }
Chris@16 393
Chris@16 394 template<typename Path>
Chris@16 395 void mapped_file_source::open(const basic_mapped_file_params<Path>& p)
Chris@16 396 {
Chris@16 397 param_type params(p);
Chris@16 398 if (params.flags) {
Chris@16 399 if (params.flags != mapped_file::readonly)
Chris@16 400 boost::throw_exception(BOOST_IOSTREAMS_FAILURE("invalid flags"));
Chris@16 401 } else {
Chris@16 402 if (params.mode & BOOST_IOS::out)
Chris@16 403 boost::throw_exception(BOOST_IOSTREAMS_FAILURE("invalid mode"));
Chris@16 404 params.mode |= BOOST_IOS::in;
Chris@16 405 }
Chris@16 406 open_impl(params);
Chris@16 407 }
Chris@16 408
Chris@16 409 template<typename Path>
Chris@16 410 void mapped_file_source::open(
Chris@16 411 const Path& path, size_type length, boost::intmax_t offset)
Chris@16 412 {
Chris@16 413 param_type p(path);
Chris@16 414 p.length = length;
Chris@16 415 p.offset = offset;
Chris@16 416 open(p);
Chris@16 417 }
Chris@16 418
Chris@16 419 //------------------Implementation of mapped_file-----------------------------//
Chris@16 420
Chris@16 421 template<typename Path>
Chris@16 422 mapped_file::mapped_file(const basic_mapped_file_params<Path>& p)
Chris@16 423 { open(p); }
Chris@16 424
Chris@16 425 template<typename Path>
Chris@16 426 mapped_file::mapped_file(
Chris@16 427 const Path& path, mapmode flags,
Chris@16 428 size_type length, stream_offset offset )
Chris@16 429 { open(path, flags, length, offset); }
Chris@16 430
Chris@16 431 template<typename Path>
Chris@16 432 mapped_file::mapped_file(
Chris@16 433 const Path& path, BOOST_IOS::openmode mode,
Chris@16 434 size_type length, stream_offset offset )
Chris@16 435 { open(path, mode, length, offset); }
Chris@16 436
Chris@16 437 template<typename Path>
Chris@16 438 void mapped_file::open(const basic_mapped_file_params<Path>& p)
Chris@16 439 { delegate_.open_impl(p); }
Chris@16 440
Chris@16 441 template<typename Path>
Chris@16 442 void mapped_file::open(
Chris@16 443 const Path& path, mapmode flags,
Chris@16 444 size_type length, stream_offset offset )
Chris@16 445 {
Chris@16 446 param_type p(path);
Chris@16 447 p.flags = flags;
Chris@16 448 p.length = length;
Chris@16 449 p.offset = offset;
Chris@16 450 open(p);
Chris@16 451 }
Chris@16 452
Chris@16 453 template<typename Path>
Chris@16 454 void mapped_file::open(
Chris@16 455 const Path& path, BOOST_IOS::openmode mode,
Chris@16 456 size_type length, stream_offset offset )
Chris@16 457 {
Chris@16 458 param_type p(path);
Chris@16 459 p.mode = mode;
Chris@16 460 p.length = length;
Chris@16 461 p.offset = offset;
Chris@16 462 open(p);
Chris@16 463 }
Chris@16 464
Chris@16 465 inline char* mapped_file::data() const
Chris@16 466 { return (flags() != readonly) ? const_cast<char*>(delegate_.data()) : 0; }
Chris@16 467
Chris@16 468 //------------------Implementation of mapped_file_sink------------------------//
Chris@16 469
Chris@16 470 template<typename Path>
Chris@16 471 mapped_file_sink::mapped_file_sink(const basic_mapped_file_params<Path>& p)
Chris@16 472 { open(p); }
Chris@16 473
Chris@16 474 template<typename Path>
Chris@16 475 mapped_file_sink::mapped_file_sink(
Chris@16 476 const Path& path, size_type length,
Chris@16 477 boost::intmax_t offset, mapmode flags )
Chris@16 478 { open(path, length, offset, flags); }
Chris@16 479
Chris@16 480 template<typename Path>
Chris@16 481 void mapped_file_sink::open(const basic_mapped_file_params<Path>& p)
Chris@16 482 {
Chris@16 483 param_type params(p);
Chris@16 484 if (params.flags) {
Chris@16 485 if (params.flags & mapped_file::readonly)
Chris@16 486 boost::throw_exception(BOOST_IOSTREAMS_FAILURE("invalid flags"));
Chris@16 487 } else {
Chris@16 488 if (params.mode & BOOST_IOS::in)
Chris@16 489 boost::throw_exception(BOOST_IOSTREAMS_FAILURE("invalid mode"));
Chris@16 490 params.mode |= BOOST_IOS::out;
Chris@16 491 }
Chris@16 492 mapped_file::open(params);
Chris@16 493 }
Chris@16 494
Chris@16 495 template<typename Path>
Chris@16 496 void mapped_file_sink::open(
Chris@16 497 const Path& path, size_type length,
Chris@16 498 boost::intmax_t offset, mapmode flags )
Chris@16 499 {
Chris@16 500 param_type p(path);
Chris@16 501 p.flags = flags;
Chris@16 502 p.length = length;
Chris@16 503 p.offset = offset;
Chris@16 504 open(p);
Chris@16 505 }
Chris@16 506
Chris@16 507 //------------------Specialization of direct_impl-----------------------------//
Chris@16 508
Chris@16 509 template<>
Chris@16 510 struct operations<mapped_file_source>
Chris@16 511 : boost::iostreams::detail::close_impl<closable_tag>
Chris@16 512 {
Chris@16 513 static std::pair<char*, char*>
Chris@16 514 input_sequence(mapped_file_source& src)
Chris@16 515 {
Chris@16 516 return std::make_pair( const_cast<char*>(src.begin()),
Chris@16 517 const_cast<char*>(src.end()) );
Chris@16 518 }
Chris@16 519 };
Chris@16 520
Chris@16 521 template<>
Chris@16 522 struct operations<mapped_file>
Chris@16 523 : boost::iostreams::detail::close_impl<closable_tag>
Chris@16 524 {
Chris@16 525 static std::pair<char*, char*>
Chris@16 526 input_sequence(mapped_file& file)
Chris@16 527 {
Chris@16 528 return std::make_pair(file.begin(), file.end());
Chris@16 529 }
Chris@16 530 static std::pair<char*, char*>
Chris@16 531 output_sequence(mapped_file& file)
Chris@16 532 {
Chris@16 533 return std::make_pair(file.begin(), file.end());
Chris@16 534 }
Chris@16 535 };
Chris@16 536
Chris@16 537 template<>
Chris@16 538 struct operations<mapped_file_sink>
Chris@16 539 : boost::iostreams::detail::close_impl<closable_tag>
Chris@16 540 {
Chris@16 541 static std::pair<char*, char*>
Chris@16 542 output_sequence(mapped_file_sink& sink)
Chris@16 543 {
Chris@16 544 return std::make_pair(sink.begin(), sink.end());
Chris@16 545 }
Chris@16 546 };
Chris@16 547
Chris@16 548 //------------------Definition of mapmode operators---------------------------//
Chris@16 549
Chris@16 550 inline mapped_file::mapmode
Chris@16 551 operator|(mapped_file::mapmode a, mapped_file::mapmode b)
Chris@16 552 {
Chris@16 553 return static_cast<mapped_file::mapmode>
Chris@16 554 (static_cast<int>(a) | static_cast<int>(b));
Chris@16 555 }
Chris@16 556
Chris@16 557 inline mapped_file::mapmode
Chris@16 558 operator&(mapped_file::mapmode a, mapped_file::mapmode b)
Chris@16 559 {
Chris@16 560 return static_cast<mapped_file::mapmode>
Chris@16 561 (static_cast<int>(a) & static_cast<int>(b));
Chris@16 562 }
Chris@16 563
Chris@16 564 inline mapped_file::mapmode
Chris@16 565 operator^(mapped_file::mapmode a, mapped_file::mapmode b)
Chris@16 566 {
Chris@16 567 return static_cast<mapped_file::mapmode>
Chris@16 568 (static_cast<int>(a) ^ static_cast<int>(b));
Chris@16 569 }
Chris@16 570
Chris@16 571 inline mapped_file::mapmode
Chris@16 572 operator~(mapped_file::mapmode a)
Chris@16 573 {
Chris@16 574 return static_cast<mapped_file::mapmode>(~static_cast<int>(a));
Chris@16 575 }
Chris@16 576
Chris@16 577 inline mapped_file::mapmode
Chris@16 578 operator|=(mapped_file::mapmode& a, mapped_file::mapmode b)
Chris@16 579 {
Chris@16 580 return a = a | b;
Chris@16 581 }
Chris@16 582
Chris@16 583 inline mapped_file::mapmode
Chris@16 584 operator&=(mapped_file::mapmode& a, mapped_file::mapmode b)
Chris@16 585 {
Chris@16 586 return a = a & b;
Chris@16 587 }
Chris@16 588
Chris@16 589 inline mapped_file::mapmode
Chris@16 590 operator^=(mapped_file::mapmode& a, mapped_file::mapmode b)
Chris@16 591 {
Chris@16 592 return a = a ^ b;
Chris@16 593 }
Chris@16 594
Chris@16 595 } } // End namespaces iostreams, boost.
Chris@16 596
Chris@16 597 #include <boost/config/abi_suffix.hpp> // pops abi_suffix.hpp pragmas
Chris@16 598
Chris@16 599 #endif // #ifndef BOOST_IOSTREAMS_MAPPED_FILE_HPP_INCLUDED