CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
File.h
Go to the documentation of this file.
1 #ifndef STORAGE_FACTORY_FILE_H
2 #define STORAGE_FACTORY_FILE_H
3 
7 #include <string>
8 
9 namespace edm::storage {
10 
12  class File : public Storage {
13  public:
14  File();
15  File(IOFD fd, bool autoclose = true);
16  File(const char *name, int flags = IOFlags::OpenRead, int perms = 0666);
17  File(const std::string &name, int flags = IOFlags::OpenRead, int perms = 0666);
18  ~File() override;
19  // implicit copy constructor
20  // implicit assignment operator
21 
22  virtual void create(const char *name, bool exclusive = false, int perms = 0666);
23  virtual void create(const std::string &name, bool exclusive = false, int perms = 0666);
24  virtual void open(const char *name, int flags = IOFlags::OpenRead, int perms = 0666);
25  virtual void open(const std::string &name, int flags = IOFlags::OpenRead, int perms = 0666);
26  virtual void attach(IOFD fd);
27 
28  using Storage::position;
29  using Storage::read;
30  using Storage::readv;
31  using Storage::write;
32  using Storage::writev;
33 
34  IOFD fd() const { return m_fd; }
35 
36  bool prefetch(const IOPosBuffer *what, IOSize n) override;
37  IOSize read(void *into, IOSize n) override;
38  IOSize read(void *into, IOSize n, IOOffset pos) override;
39  IOSize readv(IOBuffer *into, IOSize length) override;
40 
41  IOSize write(const void *from, IOSize n) override;
42  IOSize write(const void *from, IOSize n, IOOffset pos) override;
43  IOSize writev(const IOBuffer *from, IOSize length) override;
44 
45  IOOffset size() const override;
46  IOOffset position(IOOffset offset, Relative whence = SET) override;
47 
48  void resize(IOOffset size) override;
49 
50  void flush() override;
51  void close() override;
52  virtual void abort();
53 
54  virtual void setAutoClose(bool closeit);
55 
56  private:
57  enum { InternalAutoClose = 4096 }; //< Close on delete
58 
59  File(IOFD fd, unsigned flags);
60 
61  IOSize syswrite(const void *from, IOSize n);
62  IOSize syswritev(const IOBuffer *from, IOSize length);
63 
64  File *duplicate(bool copy) const;
65  File *duplicate(File *child) const;
66  static IOFD sysduplicate(IOFD fd);
67  static void sysopen(const char *name, int flags, int perms, IOFD &newfd, unsigned &newflags);
68  static bool sysclose(IOFD fd, int *error = nullptr);
69 
70  IOFD m_fd = EDM_IOFD_INVALID; /*< System file descriptor. */
71  unsigned m_flags;
72  };
73 } // namespace edm::storage
74 #endif // STORAGE_FACTORY_FILE_H
int64_t IOOffset
Definition: IOTypes.h:20
virtual IOSize readv(IOBuffer *into, IOSize buffers)
Definition: Storage.cc:146
void flush() override
Definition: UnixFile.cc:207
IOSize syswrite(const void *from, IOSize n)
Definition: UnixFile.cc:116
virtual void setAutoClose(bool closeit)
Definition: File.cc:90
IOFD fd() const
Definition: File.h:34
virtual void abort()
Definition: File.cc:240
~File() override
Definition: File.cc:79
IOSize syswritev(const IOBuffer *from, IOSize length)
Definition: UnixFile.cc:128
virtual IOOffset position() const
Definition: Storage.cc:504
virtual void open(const char *name, int flags=IOFlags::OpenRead, int perms=0666)
Definition: File.cc:148
bool prefetch(const IOPosBuffer *what, IOSize n) override
Definition: File.cc:177
void close() override
Definition: File.cc:227
unsigned m_flags
Definition: File.h:71
static void sysopen(const char *name, int flags, int perms, IOFD &newfd, unsigned &newflags)
Definition: UnixFile.cc:20
static IOFD sysduplicate(IOFD fd)
Definition: UnixFile.cc:12
IOSize write(const void *from, IOSize n) override
Definition: File.cc:195
size_t IOSize
Definition: IOTypes.h:15
IOSize readv(IOBuffer *into, IOSize length) override
Definition: UnixFile.cc:73
virtual IOSize writev(const IOBuffer *from, IOSize buffers)
Definition: Storage.cc:374
File * duplicate(bool copy) const
Definition: File.cc:102
IOOffset size() const override
Definition: UnixFile.cc:175
void resize(IOOffset size) override
Definition: UnixFile.cc:199
virtual void create(const char *name, bool exclusive=false, int perms=0666)
Definition: File.cc:123
IOSize write(unsigned char byte)
Definition: Storage.cc:329
constexpr int EDM_IOFD_INVALID
Definition: IOTypes.h:9
int IOFD
Definition: IOTypes.h:23
virtual void attach(IOFD fd)
Definition: File.cc:170
static bool sysclose(IOFD fd, int *error=nullptr)
Definition: UnixFile.cc:220
IOSize writev(const IOBuffer *from, IOSize length) override
Definition: File.cc:211