Phonon

packet.cpp
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
25namespace Phonon
26{
27
28Q_GLOBAL_STATIC(PacketPrivate, shared_null_packet)
29
30Packet::Packet() : d_ptr(shared_null_packet()) { d_ptr->ref.ref(); }
31Packet::Packet(PacketPool &pool) : d_ptr(pool.d_ptr->acquirePacket().d_ptr) { d_ptr->ref.ref(); }
32Packet::Packet(const Packet &rhs) : d_ptr(rhs.d_ptr) { d_ptr->ref.ref(); }
33Packet::Packet(PacketPrivate &dd) : d_ptr(&dd) { d_ptr->ref.ref(); }
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}
45{
46 if (!d_ptr->ref.deref()) {
47 Q_ASSERT(d_ptr->m_pool);
48 d_ptr->m_pool->releasePacket(*this);
49 }
50}
51bool Packet::operator==(const Packet &rhs) const { return d_ptr == rhs.d_ptr; }
52bool Packet::operator!=(const Packet &rhs) const { return d_ptr != rhs.d_ptr; }
53bool Packet::isNull() const { return d_ptr->m_pool == nullptr; }
54const char *Packet::data() const { return d_ptr->m_data; }
55char *Packet::data() { return d_ptr->m_data; }
56int Packet::size() const { return d_ptr->m_size; }
57void Packet::setSize(int size) { d_ptr->m_size = size; }
58int Packet::capacity() const { return d_ptr->m_pool ? d_ptr->m_pool->packetSize : 0; }
59
60} // namespace Phonon
Class to preallocate memory.
Definition packetpool.h:38
Class to access memory preallocated by PacketPool.
Definition packet.h:39
int capacity() const
Returns the number of bytes that may be accessed.
Definition packet.cpp:58
int size() const
Returns the number of bytes that have a defined value.
Definition packet.cpp:56
bool isNull() const
Returns whether this object is a null packet.
Definition packet.cpp:53
const char * data() const
Returns a pointer to read the data this packet references.
Definition packet.cpp:54
Packet & operator=(const Packet &rhs)
Assigns a shared copy of the object.
Definition packet.cpp:34
bool operator!=(const Packet &rhs) const
Returns whether the packets reference different data.
Definition packet.cpp:52
~Packet()
Dereferences the packet data.
Definition packet.cpp:44
void setSize(int size)
Sets how many bytes in the data pointer have a defined value.
Definition packet.cpp:57
Packet()
Constructs a null packet.
Definition packet.cpp:30
bool operator==(const Packet &rhs) const
Returns whether the packets reference the same data.
Definition packet.cpp:51
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 24 2024 11:53:28 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.