Qore FixedLengthUtil Module Reference 1.5
Loading...
Searching...
No Matches
FixedLengthUtil::FixedLengthDataWriter Class Reference

Writer class for fixed-length line string data. More...

#include <FixedLengthDataWriter.qc.dox.h>

Inheritance diagram for FixedLengthUtil::FixedLengthDataWriter:
[legend]

Public Member Methods

 constructor (hash< auto > specs, *hash< auto > opts)
 Instantiates the FixedLengthDataWriter object. More...
 
string write (hash< auto > line)
 Return a single line for a single input record hash. More...
 
string write (list< auto > lines)
 iterates the input records and returns a string corresponding to the rendered versions of all input records More...
 
string write (Qore::AbstractIterator lines)
 iterates the input records and returns a string corresponding to the rendered versions of all input records More...
 
- Public Member Methods inherited from FixedLengthUtil::FixedLengthAbstractWriter
bool checkTransition (*string from, *string to)
 A verification function to be called for each line. This method can be overridden to achieve a begin-to-end validation of the whole input file. More...
 
 constructor (hash< auto > specs, *hash< auto > opts)
 creates the FixedLengthAbstractWriter object More...
 
string formatLine (hash< auto > line)
 Formats a single line from a hash describing the record type and its contents. More...
 
int linesCount ()
 get processed lines count
 
abstract write (hash< auto > line)
 Renders a single line for a single input record hash to the output. More...
 
abstract write (list< auto > lines)
 iterates the input records and writes rendered versions of all input records to the output More...
 
abstract write (Qore::AbstractIterator lines)
 iterates the input records and writes rendered versions of all input records to the output More...
 
- Public Member Methods inherited from FixedLengthUtil::FixedLengthBase
 constructor (hash< auto > m_specs, *hash< auto > m_opts)
 Creates the object from the record specifications.
 
*hash< string, AbstractDataField > getRecordType ()
 Returns the description of the record type, if any.
 

Additional Inherited Members

- Private Attributes inherited from FixedLengthUtil::FixedLengthBase
const GlobalOptionMap
 Translates from global options to data provider options.
 
*hash< auto > m_opts
 Global input or output options.
 
hash< auto > m_specs
 The record specifications.
 

Detailed Description

Writer class for fixed-length line string data.

Example:
const Spec = {
"header": {
"flow_type": {"length": 3, "type": "string", "value": "001"},
"record_type": {"length": 3, "type": "int", "padding_char": "0"},
"number_of_records": {"length": 8, "type": "int", "padding_char": "0"},
},
"line": {
"flow_type": {"length": 3, "type": "string"},
"record_type": {"length": 3, "type": "int", "padding_char": "0"},
"processing_id": {"length": 10, "type": "int", "padding_char": "0"},
"processing_name": {"length": 10, "type": "string"},
"po_number": {"length": 10, "type": "int", "padding_char": "0"},
},
"trailer": {
"flow_type": {"length": 3, "type": "string", "value": "003"},
"record_type": {"length": 3, "type": "int", "padding_char": "0"},
"number_of_records": {"length": 8, "type": "int", "padding_char": "0"},
},
};
FixedLengthDataWriter w(Spec);
AbstractIterator i = get_record_iterator();
string data = w.write(i);
See also
  • FixedLengthWriter for a stream-based class providing the same functionality as this class in a more generic way

Member Function Documentation

◆ constructor()

FixedLengthUtil::FixedLengthDataWriter::constructor ( hash< auto >  specs,
*hash< auto >  opts 
)

Instantiates the FixedLengthDataWriter object.

Parameters
specsFixed-length line specification; see Specification Hash for more information
optsGlobal formatting options; see Global Options for valid values

◆ write() [1/3]

string FixedLengthUtil::FixedLengthDataWriter::write ( hash< auto >  line)
virtual

Return a single line for a single input record hash.

Example:
const Spec = (
"header": (
"flow_type": ("length": 3, "type": "string"),
"record_type": ("length": 3, "type": "int", "padding_char": "0"),
"number_of_records": ("length": 8, "type": "int", "padding_char": "0"),
),
);
hash hh = (
"type": "header",
"record": (
"flow_type": "WTS",
"record_type": "950",
"number_of_records": 1,
),
);
FixedLengthDataWriter w(Spec);
string line = w.write(hh);
Parameters
lineA hash representing input data to be rendered as a string; the hash must have the following keys:
  • "type": a string giving the record type (must be defined in Specification Hash given in the constructor)
  • "record": a hash giving the input record to be rendered (with keys as defined in the Record Description Hash for the record identified by the type argument)
Returns
a single line for a single input record hash
Exceptions
INVALID-RECORDrecord name (type key in the record hash) not recognized
FIELD-INPUT-ERRORthe input value is too large to render into the output field
RECORD-TRANSITION-ERRORa record transition error occurred; an invalid record sequence was given in the input data

Implements FixedLengthUtil::FixedLengthAbstractWriter.

◆ write() [2/3]

string FixedLengthUtil::FixedLengthDataWriter::write ( list< auto >  lines)
virtual

iterates the input records and returns a string corresponding to the rendered versions of all input records

Example:
FixedLengthDataWriter w(Spec);
string file = w.write(input_list);
Parameters
linesAn iterator to stream input records; each iterator value must be a hash with the following keys:
  • "type": a string giving the record type (must be defined in Specification Hash given in the constructor)
  • "record": a hash giving the input record to be rendered (with keys as defined in the Record Description Hash for the record identified by the type argument)
Returns
the rendered string for all input records
Exceptions
INVALID-RECORDrecord name (type key in the record hash) not recognized
FIELD-INPUT-ERRORthe input value is too large to render into the output field
RECORD-TRANSITION-ERRORa record transition error occurred; an invalid record sequence was given in the input data

Implements FixedLengthUtil::FixedLengthAbstractWriter.

◆ write() [3/3]

string FixedLengthUtil::FixedLengthDataWriter::write ( Qore::AbstractIterator  lines)
virtual

iterates the input records and returns a string corresponding to the rendered versions of all input records

Example:
FixedLengthDataWriter w(Spec);
string file = w.write(i);
Parameters
linesAn iterator to stream input records; each iterator value must be a hash with the following keys:
  • "type": a string giving the record type (must be defined in Specification Hash given in the constructor)
  • "record": a hash giving the input record to be rendered (with keys as defined in the Record Description Hash for the record identified by the type argument)
Returns
the rendered string for all input records
Exceptions
INVALID-RECORDrecord name (type key in the record hash) not recognized
FIELD-INPUT-ERRORthe input value is too large to render into the output field
RECORD-TRANSITION-ERRORa record transition error occurred; an invalid record sequence was given in the input data

Implements FixedLengthUtil::FixedLengthAbstractWriter.