| Qore FileLocationHandler Module Reference 2.0

FileLocationHandler.qc.dox.h
1 // -*- mode: c++; indent-tabs-mode: nil -*-
3
4 /* FileLocationHandler Copyright 2021 - 2022 Qore Technologies, s.r.o.
5
6 Permission is hereby granted, free of charge, to any person obtaining a
7 copy of this software and associated documentation files (the "Software"),
8 to deal in the Software without restriction, including without limitation
9 the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 and/or sell copies of the Software, and to permit persons to whom the
11 Software is furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 DEALINGS IN THE SOFTWARE.
23 */
24
26 namespace FileLocationHandler {
28 public struct FileHandlerOptionInfo {
30 string type;
31
33 bool required = False;
34
36 string desc;
37
39 auto default_value;
40 };
41
43 class AbstractFileLocationHandler {
44
45 public:
47
53 string getTextFile(string scheme, string location, *hash<auto> opts);
54
55
57
63 binary getBinaryFile(string scheme, string location, *hash<auto> opts);
64
65
67
75 Qore::StreamReader getStreamReader(string scheme, string location, *hash<auto> opts);
76
77
79
87 Qore::InputStream getBinaryStream(string scheme, string location, *hash<auto> opts);
88
89
91
96 writeFile(string scheme, string location, data contents, *hash<auto> opts);
97
98
100
112 OutputStreamWrapper getOutputStream(string scheme, string location, *hash<auto> opts);
113
114
116
118 hash<string, hash<FileHandlerOptionInfo>> getReadOptions();
119
120
122
124 hash<string, hash<FileHandlerOptionInfo>> getWriteOptions();
125
126
128 protected:
129 static string forceEncoding(string str, *string encoding);
130 public:
131
132
134
140 protected:
141 abstract string getTextFileImpl(string scheme, string location, *hash<auto> opts);
142 public:
143
145
151 protected:
152 abstract binary getBinaryFileImpl(string scheme, string location, *hash<auto> opts);
153 public:
154
156
162 protected:
163 abstract Qore::StreamReader getStreamReaderImpl(string scheme, string location, *hash<auto> opts);
164 public:
165
167
173 protected:
174 abstract Qore::InputStream getBinaryStreamImpl(string scheme, string location, *hash<auto> opts);
175 public:
176
178
183 protected:
184 abstract writeFileImpl(string scheme, string location, data contents, *hash<auto> opts);
185 public:
186
188
200 protected:
201 abstract OutputStreamWrapper getOutputStreamImpl(string scheme, string location, *hash<auto> opts);
202 public:
203
205
207 protected:
208 abstract hash<string, hash<FileHandlerOptionInfo>> getReadOptionsImpl();
209 public:
210
212
214 protected:
215 abstract hash<string, hash<FileHandlerOptionInfo>> getWriteOptionsImpl();
216 public:
217 };
218
220 class FileLocationHandler {
221
222 public:
223 protected:
225
227 static hash<string, AbstractFileLocationHandler> cache;
228
230 static Mutex handler_lock();
231
232 public:
233
235
241 static registerHandler(string scheme, AbstractFileLocationHandler handler);
242
244
246 static list<string> getSupportedSchemes();
247
249
253 static bool isSchemeSupported(string scheme);
254
256
262 static string getTextFileFromLocation(string location);
263
265
271 static binary getBinaryFileFromLocation(string location);
272
274
279 static data getFileFromLocation(bool text, string location);
280
282
286 static Qore::StreamReader getStreamReaderFromLocation(string location);
287
289
293 static Qore::InputStream getBinaryStreamFromLocation(string location);
294
296
299 static writeFileToLocation(string location, data contents);
300
302
312 static OutputStreamWrapper getOutputStreamForLocation(string location);
313
315
320 static hash<LocationInfo> getInfo(string location, bool read);
321
323 protected:
324 static *hash<auto> getOptions(reference<string> location);
325 public:
326
327 };
328 };
329
330 namespace Priv {
331 hashdecl LocationInfo {
332 string scheme;
333 string location;
334 *hash<auto> opts;
335 AbstractFileLocationHandler handler;
336 }
337 }
FileLocationHandler::AbstractFileLocationHandler
The abstract file location handler class.
Definition: FileLocationHandler.qc.dox.h:43
FileLocationHandler::AbstractFileLocationHandler::getTextFileImpl
abstract string getTextFileImpl(string scheme, string location, *hash< auto > opts)
Retrieves a text file from the given location.
FileLocationHandler::AbstractFileLocationHandler::getBinaryFileImpl
abstract binary getBinaryFileImpl(string scheme, string location, *hash< auto > opts)
Retrieves a binary file from the given location.
FileLocationHandler::AbstractFileLocationHandler::getStreamReader
Qore::StreamReader getStreamReader(string scheme, string location, *hash< auto > opts)
Returns a string stream for the file's data at the given location.
FileLocationHandler::AbstractFileLocationHandler::getBinaryFile
binary getBinaryFile(string scheme, string location, *hash< auto > opts)
Retrieves a binary file from the given location.
FileLocationHandler::AbstractFileLocationHandler::getTextFile
string getTextFile(string scheme, string location, *hash< auto > opts)
Retrieves a text file from the given location.
FileLocationHandler::AbstractFileLocationHandler::getWriteOptions
hash< string, hash< FileHandlerOptionInfo > > getWriteOptions()
Gets supported write options.
FileLocationHandler::AbstractFileLocationHandler::getReadOptionsImpl
abstract hash< string, hash< FileHandlerOptionInfo > > getReadOptionsImpl()
Gets supported read options.
FileLocationHandler::AbstractFileLocationHandler::getStreamReaderImpl
abstract Qore::StreamReader getStreamReaderImpl(string scheme, string location, *hash< auto > opts)
Returns a string stream for the file's data at the given location.
FileLocationHandler::AbstractFileLocationHandler::writeFile
writeFile(string scheme, string location, data contents, *hash< auto > opts)
Writes data to a file at the given location.
FileLocationHandler::AbstractFileLocationHandler::getWriteOptionsImpl
abstract hash< string, hash< FileHandlerOptionInfo > > getWriteOptionsImpl()
Gets supported write options.
FileLocationHandler::AbstractFileLocationHandler::getOutputStream
OutputStreamWrapper getOutputStream(string scheme, string location, *hash< auto > opts)
Returns an output stream for writing data to the given location.
FileLocationHandler::AbstractFileLocationHandler::getBinaryStream
Qore::InputStream getBinaryStream(string scheme, string location, *hash< auto > opts)
Retrieves a binary file from the given location.
FileLocationHandler::AbstractFileLocationHandler::getOutputStreamImpl
abstract OutputStreamWrapper getOutputStreamImpl(string scheme, string location, *hash< auto > opts)
Returns an output stream for writing data to the given location.
FileLocationHandler::AbstractFileLocationHandler::getBinaryStreamImpl
abstract Qore::InputStream getBinaryStreamImpl(string scheme, string location, *hash< auto > opts)
Retrieves a binary file from the given location.
FileLocationHandler::AbstractFileLocationHandler::forceEncoding
static string forceEncoding(string str, *string encoding)
Returns a string tagged with the given encoding, if any.
FileLocationHandler::AbstractFileLocationHandler::writeFileImpl
abstract writeFileImpl(string scheme, string location, data contents, *hash< auto > opts)
Writes data to a file at the given location.
FileLocationHandler::AbstractFileLocationHandler::getReadOptions
hash< string, hash< FileHandlerOptionInfo > > getReadOptions()
Gets supported read options.
FileLocationHandler::FileLocationHandler::getFileFromLocation
static data getFileFromLocation(bool text, string location)
Returns the file data from the given location.
FileLocationHandler::FileLocationHandler::getStreamReaderFromLocation
static Qore::StreamReader getStreamReaderFromLocation(string location)
Returns a string stream for the file's data at the given location.
FileLocationHandler::FileLocationHandler::getBinaryStreamFromLocation
static Qore::InputStream getBinaryStreamFromLocation(string location)
Returns an input stream for file data at the given location.
FileLocationHandler::FileLocationHandler::isSchemeSupported
static bool isSchemeSupported(string scheme)
Returns True if the scheme is supported.
FileLocationHandler::FileLocationHandler::registerHandler
static registerHandler(string scheme, AbstractFileLocationHandler handler)
Register a new location handler.
FileLocationHandler::FileLocationHandler::cache
static hash< string, AbstractFileLocationHandler > cache
The location handler cache; scheme -> handler;.
Definition: FileLocationHandler.qc.dox.h:227
FileLocationHandler::FileLocationHandler::getInfo
static hash< LocationInfo > getInfo(string location, bool read)
Returns info about the requested location.
FileLocationHandler::FileLocationHandler::getOutputStreamForLocation
static OutputStreamWrapper getOutputStreamForLocation(string location)
Returns an output stream for writing data to the given location.
FileLocationHandler::FileLocationHandler::getSupportedSchemes
static list< string > getSupportedSchemes()
Retuns a list of supported schemes.
FileLocationHandler::FileLocationHandler::getOptions
static *hash< auto > getOptions(reference< string > location)
Returns a hash of options from the location string.
FileLocationHandler::FileLocationHandler::getBinaryFileFromLocation
static binary getBinaryFileFromLocation(string location)
Returns binary data for the given file location.
FileLocationHandler::FileLocationHandler::handler_lock
static Mutex handler_lock()
The location handler lock to ensure atomic operations.
FileLocationHandler::FileLocationHandler::writeFileToLocation
static writeFileToLocation(string location, data contents)
Writes data to a file at the given location.
FileLocationHandler::FileLocationHandler::getTextFileFromLocation
static string getTextFileFromLocation(string location)
Returns string data for the given file location.
FileLocationHandler::OutputStreamWrapper
The abstract file location handler class.
Definition: OutputStramWrapper.qc.dox.h:28
Qore::InputStream
Qore::StreamReader
False
const False
binary
binary binary()
FileLocationHandler
Contains all public definitions in the FileLocationHandler module.
Definition: FileLocationHandler.qc.dox.h:26
FileLocationHandler::FileHandlerOptionInfo
File handler option info.
Definition: FileLocationHandler.qc.dox.h:28
FileLocationHandler::FileHandlerOptionInfo::type
string type
The option value type: "string", "bool", or "int".
Definition: FileLocationHandler.qc.dox.h:30
FileLocationHandler::FileHandlerOptionInfo::default_value
auto default_value
Default value, if any.
Definition: FileLocationHandler.qc.dox.h:39
FileLocationHandler::FileHandlerOptionInfo::desc
string desc
The option description.
Definition: FileLocationHandler.qc.dox.h:36
FileLocationHandler::FileHandlerOptionInfo::required
bool required
Required flag.
Definition: FileLocationHandler.qc.dox.h:33