CMS 3D CMS Logo

Storage.cc
Go to the documentation of this file.
3 #include <cassert>
4 
6 
8 
10 IOSize Storage::read(IOBuffer into, IOOffset pos) { return read(into.data(), into.size(), pos); }
11 
13  // FIXME: this is not thread safe! split into separate interface
14  // that a particular storage can choose to support or not? make
15  // sure that throw semantics are correct here!
16  // FIXME: use saveposition object in case exceptions are thrown?
17  IOOffset here = position();
18  position(pos);
19  n = read(into, n);
20  position(here);
21  return n;
22 }
23 
25  IOOffset here = position();
26  IOSize total = 0;
27  for (IOSize i = 0; i < n; ++i) {
28  try {
29  position(into[i].offset());
30  total += read(into[i].data(), into[i].size());
31  } catch (cms::Exception &) {
32  if (!total)
33  throw;
34  break;
35  }
36  }
37  position(here);
38  return total;
39 }
40 
42 IOSize Storage::write(IOBuffer from, IOOffset pos) { return write(from.data(), from.size(), pos); }
43 
44 IOSize Storage::write(const void *from, IOSize n, IOOffset pos) {
45  // FIXME: this is not thread safe! split into separate interface
46  // that a particular storage can choose to support or not? make
47  // sure that throw semantics are correct here!
48 
49  // FIXME: use saveposition object in case exceptions are thrown?
50  IOOffset here = position();
51  position(pos);
52  n = write(from, n);
53  position(here);
54  return n;
55 }
56 
58  IOSize total = 0;
59  for (IOSize i = 0; i < n; ++i) {
60  try {
61  total += write(from[i].data(), from[i].size(), from[i].offset());
62  } catch (cms::Exception &) {
63  if (!total)
64  throw;
65  break;
66  }
67  }
68  return total;
69 }
70 
73  Storage *self = const_cast<Storage *>(this);
74  return self->position(0, CURRENT);
75 }
76 
77 IOOffset Storage::size(void) const {
78  // FIXME: use saveposition object in case exceptions are thrown?
79  Storage *self = const_cast<Storage *>(this);
80  IOOffset here = position();
81  self->position(0, END);
83  self->position(here); // FIXME: VERIFY()?
84  return size;
85 }
86 
87 void Storage::rewind(void) { position(0); }
88 
90 bool Storage::prefetch(const IOPosBuffer * /* what */, IOSize /* n */) { return false; }
91 
93 void Storage::flush(void) {}
94 
95 void Storage::close(void) {}
96 
98 bool Storage::eof(void) const { return position() == size(); }
virtual IOSize readv(IOPosBuffer *into, IOSize buffers)
Definition: Storage.cc:24
void * data(void) const
Definition: IOBuffer.h:31
virtual IOSize write(const void *from, IOSize n, IOOffset pos)
Definition: Storage.cc:44
~Storage(void) override
Definition: Storage.cc:7
virtual void close(void)
Definition: Storage.cc:95
virtual IOOffset position(void) const
Definition: Storage.cc:72
virtual void flush(void)
Definition: Storage.cc:93
int read(void)
Definition: IOInput.cc:52
IOSize size(void) const
Definition: IOBuffer.h:34
virtual bool prefetch(const IOPosBuffer *what, IOSize n)
Definition: Storage.cc:90
virtual IOOffset size(void) const
Definition: Storage.cc:77
int64_t IOOffset
Definition: IOTypes.h:19
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
size_t IOSize
Definition: IOTypes.h:14
virtual bool eof(void) const
Definition: Storage.cc:98
virtual void rewind(void)
Definition: Storage.cc:87
Storage(void)
Definition: Storage.cc:5
virtual IOSize writev(const IOPosBuffer *from, IOSize buffers)
Definition: Storage.cc:57