HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
NET_IODevice.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: NET_IODevice.h
7  *
8  * COMMENTS:
9  *
10  *
11  */
12 
13 #ifndef __NET_IODEVICE_H__
14 #define __NET_IODEVICE_H__
15 
16 #include "NET_API.h"
17 
18 #include <UT/UT_ErrorCode.h>
19 #include <UT/UT_StringHolder.h>
20 #include <UT/UT_NonCopyable.h>
21 #include <UT/UT_EnumHelper.h>
22 
23 template <typename T>
24 class UT_Array;
25 
26 /// Bit flags for how the device should behave.
27 /// NotOpen: Device is not open
28 /// ReadOnly: Device is open for reading
29 /// WriteOnly: Device is open for writing
30 /// ReadWrite: Device is open for reading and writing
31 /// Append: Device is in append mode so all data is written to EOF
32 /// Truncate: All earlier contents of the device are lost.
33 /// Unbuffered: Any buffer in the device is bypassed.
34 /// NewOnly: Fail if the the file already exists.
35 /// ExistingOnly: Fail if the file opened does not already exist.
37 {
38  NotOpen = 0,
39  ReadOnly = 1 << 0,
40  WriteOnly = 1 << 1,
42  Append = 1 << 2,
43  Truncate = 1 << 3,
44  Unbuffered = 1 << 4,
45  NewOnly = 1 << 5,
46  ExistingOnly = 1 << 6
47 };
49 
51 {
52 public:
54 
55  virtual ~NET_IODevice() = default;
57 
58  virtual bool atEnd() const { return pos() >= size();}
59  virtual exint bytesAvailable() const = 0;
60  virtual exint read(char* data, exint max_size) { return 0; }
61  virtual UT_Array<char> read(exint max_size);
62  virtual UT_Array<char> readAll();
63  virtual bool seek(exint pos) { return true; }
64  virtual void flush() {}
65  virtual exint size() const { return 0; }
66  virtual exint write(const char* data, exint max_size) { return 0; }
67  virtual exint write(const char* data) { return 0; }
68  virtual exint write(const UT_Array<char>& data) { return 0; }
69  virtual exint pos() const = 0;
70  virtual void close()
71  {
72  myMode = OpenMode::NotOpen;
73  myError = UT_ErrorCode();
74  }
75  virtual bool open(OpenMode mode)
76  {
77  if (mode == OpenMode::Append)
78  mode |= OpenMode::ReadWrite;
79  myMode = mode;
80  return true;
81  }
82  virtual bool isSequential() const { return false; }
83  const UT_ErrorCode& error() const { return myError; }
84 
85  const UT_StringHolder& mime() const { return myMime; }
86  void setMime(const UT_StringHolder& mime) { myMime = mime;}
87 
88  OpenMode mode() const { return myMode; }
89  bool isReadable() const
90  {
91  return static_cast<uint32>(myMode)
92  & static_cast<uint32>(OpenMode::ReadOnly);
93  }
94  bool isWriteable() const
95  {
96  return static_cast<uint32>(myMode)
97  & static_cast<uint32>(OpenMode::WriteOnly);
98  }
99  bool isOpen() const
100  {
101  return myMode != OpenMode::NotOpen;
102  }
103 
104 protected:
105  NET_IODevice() = default;
108  OpenMode myMode = OpenMode::NotOpen;
109 };
110 
111 #endif // __NET_IODEVICE_H__
UT_StringHolder myMime
Definition: NET_IODevice.h:107
virtual exint size() const
Definition: NET_IODevice.h:65
int64 exint
Definition: SYS_Types.h:125
#define NET_API
Definition: NET_API.h:9
const UT_ErrorCode & error() const
Definition: NET_IODevice.h:83
virtual void close()
Definition: NET_IODevice.h:70
virtual exint write(const UT_Array< char > &data)
Definition: NET_IODevice.h:68
virtual exint write(const char *data, exint max_size)
Definition: NET_IODevice.h:66
virtual bool seek(exint pos)
Definition: NET_IODevice.h:63
virtual bool isSequential() const
Definition: NET_IODevice.h:82
virtual bool open(OpenMode mode)
Definition: NET_IODevice.h:75
#define UT_NON_COPYABLE(CLASS)
Define deleted copy constructor and assignment operator inside a class.
virtual exint write(const char *data)
Definition: NET_IODevice.h:67
virtual void flush()
Definition: NET_IODevice.h:64
UT_ErrorCode myError
Definition: NET_IODevice.h:106
virtual exint read(char *data, exint max_size)
Definition: NET_IODevice.h:60
bool isWriteable() const
Definition: NET_IODevice.h:94
GLenum mode
Definition: glcorearb.h:99
UT_ENABLE_ENUM_BIT_FLAGS(NET_IODeviceOpenMode)
virtual bool atEnd() const
Definition: NET_IODevice.h:58
NET_IODeviceOpenMode
Definition: NET_IODevice.h:36
std::error_code UT_ErrorCode
Definition: UT_ErrorCode.h:20
GLsizeiptr size
Definition: glcorearb.h:664
bool isReadable() const
Definition: NET_IODevice.h:89
unsigned int uint32
Definition: SYS_Types.h:40
const UT_StringHolder & mime() const
Definition: NET_IODevice.h:85
Definition: format.h:1821
bool isOpen() const
Definition: NET_IODevice.h:99
OpenMode mode() const
Definition: NET_IODevice.h:88
void setMime(const UT_StringHolder &mime)
Definition: NET_IODevice.h:86