BeFile.h
Go to the documentation of this file.
1 /*--------------------------------------------------------------------------------------+
2 |
3 | Supplied under applicable software license agreement.
4 |
5 | Copyright (c) 2018 Bentley Systems, Incorporated. All rights reserved.
6 |
7 +---------------------------------------------------------------------------------------*/
8 #pragma once
9 
11 
12 #include "Bentley.h"
13 #include <assert.h>
14 #include "BeFileName.h"
15 #include "ByteStream.h"
16 #include <stdio.h>
17 
18 #define CSS_UTF8 L", ccs=UTF-8"
19 
20 struct _FILETIME;
21 
23 
26 
28 enum class BeFileStatus
29  {
30  Success = SUCCESS,
37  ReadError,
39  };
40 
42 enum class BeFileAccess
43  {
44  Read = 1,
45  Write = 2,
46  ReadWrite = 3,
47  };
48 
50 enum class BeFileSharing
51  {
52  None = 0,
53  Read = 1,
54  Write = 2,
55  ReadWrite = 3,
56  };
57 
59 enum class BeFileAttributes
60  {
61  Normal = 0,
62  RandomIO = 1,
63  DeleteOnClose = 2,
64  };
65 
67 enum class BeFileSeekOrigin
68  {
69  Begin = 0,
70  Current = 1,
71  End = 2,
72  };
73 
74 /*=================================================================================**/
78 struct BeFile
79 {
80 private:
81  void* m_handle;
82  BeFileAccess m_mode;
83  BeFileSharing m_sh;
84  mutable BeFileStatus m_lastError;
85 
86  BeFile (BeFile const&) {assert(false);} // No!
87  BeFile& operator=(BeFile const&) {assert(false); return *this;} // No!
88 
89 public:
91  BeFileStatus SetLastError () const;
92 
93 public:
96 
98  ~BeFile() {Close();}
99 
102  BENTLEYDLL_EXPORT void Swap (BeFile& other);
103 
109  BENTLEYDLL_EXPORT BeFileStatus Create (wchar_t const* filename, bool createAlways = true, BeFileAttributes attributes = BeFileAttributes::Normal);
110 
118  BENTLEYDLL_EXPORT BeFileStatus Open (wchar_t const* filename, BeFileAccess mode, BeFileSharing shareOptions, BeFileAttributes attributes = BeFileAttributes::Normal, int numRetries = 0);
119 
125  BENTLEYDLL_EXPORT static FILE* Fsopen (wchar_t const* filename, wchar_t const* mode, BeFileSharing shareOptions);
126 
129 
131  BENTLEYDLL_EXPORT bool IsOpen () const;
132 
134  BeFileAccess GetAccess() const {return m_mode;}
135 
137  BeFileSharing GetShareMode() const {return m_sh;}
138 
140  void* GetHandle() const {return (void*)(intptr_t)m_handle;}
141 
143  BeFileStatus GetLastError() const {return m_lastError;}
144 
149  BENTLEYDLL_EXPORT BeFileStatus SetPointer (UInt64 position, BeFileSeekOrigin origin);
150 
154  BENTLEYDLL_EXPORT BeFileStatus GetPointer (UInt64& position);
155 
161  BENTLEYDLL_EXPORT BeFileStatus Read (void* buffer, UInt32* bytesRead, UInt32 numBytes);
162 
168  BENTLEYDLL_EXPORT BeFileStatus Write (UInt32* bytesWritten, void const* buffer, UInt32 numBytes);
169 
173 
177  BENTLEYDLL_EXPORT BeFileStatus GetSize (UInt64& length) const;
178 
182  BENTLEYDLL_EXPORT BeFileStatus SetSize (UInt64 length);
183 
188  BENTLEYDLL_EXPORT static BeFileStatus SetSize (FILE* file, long length);
189 
191  BENTLEYDLL_EXPORT BeFileStatus ReadEntireFile(bvector<Byte>& buffer);
192 
194  BENTLEYDLL_EXPORT BeFileStatus ReadEntireFile(ByteStream& bytestream);
195 
196 
202  BENTLEYDLL_EXPORT BeFileStatus GetTime (_FILETIME* ctime, _FILETIME* atime, _FILETIME* mtime) const;
203 
209  BENTLEYDLL_EXPORT BeFileStatus SetTime (_FILETIME const* ctime, _FILETIME const* atime, _FILETIME const* mtime);
210 };
211 
216 
221 
223 
BeFileStatus TranslateHResultToBeFileStatus(Long32 status)
Translates an HRESULT to a BeFileStatus value.
#define BENTLEYDLL_EXPORT
Definition: Bentley.h:249
An operation was attempted on a file that has already been closed.
Definition: Bentley.h:212
Delete this file when closed. Used for temporary files.
The default file attribute.
BeFileStatus GetLastError() const
Gets the status returned by the last operation that failed.
Definition: BeFile.h:143
There are too many files already open.
Open for write access.
void * GetHandle() const
Query the native file handle to the the open disk file. This is useful only if you want to pass the h...
Definition: BeFile.h:140
BeFileSharing
The possible file sharing modes for the Create and Open methods.
Definition: BeFile.h:50
long Long32
Definition: Bentley.r.h:145
Optimize the file for random input and output operations.
BeFileAccess
The possible file access values for the Open method.
Definition: BeFile.h:42
Unable to open the file because there is no file of the specified name.
The specified position is relative to the current read/write position of the file.
The file exists, but is already open in a sharing mode that does not allow this open.
The file exists, but is either already open or protected from an open of the type specified...
uint32_t UInt32
Definition: Bentley.r.h:128
bstdmap & operator=(const bstdmap &__rhs)
Definition: stdcxx/bstdmap.h:170
#define BEGIN_BENTLEY_NAMESPACE
Definition: Bentley.r.h:24
~BeFile()
Destroys a BeTextFile instance.
Definition: BeFile.h:98
BeFileSeekOrigin
Possible origin modes for the SetPosition method.
Definition: BeFile.h:67
Open for both read and write.
A stream of bytes in a resizeable buffer.
Definition: ByteStream.h:22
Long32 TranslateBeFileStatusToHresult(BeFileStatus status)
Translates a BeFileStatus value to an HRESULT.
Defines typedefs and constants that can be used across other namespaces. All Bentley-authored C++ sou...
Open for read access.
BeFileAccess GetAccess() const
Gets the access mode used to open the disk file.
Definition: BeFile.h:134
uint64_t UInt64
Definition: Bentley.r.h:131
BeFile provides a way to open a file and methods to access its contents and attributes.
Definition: BeFile.h:78
BeFileSharing GetShareMode() const
Gets the sharing option used to open the disk file.
Definition: BeFile.h:137
An error during read.
Curve's end point.
Definition: Bentley.h:210
BeFileAttributes
Possible file attributes for the Create and Open methods.
Definition: BeFile.h:59
#define END_BENTLEY_NAMESPACE
Definition: Bentley.r.h:25
BeFileStatus
The possible status returns for the BeFile methods.
Definition: BeFile.h:28

Copyright © 2017 Bentley Systems, Incorporated. All rights reserved.