File indexing completed on 2024-12-08 03:47:31
0001 /*************************************************************************** 0002 kstringvector.h - description 0003 ------------------- 0004 begin : Mon Sep 26 2005 0005 copyright : (C) 2005-2007 by Gael de Chalendar (aka Kleag) 0006 email : kleag@free.fr 0007 ***************************************************************************/ 0008 0009 /*************************************************************************** 0010 * * 0011 * This program is free software; you can redistribute it and/or modify * 0012 * it under the terms of the GNU General Public License as published by * 0013 * the Free Software Foundation; either either version 2 0014 of the License, or (at your option) any later version.of the License, or * 0015 * (at your option) any later version. * 0016 * * 0017 * You should have received a copy of the GNU General Public License 0018 * along with this program; if not, write to the Free Software 0019 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 0020 * 02110-1301, USA 0021 ***************************************************************************/ 0022 0023 #ifndef KSIRK_GAMELOGICKMESSAGEPARTS_H 0024 #define KSIRK_GAMELOGICKMESSAGEPARTS_H 0025 0026 #include <QList> 0027 #include <QString> 0028 #include <QPixmap> 0029 0030 namespace Ksirk { 0031 0032 namespace GameLogic { 0033 0034 /** 0035 * This class holds a serie of strings and pixmaps that have to be transferred 0036 * on the network and displayed in a specified order. 0037 * 0038 * It stores one collection of strings and one collection of pixmaps, each of 0039 * the same size. When an item at position i is a string the corresponding 0040 * pixmap is an empty one and conversely. 0041 * @author Gaƫl de Chalendar 0042 */ 0043 class KMessageParts 0044 { 0045 public: 0046 /** The possible types of the elements. */ 0047 enum ElemType {Text,Pixmap,StringId}; 0048 0049 /** Inner class to iterate on the message parts with the various standard 0050 * functions of a STL iterator */ 0051 class iterator 0052 { 0053 friend class KMessageParts; 0054 public: 0055 iterator& operator++(int) 0056 { 0057 m_pixmaps_it++; 0058 m_strings_it++; 0059 m_order_it++; 0060 return *this; 0061 } 0062 bool operator==(const iterator& it) const 0063 { 0064 return ( (m_pixmaps_it == it.m_pixmaps_it) 0065 && (m_strings_it == it.m_strings_it) 0066 && (m_order_it == it.m_order_it) ); 0067 } 0068 bool operator!=(const iterator& it) const 0069 { 0070 return !((*this)==it); 0071 } 0072 iterator() = default; 0073 iterator(const iterator& it) = default; 0074 iterator& operator=(const iterator& it) = default; 0075 QPixmap& curPix() {return *m_pixmaps_it;} 0076 QString& curStr() {return *m_strings_it;} 0077 bool curIsPix() { return (*m_order_it == Pixmap);} 0078 bool curIsStr() { return (*m_order_it == Text);} 0079 0080 private: 0081 QList<QPixmap>::iterator m_pixmaps_it; 0082 QList<QString>::iterator m_strings_it; 0083 QList<ElemType>::iterator m_order_it; 0084 }; 0085 friend class iterator; 0086 0087 /** Default constructor */ 0088 KMessageParts(); 0089 0090 /** Default destructor */ 0091 ~KMessageParts(); 0092 0093 //@{ 0094 /** push and pop operators for strings */ 0095 KMessageParts& operator<<(const QString& s); 0096 KMessageParts& operator>>(QString& s); 0097 //@} 0098 0099 //@{ 0100 /** push and pop operators for pixmaps */ 0101 KMessageParts& operator<<(const QPixmap& s); 0102 KMessageParts& operator>>(QPixmap& s); 0103 //@} 0104 0105 //@{ 0106 /** Testers of the type of the next item */ 0107 bool nextIsText(); 0108 bool nextIsPixmap(); 0109 //@} 0110 0111 /** 0112 * Tester of the parts collection emptiness 0113 * @return true if this collection is empty and false otherwise 0114 */ 0115 bool empty(); 0116 0117 /** 0118 * Tester of the parts collection size. 0119 * @return The size of the collection. 0120 */ 0121 unsigned int size(); 0122 0123 /** Removes all elements from this collection */ 0124 void clear(); 0125 0126 //@{ 0127 /** Returns iterators on the first and past-the-end elements of this 0128 * collection */ 0129 iterator begin(); 0130 iterator end(); 0131 //@} 0132 0133 private: 0134 QList<QPixmap> m_pixmaps; 0135 QList<QString> m_strings; 0136 QList<ElemType> m_order; 0137 }; 0138 0139 } // closing namespace GameLogic 0140 0141 } // closing namespace Ksirk 0142 0143 #endif