Commits

Ivan Andrianov committed 7b9f0d2

StreamInfo implicit sharing.

  • Participants
  • Parent commits 2d7e0a5

Comments (0)

Files changed (3)

src/codecs/streaminfo.cpp

  */
 
 #include "streaminfo.h"
-#include "streaminfo_p.h"
 
 namespace FFTranscoder
 {
 namespace Codecs
 {
 
+class StreamInfo::Data : public QSharedData
+{
+public:
+    uint bytesPerSamples;
+    uint sampleRate;
+    uint channelCount;
+};
+
 StreamInfo::StreamInfo() :
-        d(new StreamInfoPrivate())
+        d(new Data())
 {
-    d->bytesPerSamples = 0;
-    d->sampleRate = 0;
-    d->channelCount = 0;
+    setBytesPerSample(0);
+    setSampleRate(0);
+    setChannelCount(0);
 }
 
 StreamInfo::StreamInfo(uint bytesPerSample, uint sampleRate, uint channelCount) :
-        d(new StreamInfoPrivate())
+        d(new Data())
 {
-    d->bytesPerSamples = bytesPerSample;
-    d->sampleRate = sampleRate;
-    d->channelCount = channelCount;
+    setBytesPerSample(bytesPerSample);
+    setSampleRate(sampleRate);
+    setChannelCount(channelCount);
 }
 
 StreamInfo::StreamInfo(const StreamInfo & other) :
-        d(new StreamInfoPrivate(*other.d.data()))
+        d(other.d)
 {
 }
 
 StreamInfo & StreamInfo::operator=(const StreamInfo & other)
 {
-    d.reset(new StreamInfoPrivate(*other.d.data()));
+    d = other.d;
     return *this;
 }
 
     d->channelCount = channelCount;
 }
 
-StreamInfoPrivate::StreamInfoPrivate()
-{
 }
-
-StreamInfoPrivate::~StreamInfoPrivate()
-{
 }
-
-}
-}

src/codecs/streaminfo.h

 #ifndef FFTRANSCODER_CODECS_STREAMINFO_H
 #define FFTRANSCODER_CODECS_STREAMINFO_H
 
-#include <QScopedPointer>
+#include <QtCore/qshareddata.h>
 
 #include "global.h"
 
 namespace Codecs
 {
 
-class StreamInfoPrivate;
-
 /**
  * Meta data block of stream containing basic information, e.g. sample rate.
  */
     void setChannelCount(uint channelCount);
 
 private:
-    QScopedPointer<StreamInfoPrivate> d;
+    class Data;
+    QSharedDataPointer<Data> d;
 };
 
 }
 }
 
-#endif // FFTRANSCODER_CODECS_STREAMINFO_H
+#endif

src/codecs/streaminfo_p.h

-/*
- * Copyright (C) 2012 by Ivan Andrianov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-#ifndef FFTRANSCODER_CODECS_STREAMINFO_P_H
-#define FFTRANSCODER_CODECS_STREAMINFO_P_H
-
-#include <QtGlobal>
-
-namespace FFTranscoder
-{
-namespace Codecs
-{
-
-class StreamInfoPrivate
-{
-public:
-    StreamInfoPrivate();
-    ~StreamInfoPrivate();
-
-    uint bytesPerSamples;
-    uint sampleRate;
-    uint channelCount;
-};
-
-}
-}
-
-#endif // FFTRANSCODER_CODECS_STREAMINFO_P_H