| Qore FixedLengthUtil Module Reference 1.6

Loading...
Searching...
No Matches
Public Member Functions | Protected Attributes | List of all members
FixedLengthUtil::FixedLengthFileIterator Class Reference

Structured line iterator for fixed-length line files allowing efficient "pipelined" processing. More...

`#include <FixedLengthFileIterator.qc.dox.h>`

Inheritance diagram for FixedLengthUtil::FixedLengthFileIterator:
[legend]

## Public Member Functions
| constructor (string path, hash< auto > spec, *hash< auto > opts)
| Instantiates the FixedLengthFileIterator object.
string | getEncoding ()
| Returns the character encoding for the file.
string | getFileName ()
| Returns the file path/name used to open the file.
hash< Qore::StatInfo > | hstat ()
| Returns a StatInfo hash of the underlying file.
list< auto > | stat ()
| Returns a stat list of the underlying file.
Public Member Functions inherited from FixedLengthUtil::FixedLengthAbstractIterator
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.
| constructor (AbstractLineIterator li, hash< auto > spec, *hash< auto > opts)
| Instantiates the FixedLengthAbstractIterator object.
*hash< auto > | getValue ()
| Returns the current record as a hash.
bool | identifyRecord (list< auto > rec_rule, string input_line)
| Attempts to identify a single record.
string | identifyType (string input_line)
| Identify a fixed-length line type using identifyTypeImpl(), that may be overridden if necessary.
*string | identifyTypeImpl (string input_line)
| Identify a fixed-length line type, given the raw line string. This method performs a lookup to a precalculated table based on line lengths (see constructor()). In case different criteria are needed, eg. when two line types in a spec have the same length and no unique resolving rule are specified, this method needs to be overridden, and will throw an exception, because the precalculated mapping will be empty.
bool | next ()
| Moves the current line / record position to the next line / record; returns False if there are no more lines to iterate.
auto | transform (auto value, hash< auto > type)
| parses the input value based on global configuration and the current field definition
Public Member Functions 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.

## Protected Attributes
string | m_file_path
| the path of the file being iterated
Protected Attributes inherited from FixedLengthUtil::FixedLengthAbstractIterator
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
Protected 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.

## Additional Inherited Members
Static Protected Member Functions inherited from FixedLengthUtil::FixedLengthAbstractIterator
static *hash< auto > | checkOptions (*hash< auto > opts)
| Validate and prepare global fixed-length options.

## Detailed Description

Structured line iterator for fixed-length line files allowing efficient "pipelined" processing.

Example:
  #!/usr/bin/env qore
  %new-style
  %enable-all-warnings
  %require-types
  %strict-args
  %requires FixedLengthUtil
  hash<auto> specs = {
  "type1": {
  "col1": {"length": 5, "type": "int"},
  "col2": {"length": 2, "type": "string"},
  },
  "type2": {
  "col3": {"length": 1, "type": "string"},
  "col4": {"length": 3, "type": "string"},
  "col5": {"length": 8, "type": "date", "format": "DDMMYYYY", "timezone": "Europe/Prague"},
  },
  };
  hash<auto> global_options = {
  "encoding" : "UTF-8",
  "eol" : "\n",
  "ignore_empty": True,
  "timezone" : "Europe/Prague", # used if not overridden in a date field specification
  };
  FixedLengthFileIterator i(file, specs, global_options);
  # output all records
  map printf("%y\n", $1), i;

See also
  - FixedLengthIterator for a stream-based class providing the same functionality as this class in a more generic way

## Member Function Documentation

## ◆ constructor()

FixedLengthUtil::FixedLengthFileIterator::constructor | ( | string | path,
|  | hash< auto > | spec,
|  | *hash< auto > | opts )

Instantiates the FixedLengthFileIterator object.

Parameters

  path | File path to read
  spec | Fixed-length line specification; see Specification Hash for more information
  opts | Global options; see Global Options for more information