Loading...
Searching...
No Matches
FileLocationHandler.qc.dox.h
// -*- mode: c++; indent-tabs-mode: nil -*-
/* FileLocationHandler Copyright 2021 - 2023 Qore Technologies, s.r.o.
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/
namespace FileLocationHandler {
public struct FileHandlerOptionInfo {
string type;
bool required = False;
string desc;
auto default_value;
};
public struct FileHandlerInfo {
string scheme;
*hash<string, hash<FileHandlerOptionInfo>> read_options;
*hash<string, hash<FileHandlerOptionInfo>> write_options;
};
class AbstractFileLocationHandler {
public:
string getTextFile(string scheme, string location, *hash<auto> opts);
binary getBinaryFile(string scheme, string location, *hash<auto> opts);
Qore::AbstractPollOperation getIoPollerForLocation(string scheme, string location, *hash<auto> opts);
Qore::StreamReader getStreamReader(string scheme, string location, *hash<auto> opts);
Qore::InputStream getBinaryStream(string scheme, string location, *hash<auto> opts);
writeFile(string scheme, string location, data contents, *hash<auto> opts);
OutputStreamWrapper getOutputStream(string scheme, string location, *hash<auto> opts);
hash<string, hash<FileHandlerOptionInfo>> getReadOptions();
hash<string, hash<FileHandlerOptionInfo>> getWriteOptions();
protected:
static string forceEncoding(string str, *string encoding);
public:
protected:
abstract string getTextFileImpl(string scheme, string location, *hash<auto> opts);
public:
protected:
abstract binary getBinaryFileImpl(string scheme, string location, *hash<auto> opts);
public:
protected:
abstract Qore::AbstractPollOperation getIoPollerForLocationImpl(string scheme, string location, *hash<auto> opts);
public:
protected:
abstract Qore::StreamReader getStreamReaderImpl(string scheme, string location, *hash<auto> opts);
public:
protected:
abstract Qore::InputStream getBinaryStreamImpl(string scheme, string location, *hash<auto> opts);
public:
protected:
abstract writeFileImpl(string scheme, string location, data contents, *hash<auto> opts);
public:
protected:
abstract OutputStreamWrapper getOutputStreamImpl(string scheme, string location, *hash<auto> opts);
public:
protected:
abstract hash<string, hash<FileHandlerOptionInfo>> getReadOptionsImpl();
public:
protected:
abstract hash<string, hash<FileHandlerOptionInfo>> getWriteOptionsImpl();
public:
};
class FileLocationHandler {
public:
protected:
static hash<string, AbstractFileLocationHandler> cache;
static Mutex handler_lock();
static bool dynamic_init;
public:
static init();
static registerHandler(string scheme, AbstractFileLocationHandler handler);
static bool tryRegisterHandler(string scheme, AbstractFileLocationHandler handler);
static list<string> getSupportedSchemes();
static bool isSchemeSupported(string scheme);
static string getTextFileFromLocation(string location);
static binary getBinaryFileFromLocation(string location);
static data getFileFromLocation(bool text, string location);
static Qore::AbstractPollOperation getIoPollerForLocation(string location);
static Qore::StreamReader getStreamReaderFromLocation(string location);
static Qore::InputStream getBinaryStreamFromLocation(string location);
static writeFileToLocation(string location, data contents);
static OutputStreamWrapper getOutputStreamForLocation(string location);
static list<string> getHandlerNames();
static hash<string, hash<FileHandlerInfo>> getHandlers(*bool write);
static hash<FileHandlerInfo> getHandlerInfo(string scheme);
protected:
static hash<InternallLocationInfo> getInfo(string location, bool read);
public:
protected:
static *hash<auto> getOptions(reference<string> location);
public:
protected:
static checkDynamicInit();
public:
};
};
namespace Priv {
hashdecl InternallLocationInfo {
string scheme;
string location;
*hash<auto> opts;
AbstractFileLocationHandler handler;
}
};
FileLocationHandler::AbstractFileLocationHandler
The abstract file location handler class.
Definition: FileLocationHandler.qc.dox.h:53
FileLocationHandler::AbstractFileLocationHandler::getReadOptionsImpl
abstract hash< string, hash< FileHandlerOptionInfo > > getReadOptionsImpl()
Gets supported read options.
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::getIoPollerForLocationImpl
abstract Qore::AbstractPollOperation getIoPollerForLocationImpl(string scheme, string location, *hash< auto > opts)
Retrieves an I/O poller to retrieve a binary file from the given location.
FileLocationHandler::AbstractFileLocationHandler::getReadOptions
hash< string, hash< FileHandlerOptionInfo > > getReadOptions()
Gets supported read options.
FileLocationHandler::AbstractFileLocationHandler::getBinaryFile
binary getBinaryFile(string scheme, string location, *hash< auto > opts)
Retrieves a binary file from the given location.
FileLocationHandler::AbstractFileLocationHandler::getIoPollerForLocation
Qore::AbstractPollOperation getIoPollerForLocation(string scheme, string location, *hash< auto > opts)
Retrieves an I/O poller to retrieve a binary file from the given location.
FileLocationHandler::AbstractFileLocationHandler::getWriteOptions
hash< string, hash< FileHandlerOptionInfo > > getWriteOptions()
Gets supported write options.
FileLocationHandler::AbstractFileLocationHandler::getTextFile
string getTextFile(string scheme, string location, *hash< auto > opts)
Retrieves a text file from the given location.
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::getWriteOptionsImpl
abstract hash< string, hash< FileHandlerOptionInfo > > getWriteOptionsImpl()
Gets supported write options.
FileLocationHandler::AbstractFileLocationHandler::writeFile
writeFile(string scheme, string location, data contents, *hash< auto > opts)
Writes data to a file at the given location.
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::FileLocationHandler::getHandlers
static hash< string, hash< FileHandlerInfo > > getHandlers(*bool write)
Returns info about all cached handlers.
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::getInfo
static hash< InternallLocationInfo > getInfo(string location, bool read)
Returns info about the requested location.
FileLocationHandler::FileLocationHandler::getIoPollerForLocation
static Qore::AbstractPollOperation getIoPollerForLocation(string location)
Returns a non-blocking I/O poller object to retrieve a binary file from the given location.
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:258
FileLocationHandler::FileLocationHandler::dynamic_init
static bool dynamic_init
Flag for dynamic initialization.
Definition: FileLocationHandler.qc.dox.h:264
FileLocationHandler::FileLocationHandler::getHandlerNames
static list< string > getHandlerNames()
Returns a list of all handler names.
FileLocationHandler::FileLocationHandler::getHandlerInfo
static hash< FileHandlerInfo > getHandlerInfo(string scheme)
Returns info about the location handler for he given scheme.
FileLocationHandler::FileLocationHandler::tryRegisterHandler
static bool tryRegisterHandler(string scheme, AbstractFileLocationHandler handler)
Tries to register a new location handler; if the scheme is already registered, the method returns Fal...
FileLocationHandler::FileLocationHandler::getSupportedSchemes
static list< string > getSupportedSchemes()
Retuns a list of supported schemes.
FileLocationHandler::FileLocationHandler::getOutputStreamForLocation
static OutputStreamWrapper getOutputStreamForLocation(string location)
Returns an output stream for writing data to the given location.
FileLocationHandler::FileLocationHandler::init
static init()
Initializes default handlers.
FileLocationHandler::FileLocationHandler::checkDynamicInit
static checkDynamicInit()
Checks for dynamic initialization.
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::AbstractPollOperation
Qore::InputStream
Qore::StreamReader
FileLocationHandler
Contains all public definitions in the FileLocationHandler module.
Definition: FileLocationHandler.qc.dox.h:26
FileLocationHandler::FileHandlerInfo
File handler info.
Definition: FileLocationHandler.qc.dox.h:43
FileLocationHandler::FileHandlerInfo::read_options
*hash< string, hash< FileHandlerOptionInfo > > read_options
Read options, if any.
Definition: FileLocationHandler.qc.dox.h:47
FileLocationHandler::FileHandlerInfo::write_options
*hash< string, hash< FileHandlerOptionInfo > > write_options
Write options, if any.
Definition: FileLocationHandler.qc.dox.h:49
FileLocationHandler::FileHandlerInfo::scheme
string scheme
The schema handled.
Definition: FileLocationHandler.qc.dox.h:45
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