PLCnext API Documentation  21.0.0.35466
FileStream.hpp
1 //
3 // Copyright PHOENIX CONTACT Electronics GmbH
4 //
6 #pragma once
7 #include "Arp/System/Core/Arp.h"
8 #include "Arp/System/Commons/Io/Stream.hpp"
9 #include "Arp/System/Commons/Io/FileMode.hpp"
10 #include "Arp/System/Commons/Io/FileAccess.hpp"
11 
12 // forwards
13 namespace Arp { namespace System { namespace Ve
14 {
15 class IFileService;
16 }}}
17 
18 namespace Arp { namespace System { namespace Commons { namespace Io
19 {
20 
24 class FileStream : public Stream
25 {
26 public: // typedefs/usings
27  using IFileService = Arp::System::Ve::IFileService;
28 
29 public: // construction/destruction
30 
41  FileStream(const String& path, FileMode mode);
42 
53  FileStream(const String& path, FileMode mode, FileAccess access);
54 
56  FileStream(const FileStream& arg) = delete;
57 
59  FileStream& operator=(const FileStream& arg) = delete;
60 
62  virtual ~FileStream(void);
63 
64 public: // setter/getter operations
65 
68  boolean CanRead(void) override;
69 
72  boolean CanWrite(void) override;
73 
76  boolean CanSeek(void) override;
77 
81  size_t GetLength(void) override;
82 
87  void SetLength(size_t length) override;
88 
93  size_t GetPosition(void) override;
94 
99  void SetPosition(size_t position) override;
100 
101 
102 public: // operations
103 
106  void Flush(void) override;
107 
113  size_t Seek(size_t offset, SeekOrigin origin) override;
114 
128  size_t Read(byte* pBuffer, size_t bufferSize, size_t offset, size_t count) override;
129 
143  void Write(const byte* pBuffer, size_t bufferSize, size_t offset, size_t count) override;
144 
145 protected: // operations
146  void InternalDispose(void) override;
147 
148 private: // methods
149  void InternalConstructor(const String& path, FileMode mode, FileAccess access);
150 
151 private: // fields
152  // flags storing internal status bits
153  boolean canRead;
154  boolean canWrite;
155  boolean canSeek;
156  // containing path and filename including extension
157  String pathName;
158  // native FileStream object providing system dependent part of implementation
159  IFileService* pFileService;
160 };
161 
163 // inline methods of class FileStream
164 
165 inline FileStream::FileStream(const String& path, FileMode mode)
166  : canRead(false), canWrite(false), canSeek(false), pathName(""), pFileService(nullptr)
167 {
168  this->InternalConstructor(path, mode, FileAccess::ReadWrite);
169 }
170 
171 inline FileStream::FileStream(const String& path, FileMode mode, FileAccess access)
172  : canRead(false), canWrite(false), canSeek(false), pathName(""), pFileService(nullptr)
173 {
174  this->InternalConstructor(path, mode, access);
175 }
176 
177 }}}} // end of namespace Arp::System::Commons::Io
Specifies write access to the file. Data can be written to the file and the file pointer can be moved...
FileMode
Contains constants for specifying how the OS should open a file.
Definition: FileMode.hpp:23
FileStream(const String &path, FileMode mode)
Initializes a new instance of the FileStream class.
Definition: FileStream.hpp:165
Provides a generic view of a sequence of bytes.
Definition: Stream.hpp:16
Specifies read access to the file. Data can be read from the file and the file pointer can be moved...
Root namespace for the PLCnext API
Specifies read and write access to the file. Data can be written to the file and the file pointer can...
FileAccess
Contains constants for specifying the access you want for a file. You can have Read, Write or ReadWrite access.
Definition: FileAccess.hpp:17
Exposes a Stream around a file, supporting read and write operations.
Definition: FileStream.hpp:24
SeekOrigin
Provides seek reference points. To seek to the end of a stream, call stream.Seek(0, SeekOrigin.End).
Definition: SeekOrigin.hpp:19
System components used by the System, Device, Plc or Io domains.
unsigned char byte
The Arp character type.
Definition: PrimitiveTypes.hpp:23