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 - 2016 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:
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
public:
constructor(hash spec, *hash opts);
abstract *string getLine();
*hash getValue();
any transform(any value, hash type);
private *hash checkOptions(*hash opts);
string identifyType(string input_line);
*string identifyTypeImpl(string input_line);
bool checkTransition(*string from, *string to);
};
class FixedLengthUtil::FixedLengthFileIterator : public FixedLengthUtil::FixedLengthAbstractIterator,public Qore::FileLineIterator {
public:
constructor(string file_name, hash spec, *hash opts) ;
private string getLine();
bool next();
};
class FixedLengthUtil::FixedLengthDataIterator : public FixedLengthUtil::FixedLengthAbstractIterator,public Qore::DataLineIterator {
public:
private :
int position;
int max_index;
list lines;
int lines_pos;
string data;
public:
constructor(string input_data, hash spec, *hash opts) ;
bool next();
};
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);
int linesCount();
string formatLine(hash line);
bool checkTransition(*string from, *string to);
};
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
Structured line iterator for abstract data allowing efficient "pipelined" processing.
Definition: FixedLengthUtil.qm.dox.h:313
FixedLengthUtil::EOL_UNIX
const EOL_UNIX
Unix end of line character sequence (for new OS X too)
Definition: FixedLengthUtil.qm.dox.h:298
FixedLengthUtil::EOL_WIN
const EOL_WIN
MS DOS/Windows end of line character sequence.
Definition: FixedLengthUtil.qm.dox.h:300
FixedLengthUtil::FixedLengthFileIterator::next
bool next()
Moves the current line / record position to the next line / record; returns False if there are no mor...
Qore::DataLineIterator
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::FixedLengthAbstractIterator::transform
any transform(any value, hash type)
parses the input value based on global configuration and the current field definition ...
FixedLengthUtil::FixedLengthFileIterator::constructor
constructor(string file_name, hash spec, *hash opts)
Instantiates the FixedLengthFileIterator object.
FixedLengthUtil::FixedLengthDataWriter
Writer class for fixed-length-line data.
Definition: FixedLengthUtil.qm.dox.h:766
FixedLengthUtil::FixedLengthDataIterator
Structured line iterator for fixed-length line strings allowing efficient "pipelined" processing...
Definition: FixedLengthUtil.qm.dox.h:492
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::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:432
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...
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:302
FixedLengthUtil::FixedLengthAbstractIterator::constructor
constructor(hash spec, *hash opts)
Instantiates the FixedLengthAbstractIterator object.
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:321
FixedLengthUtil::FixedLengthAbstractWriter::constructor
constructor(hash specs, *hash opts)
creates the FixedLengthAbstractWriter object
FixedLengthUtil::FixedLengthAbstractIterator::checkOptions
private *hash checkOptions(*hash opts)
Validate and prepare global fixed-length options.
FixedLengthUtil::FixedLengthFileWriter::constructor
constructor(string file_name, hash specs, *hash opts)
Instantiates the FixedLengthFileWriter object.
FixedLengthUtil
The FixedLengthUtil namespace contains all the definitions in the FixedLengthUtil module...
Definition: FixedLengthUtil.qm.dox.h:296
type
string type(any arg)
FixedLengthUtil::FixedLengthFileIterator::getLine
private string getLine()
returns a line
FixedLengthUtil::FixedLengthAbstractWriter
Structured abstract writer for fixed-length lines.
Definition: FixedLengthUtil.qm.dox.h:555
FixedLengthUtil::FixedLengthDataWriter::constructor
constructor(hash specs, *hash opts)
Instantiates the FixedLengthDataWriter object.
FixedLengthUtil::FixedLengthDataIterator::constructor
constructor(string input_data, hash spec, *hash opts)
Instantiates the FixedLengthFileIterator object.
FixedLengthUtil::FixedLengthAbstractWriter::formatLine
string formatLine(hash line)
Formats a single line from a hash describing the record type and its contents.
FixedLengthUtil::FixedLengthDataIterator::next
bool next()
Moves the current line / record position to the next line / record; returns False if there are no mor...
FixedLengthUtil::FixedLengthFileWriter::write
write(hash line)
Renders a single line for a single input record hash to the output file.
Qore::FileLineIterator
FixedLengthUtil::FixedLengthFileWriter::getFileName
string getFileName()
Return the file name.
hash
hash hash(object obj)
FixedLengthUtil::FixedLengthFileWriter
Writer for fixed-length-line output files.
Definition: FixedLengthUtil.qm.dox.h:644
Qore::AbstractIterator