Loading...
Searching...
No Matches
FileLocationHandler.qc.dox.h
// -*- mode: c++; indent-tabs-mode: nil -*-
/* FileLocationHandler Copyright 2021 - 2022 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;
};
class AbstractFileLocationHandler {
public:
string getTextFile(string scheme, string location, *hash<auto> opts);
binary getBinaryFile(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::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();
public:
static registerHandler(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::StreamReader getStreamReaderFromLocation(string location);
static Qore::InputStream getBinaryStreamFromLocation(string location);
static writeFileToLocation(string location, data contents);
static OutputStreamWrapper getOutputStreamForLocation(string location);
static hash<LocationInfo> getInfo(string location, bool read);
protected:
static *hash<auto> getOptions(reference<string> location);
public:
};
};
namespace Priv {
hashdecl LocationInfo {
string scheme;
string location;
*hash<auto> opts;
AbstractFileLocationHandler handler;
}
};
FileLocationHandler::AbstractFileLocationHandler
The abstract file location handler class.
Definition: FileLocationHandler.qc.dox.h:43
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::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::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::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::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::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
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