STXXL  1.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
request.h
Go to the documentation of this file.
1 /***************************************************************************
2  * include/stxxl/bits/io/request.h
3  *
4  * Part of the STXXL. See http://stxxl.sourceforge.net
5  *
6  * Copyright (C) 2002 Roman Dementiev <[email protected]>
7  * Copyright (C) 2008 Andreas Beckmann <[email protected]>
8  * Copyright (C) 2013 Timo Bingmann <[email protected]>
9  *
10  * Distributed under the Boost Software License, Version 1.0.
11  * (See accompanying file LICENSE_1_0.txt or copy at
12  * http://www.boost.org/LICENSE_1_0.txt)
13  **************************************************************************/
14 
15 #ifndef STXXL_IO_REQUEST_HEADER
16 #define STXXL_IO_REQUEST_HEADER
17 
18 #include <cassert>
19 
20 #include <stxxl/bits/namespace.h>
26 #include <stxxl/bits/verbose.h>
27 
28 
30 
31 //! \addtogroup iolayer
32 //! \{
33 
34 #define BLOCK_ALIGN 4096
35 
36 class file;
37 
38 //! Request with basic properties like file and offset.
39 class request : virtual public request_interface, public atomic_counted_object
40 {
41 protected:
44 
45 protected:
47  void* buffer;
51 
52  void completed();
53 
54 public:
55  request(const completion_handler& on_compl,
56  file* file__,
57  void* buffer_,
58  offset_type offset_,
59  size_type bytes_,
60  request_type type_);
61 
62  virtual ~request();
63 
64  file * get_file() const { return file_; }
65  void * get_buffer() const { return buffer; }
66  offset_type get_offset() const { return offset; }
67  size_type get_size() const { return bytes; }
68  request_type get_type() const { return type; }
69 
70  void check_alignment() const;
71 
72  std::ostream & print(std::ostream& out) const;
73 
74  //! Inform the request object that an error occurred during the I/O
75  //! execution.
76  void error_occured(const char* msg)
77  {
78  error.reset(new stxxl::io_error(msg));
79  }
80 
81  //! Inform the request object that an error occurred during the I/O
82  //! execution.
83  void error_occured(const std::string& msg)
84  {
85  error.reset(new stxxl::io_error(msg));
86  }
87 
88  //! Rises an exception if there were error with the I/O.
89  void check_errors() throw (stxxl::io_error)
90  {
91  if (error.get())
92  throw *(error.get());
93  }
94 
95 protected:
96  void check_nref(bool after = false)
97  {
98  if (get_reference_count() < 2)
99  check_nref_failed(after);
100  }
101 
102 private:
103  void check_nref_failed(bool after);
104 };
105 
106 inline std::ostream& operator << (std::ostream& out, const request& req)
107 {
108  return req.print(out);
109 }
110 
111 //! A reference counting pointer for \c request.
113 
114 //! \}
115 
117 
118 #endif // !STXXL_IO_REQUEST_HEADER
119 // vim: et:ts=4:sw=4
friend std::ostream & operator<<(std::ostream &os, const uint_pair &a)
make a uint_pair outputtable via iostreams, using unsigned long long.
Definition: uint_types.h:231
static const int bytes
number of bytes in uint_pair
Definition: uint_types.h:99
offset_type offset
Definition: request.h:48
Completion handler class (Loki-style).
void error_occured(const std::string &msg)
Inform the request object that an error occurred during the I/O execution.
Definition: request.h:83
request_type type
Definition: request.h:50
counting_ptr< request > request_ptr
A reference counting pointer for request.
Definition: request.h:112
Provides reference counting abilities for use with counting_ptr with mutex locking.
Definition: counting_ptr.h:459
std::auto_ptr< _Tp > result
Definition: unique_ptr.h:31
offset_type get_offset() const
Definition: request.h:66
compat_unique_ptr< stxxl::io_error >::result error
Definition: request.h:43
Defines interface of file.
Definition: file.h:52
void check_nref(bool after=false)
Definition: request.h:96
size_type bytes
Definition: request.h:49
#define STXXL_BEGIN_NAMESPACE
Definition: namespace.h:16
completion_handler on_complete
Definition: request.h:42
size_type get_size() const
Definition: request.h:67
void check_errors()
Rises an exception if there were error with the I/O.
Definition: request.h:89
stxxl::internal_size_type size_type
Functional interface of a request.
file * file_
Definition: request.h:46
request_type get_type() const
Definition: request.h:68
std::ostream & print(std::ostream &out) const
Dumps properties of a request.
Definition: request.cpp:83
void * get_buffer() const
Definition: request.h:65
void * buffer
Definition: request.h:47
stxxl::external_size_type offset_type
Request with basic properties like file and offset.
Definition: request.h:39
void error_occured(const char *msg)
Inform the request object that an error occurred during the I/O execution.
Definition: request.h:76
file * get_file() const
Definition: request.h:64
#define STXXL_END_NAMESPACE
Definition: namespace.h:17