Thrill  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
fileperblock_file.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  * foxxll/io/fileperblock_file.hpp
3  *
4  * Part of FOXXLL. See http://foxxll.org
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 FOXXLL_IO_FILEPERBLOCK_FILE_HEADER
14 #define FOXXLL_IO_FILEPERBLOCK_FILE_HEADER
15 
16 #include <string>
17 
19 
20 namespace foxxll {
21 
22 //! \addtogroup foxxll_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  constexpr static bool debug = false;
31 
32 private:
34  int mode_;
37 
38 protected:
39  //! Constructs a file name for a given block.
41 
42 public:
43  //! Constructs file object.
44  //! param filename_prefix_ filename prefix, numbering will be appended to it
45  //! param mode_ open mode_, see \c file::open_modes
47  const std::string& filename_prefix,
48  int mode,
49  int queue_id = DEFAULT_QUEUE,
50  int allocator_id = NO_ALLOCATOR,
51  unsigned int device_id = DEFAULT_DEVICE_ID);
52 
53  virtual ~fileperblock_file();
54 
55  void serve(void* buffer, offset_type offset, size_type bytes,
56  request::read_or_write op) final;
57 
58  //! Changes the size of the file.
59  //! \param new_size value of the new file size
60  virtual void set_size(offset_type new_size) { current_size_ = new_size; }
61 
62  //! Returns size of the file.
63  //! \return file size in length
64  virtual offset_type size() { return current_size_; }
65 
66  virtual void lock();
67 
68  //! Frees the specified region.
69  //! Actually deletes the corresponding file if the whole thing is deleted.
70  virtual void discard(offset_type offset, offset_type length);
71 
72  //! Rename the file corresponding to the offset such that it is out of reach for deleting.
73  virtual void export_files(offset_type offset, offset_type length, std::string filename);
74 
75  const char * io_type() const final;
76 };
77 
78 //! \}
79 
80 } // namespace foxxll
81 
82 #endif // !FOXXLL_IO_FILEPERBLOCK_FILE_HEADER
83 
84 /**************************************************************************/
static const unsigned int DEFAULT_DEVICE_ID
Definition: file.hpp:92
request::offset_type offset_type
the offset of a request, also the size of the file
Definition: file.hpp:58
Implementation of some file methods based on serving_request.
const char * io_type() const final
request::size_type size_type
the size of a request
Definition: file.hpp:60
virtual void discard(offset_type offset, offset_type length)
tlx::counting_ptr< base_file_type > lock_file_
fileperblock_file(const std::string &filename_prefix, int mode, int queue_id=DEFAULT_QUEUE, int allocator_id=NO_ALLOCATOR, unsigned int device_id=DEFAULT_DEVICE_ID)
std::string filename_for_block(offset_type offset)
Constructs a file name for a given block.
static const int DEFAULT_QUEUE
Definition: file.hpp:89
std::basic_string< char, std::char_traits< char >, Allocator< char > > string
string with Manager tracking
Definition: allocator.hpp:220
virtual void lock()
Locks file for reading and writing (acquires a lock in the file system).
High-performance smart pointer used as a wrapping reference counting pointer.
static const size_t bytes
number of bytes in uint_pair
Definition: uint_types.hpp:75
static constexpr bool debug
virtual void set_size(offset_type new_size)
static const int NO_ALLOCATOR
Definition: file.hpp:91
void serve(void *buffer, offset_type offset, size_type bytes, request::read_or_write op) final
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.
virtual offset_type size()