@@ -55,24 +55,15 @@ using namespace edm::storage::IOFlags;
5555// ////////////////////////////////////////////////////////////////////
5656// ////////////////////////////////////////////////////////////////////
5757/* * Create a new file object without a file attached to it. */
58- File::File (void ) {
59- fd (EDM_IOFD_INVALID);
60- m_flags = 0 ;
61- }
58+ File::File () : m_channel(EDM_IOFD_INVALID) { m_flags = 0 ; }
6259
6360/* * Create a new file object from a file descriptor. The descriptor
6461 will be closed automatically when the file object is destructed
6562 if @a autoclose is @c true (the default). */
66- File::File (IOFD fd, bool autoclose /* = true */ ) {
67- this ->fd (fd);
68- m_flags = autoclose ? InternalAutoClose : 0 ;
69- }
63+ File::File (IOFD fd, bool autoclose /* = true */ ) : m_channel(fd) { m_flags = autoclose ? InternalAutoClose : 0 ; }
7064
7165/* * Internal function for copying file objects to retain the state flags. */
72- File::File (IOFD fd, unsigned flags) {
73- this ->fd (fd);
74- m_flags = flags;
75- }
66+ File::File (IOFD fd, unsigned flags) : m_channel(fd) { m_flags = flags; }
7667
7768/* * Create a new file object by calling #open() with the given arguments. */
7869File::File (const char *name, int flags /* = OpenRead*/ , int perms /* = 0666*/ ) { open (name, flags, perms); }
@@ -109,17 +100,17 @@ void File::setAutoClose(bool autoclose) {
109100 will not close its file descriptor on destruction, the original
110101 object (@c this) will. */
111102File *File::duplicate (bool copy) const {
112- File *dup = new File (fd (), copy ? m_flags : 0 );
103+ File *dup = new File (m_channel. fd (), copy ? m_flags : 0 );
113104 return copy ? this ->duplicate (dup) : dup;
114105}
115106
116107/* * Internal implementation of #duplicate() to actually duplicate the
117108 file handle into @a child. */
118109File *File::duplicate (File *child) const {
119- IOFD fd = this -> fd ();
110+ IOFD fd = m_channel. fd ();
120111 assert (fd != EDM_IOFD_INVALID);
121112 assert (child);
122- child->fd (sysduplicate (fd));
113+ child->m_channel . fd (sysduplicate (fd));
123114 child->m_flags = m_flags;
124115 return child;
125116}
@@ -164,27 +155,27 @@ void File::open(const char *name, int flags /*= OpenRead*/, int perms /*= 0666*/
164155 assert (flags & (OpenRead | OpenWrite));
165156
166157 // If I am already open, close the old file first.
167- if (fd () != EDM_IOFD_INVALID && (m_flags & InternalAutoClose))
158+ if (m_channel. fd () != EDM_IOFD_INVALID && (m_flags & InternalAutoClose))
168159 close ();
169160
170161 IOFD newfd = EDM_IOFD_INVALID;
171162 unsigned newflags = InternalAutoClose;
172163
173164 sysopen (name, flags, perms, newfd, newflags);
174165
175- fd (newfd);
166+ m_channel. fd (newfd);
176167 m_flags = newflags;
177168}
178169
179170void File::attach (IOFD fd) {
180- this -> fd (fd);
171+ m_channel. fd (fd);
181172 m_flags = 0 ;
182173}
183174
184175// ////////////////////////////////////////////////////////////////////
185176/* * Prefetch data for the file. */
186177bool File::prefetch (const IOPosBuffer *what, IOSize n) {
187- IOFD fd = this -> fd ();
178+ IOFD fd = m_channel. fd ();
188179 for (IOSize i = 0 ; i < n; ++i) {
189180#if F_RDADVISE
190181 radvisory info;
@@ -201,10 +192,10 @@ bool File::prefetch(const IOPosBuffer *what, IOSize n) {
201192}
202193
203194/* * Read from the file. */
204- IOSize File::read (void *into, IOSize n) { return IOChannel:: read (into, n); }
195+ IOSize File::read (void *into, IOSize n) { return m_channel. read (into, n); }
205196
206197/* * Read from the file. */
207- IOSize File::readv (IOBuffer *into, IOSize length) { return IOChannel:: readv (into, length); }
198+ IOSize File::readv (IOBuffer *into, IOSize length) { return m_channel. readv (into, length); }
208199
209200/* * Write to the file. */
210201IOSize File::write (const void *from, IOSize n) {
@@ -213,7 +204,7 @@ IOSize File::write(const void *from, IOSize n) {
213204 if (m_flags & OpenAppend)
214205 position (0 , END);
215206
216- IOSize s = IOChannel:: write (from, n);
207+ IOSize s = m_channel. write (from, n);
217208
218209 if (m_flags & OpenUnbuffered)
219210 // FIXME: Exception handling?
@@ -229,7 +220,7 @@ IOSize File::writev(const IOBuffer *from, IOSize length) {
229220 if (m_flags & OpenAppend)
230221 position (0 , END);
231222
232- IOSize s = IOChannel:: writev (from, length);
223+ IOSize s = m_channel. writev (from, length);
233224
234225 if (m_flags & OpenUnbuffered)
235226 // FIXME: Exception handling?
@@ -240,23 +231,23 @@ IOSize File::writev(const IOBuffer *from, IOSize length) {
240231
241232/* * Close the file. */
242233void File::close () {
243- IOFD fd = this -> fd ();
234+ IOFD fd = m_channel. fd ();
244235 assert (fd != EDM_IOFD_INVALID);
245236
246237 int error;
247238 if (!sysclose (fd, &error))
248239 throwStorageError (" FileCloseError" , " Calling File::close()" , " sysclose" , error);
249240
250241 m_flags &= ~InternalAutoClose;
251- this -> fd (EDM_IOFD_INVALID);
242+ m_channel. fd (EDM_IOFD_INVALID);
252243}
253244
254245/* * Close the file and ignore all errors. */
255246void File::abort () {
256- IOFD fd = this -> fd ();
247+ IOFD fd = m_channel. fd ();
257248 if (fd != EDM_IOFD_INVALID) {
258249 sysclose (fd);
259250 m_flags &= ~InternalAutoClose;
260- this -> fd (EDM_IOFD_INVALID);
251+ m_channel. fd (EDM_IOFD_INVALID);
261252 }
262253}
0 commit comments