Loading...
Searching...
No Matches
juce_Reservoir.h
/*
==============================================================================
This file is part of the JUCE library.
Copyright (c) 2022 - Raw Material Software Limited
JUCE is an open source library subject to commercial or open-source
licensing.
The code included in this file is provided under the terms of the ISC license
http://www.isc.org/downloads/software-support-policy/isc-license. Permission
To use, copy, modify, and/or distribute this software for any purpose with or
without fee is hereby granted provided that the above copyright notice and
this permission notice appear in all copies.
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
DISCLAIMED.
==============================================================================
*/
namespace juce
{
struct Reservoir
{
template <typename Index, typename GetBufferedRange, typename ReadFromReservoir, typename FillReservoir>
static Range<Index> doBufferedRead (Range<Index> rangeToRead,
GetBufferedRange&& getBufferedRange,
ReadFromReservoir&& readFromReservoir,
FillReservoir&& fillReservoir)
{
while (! rangeToRead.isEmpty())
{
const auto bufferedRange = getBufferedRange();
if (bufferedRange.contains (rangeToRead.getStart()))
{
const auto rangeToReadInBuffer = rangeToRead.getIntersectionWith (getBufferedRange());
readFromReservoir (rangeToReadInBuffer);
rangeToRead.setStart (rangeToReadInBuffer.getEnd());
}
else
{
fillReservoir (rangeToRead.getStart());
const auto newRange = getBufferedRange();
if (newRange.isEmpty() || ! newRange.contains (rangeToRead.getStart()))
break;
}
}
return rangeToRead;
}
};
} // namespace juce
juce::Range
Definition juce_Range.h:40
juce::Range::getStart
constexpr ValueType getStart() const noexcept
Definition juce_Range.h:80
juce::Range::isEmpty
constexpr bool isEmpty() const noexcept
Definition juce_Range.h:89
juce::Range::getIntersectionWith
constexpr Range getIntersectionWith(Range other) const noexcept
Definition juce_Range.h:239
juce::Range::setStart
void setStart(const ValueType newStart) noexcept
Definition juce_Range.h:96
juce::Reservoir
Definition juce_Reservoir.h:32
juce::Reservoir::doBufferedRead
static Range< Index > doBufferedRead(Range< Index > rangeToRead, GetBufferedRange &&getBufferedRange, ReadFromReservoir &&readFromReservoir, FillReservoir &&fillReservoir)
Definition juce_Reservoir.h:69