mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Rename beast sources for consistency
This commit is contained in:
77
modules/beast_core/streams/SubregionStream.cpp
Normal file
77
modules/beast_core/streams/SubregionStream.cpp
Normal file
@@ -0,0 +1,77 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
This file is part of Beast: https://github.com/vinniefalco/Beast
|
||||
Copyright 2013, Vinnie Falco <vinnie.falco@gmail.com>
|
||||
|
||||
Portions of this file are from JUCE.
|
||||
Copyright (c) 2013 - Raw Material Software Ltd.
|
||||
Please visit http://www.juce.com
|
||||
|
||||
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.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
SubregionStream::SubregionStream (InputStream* const sourceStream,
|
||||
const int64 start, const int64 length,
|
||||
const bool deleteSourceWhenDestroyed)
|
||||
: source (sourceStream, deleteSourceWhenDestroyed),
|
||||
startPositionInSourceStream (start),
|
||||
lengthOfSourceStream (length)
|
||||
{
|
||||
SubregionStream::setPosition (0);
|
||||
}
|
||||
|
||||
SubregionStream::~SubregionStream()
|
||||
{
|
||||
}
|
||||
|
||||
int64 SubregionStream::getTotalLength()
|
||||
{
|
||||
const int64 srcLen = source->getTotalLength() - startPositionInSourceStream;
|
||||
|
||||
return lengthOfSourceStream >= 0 ? bmin (lengthOfSourceStream, srcLen)
|
||||
: srcLen;
|
||||
}
|
||||
|
||||
int64 SubregionStream::getPosition()
|
||||
{
|
||||
return source->getPosition() - startPositionInSourceStream;
|
||||
}
|
||||
|
||||
bool SubregionStream::setPosition (int64 newPosition)
|
||||
{
|
||||
return source->setPosition (bmax ((int64) 0, newPosition + startPositionInSourceStream));
|
||||
}
|
||||
|
||||
int SubregionStream::read (void* destBuffer, int maxBytesToRead)
|
||||
{
|
||||
bassert (destBuffer != nullptr && maxBytesToRead >= 0);
|
||||
|
||||
if (lengthOfSourceStream < 0)
|
||||
return source->read (destBuffer, maxBytesToRead);
|
||||
|
||||
maxBytesToRead = (int) bmin ((int64) maxBytesToRead, lengthOfSourceStream - getPosition());
|
||||
|
||||
if (maxBytesToRead <= 0)
|
||||
return 0;
|
||||
|
||||
return source->read (destBuffer, maxBytesToRead);
|
||||
}
|
||||
|
||||
bool SubregionStream::isExhausted()
|
||||
{
|
||||
if (lengthOfSourceStream >= 0 && getPosition() >= lengthOfSourceStream)
|
||||
return true;
|
||||
|
||||
return source->isExhausted();
|
||||
}
|
||||
Reference in New Issue
Block a user