FixedLengthUtil.qm.dox.h
// -*- mode: c++; indent-tabs-mode: nil -*-
// @file FixedLengthUtil.qm Qore user module for working with files with fixed lines length
/* FixedLengthUtil.qm Copyright 2015 - 2017 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.
*/
// minimum required Qore version
/* see release notes below for version history
*/
namespace FixedLengthUtil {
const EOL_UNIX = "\n";
const EOL_WIN = "\r\n";
const EOL_MACINTOSH = "\r";
// helper hash (for O(ln(n)) lookups in the worst case) of end of line values
const EOLS = (
EOL_UNIX: True,
EOL_WIN: True,
EOL_MACINTOSH: True,
);
};
class FixedLengthUtil::FixedLengthAbstractIterator : public Qore::AbstractIterator {
public:
private :
hash m_specs;
hash m_resolve_by_rule;
string m_state;
hash m_resolve_by_length;
*hash m_opts; // encoding, eol, ignore_empty, timezone, etc
AbstractLineIterator lineIterator;
public:
constructor(AbstractLineIterator li, hash spec, *hash opts);
bool valid();
bool next();
string getLine();
*hash getValue();
int index();
auto transform(auto value, hash type);
private:
*hash checkOptions(*hash opts);
public:
string identifyType(string input_line);
*string identifyTypeImpl(string input_line);
bool checkTransition(*string from, *string to);
};
class FixedLengthUtil::FixedLengthIterator : public FixedLengthUtil::FixedLengthAbstractIterator {
public:
constructor(Qore::AbstractLineIterator li, hash spec, *hash opts) ;
constructor(Qore::InputStream input, string encoding = "UTF-8", hash spec, *hash opts) ;
};
class FixedLengthUtil::FixedLengthFileIterator : public FixedLengthUtil::FixedLengthAbstractIterator {
public:
private :
string m_file_path;
public:
constructor(string path, hash spec, *hash opts) ;
string getEncoding();
string getFileName();
hash<Qore::StatInfo> hstat();
list stat();
};
class FixedLengthUtil::FixedLengthDataIterator : public FixedLengthUtil::FixedLengthAbstractIterator {
public:
constructor(string data, hash spec, *hash opts) ;
};
class FixedLengthUtil::FixedLengthAbstractWriter {
public:
private :
hash m_specs;
string m_state;
int m_linescount = 0;
*hash m_opts;
public:
constructor(hash specs, *hash opts);
private:
*hash checkOptions(*hash opts);
public:
int linesCount();
string formatLine(hash line);
bool checkTransition(*string from, *string to);
};
class FixedLengthUtil::FixedLengthWriter : public FixedLengthUtil::FixedLengthAbstractWriter {
public:
private :
StreamWriter output;
public:
constructor(Qore::OutputStream output, hash specs, *hash opts) ;
write(hash line);
write(list lines);
write(Qore::AbstractIterator lines);
};
class FixedLengthUtil::FixedLengthFileWriter : public FixedLengthUtil::FixedLengthAbstractWriter {
public:
private :
string file;
File m_file();
public:
constructor(string file_name, hash specs, *hash opts) ;
string getFileName();
write(hash line);
write(list lines);
write(Qore::AbstractIterator lines);
};
class FixedLengthUtil::FixedLengthDataWriter : public FixedLengthUtil::FixedLengthAbstractWriter {
public:
constructor(hash specs, *hash opts) ;
string write(list lines);
string write(hash line);
string write(Qore::AbstractIterator lines);
};
FixedLengthUtil::FixedLengthAbstractIterator::transform
auto transform(auto value, hash type)
parses the input value based on global configuration and the current field definition ...
FixedLengthUtil::FixedLengthAbstractIterator
Structured line iterator for abstract data allowing efficient "pipelined" processing.
Definition: FixedLengthUtil.qm.dox.h:339
FixedLengthUtil::EOL_UNIX
const EOL_UNIX
Unix end of line character sequence (for new OS X too)
Definition: FixedLengthUtil.qm.dox.h:324
FixedLengthUtil::EOL_WIN
const EOL_WIN
MS DOS/Windows end of line character sequence.
Definition: FixedLengthUtil.qm.dox.h:326
FixedLengthUtil::FixedLengthDataWriter::write
string write(list lines)
iterates the input records and returns a string corresponding to the rendered versions of all input r...
FixedLengthUtil::FixedLengthDataIterator::constructor
constructor(string data, hash spec, *hash opts)
Instantiates the FixedLengthDataIterator object.
FixedLengthUtil::FixedLengthWriter::output
StreamWriter output
the output stream for the fixed-length data
Definition: FixedLengthUtil.qm.dox.h:745
FixedLengthUtil::FixedLengthFileIterator::stat
list stat()
Returns a stat list of the underlying file.
FixedLengthUtil::FixedLengthFileWriter::file
string file
file name
Definition: FixedLengthUtil.qm.dox.h:874
FixedLengthUtil::FixedLengthDataWriter
Writer class for fixed-length line string data.
Definition: FixedLengthUtil.qm.dox.h:993
FixedLengthUtil::FixedLengthFileIterator::constructor
constructor(string path, hash spec, *hash opts)
Instantiates the FixedLengthFileIterator object.
FixedLengthUtil::FixedLengthDataIterator
Structured line iterator for fixed-length line strings allowing efficient "pipelined" processing...
Definition: FixedLengthUtil.qm.dox.h:606
FixedLengthUtil::FixedLengthAbstractIterator::getValue
*hash getValue()
Returns the current record as a hash.
True
const True
FixedLengthUtil::FixedLengthAbstractIterator::identifyType
string identifyType(string input_line)
Identify a fixed-length line type using identifyTypeImpl(), that may be overridden if necessary...
FixedLengthUtil::FixedLengthWriter::write
write(hash line)
Renders a single line for a single input record hash to the output stream.
FixedLengthUtil::FixedLengthFileWriter::m_file
File m_file()
file object
FixedLengthUtil::FixedLengthAbstractWriter::checkTransition
bool checkTransition(*string from, *string to)
A verification function to be called for each line. This method can be overridden to achieve a begin-...
FixedLengthUtil::FixedLengthFileIterator
Structured line iterator for fixed-length line files allowing efficient "pipelined" processing...
Definition: FixedLengthUtil.qm.dox.h:535
FixedLengthUtil::FixedLengthAbstractIterator::checkTransition
bool checkTransition(*string from, *string to)
A verification function to be called for each line. This method can be overridden to achieve a begin-...
FixedLengthUtil::FixedLengthIterator::constructor
constructor(Qore::AbstractLineIterator li, hash spec, *hash opts)
Creates the FixedLengthIterator in single-type mode with general line iterator to read and an option ...
FixedLengthUtil::FixedLengthAbstractIterator::identifyTypeImpl
*string identifyTypeImpl(string input_line)
Identify a fixed-length line type, given the raw line string. This method performs a lookup to a prec...
FixedLengthUtil::FixedLengthAbstractWriter::linesCount
int linesCount()
get processed lines count
list
list list(...)
FixedLengthUtil::EOL_MACINTOSH
const EOL_MACINTOSH
Old (pre-OSX) Macintosh end of line character sequence.
Definition: FixedLengthUtil.qm.dox.h:328
FixedLengthUtil::FixedLengthFileIterator::getFileName
string getFileName()
Returns the file path/name used to open the file.
Qore::AbstractLineIterator
FixedLengthUtil::FixedLengthAbstractIterator::next
bool next()
Moves the current line / record position to the next line / record; returns False if there are no mor...
FixedLengthUtil::FixedLengthAbstractIterator::m_resolve_by_length
hash m_resolve_by_length
hash of type without rule, i.e.potentially conflicting records; key = record length, value = list of no-rule type names
Definition: FixedLengthUtil.qm.dox.h:347
FixedLengthUtil::FixedLengthAbstractWriter::constructor
constructor(hash specs, *hash opts)
creates the FixedLengthAbstractWriter object
FixedLengthUtil::FixedLengthIterator
The FixedLengthIterator class allows CSV sources to be iterated on a record basis. The source of the input data is an AbstractLineIterator object or an InputStream.
Definition: FixedLengthUtil.qm.dox.h:441
FixedLengthUtil::FixedLengthWriter::constructor
constructor(Qore::OutputStream output, hash specs, *hash opts)
Instantiates the FixedLengthWriter object.
FixedLengthUtil::FixedLengthFileWriter::constructor
constructor(string file_name, hash specs, *hash opts)
Instantiates the FixedLengthFileWriter object.
FixedLengthUtil::FixedLengthFileIterator::getEncoding
string getEncoding()
Returns the character encoding for the file.
Qore::OutputStream
FixedLengthUtil
The FixedLengthUtil namespace contains all the definitions in the FixedLengthUtil module...
Definition: FixedLengthUtil.qm.dox.h:322
type
string type(auto arg)
FixedLengthUtil::FixedLengthAbstractWriter
Structured abstract writer for fixed-length lines.
Definition: FixedLengthUtil.qm.dox.h:649
FixedLengthUtil::FixedLengthDataWriter::constructor
constructor(hash specs, *hash opts)
Instantiates the FixedLengthDataWriter object.
FixedLengthUtil::FixedLengthAbstractWriter::formatLine
string formatLine(hash line)
Formats a single line from a hash describing the record type and its contents.
FixedLengthUtil::FixedLengthFileWriter::write
write(hash line)
Renders a single line for a single input record hash to the output file.
FixedLengthUtil::FixedLengthWriter
Writer for fixed-length line output data.
Definition: FixedLengthUtil.qm.dox.h:740
FixedLengthUtil::FixedLengthFileIterator::hstat
hash< Qore::StatInfo > hstat()
Returns a StatInfo hash of the underlying file.
FixedLengthUtil::FixedLengthAbstractIterator::constructor
constructor(AbstractLineIterator li, hash spec, *hash opts)
Instantiates the FixedLengthAbstractIterator object.
FixedLengthUtil::FixedLengthFileWriter::getFileName
string getFileName()
Return the file name (including path, if used)
Qore::InputStream
hash
hash hash(object obj)
FixedLengthUtil::FixedLengthFileWriter
Writer for fixed-length line output files.
Definition: FixedLengthUtil.qm.dox.h:869
FixedLengthUtil::FixedLengthFileIterator::m_file_path
string m_file_path
the path of the file being iterated
Definition: FixedLengthUtil.qm.dox.h:540
Qore::AbstractIterator
FixedLengthUtil::FixedLengthAbstractIterator::checkOptions
*hash checkOptions(*hash opts)
Validate and prepare global fixed-length options.