~ubuntu-branches/ubuntu/wily/libspiff/wily

« back to all changes in this revision

Viewing changes to src/SpiffData.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Adeodato Simó
  • Date: 2007-10-11 14:44:38 UTC
  • Revision ID: james.westby@ubuntu.com-20071011144438-zpl4gtvl3bf2ocnx
Tags: upstream-0.8.2
Import upstream version 0.8.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * libSpiff - XSPF playlist handling library
 
3
 *
 
4
 * Copyright (C) 2007, Sebastian Pipping / Xiph.Org Foundation
 
5
 * All rights reserved.
 
6
 *
 
7
 * Redistribution  and use in source and binary forms, with or without
 
8
 * modification,  are permitted provided that the following conditions
 
9
 * are met:
 
10
 *
 
11
 *     * Redistributions   of  source  code  must  retain  the   above
 
12
 *       copyright  notice, this list of conditions and the  following
 
13
 *       disclaimer.
 
14
 *
 
15
 *     * Redistributions  in  binary  form must  reproduce  the  above
 
16
 *       copyright  notice, this list of conditions and the  following
 
17
 *       disclaimer   in  the  documentation  and/or  other  materials
 
18
 *       provided with the distribution.
 
19
 *
 
20
 *     * Neither  the name of the Xiph.Org Foundation nor the names of
 
21
 *       its  contributors may be used to endorse or promote  products
 
22
 *       derived  from  this software without specific  prior  written
 
23
 *       permission.
 
24
 *
 
25
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 
26
 * "AS  IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT  NOT
 
27
 * LIMITED  TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND  FITNESS
 
28
 * FOR  A  PARTICULAR  PURPOSE ARE DISCLAIMED. IN NO EVENT  SHALL  THE
 
29
 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 
30
 * INCIDENTAL,    SPECIAL,   EXEMPLARY,   OR   CONSEQUENTIAL   DAMAGES
 
