Nebula
Loading...
Searching...
No Matches
stream.h
Go to the documentation of this file.
1#pragma once
2#ifndef IO_STREAM_H
3#define IO_STREAM_H
4//------------------------------------------------------------------------------
19#include "core/refcounted.h"
20#include "io/uri.h"
22#include "io/mediatype.h"
23
24//------------------------------------------------------------------------------
25namespace IO
26{
28{
30public:
32 typedef int64_t Position; // DON'T DEFINE AS UNSIGNED!
33 typedef int64_t Offset; // DON'T DEFINE AS UNSIGNED!
34 typedef int64_t Size; // DON'T DEFINE AS UNSIGNED!
35
44
51
60 Stream();
62 virtual ~Stream();
64 void SetURI(const URI& u);
66 const URI& GetURI() const;
68 virtual bool CanRead() const;
70 virtual bool CanWrite() const;
72 virtual bool CanSeek() const;
74 virtual bool CanBeMapped() const;
76 virtual void SetSize(Size s);
78 virtual Size GetSize() const;
80 virtual Position GetPosition() const;
90 void SetMediaType(const MediaType& t);
92 const MediaType& GetMediaType() const;
94 virtual bool Open();
96 virtual void Close();
98 bool IsOpen() const;
100 virtual void Write(const void* ptr, Size numBytes);
102 virtual Size Read(void* ptr, Size numBytes);
104 virtual void Seek(Offset offset, SeekOrigin origin);
106 virtual void Flush();
108 virtual bool Eof() const;
110 virtual void* Map();
112 virtual void Unmap();
114 virtual void* MemoryMap();
116 virtual void MemoryUnmap();
118 bool IsMapped() const;
119
120protected:
124 bool isOpen;
127};
128
129} // namespace IO
130//------------------------------------------------------------------------------
131#endif
The common base class of Nebula.
Definition refcounted.h:38
Encapsulates a MIME conformant media type description (text/plain, image/jpg, etc....
Definition mediatype.h:19
Offers an abstract interface for read/write access to a sequence of bytes.
Definition stream.h:28
SeekOrigin
seek origins
Definition stream.h:54
@ Current
Definition stream.h:56
@ End
Definition stream.h:57
@ Begin
Definition stream.h:55
virtual Position GetPosition() const
get the current position of the read/write cursor
Definition stream.cc:126
int64_t Offset
Definition stream.h:33
void SetMediaType(const MediaType &t)
set optional media type of stream content
Definition stream.cc:182
virtual void * MemoryMap()
memory map stream to memory
Definition stream.cc:334
virtual void * Map()
map stream to memory
Definition stream.cc:308
const MediaType & GetMediaType() const
get optional media type
Definition stream.cc:191
virtual void Flush()
flush unsaved data
Definition stream.cc:279
virtual bool CanSeek() const
return true if the stream supports seeking
Definition stream.cc:83
bool isMapped
Definition stream.h:125
AccessPattern accessPattern
Definition stream.h:123
AccessMode GetAccessMode() const
get the access mode of the stream
Definition stream.cc:149
__DeclareClass(Stream)
int64_t Position
typedefs
Definition stream.h:32
void SetAccessMode(AccessMode m)
set the access mode of the stream (default is ReadAccess)
Definition stream.cc:138
virtual void SetSize(Size s)
set a new size for the stream
Definition stream.cc:106
bool IsOpen() const
return true if currently open
Definition stream.cc:225
virtual void Unmap()
unmap stream
Definition stream.cc:322
bool isOpen
Definition stream.h:124
Stream()
constructor
Definition stream.cc:18
virtual void MemoryUnmap()
unmap memory stream
Definition stream.cc:347
void SetAccessPattern(AccessPattern p)
set the prefered access pattern (default is Sequential)
Definition stream.cc:162
AccessPattern GetAccessPattern() const
get the prefered access pattern
Definition stream.cc:173
virtual bool CanWrite() const
return true if the stream supports writing
Definition stream.cc:73
int64_t Size
Definition stream.h:34
virtual void Seek(Offset offset, SeekOrigin origin)
seek in stream
Definition stream.cc:267
virtual bool Open()
open the stream
Definition stream.cc:202
bool IsMapped() const
return true if stream is currently mapped to memory
Definition stream.cc:360
MediaType mediaType
Definition stream.h:126
virtual bool CanRead() const
return true if the stream supports reading
Definition stream.cc:63
AccessMode accessMode
Definition stream.h:122
URI uri
Definition stream.h:121
virtual Size Read(void *ptr, Size numBytes)
directly read from the stream
Definition stream.cc:253
void SetURI(const URI &u)
set stream location as URI
Definition stream.cc:42
AccessMode
access modes
Definition stream.h:38
@ WriteAccess
Definition stream.h:40
@ ReadAccess
Definition stream.h:39
@ ReadWriteAccess
Definition stream.h:42
@ AppendAccess
Definition stream.h:41
virtual bool CanBeMapped() const
return true if the stream provides direct memory access
Definition stream.cc:94
virtual bool Eof() const
return true if end-of-stream reached
Definition stream.cc:290
const URI & GetURI() const
get stream URI
Definition stream.cc:53
virtual Size GetSize() const
get the size of the stream in bytes
Definition stream.cc:116
virtual void Close()
close the stream
Definition stream.cc:214
AccessPattern
access prefered pattern
Definition stream.h:47
@ Sequential
Definition stream.h:49
@ Random
Definition stream.h:48
virtual ~Stream()
destructor
Definition stream.cc:30
An URI object can split a Uniform Resource Identifier string into its components or build a string fr...
Definition uri.h:67
Instances of wrapped stream classes.
Definition orientation.cc:10
@ Write
Definition filewatcher.h:47