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