1 | /* This file is part of the KDE project |
---|---|
2 | Copyright (C) 2007-2008 Matthias Kretz <kretz@kde.org> |
3 | |
4 | This library is free software; you can redistribute it and/or |
5 | modify it under the terms of the GNU Library General Public |
6 | License version 2 as published by the Free Software Foundation. |
7 | |
8 | This library is distributed in the hope that it will be useful, |
9 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
11 | Library General Public License for more details. |
12 | |
13 | You should have received a copy of the GNU Library General Public License |
14 | along with this library; see the file COPYING.LIB. If not, write to |
15 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
16 | Boston, MA 02110-1301, USA. |
17 | |
18 | */ |
19 | |
20 | #include "packet.h" |
21 | #include "packet_p.h" |
22 | #include "packetpool.h" |
23 | #include "packetpool_p.h" |
24 | |
25 | namespace Phonon |
26 | { |
27 | |
28 | Q_GLOBAL_STATIC(PacketPrivate, shared_null_packet) |
29 | |
30 | Packet::Packet() : d_ptr(shared_null_packet()) { d_ptr->ref.ref(); } |
31 | Packet::Packet(PacketPool &pool) : d_ptr(pool.d_ptr->acquirePacket().d_ptr) { d_ptr->ref.ref(); } |
32 | Packet::Packet(const Packet &rhs) : d_ptr(rhs.d_ptr) { d_ptr->ref.ref(); } |
33 | Packet::Packet(PacketPrivate &dd) : d_ptr(&dd) { d_ptr->ref.ref(); } |
34 | Packet &Packet::operator=(const Packet &rhs) |
35 | { |
36 | if (!d_ptr->ref.deref()) { |
37 | Q_ASSERT(d_ptr->m_pool); |
38 | d_ptr->m_pool->releasePacket(*this); |
39 | } |
40 | d_ptr = rhs.d_ptr; |
41 | d_ptr->ref.ref(); |
42 | return *this; |
43 | } |
44 | Packet::~Packet() |
45 | { |
46 | if (!d_ptr->ref.deref()) { |
47 | Q_ASSERT(d_ptr->m_pool); |
48 | d_ptr->m_pool->releasePacket(*this); |
49 | } |
50 | } |
51 | bool Packet::operator==(const Packet &rhs) const { return d_ptr == rhs.d_ptr; } |
52 | bool Packet::operator!=(const Packet &rhs) const { return d_ptr != rhs.d_ptr; } |
53 | bool Packet::isNull() const { return d_ptr->m_pool == nullptr; } |
54 | const char *Packet::data() const { return d_ptr->m_data; } |
55 | char *Packet::data() { return d_ptr->m_data; } |
56 | int Packet::size() const { return d_ptr->m_size; } |
57 | void Packet::setSize(int size) { d_ptr->m_size = size; } |
58 | int Packet::capacity() const { return d_ptr->m_pool ? d_ptr->m_pool->packetSize : 0; } |
59 | |
60 | } // namespace Phonon |
61 |