Qore FixedLengthUtil Module Reference  1.0
FixedLengthUtil::FixedLengthDataIterator Class Reference

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

Inheritance diagram for FixedLengthUtil::FixedLengthDataIterator:

Public Member Functions

 constructor (string input_data, hash spec, *hash opts)
 Instantiates the FixedLengthFileIterator object. More...
 
bool next ()
 Moves the current line / record position to the next line / record; returns False if there are no more lines to iterate. More...
 
- Public Member Functions inherited from FixedLengthUtil::FixedLengthAbstractIterator
private *hash checkOptions (*hash opts)
 Validate and prepare global fixed-length options. More...
 
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 spec, *hash opts)
 Instantiates the FixedLengthAbstractIterator object. More...
 
*hash getValue ()
 Returns the current record as a hash. More...
 
string identifyType (string input_line)
 Identify a fixed-length line type using identifyTypeImpl(), that may be overridden if necessary. More...
 
*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. More...
 
any transform (any value, hash type)
 parses the input value based on global configuration and the current field definition
 

Detailed Description

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

Example:
1 string data = "00001AV\n00002BN\00003CZ\n";
2 
3 hash specs = (
4  "type1" : (
5  "col1": ("length": 5, "type": "int"),
6  "col2": ("length": 2, "type": "string"),
7  ),
8  "type2": (
9  "col3": ("length": 1, "type": "string"),
10  "col4": ("length": 3, "type": "string"),
11  "col5": ("length": 8, "type": "date", "format": "DDMMYYYY",
12  # "timezone" : "Europe/Prague", # use global if omitted
13  ),
14  ),
15 );
16 
17 hash global_options = (
18  "encoding" : "UTF-8",
19  "eol" : "\n",
20  "ignore_empty" : True,
21  "timezone" : "Europe/Prague", # used if not overridden in a date field specification
22 );
23 
24 FixedLengthDataIterator i(data, specs, global_options);
25 while (i.next()) {
26  operation_with_hash(i.getValue())
27 }

Member Function Documentation

FixedLengthUtil::FixedLengthDataIterator::constructor ( string  input_data,
hash  spec,
*hash  opts 
)

Instantiates the FixedLengthFileIterator object.

Example:
1 hash specs = (
2  "type1" : (
3  "col1": ("length": 5, "type": "int"),
4  "col2": ("length": 2, "type": "string"),
5  ),
6  "type2": (
7  "col3": ("length": 1, "type": "string"),
8  "col4": ("length": 3, "type": "string"),
9  "col5": ("length": 8, "type": "date", "format": "DDMMYYYY",
10  # "timezone" : "Europe/Prague", # use global if omitted
11  ),
12  ),
13 );
14 
15 hash global_options = (
16  "encoding" : "UTF-8",
17  "eol" : "\n",
18  "ignore_empty" : True,
19  "timezone" : "Europe/Prague", # used if not overridden in a date field specification
20 );
21 
22 FixedLengthDataIterator i(string, specs, global_options);
23 while (i.next()) {
24  operation_with_hash(i.getValue())
25 }
Parameters
input_dataThe input string to process
specFixed-length line specification; see Specification Hash for more information
optsGlobal options; see Global Options for valid values
bool FixedLengthUtil::FixedLengthDataIterator::next ( )
virtual

Moves the current line / record position to the next line / record; returns False if there are no more lines to iterate.

This method will return True again after it returns False once if the file being iterated has data that can be iterated, otherwise it will always return False. The iterator object should not be used to retrieve a value after this method returns False.

Returns
False if there are no lines / records to iterate (in which case the iterator object is invalid and should not be used); True if successful (meaning that the iterator object is valid)
Note
that empty lines are ignored if "ignore_empty" option is in effect

Reimplemented from Qore::DataLineIterator.