Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

FileInputStream.h 3.6KB

7 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. ==============================================================================
  3. This file is part of the Water library.
  4. Copyright (c) 2016 ROLI Ltd.
  5. Copyright (C) 2017 Filipe Coelho <falktx@falktx.com>
  6. Permission is granted to use this software under the terms of the ISC license
  7. http://www.isc.org/downloads/software-support-policy/isc-license/
  8. Permission to use, copy, modify, and/or distribute this software for any
  9. purpose with or without fee is hereby granted, provided that the above
  10. copyright notice and this permission notice appear in all copies.
  11. THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH REGARD
  12. TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  13. FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT,
  14. OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
  15. USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  16. TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
  17. OF THIS SOFTWARE.
  18. ==============================================================================
  19. */
  20. #ifndef WATER_FILEINPUTSTREAM_H_INCLUDED
  21. #define WATER_FILEINPUTSTREAM_H_INCLUDED
  22. #include "File.h"
  23. #include "../streams/InputStream.h"
  24. namespace water {
  25. //==============================================================================
  26. /**
  27. An input stream that reads from a local file.
  28. @see InputStream, FileOutputStream, File::createInputStream
  29. */
  30. class FileInputStream : public InputStream
  31. {
  32. public:
  33. //==============================================================================
  34. /** Creates a FileInputStream to read from the given file.
  35. After creating a FileInputStream, you should use openedOk() or failedToOpen()
  36. to make sure that it's OK before trying to read from it! If it failed, you
  37. can call getStatus() to get more error information.
  38. */
  39. explicit FileInputStream (const File& fileToRead);
  40. /** Destructor. */
  41. ~FileInputStream();
  42. //==============================================================================
  43. /** Returns the file that this stream is reading from. */
  44. const File& getFile() const noexcept { return file; }
  45. /** Returns the status of the file stream.
  46. The result will be ok if the file opened successfully. If an error occurs while
  47. opening or reading from the file, this will contain an error message.
  48. */
  49. const Result& getStatus() const noexcept { return status; }
  50. /** Returns true if the stream couldn't be opened for some reason.
  51. @see getResult()
  52. */
  53. bool failedToOpen() const noexcept { return status.failed(); }
  54. /** Returns true if the stream opened without problems.
  55. @see getResult()
  56. */
  57. bool openedOk() const noexcept { return status.wasOk(); }
  58. //==============================================================================
  59. int64 getTotalLength() override;
  60. int read (void*, int) override;
  61. bool isExhausted() override;
  62. int64 getPosition() override;
  63. bool setPosition (int64) override;
  64. private:
  65. //==============================================================================
  66. const File file;
  67. void* fileHandle;
  68. int64 currentPosition;
  69. Result status;
  70. void openHandle();
  71. size_t readInternal (void*, size_t);
  72. CARLA_DECLARE_NON_COPY_CLASS (FileInputStream)
  73. };
  74. }
  75. #endif // WATER_FILEINPUTSTREAM_H_INCLUDED