~ubuntu-branches/ubuntu/trusty/kvirc/trusty

« back to all changes in this revision

Viewing changes to src/kvirc/kvs/kvi_kvs_treenode_specialcommandforeach.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Kai Wasserbäch, Kai Wasserbäch, Raúl Sánchez Siles
  • Date: 2011-02-12 10:40:21 UTC
  • mfrom: (14.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20110212104021-5mh4f75jlku20mnt
The combined "Twisted Experiment" and "Nocturnal Raid" release.

[ Kai Wasserbäch ]
* Synced to upstream's SVN revision 5467.
* debian/rules:
  - Added .PHONY line.
  - Resurrect -DMANUAL_REVISION, got lost somewhere and we build SVN
    revisions again.
  - Replace "-DWITH_NO_EMBEDDED_CODE=YES" with "-DWANT_CRYPTOPP=YES".
  - Change the remaining -DWITH/-DWITHOUT to the new -DWANT syntax.
* debian/control:
  - Removed DMUA, I'm a DD now.
  - Changed my e-mail address.
  - Removed unneeded relationships (no upgrades over two releases are
    supported).
  - Fix Suggests for kvirc-dbg.
  - kvirc-data: Make the "Suggests: kvirc" a Recommends, doesn't make much
    sense to install the -data package without the program.
* debian/source/local-options: Added with "unapply-patches".
* debian/kvirc.lintian-overrides: Updated to work for 4.1.1.
* debian/patches/21_make_shared-mime-info_B-D_superfluous.patch: Updated.
* debian/kvirc-data.install: Added .notifyrc.

[ Raúl Sánchez Siles ]
* Stating the right version where kvirc-data break and replace should happen.
* Fixing link to license file.
* Added French and Portuguese man pages.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//=============================================================================
2
 
//
3
 
//   File : kvi_kvs_treenode_specialcommandforeach.cpp
4
 
//   Creation date : Fri 07 Nov 2003 11:48:11 by Szymon Stefanek
5
 
//
6
 
//   This file is part of the KVIrc IRC client distribution
7
 
//   Copyright (C) 2003-2008 Szymon Stefanek <pragma at kvirc dot net>
8
 
//
9
 
//   This program is FREE software. You can redistribute it and/or
10
 
//   modify it under the terms of the GNU General Public License
11
 
//   as published by the Free Software Foundation; either version 2
12
 
//   of the License, or (at your opinion) any later version.
13
 
//
14
 
//   This program is distributed in the HOPE that it will be USEFUL,
15
 
//   but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 
//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17
 
//   See the GNU General Public License for more details.
18
 
//
19
 
//   You should have received a copy of the GNU General Public License
20
 
//   along with this program. If not, write to the Free Software Foundation,
21
 
//   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22
 
//
23
 
//=============================================================================
24
 
 
25
 
#include "kvi_kvs_treenode_specialcommandforeach.h"
26
 
#include "kvi_kvs_treenode_data.h"
27
 
#include "kvi_kvs_treenode_datalist.h"
28
 
#include "kvi_kvs_treenode_instruction.h"
29
 
#include "kvi_kvs_treenode_switchlist.h"
30
 
#include "kvi_kvs_runtimecontext.h"
31
 
#include "kvi_locale.h"
32
 
 
33
 
KviKvsTreeNodeSpecialCommandForeach::KviKvsTreeNodeSpecialCommandForeach(const QChar * pLocation,KviKvsTreeNodeData * pVar,KviKvsTreeNodeDataList * pArgs,KviKvsTreeNodeInstruction * pLoop)
34
 
: KviKvsTreeNodeSpecialCommand(pLocation,"foreach")
35
 
{
36
 
        m_pIterationVariable = pVar;
37
 
        m_pIterationVariable->setParent(this);
38
 
        m_pIterationData = pArgs;
39
 
        m_pIterationData->setParent(this);
40
 
        m_pLoop = pLoop;
41
 
        m_pLoop->setParent(this);
42
 
}
43
 
 
44
 
KviKvsTreeNodeSpecialCommandForeach::~KviKvsTreeNodeSpecialCommandForeach()
45
 
{
46
 
        delete m_pIterationVariable;
47
 
        delete m_pIterationData;
48
 
        delete m_pLoop;
49
 
}
50
 
 
51
 
void KviKvsTreeNodeSpecialCommandForeach::contextDescription(QString &szBuffer)
52
 
{
53
 
        szBuffer = "Special Command \"foreach\"";
54
 
}
55
 
 
56
 
void KviKvsTreeNodeSpecialCommandForeach::dump(const char * prefix)
57
 
{
58
 
        qDebug("%s SpecialCommandForeach",prefix);
59
 
        QString tmp = prefix;
60
 
        tmp.append("  ");
61
 
        m_pIterationVariable->dump(tmp.toUtf8().data());
62
 
        m_pIterationData->dump(tmp.toUtf8().data());
63
 
        m_pLoop->dump(tmp.toUtf8().data());
64
 
}
65
 
 
66
 
bool KviKvsTreeNodeSpecialCommandForeach::execute(KviKvsRunTimeContext * c)
67
 
{
68
 
        KviKvsVariantList l;
69
 
        l.setAutoDelete(true);
70
 
        if(!m_pIterationData->evaluate(c,&l))
71
 
                return false;
72
 
 
73
 
        KviKvsSwitchList swl;
74
 
        if(m_pSwitches)
75
 
        {
76
 
                if(!(m_pSwitches->evaluate(c,&swl)))
77
 
                        return false;
78
 
        }
79
 
 
80
 
        bool bIncludeEmptyScalars = swl.find('a',"all") != 0;
81
 
 
82
 
        for(KviKvsVariant * pArg = l.first();pArg;pArg = l.next())
83
 
        {
84
 
                switch(pArg->type())
85
 
                {
86
 
                        case KviKvsVariantData::Array:
87
 
                        {
88
 
                                unsigned int uCnt = pArg->array()->size();
89
 
                                unsigned int idx = 0;
90
 
                                while(idx < uCnt)
91
 
                                {
92
 
                                        // we evaluate this each time (as it may actually be killed at each iteration)
93
 
                                        // FIXME: maybe some kind of reference counting or a observer pattern might be a bit more efficient here
94
 
                                        //        (but might be far less efficient everywhere else...)
95
 
                                        KviKvsRWEvaluationResult * v = m_pIterationVariable->evaluateReadWrite(c);
96
 
                                        if(!v)
97
 
                                                return false;
98
 
                                        KviKvsVariant * pOne = pArg->array()->at(idx);
99
 
                                        if(pOne)
100
 
                                                v->result()->copyFrom(*pOne);
101
 
                                        else
102
 
                                                v->result()->setNothing();
103
 
                                        delete v; // we're done with it for this iteration
104
 
 
105
 
                                        if(!m_pLoop->execute(c))
106
 
                                        {
107
 
                                                if(c->error())
108
 
                                                        return false;
109
 
 
110
 
                                                // break allowed!
111
 
                                                if(c->breakPending())
112
 
                                                {
113
 
                                                        c->handleBreak();
114
 
                                                        return true;
115
 
                                                }
116
 
 
117
 
                                                if(c->continuePending())
118
 
                                                {
119
 
                                                        c->handleContinue();
120
 
                                                        idx++;
121
 
                                                        continue;
122
 
                                                }
123
 
 
124
 
                                                return false; // propagate the false return value
125
 
                                        }
126
 
 
127
 
                                        idx++;
128
 
                                }
129
 
                        }
130
 
                        break;
131
 
                        case KviKvsVariantData::Hash:
132
 
                        {
133
 
                                KviKvsHashIterator it(*(pArg->hash()->dict()));
134
 
                                while(KviKvsVariant * pOne = it.current())
135
 
                                {
136
 
                                        // we evaluate this each time (as it may actually be killed at each iteration)
137
 
                                        // FIXME: maybe some kind of reference counting or a observer pattern might be a bit more efficient here
138
 
                                        //        (but might be far less efficient everywhere else...)
139
 
                                        KviKvsRWEvaluationResult * v = m_pIterationVariable->evaluateReadWrite(c);
140
 
                                        if(!v)
141
 
                                                return false;
142
 
                                        v->result()->copyFrom(*pOne);
143
 
                                        delete v; // we're done with it for this iteration
144
 
 
145
 
                                        if(!m_pLoop->execute(c))
146
 
                                        {
147
 
                                                if(c->error())
148
 
                                                        return false;
149
 
 
150
 
                                                // break allowed!
151
 
                                                if(c->breakPending())
152
 
                                                {
153
 
                                                        c->handleBreak();
154
 
                                                        return true;
155
 
                                                }
156
 
 
157
 
                                                if(c->continuePending())
158
 
                                                {
159
 
                                                        c->handleContinue();
160
 
                                                        ++it;
161
 
                                                        continue;
162
 
                                                }
163
 
 
164
 
                                                return false; // propagate the false return value
165
 
                                        }
166
 
 
167
 
                                        ++it;
168
 
                                }
169
 
                        }
170
 
                        break;
171
 
                        default:
172
 
                                if(bIncludeEmptyScalars || (!pArg->isNothing()))
173
 
                                {
174
 
                                        // we evaluate this each time (as it may actually be killed at each iteration)
175
 
                                        // FIXME: maybe some kind of reference counting or a observer pattern might be a bit more efficient here
176
 
                                        //        (but might be far less efficient everywhere else...)
177
 
                                        KviKvsRWEvaluationResult * v = m_pIterationVariable->evaluateReadWrite(c);
178
 
                                        if(!v)
179
 
                                                return false;
180
 
                                        v->result()->copyFrom(*pArg);
181
 
                                        delete v; // we're done with it for this iteration
182
 
 
183
 
                                        if(!m_pLoop->execute(c))
184
 
                                        {
185
 
                                                if(c->error())
186
 
                                                        return false;
187
 
 
188
 
                                                // break allowed!
189
 
                                                if(c->breakPending())
190
 
                                                {
191
 
                                                        c->handleBreak();
192
 
                                                        return true;
193
 
                                                }
194
 
 
195
 
                                                if(c->continuePending())
196
 
                                                {
197
 
                                                        c->handleContinue();
198
 
                                                        continue;
199
 
                                                }
200
 
 
201
 
                                                return false; // propagate the false return value
202
 
                                        }
203
 
                                }
204
 
                        break;
205
 
                }
206
 
        }
207
 
 
208
 
        return true;
209
 
}
210