Qore FixedLengthUtil Module Reference  1.0
 All Classes Namespaces Functions Variables Groups Pages
FixedLengthUtil.qm.dox.h
1 // -*- mode: c++; indent-tabs-mode: nil -*-
2 // @file FixedLengthUtil.qm Qore user module for working with files with fixed lines length
3 
4 /* FixedLengthUtil.qm Copyright 2015 - 2016 Qore Technologies, s.r.o.
5 
6  Permission is hereby granted, free of charge, to any person obtaining a
7  copy of this software and associated documentation files (the "Software"),
8  to deal in the Software without restriction, including without limitation
9  the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  and/or sell copies of the Software, and to permit persons to whom the
11  Software is furnished to do so, subject to the following conditions:
12 
13  The above copyright notice and this permission notice shall be included in
14  all copies or substantial portions of the Software.
15 
16  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  DEALINGS IN THE SOFTWARE.
23 */
24 
25 // minimum required Qore version
26 
27 
28 /* see release notes below for version history
29 */
30 
295 namespace FixedLengthUtil {
298  const EOL_UNIX = "\n";
300  const EOL_WIN = "\r\n";
302  const EOL_MACINTOSH = "\r";
303 
304  // helper hash (for O(ln(n)) lookups in the worst case) of end of line values
305  const EOLS = (
306  EOL_UNIX: True,
307  EOL_WIN: True,
309  );
310 };
311 
314 
315 public:
316  private :
317  hash m_specs;
318  hash m_resolve_by_rule;
319  string m_state;
322  *hash m_opts; // encoding, eol, ignore_empty, timezone, etc
323 
324 public:
325 
327 
333  constructor(hash spec, *hash opts);
334 
335 
336  abstract *string getLine();
337 
339 
348  *hash getValue();
349 
350 
352  any transform(any value, hash type);
353 
354 
356 
359  private *hash checkOptions(*hash opts);
360 
361 
363 
370  string identifyType(string input_line);
371 
372 
374 
381  *string identifyTypeImpl(string input_line);
382 
383 
385 
389  bool checkTransition(*string from, *string to);
390 
391 };
392 
394 
433 
434 public:
436 
441  constructor(string file_name, hash spec, *hash opts) ;
442 
443 
445  private string getLine();
446 
447 
449 
454  bool next();
455 
456 };
457 
458 
460 
493 
494 public:
495  private :
496  int position;
497  int max_index;
498 
499  list lines;
500  int lines_pos;
501 
502  string data;
503 
504 public:
505 
507 
540  constructor(string input_data, hash spec, *hash opts) ;
541 
542 
544 
549  bool next();
550 
551 };
552 
553 
556 
557 public:
558  private :
559  hash m_specs;
560  string m_state;
561  int m_linescount = 0;
562  *hash m_opts;
563 
564 public:
565 
567 
571  constructor(hash specs, *hash opts);
572 
573 
574  private *hash checkOptions(*hash opts);
575 
576 
578  int linesCount();
579 
580 
582 
592  string formatLine(hash line);
593 
594 
596 
600  bool checkTransition(*string from, *string to);
601 
602 };
603 
605 
645 
646 public:
647  private :
648  string file;
649  File m_file();
650 
651 public:
652 
654 
659  constructor(string file_name, hash specs, *hash opts) ;
660 
661 
663  string getFileName();
664 
665 
667 
696  write(hash line);
697 
698 
700 
714  write(list lines);
715 
716 
718 
733 
734 };
735 
736 
738 
767 
768 public:
770 
774  constructor(hash specs, *hash opts) ;
775 
776 
778 
794  string write(list lines);
795 
796 
798 
829  string write(hash line);
830 
831 
833 
849  string write(Qore::AbstractIterator lines);
850 
851 };
Structured line iterator for abstract data allowing efficient "pipelined" processing.
Definition: FixedLengthUtil.qm.dox.h:313
const EOL_UNIX
Unix end of line character sequence (for new OS X too)
Definition: FixedLengthUtil.qm.dox.h:298
const EOL_WIN
MS DOS/Windows end of line character sequence.
Definition: FixedLengthUtil.qm.dox.h:300
bool next()
Moves the current line / record position to the next line / record; returns False if there are no mor...
string write(list lines)
iterates the input records and returns a string corresponding to the rendered versions of all input r...
any transform(any value, hash type)
parses the input value based on global configuration and the current field definition ...
constructor(string file_name, hash spec, *hash opts)
Instantiates the FixedLengthFileIterator object.
Writer class for fixed-length-line data.
Definition: FixedLengthUtil.qm.dox.h:766
Structured line iterator for fixed-length line strings allowing efficient "pipelined" processing...
Definition: FixedLengthUtil.qm.dox.h:492
*hash getValue()
Returns the current record as a hash.
const True
string identifyType(string input_line)
Identify a fixed-length line type using identifyTypeImpl(), that may be overridden if necessary...
bool checkTransition(*string from, *string to)
A verification function to be called for each line. This method can be overridden to achieve a begin-...
Structured line iterator for fixed-length line files allowing efficient "pipelined" processing...
Definition: FixedLengthUtil.qm.dox.h:432
bool checkTransition(*string from, *string to)
A verification function to be called for each line. This method can be overridden to achieve a begin-...
*string identifyTypeImpl(string input_line)
Identify a fixed-length line type, given the raw line string. This method performs a lookup to a prec...
int linesCount()
get processed lines count
list list(...)
const EOL_MACINTOSH
Old (pre-OSX) Macintosh end of line character sequence.
Definition: FixedLengthUtil.qm.dox.h:302
constructor(hash spec, *hash opts)
Instantiates the FixedLengthAbstractIterator object.
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
constructor(hash specs, *hash opts)
creates the FixedLengthAbstractWriter object
private *hash checkOptions(*hash opts)
Validate and prepare global fixed-length options.
constructor(string file_name, hash specs, *hash opts)
Instantiates the FixedLengthFileWriter object.
string type(any arg)
private string getLine()
returns a line
Structured abstract writer for fixed-length lines.
Definition: FixedLengthUtil.qm.dox.h:555
constructor(hash specs, *hash opts)
Instantiates the FixedLengthDataWriter object.
constructor(string input_data, hash spec, *hash opts)
Instantiates the FixedLengthFileIterator object.
string formatLine(hash line)
Formats a single line from a hash describing the record type and its contents.
bool next()
Moves the current line / record position to the next line / record; returns False if there are no mor...
write(hash line)
Renders a single line for a single input record hash to the output file.
string getFileName()
Return the file name.
hash hash(object obj)
Writer for fixed-length-line output files.
Definition: FixedLengthUtil.qm.dox.h:644