STXXL  1.4-dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
fileperblock_file.h
Go to the documentation of this file.
1 /***************************************************************************
2  * include/stxxl/bits/io/fileperblock_file.h
3  *
4  * Part of the STXXL. See http://stxxl.sourceforge.net
5  *
6  * Copyright (C) 2008, 2009 Johannes Singler <[email protected]>
7  *
8  * Distributed under the Boost Software License, Version 1.0.
9  * (See accompanying file LICENSE_1_0.txt or copy at
10  * http://www.boost.org/LICENSE_1_0.txt)
11  **************************************************************************/
12 
13 #ifndef STXXL_IO_FILEPERBLOCK_FILE_HEADER
14 #define STXXL_IO_FILEPERBLOCK_FILE_HEADER
15 
16 #include <string>
18 
20 
21 //! \addtogroup fileimpl
22 //! \{
23 
24 //! Implementation of file based on other files, dynamically allocate one file per block.
25 //! Allows for dynamic disk space consumption.
26 template <class base_file_type>
28 {
29 private:
30  std::string filename_prefix;
31  int mode;
34  base_file_type lock_file;
35 
36 protected:
37  //! Constructs a file name for a given block.
38  std::string filename_for_block(offset_type offset);
39 
40 public:
41  //! Constructs file object.
42  //! param filename_prefix filename prefix, numbering will be appended to it
43  //! param mode open mode, see \c file::open_modes
45  const std::string& filename_prefix,
46  int mode,
47  int queue_id = DEFAULT_QUEUE,
48  int allocator_id = NO_ALLOCATOR,
49  unsigned int device_id = DEFAULT_DEVICE_ID);
50 
51  virtual ~fileperblock_file();
52 
53  virtual void serve(void* buffer, offset_type offset, size_type bytes,
55 
56  //! Changes the size of the file.
57  //! \param new_size value of the new file size
58  virtual void set_size(offset_type new_size) { current_size = new_size; }
59 
60  //! Returns size of the file.
61  //! \return file size in length
62  virtual offset_type size() { return current_size; }
63 
64  virtual void lock();
65 
66  //! Frees the specified region.
67  //! Actually deletes the corresponding file if the whole thing is deleted.
68  virtual void discard(offset_type offset, offset_type length);
69 
70  //! Rename the file corresponding to the offset such that it is out of reach for deleting.
71  virtual void export_files(offset_type offset, offset_type length, std::string filename);
72 
73  const char * io_type() const;
74 };
75 
76 //! \}
77 
79 
80 #endif // !STXXL_IO_FILEPERBLOCK_FILE_HEADER
virtual void set_size(offset_type new_size)
Changes the size of the file.
virtual offset_type size()
Returns size of the file.
request::size_type size_type
the size of a request
Definition: file.h:62
#define STXXL_BEGIN_NAMESPACE
Definition: namespace.h:16
Implementation of some file methods based on serving_request.
Implementation of file based on other files, dynamically allocate one file per block. Allows for dynamic disk space consumption.
static const size_t bytes
number of bytes in uint_pair
Definition: uint_types.h:96
request::offset_type offset_type
the offset of a request, also the size of the file
Definition: file.h:60
void discard(StreamAlgorithm &in)
Reads stream content and discards it. Useful where you do not need the processed stream anymore...
Definition: stream.h:640
#define STXXL_END_NAMESPACE
Definition: namespace.h:17