juce_SubregionStream.h 4.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. ==============================================================================
  3. This file is part of the juce_core module of the JUCE library.
  4. Copyright (c) 2015 - ROLI Ltd.
  5. Permission to use, copy, modify, and/or distribute this software for any purpose with
  6. or without fee is hereby granted, provided that the above copyright notice and this
  7. permission notice appear in all copies.
  8. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
  9. TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
  10. NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  11. DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
  12. IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  13. CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  14. ------------------------------------------------------------------------------
  15. NOTE! This permissive ISC license applies ONLY to files within the juce_core module!
  16. All other JUCE modules are covered by a dual GPL/commercial license, so if you are
  17. using any other modules, be sure to check that you also comply with their license.
  18. For more details, visit www.juce.com
  19. ==============================================================================
  20. */
  21. #ifndef JUCE_SUBREGIONSTREAM_H_INCLUDED
  22. #define JUCE_SUBREGIONSTREAM_H_INCLUDED
  23. //==============================================================================
  24. /** Wraps another input stream, and reads from a specific part of it.
  25. This lets you take a subsection of a stream and present it as an entire
  26. stream in its own right.
  27. */
  28. class JUCE_API SubregionStream : public InputStream
  29. {
  30. public:
  31. //==============================================================================
  32. /** Creates a SubregionStream from an input source.
  33. @param sourceStream the source stream to read from
  34. @param startPositionInSourceStream this is the position in the source stream that
  35. corresponds to position 0 in this stream
  36. @param lengthOfSourceStream this specifies the maximum number of bytes
  37. from the source stream that will be passed through
  38. by this stream. When the position of this stream
  39. exceeds lengthOfSourceStream, it will cause an end-of-stream.
  40. If the length passed in here is greater than the length
  41. of the source stream (as returned by getTotalLength()),
  42. then the smaller value will be used.
  43. Passing a negative value for this parameter means it
  44. will keep reading until the source's end-of-stream.
  45. @param deleteSourceWhenDestroyed whether the sourceStream that is passed in should be
  46. deleted by this object when it is itself deleted.
  47. */
  48. SubregionStream (InputStream* sourceStream,
  49. int64 startPositionInSourceStream,
  50. int64 lengthOfSourceStream,
  51. bool deleteSourceWhenDestroyed);
  52. /** Destructor.
  53. This may also delete the source stream, if that option was chosen when the
  54. buffered stream was created.
  55. */
  56. ~SubregionStream();
  57. //==============================================================================
  58. int64 getTotalLength() override;
  59. int64 getPosition() override;
  60. bool setPosition (int64 newPosition) override;
  61. int read (void* destBuffer, int maxBytesToRead) override;
  62. bool isExhausted() override;
  63. private:
  64. //==============================================================================
  65. OptionalScopedPointer<InputStream> source;
  66. const int64 startPositionInSourceStream, lengthOfSourceStream;
  67. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (SubregionStream)
  68. };
  69. #endif // JUCE_SUBREGIONSTREAM_H_INCLUDED