Nuria Framework - Core
Core module of the NuriaProject Framework
 All Classes Functions Typedefs Enumerations Enumerator Groups
referencedevice.hpp
1 /* Copyright (c) 2014, The Nuria Project
2  * This software is provided 'as-is', without any express or implied
3  * warranty. In no event will the authors be held liable for any damages
4  * arising from the use of this software.
5  * Permission is granted to anyone to use this software for any purpose,
6  * including commercial applications, and to alter it and redistribute it
7  * freely, subject to the following restrictions:
8  * 1. The origin of this software must not be misrepresented; you must not
9  * claim that you wrote the original software. If you use this software
10  * in a product, an acknowledgment in the product documentation would be
11  * appreciated but is not required.
12  * 2. Altered source versions must be plainly marked as such, and must not be
13  * misrepresented as being the original software.
14  * 3. This notice may not be removed or altered from any source
15  * distribution.
16  */
17 
18 #ifndef NURIA_REFERENCEDEVICE_HPP
19 #define NURIA_REFERENCEDEVICE_HPP
20 
21 #include <QIODevice>
22 #include "essentials.hpp"
23 
24 namespace Nuria {
25 
26 class ReferenceDevicePrivate;
27 
49 class NURIA_CORE_EXPORT ReferenceDevice : public QIODevice {
50  Q_OBJECT
51 public:
52 
57  explicit ReferenceDevice (QIODevice *referencedDevice, QObject *parent = 0);
58 
60  ~ReferenceDevice () override;
61 
63  QIODevice *referencedDevice () const;
64 
66  qint64 rangeBegin () const;
67 
69  qint64 rangeEnd () const;
70 
86  void setRange (qint64 begin, qint64 end = -1);
87 
93  void extendRange (qint64 bytes);
94 
95  //
96  bool isSequential () const override;
97  bool open (OpenMode mode) override;
98  void close () override;
99  qint64 pos () const override;
100  qint64 size () const override;
101  bool seek (qint64 pos) override;
102  bool atEnd () const override;
103  bool reset () override;
104  qint64 bytesAvailable () const override;
105 
106 protected:
107  qint64 readData(char *data, qint64 maxlen);
108  qint64 writeData(const char *data, qint64 len);
109 
110 private:
111  void referencedDeviceDestroyed ();
112  void autoExtendRange ();
113 
114  ReferenceDevicePrivate *d_ptr;
115 
116 };
117 
118 }
119 
120 #endif // NURIA_REFERENCEDEVICE_HPP
Operates on a part of another QIODevice.
Definition: referencedevice.hpp:49