kwave  18.07.70
SampleArray.h
Go to the documentation of this file.
1 /*************************************************************************
2  SampleArray.h - array with Kwave's internal sample_t
3  -------------------
4  begin : Sun Oct 07 2007
5  copyright : (C) 2007 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 #ifndef SAMPLE_ARRAY_H
19 #define SAMPLE_ARRAY_H
20 
21 #include "config.h"
22 
23 #include <QtGlobal>
24 #include <QSharedData>
25 #include <QSharedDataPointer>
26 
27 #include "libkwave/Sample.h"
28 
29 namespace Kwave
30 {
31 
36  class Q_DECL_EXPORT SampleArray
37  {
38  public:
39 
41  SampleArray();
42 
48  explicit SampleArray(unsigned int size);
49 
51  virtual ~SampleArray();
52 
54  inline const sample_t * constData() const
55  {
56  if (Q_UNLIKELY(!m_storage)) return Q_NULLPTR;
57  if (m_storage->m_raw_data) return m_storage->m_raw_data;
58  return m_storage->m_data;
59  }
60 
62  inline sample_t *data() /* __attribute__((deprecated)) <- for debug */
63  {
64  if (Q_UNLIKELY(!m_storage)) return Q_NULLPTR;
65  if (m_storage->m_raw_data) return m_storage->m_raw_data;
66  return m_storage->m_data;
67  }
68 
74  void setRawData(sample_t *data, unsigned int size);
75 
80  void resetRawData();
81 
83  void fill(sample_t value);
84 
90  sample_t & operator [] (unsigned int index);
91 
97  const sample_t & operator [] (unsigned int index) const;
98 
105  bool resize(unsigned int size) Q_REQUIRED_RESULT;
106 
111  unsigned int size() const;
112 
118  inline bool isEmpty() const { return (size() == 0); }
119 
120  private:
121 
122  class SampleStorage: public QSharedData {
123  public:
124 
126  SampleStorage();
127 
129  SampleStorage(const SampleStorage &other);
130 
132  virtual ~SampleStorage();
133 
139  void resize(unsigned int size);
140 
141  public:
143  unsigned int m_size;
144 
147 
150  };
151 
152  QSharedDataPointer<SampleStorage> m_storage;
153  };
154 }
155 
156 #endif /* SAMPLE_ARRAY_H */
157 
158 //***************************************************************************
159 //***************************************************************************
Definition: App.h:33
QSharedDataPointer< SampleStorage > m_storage
Definition: SampleArray.h:152
bool isEmpty() const
Definition: SampleArray.h:118
const sample_t * constData() const
Definition: SampleArray.h:54
sample_t * data()
Definition: SampleArray.h:62
qint32 sample_t
Definition: Sample.h:37