STXXL  1.4.0
 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 
19 
21 
22 //! \addtogroup fileimpl
23 //! \{
24 
25 //! Implementation of file based on other files, dynamically allocate one file per block.
26 //! Allows for dynamic disk space consumption.
27 template <class base_file_type>
29 {
30 private:
31  std::string filename_prefix;
32  int mode;
35  base_file_type lock_file;
36 
37 protected:
38  //! Constructs a file name for a given block.
39  std::string filename_for_block(offset_type offset);
40 
41 public:
42  //! Constructs file object.
43  //! param filename_prefix filename prefix, numbering will be appended to it
44  //! param mode open mode, see \c file::open_modes
46  const std::string& filename_prefix,
47  int mode,
48  int queue_id = DEFAULT_QUEUE,
49  int allocator_id = NO_ALLOCATOR);
50 
51  virtual ~fileperblock_file();
52 
53  virtual void serve(const request* req) throw (io_error);
54 
55  //! Changes the size of the file.
56  //! \param new_size value of the new file size
57  virtual void set_size(offset_type new_size) { current_size = new_size; }
58 
59  //! Returns size of the file.
60  //! \return file size in length
61  virtual offset_type size() { return current_size; }
62 
63  virtual void lock();
64 
65  //! Frees the specified region.
66  //! Actually deletes the corresponding file if the whole thing is deleted.
67  virtual void discard(offset_type offset, offset_type length);
68 
69  //! Rename the file corresponding to the offset such that it is out of reach for deleting.
70  virtual void export_files(offset_type offset, offset_type length, std::string filename);
71 
72  const char * io_type() const;
73 };
74 
75 //! \}
76 
78 
79 #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.
#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.
void discard(StreamAlgorithm_ &in)
Reads stream content and discards it. Useful where you do not need the processed stream anymore...
Definition: stream.h:606
request::offset_type offset_type
the offset of a request, also the size of the file
Definition: file.h:64
Request with basic properties like file and offset.
Definition: request.h:39
#define STXXL_END_NAMESPACE
Definition: namespace.h:17