OpenShot Audio Library | OpenShotAudio  0.6.0
juce_UMPIterator.h
1 /*
2  ==============================================================================
3 
4  This file is part of the JUCE library.
5  Copyright (c) 2022 - Raw Material Software Limited
6 
7  JUCE is an open source library subject to commercial or open-source
8  licensing.
9 
10  The code included in this file is provided under the terms of the ISC license
11  http://www.isc.org/downloads/software-support-policy/isc-license. Permission
12  To use, copy, modify, and/or distribute this software for any purpose with or
13  without fee is hereby granted provided that the above copyright notice and
14  this permission notice appear in all copies.
15 
16  JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
17  EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
18  DISCLAIMED.
19 
20  ==============================================================================
21 */
22 
23 #ifndef DOXYGEN
24 
25 namespace juce::universal_midi_packets
26 {
27 
37 class Iterator
38 {
39 public:
41  Iterator() noexcept = default;
42 
44  explicit Iterator (const uint32_t* ptr, size_t bytes) noexcept;
45 
46  using difference_type = std::iterator_traits<const uint32_t*>::difference_type;
47  using value_type = View;
48  using reference = const View&;
49  using pointer = const View*;
50  using iterator_category = std::forward_iterator_tag;
51 
53  Iterator& operator++() noexcept
54  {
55  const auto increment = view.size();
56 
57  #if JUCE_DEBUG
58  // If you hit this, the memory region contained a truncated or otherwise
59  // malformed Universal MIDI Packet.
60  // The Iterator can only be used on regions containing complete packets!
61  jassert (increment <= bytesRemaining);
62  bytesRemaining -= increment;
63  #endif
64 
65  view = View (view.data() + increment);
66  return *this;
67  }
68 
73  Iterator operator++ (int) noexcept
74  {
75  auto copy = *this;
76  ++(*this);
77  return copy;
78  }
79 
83  bool operator== (const Iterator& other) const noexcept
84  {
85  return view == other.view;
86  }
87 
91  bool operator!= (const Iterator& other) const noexcept
92  {
93  return ! operator== (other);
94  }
95 
101  reference operator*() noexcept { return view; }
102 
108  pointer operator->() noexcept { return &view; }
109 
110 private:
111  View view;
112 
113  #if JUCE_DEBUG
114  size_t bytesRemaining = 0;
115  #endif
116 };
117 
118 } // namespace juce::universal_midi_packets
119 
120 #endif
bool operator==(const Iterator &other) const noexcept
bool operator!=(const Iterator &other) const noexcept
uint32_t size() const noexcept
const uint32_t * data() const noexcept
Definition: juce_UMPView.h:55