Skip to content

Commit 2041f64

Browse files
committed
Added '==' and '!=' overloads for mixed Iterator and ConstIterator comparisons. Added Iterator and ConstIterator traits.
Signed-off-by: Aries Moczar <arcmantis@protulae.com>
1 parent 47a65de commit 2041f64

1 file changed

Lines changed: 78 additions & 27 deletions

File tree

src/lib/OpenEXR/ImfChannelList.h

Lines changed: 78 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,12 @@ class IMF_EXPORT_TYPE ChannelList
254254
class IMF_EXPORT_TYPE ChannelList::Iterator
255255
{
256256
public:
257+
using iterator_category = std::bidirectional_iterator_tag;
258+
using value_type = Channel;
259+
using difference_type = std::ptrdiff_t;
260+
using pointer = Channel*;
261+
using reference = Channel&;
262+
257263
IMF_EXPORT
258264
Iterator ();
259265
IMF_EXPORT
@@ -270,27 +276,39 @@ class IMF_EXPORT_TYPE ChannelList::Iterator
270276
Iterator operator-- (int);
271277

272278
IMF_EXPORT
273-
Channel& operator* () const;
279+
reference operator* () const;
274280

275281
IMF_EXPORT
276-
Channel* operator-> () const;
282+
pointer operator-> () const;
277283

278284
IMF_EXPORT
279285
const char* name () const;
280286
IMF_EXPORT
281-
Channel& channel () const;
287+
reference channel () const;
282288

283289
private:
284290
friend class ChannelList::ConstIterator;
291+
285292
friend bool operator== (Iterator&, Iterator&);
293+
friend bool operator== (Iterator&, const ConstIterator&);
294+
friend bool operator== (const ConstIterator&, Iterator&);
295+
286296
friend bool operator!= (Iterator&, Iterator&);
297+
friend bool operator!= (Iterator&, const ConstIterator&);
298+
friend bool operator!= (const ConstIterator&, Iterator&);
287299

288300
ChannelList::ChannelMap::iterator _i;
289301
};
290302

291303
class IMF_EXPORT_TYPE ChannelList::ConstIterator
292304
{
293305
public:
306+
using iterator_category = std::bidirectional_iterator_tag;
307+
using value_type = Channel;
308+
using difference_type = std::ptrdiff_t;
309+
using pointer = const Channel*;
310+
using reference = const Channel&;
311+
294312
IMF_EXPORT
295313
ConstIterator ();
296314
IMF_EXPORT
@@ -309,19 +327,24 @@ class IMF_EXPORT_TYPE ChannelList::ConstIterator
309327
ConstIterator operator-- (int);
310328

311329
IMF_EXPORT
312-
const Channel& operator* () const;
330+
reference operator* () const;
313331

314332
IMF_EXPORT
315-
const Channel* operator-> () const;
333+
pointer operator-> () const;
316334

317335
IMF_EXPORT
318336
const char* name () const;
319337
IMF_EXPORT
320-
const Channel& channel () const;
338+
reference channel () const;
321339

322340
private:
323341
friend bool operator== (const ConstIterator&, const ConstIterator&);
342+
friend bool operator== (Iterator&, const ConstIterator&);
343+
friend bool operator== (const ConstIterator&, Iterator&);
344+
324345
friend bool operator!= (const ConstIterator&, const ConstIterator&);
346+
friend bool operator!= (Iterator&, const ConstIterator&);
347+
friend bool operator!= (const ConstIterator&, Iterator&);
325348

326349
ChannelList::ChannelMap::const_iterator _i;
327350
};
@@ -372,13 +395,13 @@ ChannelList::Iterator::operator-- (int)
372395
return tmp;
373396
}
374397

375-
inline Channel&
398+
inline ChannelList::Iterator::reference
376399
ChannelList::Iterator::operator* () const
377400
{
378401
return _i->second;
379402
}
380403

381-
inline Channel*
404+
inline ChannelList::Iterator::pointer
382405
ChannelList::Iterator::operator-> () const
383406
{
384407
return &_i->second;
@@ -390,26 +413,12 @@ ChannelList::Iterator::name () const
390413
return *_i->first;
391414
}
392415

393-
inline Channel&
416+
inline ChannelList::Iterator::reference
394417
ChannelList::Iterator::channel () const
395418
{
396419
return _i->second;
397420
}
398421

399-
inline bool
400-
operator== (
401-
ChannelList::Iterator& x, ChannelList::Iterator& y)
402-
{
403-
return x._i == y._i;
404-
}
405-
406-
inline bool
407-
operator!= (
408-
ChannelList::Iterator& x, ChannelList::Iterator& y)
409-
{
410-
return !(x == y);
411-
}
412-
413422
inline ChannelList::ConstIterator::ConstIterator () : _i ()
414423
{
415424
// empty
@@ -459,13 +468,13 @@ ChannelList::ConstIterator::operator-- (int)
459468
return tmp;
460469
}
461470

462-
inline const Channel&
471+
inline ChannelList::ConstIterator::reference
463472
ChannelList::ConstIterator::operator* () const
464473
{
465474
return _i->second;
466475
}
467476

468-
inline const Channel*
477+
inline ChannelList::ConstIterator::pointer
469478
ChannelList::ConstIterator::operator-> () const
470479
{
471480
return &_i->second;
@@ -477,24 +486,66 @@ ChannelList::ConstIterator::name () const
477486
return *_i->first;
478487
}
479488

480-
inline const Channel&
489+
inline ChannelList::ConstIterator::reference
481490
ChannelList::ConstIterator::channel () const
482491
{
483492
return _i->second;
484493
}
485494

495+
inline bool
496+
operator== (
497+
ChannelList::Iterator& x, ChannelList::Iterator& y)
498+
{
499+
return x._i == y._i;
500+
}
501+
486502
inline bool
487503
operator== (
488504
const ChannelList::ConstIterator& x, const ChannelList::ConstIterator& y)
489505
{
490506
return x._i == y._i;
491507
}
492508

509+
inline bool
510+
operator== (
511+
ChannelList::Iterator& x, const ChannelList::ConstIterator& y)
512+
{
513+
return x._i == y._i;
514+
}
515+
516+
inline bool
517+
operator== (
518+
const ChannelList::ConstIterator& x, ChannelList::Iterator& y)
519+
{
520+
return x._i == y._i;
521+
}
522+
523+
inline bool
524+
operator!= (
525+
ChannelList::Iterator& x, ChannelList::Iterator& y)
526+
{
527+
return !(x._i == y._i);
528+
}
529+
493530
inline bool
494531
operator!= (
495532
const ChannelList::ConstIterator& x, const ChannelList::ConstIterator& y)
496533
{
497-
return !(x == y);
534+
return !(x._i == y._i);
535+
}
536+
537+
inline bool
538+
operator!= (
539+
ChannelList::Iterator& x, const ChannelList::ConstIterator& y)
540+
{
541+
return !(x._i == y._i);
542+
}
543+
544+
inline bool
545+
operator!= (
546+
const ChannelList::ConstIterator& x, ChannelList::Iterator& y)
547+
{
548+
return !(x._i == y,_i);
498549
}
499550

500551
OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT

0 commit comments

Comments
 (0)