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
stat
*list stat(string path)
FixedLengthUtil::FixedLengthWriter::output
StreamWriter output
the output stream for the fixed-length data
Definition: FixedLengthUtil.qm.dox.h:745
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::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::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::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...
list
list list(...)
hstat
*hash< StatInfo > hstat(string path)
FixedLengthUtil::EOL_MACINTOSH
const EOL_MACINTOSH
Old (pre-OSX) Macintosh end of line character sequence.
Definition: FixedLengthUtil.qm.dox.h:328
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::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
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::FixedLengthWriter
Writer for fixed-length line output data.
Definition: FixedLengthUtil.qm.dox.h:740
FixedLengthUtil::FixedLengthAbstractIterator::constructor
constructor(AbstractLineIterator li, hash spec, *hash opts)
Instantiates the FixedLengthAbstractIterator object.
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.