CMS 3D CMS Logo

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