Stxxl  1.3.2
fileperblock_file.h
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_FILEPERBLOCK_FILE_HEADER
14 #define STXXL_FILEPERBLOCK_FILE_HEADER
15 
16 #include <string>
17 #include <stxxl/bits/io/disk_queued_file.h>
18 
19 
20 __STXXL_BEGIN_NAMESPACE
21 
24 
27 template <class base_file_type>
29 {
30 private:
31  std::string filename_prefix;
32  int mode;
33  unsigned_type current_size;
34  bool lock_file_created;
35  base_file_type lock_file;
36 
37 protected:
39  std::string filename_for_block(unsigned_type offset);
40 
41 public:
47  const std::string & filename_prefix,
48  int mode,
49  int queue_id = DEFAULT_QUEUE,
50  int allocator_id = NO_ALLOCATOR);
51 
52  virtual ~fileperblock_file();
53 
54  virtual void serve(const request * req) throw (io_error);
55 
58  virtual void set_size(offset_type new_size) { current_size = new_size; }
59 
62  virtual offset_type size() { return current_size; }
63 
64  virtual void lock();
65 
68  virtual void discard(offset_type offset, offset_type length);
69 
71  virtual void export_files(offset_type offset, offset_type length, std::string filename);
72 
73  const char * io_type() const;
74 };
75 
77 
78 __STXXL_END_NAMESPACE
79 
80 #endif // !STXXL_FILEPERBLOCK_FILE_HEADER
fileperblock_file(const std::string &filename_prefix, int mode, int queue_id=DEFAULT_QUEUE, int allocator_id=NO_ALLOCATOR)
constructs file object
Definition: fileperblock_file.cpp:28
virtual void discard(offset_type offset, offset_type length)
Frees the specified region. Actually deletes the corresponding file if the whole thing is deleted...
Definition: fileperblock_file.cpp:84
Request with basic properties like file and offset.
Definition: request.h:39
virtual void set_size(offset_type new_size)
Changes the size of the file.
Definition: fileperblock_file.h:58
std::string filename_for_block(unsigned_type offset)
Constructs a file name for a given block.
Definition: fileperblock_file.cpp:45
virtual offset_type size()
Returns size of the file.
Definition: fileperblock_file.h:62
virtual void export_files(offset_type offset, offset_type length, std::string filename)
Rename the file corresponding to the offset such that it is out of reach for deleting.
Definition: fileperblock_file.cpp:97
const char * io_type() const
Identifies the type of I/O implementation.
Definition: fileperblock_file.cpp:110
virtual void lock()
Locks file for reading and writing (acquires a lock in the file system)
Definition: fileperblock_file.cpp:67
Implementation of file based on other files, dynamically allocate one file per block. Allows for dynamic disk space consumption.
Definition: fileperblock_file.h:28
Implementation of some file methods based on serving_request.
Definition: disk_queued_file.h:26