File indexing completed on 2024-05-05 04:44:41
0001 /* This file is part of the KDE project 0002 Copyright (C) 2007-2008 Matthias Kretz <kretz@kde.org> 0003 0004 This library is free software; you can redistribute it and/or 0005 modify it under the terms of the GNU Library General Public 0006 License version 2 as published by the Free Software Foundation. 0007 0008 This library is distributed in the hope that it will be useful, 0009 but WITHOUT ANY WARRANTY; without even the implied warranty of 0010 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0011 Library General Public License for more details. 0012 0013 You should have received a copy of the GNU Library General Public License 0014 along with this library; see the file COPYING.LIB. If not, write to 0015 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0016 Boston, MA 02110-1301, USA. 0017 0018 */ 0019 0020 #ifndef PHONON_PACKETPOOL_H 0021 #define PHONON_PACKETPOOL_H 0022 0023 #include "export.h" 0024 0025 namespace Phonon 0026 { 0027 0028 class Packet; 0029 class PacketPoolPrivate; 0030 /** \class PacketPool packetpool.h phonon/PacketPool 0031 * \brief Class to preallocate memory. 0032 * 0033 * \note PacketPool and Packet are threadsafe. 0034 * 0035 * \author Matthias Kretz <kretz@kde.org> 0036 */ 0037 class PHONONEXPERIMENTAL_EXPORT PacketPool 0038 { 0039 Q_DECLARE_PRIVATE(PacketPool) 0040 friend class Packet; 0041 public: 0042 /** 0043 * Allocates \p numberOfPackets packets of \p packetSize bytes each. The memory can be 0044 * accessed through Packet objects. 0045 */ 0046 PacketPool(int packetSize, int numberOfPackets); 0047 /** 0048 * Copy constructor. Copying is fast since the class is explicitly shared. 0049 */ 0050 PacketPool(const PacketPool &); 0051 /** 0052 * Destructs this object. If this is the last reference to the pool the memory will be 0053 * freed. 0054 */ 0055 ~PacketPool(); 0056 /** 0057 * Assignmen operator. Copying is fast since the class is explicitly shared. 0058 */ 0059 PacketPool &operator=(const PacketPool &); 0060 0061 /** 0062 * Returns the packet size that was set in the constructor. 0063 */ 0064 int packetSize() const; 0065 /** 0066 * Returns the number of packets that was requested in the constructor. 0067 */ 0068 int poolSize() const; 0069 /** 0070 * Returns the number of packets that are still available for use. 0071 */ 0072 int unusedPackets() const; 0073 0074 private: 0075 PacketPoolPrivate *d_ptr; 0076 }; 0077 0078 } // namespace Phonon 0079 #endif // PHONON_PACKETPOOL_H