File indexing completed on 2024-09-29 06:39:20

0001 /* This file is part of KsirK.
0002  *   Copyright (C) 2005-2007 Gael de Chalendar (aka Kleag) <kleag@free.fr>
0003  *
0004  *   KsirK is free software; you can redistribute it and/or
0005  *   modify it under the terms of the GNU General Public
0006  *   License as published by the Free Software Foundation, either version 2
0007    of the License, or (at your option) any later version.
0008  *
0009  *   This program is distributed in the hope that it will be useful,
0010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
0011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0012  *   General Public License for more details.
0013  *
0014  *   You should have received a copy of the GNU General Public License
0015  *   along with this program; if not, write to the Free Software
0016  *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
0017  *   02110-1301, USA
0018  */
0019 
0020 #include "KMessageParts.h"
0021 
0022 #include <stdexcept>
0023 
0024 namespace Ksirk {
0025 
0026 namespace GameLogic {
0027 
0028 KMessageParts::KMessageParts()
0029 {
0030 }
0031 
0032 
0033 KMessageParts::~KMessageParts()
0034 {
0035 }
0036 
0037 KMessageParts& KMessageParts::operator<<(const QString& text)
0038 {
0039   m_strings.push_back(text);
0040   m_pixmaps.push_back(QPixmap());
0041   m_order.push_back(Text);
0042   return *this;
0043 }
0044 
0045 KMessageParts& KMessageParts::operator<<(const QPixmap& pixmap)
0046 {
0047   m_strings.push_back("");
0048   m_pixmaps.push_back(pixmap);
0049   m_order.push_back(Pixmap);
0050   return *this;
0051 }
0052 
0053 KMessageParts& KMessageParts::operator>>(QString& s)
0054 {
0055   if (nextIsText())
0056   {
0057     s = m_strings.front();
0058     m_strings.pop_front();
0059     m_pixmaps.pop_front();
0060     m_order.pop_front();
0061     return *this;
0062   }
0063   else
0064   {
0065     throw std::runtime_error("Next is not text");
0066   }
0067   return *this;
0068 }
0069 
0070 KMessageParts& KMessageParts::operator>>(QPixmap& p)
0071 {
0072   if (nextIsPixmap())
0073   {
0074     p = m_pixmaps.front();
0075     m_pixmaps.pop_front();
0076     m_strings.pop_front();
0077     m_order.pop_front();
0078     return *this;
0079   }
0080   else
0081   {
0082     throw std::runtime_error("Next is not pixmap");
0083   }
0084   return *this;
0085 }
0086 
0087 bool KMessageParts::nextIsText()
0088 {
0089   return (m_order.front() == Text);
0090 }
0091 
0092 bool KMessageParts::nextIsPixmap()
0093 {
0094   return (m_order.front() == Pixmap);
0095 }
0096 
0097 bool KMessageParts::empty()
0098 {
0099   return m_order.empty();
0100 }
0101 
0102 unsigned int KMessageParts::size()
0103 {
0104   return m_order.size();
0105 }
0106   
0107 void KMessageParts::clear()
0108 {
0109   m_strings.clear();
0110   m_pixmaps.clear();
0111   m_order.clear();
0112 }
0113 
0114 KMessageParts::iterator KMessageParts::begin()
0115 {
0116   iterator it;
0117   it.m_pixmaps_it = m_pixmaps.begin();
0118   it.m_strings_it = m_strings.begin();
0119   it.m_order_it =  m_order.begin();
0120   return it;
0121 }
0122 
0123 KMessageParts::iterator KMessageParts::end()
0124 {
0125   iterator it;
0126   it.m_pixmaps_it = m_pixmaps.end();
0127   it.m_strings_it = m_strings.end();
0128   it.m_order_it =  m_order.end();
0129   return it;
0130 }
0131 
0132 
0133 }
0134 
0135 }