Stxxl  1.3.2
boostfd_file.h
1 /***************************************************************************
2  * include/stxxl/bits/io/boostfd_file.h
3  *
4  * File implementation based on boost::iostreams::file_decriptor
5  *
6  * Part of the STXXL. See http://stxxl.sourceforge.net
7  *
8  * Copyright (C) 2006 Roman Dementiev <[email protected]>
9  * Copyright (C) 2008 Andreas Beckmann <[email protected]>
10  * Copyright (C) 2009 Johannes Singler <[email protected]>
11  *
12  * Distributed under the Boost Software License, Version 1.0.
13  * (See accompanying file LICENSE_1_0.txt or copy at
14  * http://www.boost.org/LICENSE_1_0.txt)
15  **************************************************************************/
16 
17 #ifndef STXXL_BOOSTFD_FILE_H_
18 #define STXXL_BOOSTFD_FILE_H_
19 
20 #ifndef STXXL_HAVE_BOOSTFD_FILE
21 #ifdef STXXL_BOOST_CONFIG // if boost is available
22  #define STXXL_HAVE_BOOSTFD_FILE 1
23 #else
24  #define STXXL_HAVE_BOOSTFD_FILE 0
25 #endif
26 #endif
27 
28 #if STXXL_HAVE_BOOSTFD_FILE
29 
30 #include <stxxl/bits/io/disk_queued_file.h>
31 #include <stxxl/bits/io/request.h>
32 
33 #include <boost/iostreams/device/file_descriptor.hpp>
34 
35 
36 __STXXL_BEGIN_NAMESPACE
37 
40 
42 class boostfd_file : public disk_queued_file
43 {
44  typedef boost::iostreams::file_descriptor fd_type;
45 
46 protected:
47  mutex fd_mutex; // sequentialize function calls involving file_des
48  fd_type file_des;
49  int mode_;
50  offset_type _size();
51 
52 public:
53  boostfd_file(const std::string & filename, int mode, int queue_id = DEFAULT_QUEUE, int allocator_id = NO_ALLOCATOR);
54  ~boostfd_file();
55  offset_type size();
56  void set_size(offset_type newsize);
57  void lock();
58  void serve(const request * req) throw (io_error);
59  const char * io_type() const;
60 };
61 
63 
64 __STXXL_END_NAMESPACE
65 
66 #endif // #if STXXL_HAVE_BOOSTFD_FILE
67 
68 #endif // !STXXL_BOOSTFD_FILE_H_
virtual void set_size(offset_type newsize)=0
Changes the size of the file.
virtual const char * io_type() const
Identifies the type of I/O implementation.
Definition: file.h:214
Request with basic properties like file and offset.
Definition: request.h:39
virtual offset_type size()=0
Returns size of the file.
Implementation of some file methods based on serving_request.
Definition: disk_queued_file.h:26
virtual void lock()=0
Locks file for reading and writing (acquires a lock in the file system)