kwave  18.07.70
RecoveryBuffer.cpp
Go to the documentation of this file.
1 /*************************************************************************
2  RecoveryBuffer.cpp - buffer for reconstructed audio file data
3  -------------------
4  begin : Sun May 12 2002
5  copyright : (C) 2002 by Thomas Eschenbacher
6  email : Thomas.Eschenbacher@gmx.de
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #include "config.h"
19 #include <string.h>
20 
21 #include "libkwave/Utils.h"
22 #include "libkwave/memcpy.h"
23 
24 #include "RecoveryBuffer.h"
25 
26 //***************************************************************************
28  quint64 length,
29  char *buffer)
30  :Kwave::RecoverySource(offset, length),
31  m_buffer(buffer, Kwave::toUint(length))
32 {
33 }
34 
35 //***************************************************************************
36 qint64 Kwave::RecoveryBuffer::read(quint64 offset, char *data,
37  unsigned int bytes)
38 {
39  if (offset < this->offset()) return 0;
40  if (offset > end()) return 0;
41 
42  quint64 off = offset - this->offset();
43  qint64 len = length() - off;
44  if (bytes < len) len = bytes;
45  if (!len) return 0;
46 
47  const char *src = m_buffer.constData();
48  src += off;
49  MEMCPY(data, src, static_cast<size_t>(len));
50 
51  return len;
52 }
53 
54 //***************************************************************************
55 //***************************************************************************
virtual quint64 length() const
virtual quint64 end() const
Definition: App.h:33
virtual quint64 offset() const
virtual qint64 read(quint64 offset, char *data, unsigned int bytes) Q_DECL_OVERRIDE
#define MEMCPY
Definition: memcpy.h:37
unsigned int toUint(T x)
Definition: Utils.h:109
RecoveryBuffer(quint64 offset, quint64 length, char *buffer)