libRocket
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Stream.h
Go to the documentation of this file.
1 /*
2  * This source file is part of libRocket, the HTML/CSS Interface Middleware
3  *
4  * For the latest information, see http://www.librocket.com
5  *
6  * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
7  *
8  * Permission is hereby granted, free of charge, to any person obtaining a copy
9  * of this software and associated documentation files (the "Software"), to deal
10  * in the Software without restriction, including without limitation the rights
11  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12  * copies of the Software, and to permit persons to whom the Software is
13  * furnished to do so, subject to the following conditions:
14  *
15  * The above copyright notice and this permission notice shall be included in
16  * all copies or substantial portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24  * THE SOFTWARE.
25  *
26  */
27 
28 #ifndef ROCKETCORESTREAM_H
29 #define ROCKETCORESTREAM_H
30 
31 #include "Header.h"
32 #include "ReferenceCountable.h"
33 #include "Types.h"
34 #include "URL.h"
35 #include <list>
36 
37 namespace Rocket {
38 namespace Core {
39 
40 class StreamListener;
41 
48 {
49  public:
50  // Stream modes.
52  {
53  MODE_WRITE = 1 << 0,
54  MODE_APPEND = 1 << 1,
55  MODE_READ = 1 << 2,
56  MODE_ASYNC = 1 << 3,
57 
58  MODE_MASK = MODE_WRITE | MODE_APPEND | MODE_READ
59  };
60 
61  Stream();
62  virtual ~Stream();
63 
65  virtual void Close();
66 
68  int GetStreamMode() const;
69 
71  const URL& GetSourceURL() const;
72 
74  virtual bool IsEOS() const;
75 
77  virtual size_t Length() const = 0;
78 
80  virtual size_t Tell() const = 0;
82  virtual bool Seek(long offset, int origin) const = 0;
83 
85  virtual size_t Read(void* buffer, size_t bytes) const = 0;
87  virtual size_t Read(Stream* stream, size_t bytes) const;
89  virtual size_t Read(String& buffer, size_t bytes) const;
91  virtual size_t Peek(void* buffer, size_t bytes) const;
92 
94  virtual size_t Write(const void* buffer, size_t bytes) = 0;
96  virtual size_t Write(const Stream* stream, size_t bytes);
98  virtual size_t Write(const char* string);
100  virtual size_t Write(const String& string);
101 
103  virtual size_t Truncate(size_t bytes) = 0;
104 
106  virtual size_t PushFront(const void* buffer, size_t bytes);
108  virtual size_t PushBack(const void* buffer, size_t bytes);
109 
111  virtual size_t PopFront(size_t bytes);
113  virtual size_t PopBack(size_t bytes);
114 
118  virtual bool IsReadReady() = 0;
122  virtual bool IsWriteReady() = 0;
123 
124  protected:
125 
127  void SetStreamDetails(const URL& url, int stream_mode);
128 
130  virtual void OnReferenceDeactivate();
131 
132  private:
133  URL url;
134  int stream_mode;
135 };
136 
137 }
138 }
139 
140 #endif
#define ROCKETCORE_API
Definition: Header.h:73
Definition: Clipboard.h:33
StreamMode
Definition: Stream.h:51
Definition: ReferenceCountable.h:41
Definition: URL.h:42
Definition: StringBase.h:42
Definition: Stream.h:47