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 exint size() const { return 0; }
65  virtual exint write(const char* data, exint max_size) { return 0; }
66  virtual exint write(const char* data) { return 0; }
67  virtual exint write(const UT_Array<char>& data) { return 0; }
68  virtual exint pos() const = 0;
69  virtual void close()
70  {
71  myMode = OpenMode::NotOpen;
72  myError = UT_ErrorCode();
73  }
74  virtual bool open(OpenMode mode)
75  {
76  myMode = mode;
77  return true;
78  }
79  virtual bool isSequential() const { return false; }
80  const UT_ErrorCode& error() const { return myError; }
81 
82  const UT_StringHolder& mime() const { return myMime; }
83  void setMime(const UT_StringHolder& mime) { myMime = mime;}
84 
85  OpenMode mode() const { return myMode; }
86  bool isReadable() const
87  {
88  return static_cast<uint32>(myMode)
89  & static_cast<uint32>(OpenMode::ReadOnly);
90  }
91  bool isWriteable() const
92  {
93  return static_cast<uint32>(myMode)
94  & static_cast<uint32>(OpenMode::WriteOnly);
95  }
96 
97 protected:
98  NET_IODevice() = default;
101  OpenMode myMode = OpenMode::NotOpen;
102 };
103 
104 #endif // __NET_IODEVICE_H__
UT_StringHolder myMime
Definition: NET_IODevice.h:100
virtual exint size() const
Definition: NET_IODevice.h:64
int64 exint
Definition: SYS_Types.h:125
#define NET_API
Definition: NET_API.h:9
const UT_ErrorCode & error() const
Definition: NET_IODevice.h:80
virtual void close()
Definition: NET_IODevice.h:69
virtual exint write(const UT_Array< char > &data)
Definition: NET_IODevice.h:67
virtual exint write(const char *data, exint max_size)
Definition: NET_IODevice.h:65
virtual bool seek(exint pos)
Definition: NET_IODevice.h:63
virtual bool isSequential() const
Definition: NET_IODevice.h:79
virtual bool open(OpenMode mode)
Definition: NET_IODevice.h:74
#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:66
UT_ErrorCode myError
Definition: NET_IODevice.h:99
virtual exint read(char *data, exint max_size)
Definition: NET_IODevice.h:60
bool isWriteable() const
Definition: NET_IODevice.h:91
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:86
unsigned int uint32
Definition: SYS_Types.h:40
const UT_StringHolder & mime() const
Definition: NET_IODevice.h:82
Definition: format.h:895
OpenMode mode() const
Definition: NET_IODevice.h:85
void setMime(const UT_StringHolder &mime)
Definition: NET_IODevice.h:83