31
 * (INCLUDING,  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 
32
 * SERVICES;  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 
33
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 
34
 * STRICT  LIABILITY,  OR  TORT (INCLUDING  NEGLIGENCE  OR  OTHERWISE)
 
35
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 
36
 * OF THE POSSIBILITY OF SUCH DAMAGE.
 
37
 *
 
38
 * Sebastian Pipping, sping@xiph.org
 
39
 */
 
40
 
 
41
/**
 
42
 * @file SpiffData.cpp
 
43
 * Implementation of SpiffData.
 
44
 */
 
45
 
 
46
#include <spiff/SpiffData.h>
 
47
#include <spiff/SpiffExtension.h>
 
48
#include <spiff/SpiffToolbox.h>
 
49
using namespace Spiff::Toolbox;
 
50
using namespace std;
 
51
 
 
52
namespace Spiff {
 
53
 
 
54
 
 
55
 
 
56
/// @cond DOXYGEN_NON_API
 
57
 
 
58
/**
 
59
 * D object for SpiffData.
 
60
 */
 
61
class SpiffDataPrivate {
 
62
 
 
63
        friend class SpiffData;
 
64
 
 
65
        const XML_Char * image; ///< Image URI
 
66
        const XML_Char * info; ///< Info URI
 
67
        const XML_Char * annotation; ///< Annotation
 
68
        const XML_Char * creator; ///< Creator/artist
 
69
        const XML_Char * title; ///< Title
 
70
        bool ownImage; ///< Image memory ownership flag
 
71
        bool ownInfo; ///< Info memory ownership flag
 
72
        bool ownAnnotation; ///< Annotation memory ownership flag
 
73
        bool ownCreator; ///< Creator memory ownership flag
 
74
        bool ownTitle; ///< Title memory ownership flag
 
75
        std::deque<std::pair<std::pair<const XML_Char *, bool> *, std::pair<const XML_Char *, bool> *> *> * links; ///< List of link pairs
 
76
        std::deque<std::pair<std::pair<const XML_Char *, bool> *, std::pair<const XML_Char *, bool> *> *> * metas; ///< List of meta pairs
 
77
        std::deque<std::pair<const SpiffExtension *, bool> *> * extensions; ///< List of extensions
 
78
 
 
79
        /**
 
80
         * Creates a new D object.
 
81
         */
 
82
        SpiffDataPrivate()
 
83
                        : image(NULL),
 
84
                        info(NULL),
 
85
                        annotation(NULL),
 
86
                        creator(NULL),
 
87
                        title(NULL),
 
88
                        ownImage(false),
 
89
                        ownInfo(false),
 
90
                        ownAnnotation(false),
 
91
                        ownCreator(false),
 
92
                        ownTitle(false),
 
93
                        links(NULL),
 
94
                        metas(NULL),
 
95
                        extensions(NULL) {
 
96
 
 
97
        }
 
98
 
 
99
        /**
 
100
         * Copy constructor.
 
101
         *
 
102
         * @param source  Source to copy from
 
103
         */
 
104
        SpiffDataPrivate(const SpiffDataPrivate & source)
 
105
                        : image(source.ownImage
 
106
                                ? newAndCopy(source.image)
 
107
                                : source.image),
 
108
                        info(source.ownInfo
 
109
                                ? newAndCopy(source.info)
 
110
                                : source.info),
 
111
                        annotation(source.ownAnnotation
 
112
                                ? newAndCopy(source.annotation)
 
113
                                : source.annotation),
 
114
                        creator(source.ownCreator
 
115
                                ? newAndCopy(source.creator)
 
116
                                : source.creator),
 
117
                        title(source.ownTitle
 
118
                                ? newAndCopy(source.title)
 
119
                                : source.title),
 
120
                        ownImage(source.ownImage),
 
121
                        ownInfo(source.ownInfo),
 
122
                        ownAnnotation(source.ownAnnotation),
 
123
                        ownCreator(source.ownCreator),
 
124
                        ownTitle(source.ownTitle),
 
125
                        links(NULL),
 
126
                        metas(NULL),
 
127
                        extensions(NULL) {
 
128
                copyMetasOrLinks(this->links, source.links);
 
129
                copyMetasOrLinks(this->metas, source.metas);
 
130
                copyExtensions(this->extensions, source.extensions);
 
131
        }
 
132
 
 
133
        /**
 
134
         * Assignment operator.
 
135
         *
 
136
         * @param source  Source to copy from
 
137
         */
 
138
        SpiffDataPrivate & operator=(const SpiffDataPrivate & source) {
 
139
                if (this != &source) {
 
140
                        free();
 
141
                        copyIfOwned(this->title, this->ownTitle, source.title, source.ownTitle);
 
142
                        copyIfOwned(this->creator, this->ownCreator, source.creator, source.ownCreator);
 
143
                        copyIfOwned(this->annotation, this->ownAnnotation, source.annotation, source.ownAnnotation);
 
144
                        copyIfOwned(this->image, this->ownImage, source.image, source.ownImage);
 
145
                        copyIfOwned(this->info, this->ownInfo, source.info, source.ownInfo);
 
146
                        copyMetasOrLinks(this->links, source.links);
 
147
                        copyMetasOrLinks(this->metas, source.metas);
 
148
                        copyExtensions(this->extensions, source.extensions);
 
149
                }
 
150
                return *this;
 
151
        }
 
152
 
 
153
        /**
 
154
         * Destroys this D object.
 
155
         */
 
156
        ~SpiffDataPrivate() {
 
157
                free();
 
158
        }
 
159
 
 
160
        void free() {
 
161
                freeIfOwned(this->title, this->ownTitle);
 
162
                freeIfOwned(this->creator, this->ownCreator);
 
163
                freeIfOwned(this->annotation, this->ownAnnotation);
 
164
                freeIfOwned(this->image, this->ownImage);
 
165
                freeIfOwned(this->info, this->ownInfo);
 
166
                freeMetasOrLinks(this->links);
 
167
                freeMetasOrLinks(this->metas);
 
168
                freeExtensions(this->extensions);
 
169
        }
 
170
 
 
171
        static inline void freeMetasOrLinks(std::deque<std::pair<std::pair<
 
172
                        const XML_Char *, bool> *, std::pair<const XML_Char *,
 
173
                        bool> *> *> * & container) {
 
174
                if (container != NULL) {
 
175
                        deque<pair<pair<const XML_Char *, bool> *,
 
176
                                        pair<const XML_Char *, bool> *> *>
 
177
                                        ::const_iterator iter = container->begin();
 
178
                        while (iter != container->end()) {
 
179
                                pair<pair<const XML_Char *, bool> *,
 
180
                                                pair<const XML_Char *, bool> *>
 
181
                                                * const entry = *iter;
 
182
                                if (entry->first->second) {
 
183
                                        delete [] entry->first->first;
 
184
                                }
 
185
                                delete entry->first;
 
186
                                if (entry->second->second) {
 
187
                                        delete [] entry->second->first;
 
188
                                }
 
189
                                delete entry->second;
 
190
                                delete entry;
 
191
                                iter++;
 
192
                        }
 
193
                        container->clear();
 
194
                        delete container;
 
195
                        container = NULL;
 
196
                }
 
197
        }
 
198
 
 
199
        static inline void copyMetasOrLinks(std::deque<std::pair<
 
200
                        std::pair<const XML_Char *, bool> *,
 
201
                        std::pair<const XML_Char *, bool> *> *> * & dest,
 
202
                        std::deque<std::pair<
 
203
                        std::pair<const XML_Char *, bool> *,
 
204
                        std::pair<const XML_Char *, bool> *> *> * const & source) {
 
205
                dest = new deque<pair<
 
206
                                pair<const XML_Char *, bool> *,
 
207
                                pair<const XML_Char *, bool> *> *>();
 
208
 
 
209
                if (source != NULL) {
 
210
                        deque<pair<pair<const XML_Char *, bool> *,
 
211
                                        pair<const XML_Char *, bool> *> *>::const_iterator
 
212
                                        iter = source->begin();
 
213
                        while (iter != source->end()) {
 
214
                                const pair<pair<const XML_Char *, bool> *,
 
215
                                                pair<const XML_Char *, bool> *>
 
216
                                                * const entry = *iter;
 
217
 
 
218
                                const bool ownRel = entry->first->second;
 
219
                                const bool ownContent = entry->second->second;
 
220
                                const XML_Char * const rel = ownRel
 
221
                                                ? entry->first->first
 
222
                                                : Toolbox::newAndCopy(entry->first->first);
 
223
                                const XML_Char * const content = ownContent
 
224
                                                ? entry->second->first
 
225
                                                : Toolbox::newAndCopy(entry->second->first);
 
226
 
 
227
                                SpiffData::appendHelper(dest, rel, ownRel,
 
228
                                                content, ownContent);
 
229
                                iter++;
 
230
                        }
 
231
                }
 
232
        }
 
233
 
 
234
        static inline void freeExtensions(std::deque<std::pair<
 
235
                        const SpiffExtension *, bool> *> * & container) {
 
236
                if (container != NULL) {
 
237
                        deque<pair<const SpiffExtension *, bool> *>::const_iterator
 
238
                                        iter = container->begin();
 
239
                        while (iter != container->end()) {
 
240
                                pair<const SpiffExtension *, bool>
 
241
                                                * const entry = *iter;
 
242
                                if (entry->second) {
 
243
                                        delete entry->first;
 
244
                                }
 
245
                                delete entry;
 
246
                                iter++;
 
247
                        }
 
248
                        container->clear();
 
249
                        delete container;
 
250
                        container = NULL;
 
251
                }
 
252
        }
 
253
 
 
254
        static inline void copyExtensions(std::deque<
 
255
                        std::pair<const SpiffExtension *, bool> *> * & dest,
 
256
                        std::deque<
 
257
                        std::pair<const SpiffExtension *, bool> *> * const & source) {
 
258
                dest = new deque<pair<const SpiffExtension *, bool> *>();
 
259
 
 
260
                if (source != NULL) {
 
261
                        deque<pair<const SpiffExtension *, bool> *>::const_iterator
 
262
                                        iter = source->begin();
 
263
                        while (iter != source->end()) {
 
264
                                const pair<const SpiffExtension *, bool>
 
265
                                                * const entry = *iter;
 
266
 
 
267
                                const bool own = entry->second;
 
268
                                const SpiffExtension * const extension = own
 
269
                                                ? entry->first->clone()
 
270
                                                : entry->first;
 
271
                                SpiffData::appendHelper(dest, extension, own);
 
272
 
 
273
                                iter++;
 
274
                        }
 
275
                }
 
276
        }
 
277
 
 
278
};
 
279
 
 
280
/// @endcond
 
281
 
 
282
 
 
283
 
 
284
SpiffData::SpiffData() : d(new SpiffDataPrivate()) {
 
285
        // NOOP
 
286
}
 
287
 
 
288
 
 
289
 
 
290
SpiffData::SpiffData(const SpiffData & source)
 
291
                : d(new SpiffDataPrivate(*(source.d))) {
 
292
        // NOOP
 
293
}
 
294
 
 
295
 
 
296
 
 
297
SpiffData & SpiffData::operator=(const SpiffData & source) {
 
298
        if (this != &source) {
 
299
                *(this->d) = *(source.d);
 
300
        }
 
301
        return *this;
 
302
}
 
303
 
 
304
 
 
305
 
 
306
SpiffData::~SpiffData() {
 
307
        delete this->d;
 
308
}
 
309
 
 
310
 
 
311
 
 
312
void SpiffData::giveAnnotation(const XML_Char * annotation, bool copy) {
 
313
        Toolbox::deleteNewAndCopy(this->d->annotation, this->d->ownAnnotation,
 
314
                        annotation, copy);
 
315
}
 
316
 
 
317
 
 
318
 
 
319
void SpiffData::giveCreator(const XML_Char * creator, bool copy) {
 
320
        Toolbox::deleteNewAndCopy(this->d->creator, this->d->ownCreator,
 
321
                        creator, copy);
 
322
}
 
323
 
 
324
 
 
325
 
 
326
void SpiffData::giveInfo(const XML_Char * info, bool copy) {
 
327
        Toolbox::deleteNewAndCopy(this->d->info, this->d->ownInfo, info, copy);
 
328
}
 
329
 
 
330
 
 
331
 
 
332
void SpiffData::giveImage(const XML_Char * image, bool copy) {
 
333
        Toolbox::deleteNewAndCopy(this->d->image, this->d->ownImage, image, copy);
 
334
}
 
335
 
 
336
 
 
337
 
 
338
void SpiffData::giveTitle(const XML_Char * title, bool copy) {
 
339
        Toolbox::deleteNewAndCopy(this->d->title, this->d->ownTitle, title, copy);
 
340
}
 
341
 
 
342
 
 
343
 
 
344
void SpiffData::giveAppendLink(const XML_Char * rel, bool copyRel, const XML_Char * content, bool copyContent) {
 
345
        appendHelper(this->d->links, copyRel ? Toolbox::newAndCopy(rel) : rel, true,
 
346
                        copyContent ? Toolbox::newAndCopy(content) : content, true);
 
347
}
 
348
 
 
349
 
 
350
 
 
351
void SpiffData::giveAppendMeta(const XML_Char * rel, bool copyRel, const XML_Char * content, bool copyContent) {
 
352
        appendHelper(this->d->metas, copyRel ? Toolbox::newAndCopy(rel) : rel, true,
 
353
                        copyContent ? Toolbox::newAndCopy(content) : content, true);
 
354
}
 
355
 
 
356
 
 
357
 
 
358
void SpiffData::giveAppendExtension(const SpiffExtension * extension, bool copy) {
 
359
        appendHelper(this->d->extensions,
 
360
                        copy
 
361
                                ? extension->clone()
 
362
                                : extension,
 
363
                        true);
 
364
}
 
365
 
 
366
 
 
367
 
 
368
void SpiffData::lendAnnotation(const XML_Char * annotation) {
 
369
        Toolbox::deleteNewAndCopy(this->d->annotation, this->d->ownAnnotation,
 
370
                        annotation, false);
 
371
}
 
372
 
 
373
 
 
374
 
 
375
void SpiffData::lendCreator(const XML_Char * creator) {
 
376
        Toolbox::deleteNewAndCopy(this->d->creator, this->d->ownCreator,
 
377
                        creator, false);
 
378
}
 
379
 
 
380
 
 
381
 
 
382
void SpiffData::lendInfo(const XML_Char * info) {
 
383
        Toolbox::deleteNewAndCopy(this->d->info, this->d->ownInfo, info, false);
 
384
}
 
385
 
 
386
 
 
387
 
 
388
void SpiffData::lendImage(const XML_Char * image) {
 
389
        Toolbox::deleteNewAndCopy(this->d->image, this->d->ownImage, image, false);
 
390
}
 
391
 
 
392
 
 
393
 
 
394
void SpiffData::lendTitle(const XML_Char * title) {
 
395
        Toolbox::deleteNewAndCopy(this->d->title, this->d->ownTitle, title, false);
 
396
}
 
397
 
 
398
 
 
399
 
 
400
void SpiffData::lendAppendLink(const XML_Char * rel, const XML_Char * content) {
 
401
        appendHelper(this->d->links, rel, false, content, false);
 
402
}
 
403
 
 
404
 
 
405
 
 
406
void SpiffData::lendAppendMeta(const XML_Char * rel, const XML_Char * content) {
 
407
        appendHelper(this->d->metas, rel, false, content, false);
 
408
}
 
409
 
 
410
 
 
411
 
 
412
void SpiffData::lendAppendExtension(SpiffExtension * extension) {
 
413
        appendHelper(this->d->extensions, extension, false);
 
414
}
 
415
 
 
416
 
 
417
 
 
418
XML_Char * SpiffData::stealTitle() {
 
419
        return stealHelper(this->d->title, this->d->ownTitle);
 
420
}
 
421
 
 
422
 
 
423
 
 
424
XML_Char * SpiffData::stealAnnotation() {
 
425
        return stealHelper(this->d->annotation, this->d->ownAnnotation);
 
426
}
 
427
 
 
428
 
 
429
 
 
430
XML_Char * SpiffData::stealCreator() {
 
431
        return stealHelper(this->d->creator, this->d->ownCreator);
 
432
}
 
433
 
 
434
 
 
435
 
 
436
XML_Char * SpiffData::stealInfo() {
 
437
        return stealHelper(this->d->info, this->d->ownInfo);
 
438
}
 
439
 
 
440
 
 
441
 
 
442
XML_Char * SpiffData::stealImage() {
 
443
        return stealHelper(this->d->image, this->d->ownImage);
 
444
}
 
445
 
 
446
 
 
447
 
 
448
pair<XML_Char *, XML_Char *> * SpiffData::stealFirstMeta() {
 
449
        return stealFirstHelper(this->d->metas);
 
450
}
 
451
 
 
452
 
 
453
 
 
454
pair<XML_Char *, XML_Char *> * SpiffData::stealFirstLink() {
 
455
        return stealFirstHelper(this->d->links);
 
456
}
 
457
 
 
458
 
 
459
 
 
460
SpiffExtension * SpiffData::stealFirstExtension() {
 
461
        return stealFirstHelper(this->d->extensions);
 
462
}
 
463
 
 
464
 
 
465
 
 
466
const XML_Char * SpiffData::getImage() const {
 
467
        return this->d->image;
 
468
}
 
469
 
 
470
 
 
471
 
 
472
const XML_Char * SpiffData::getInfo() const {
 
473
        return this->d->info;
 
474
}
 
475
 
 
476
 
 
477
 
 
478
const XML_Char * SpiffData::getAnnotation() const {
 
479
        return this->d->annotation;
 
480
}
 
481
 
 
482
 
 
483
 
 
484
const XML_Char * SpiffData::getCreator() const {
 
485
        return this->d->creator;
 
486
}
 
487
 
 
488
 
 
489
 
 
490
const XML_Char * SpiffData::getTitle() const {
 
491
        return this->d->title;
 
492
}
 
493
 
 
494
 
 
495
 
 
496
pair<const XML_Char *, const XML_Char *> * SpiffData::getLink(int index) const {
 
497
        return getHelper(this->d->links, index);
 
498
}
 
499
 
 
500
 
 
501
 
 
502
pair<const XML_Char *, const XML_Char *> * SpiffData::getMeta(int index) const {
 
503
        return getHelper(this->d->metas, index);
 
504
}
 
505
 
 
506
 
 
507
const SpiffExtension * SpiffData::getExtension(int index) const {
 
508
        return getHelper(this->d->extensions, index);
 
509
}
 
510
 
 
511
 
 
512
 
 
513
int SpiffData::getLinkCount() const {
 
514
        return (this->d->links == NULL) ? 0 : static_cast<int>(this->d->links->size());
 
515
}
 
516
 
 
517
 
 
518
 
 
519
int SpiffData::getMetaCount() const {
 
520
        return (this->d->metas == NULL) ? 0 : static_cast<int>(this->d->metas->size());
 
521
}
 
522
 
 
523
 
 
524
 
 
525
int SpiffData::getExtensionCount() const {
 
526
        return (this->d->extensions == NULL) ? 0 : static_cast<int>(this->d->extensions->size());
 
527
}
 
528
 
 
529
 
 
530
 
 
531
/*static*/ void SpiffData::appendHelper(
 
532
                std::deque<std::pair<std::pair<const XML_Char *, bool> *,
 
533
                std::pair<const XML_Char *, bool> *> *> * & container,
 
534
                const XML_Char * rel, bool ownRel,
 
535
                const XML_Char * content, bool ownContent) {
 
536
        if (container == NULL) {
 
537
                container = new deque<pair<pair<const XML_Char *, bool> *, pair<const XML_Char *, bool> *> *>;
 
538
        }
 
539
        pair<const XML_Char *, bool> * const first = new pair<const XML_Char *, bool>(rel, ownRel);
 
540
        pair<const XML_Char *, bool> * const second = new pair<const XML_Char *, bool>(content, ownContent);
 
541
        pair<pair<const XML_Char *, bool> *, pair<const XML_Char *, bool> *> * const entry =
 
542
                        new pair<pair<const XML_Char *, bool> *, pair<const XML_Char *, bool> *>(first, second);
 
543
        container->push_back(entry);
 
544
}
 
545
 
 
546
 
 
547
 
 
548
/*static*/ void SpiffData::appendHelper(
 
549
                std::deque<std::pair<const SpiffExtension *, bool> *> * & container,
 
550
                const SpiffExtension * extension, bool own) {
 
551
        if (container == NULL) {
 
552
                container = new deque<pair<const SpiffExtension *, bool> *>;
 
553
        }
 
554
        pair<const SpiffExtension *, bool> * const entry =
 
555
                        new pair<const SpiffExtension *, bool>(extension, own);
 
556
        container->push_back(entry);
 
557
}
 
558
 
 
559
 
 
560
 
 
561
/*static*/ XML_Char * SpiffData::stealHelper(const XML_Char * & property,
 
562
                bool own) {
 
563
        const XML_Char * const res = Toolbox::getSetNull<XML_Char>(property);
 
564
        if (own) {
 
565
                return const_cast<XML_Char *>(res);
 
566
        } else if (res == NULL) {
 
567
                return NULL;
 
568
        } else {
 
569
                return Toolbox::newAndCopy(res);
 
570
        }
 
571
}
 
572
 
 
573
 
 
574
 
 
575
/*static*/ pair<XML_Char *, XML_Char *> * SpiffData::stealFirstHelper(
 
576
                std::deque<std::pair<std::pair<const XML_Char *, bool> *,
 
577
                std::pair<const XML_Char *, bool> *> *> * & container) {
 
578
        if ((container == NULL) || container->empty()) {
 
579
                return NULL;
 
580
        }
 
581
        pair<pair<const XML_Char *, bool> *, pair<const XML_Char *, bool> *> * const entry =
 
582
                        container->front();
 
583
        container->pop_front();
 
584
        pair<XML_Char *, XML_Char *> * const res = new pair<XML_Char *, XML_Char *>(
 
585
                        entry->first->second
 
586
                        ? const_cast<XML_Char *>(entry->first->first)
 
587
                        : Toolbox::newAndCopy(entry->first->first), entry->second->second
 
588
                        ? const_cast<XML_Char *>(entry->second->first)
 
589
                        : Toolbox::newAndCopy(entry->second->first));
 
590
        delete entry->first;
 
591
        delete entry->second;
 
592
        delete entry;
 
593
        return res;
 
594
}
 
595
 
 
596
 
 
597
 
 
598
/*static*/ SpiffExtension * SpiffData::stealFirstHelper(
 
599
                std::deque<std::pair<const SpiffExtension *, bool> *> * & container) {
 
600
        if ((container == NULL) || container->empty()) {
 
601
                return NULL;
 
602
        }
 
603
        pair<const SpiffExtension *, bool> * const entry = container->front();
 
604
        container->pop_front();
 
605
        SpiffExtension * res = entry->second
 
606
                        ? const_cast<SpiffExtension *>(entry->first)
 
607
                        : entry->first->clone();
 
608
        delete entry;
 
609
        return res;
 
610
}
 
611
 
 
612
 
 
613
 
 
614
/*static*/ pair<const XML_Char *, const XML_Char *> * SpiffData::getHelper(
 
615
                std::deque<std::pair<std::pair<const XML_Char *, bool> *,
 
616
                std::pair<const XML_Char *, bool> *> *> * & container, int index) {
 
617
        if ((container == NULL) || container->empty() || (index < 0)
 
618
                        || (index >= static_cast<int>(container->size()))) {
 
619
                return NULL;
 
620
        }
 
621
        pair<pair<const XML_Char *, bool> *, pair<const XML_Char *, bool> *> * const entry =
 
622
                        container->at(index);
 
623
 
 
624
        // NOTE: getX() just peeps at data so don't clone anything
 
625
        pair<const XML_Char *, const XML_Char *> * const res =
 
626
                        new pair<const XML_Char *, const XML_Char *>(
 
627
                                entry->first->first, entry->second->first);
 
628
        return res;
 
629
}
 
630
 
 
631
 
 
632
 
 
633
/*static*/ const SpiffExtension * SpiffData::getHelper(
 
634
                std::deque<std::pair<const SpiffExtension *, bool> *> * & container,
 
635
                int index) {
 
636
        if ((container == NULL) || container->empty() || (index < 0)
 
637
                        || (index >= static_cast<int>(container->size()))) {
 
638
                return NULL;
 
639
        }
 
640
 
 
641
        // NOTE: getX() just peeps at data so don't clone anything
 
642
        pair<const SpiffExtension *, bool> * const entry
 
643
                        = container->at(index);
 
644
        return entry->first;
 
645
}
 
646
 
 
647
 
 
648
 
 
649
}