Qore FixedLengthUtil Module Reference  1.1
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 - 2017 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 
321 namespace FixedLengthUtil {
324  const EOL_UNIX = "\n";
326  const EOL_WIN = "\r\n";
328  const EOL_MACINTOSH = "\r";
329 
330  // helper hash (for O(ln(n)) lookups in the worst case) of end of line values
331  const EOLS = (
332  EOL_UNIX: True,
333  EOL_WIN: True,
335  );
336 };
337 
340 
341 public:
342  private :
343  hash m_specs;
344  hash m_resolve_by_rule;
345  string m_state;
348  *hash m_opts; // encoding, eol, ignore_empty, timezone, etc
349  AbstractLineIterator lineIterator;
350 
351 public:
352 
354 
361  constructor(AbstractLineIterator li, hash spec, *hash opts);
362 
363 
364  bool valid();
365 
366 
368 
373  bool next();
374 
375 
376  string getLine();
377 
378 
380 
389  *hash getValue();
390 
391 
392  int index();
393 
394 
396  auto transform(auto value, hash type);
397 
398 
400 
404 private:
405  *hash checkOptions(*hash opts);
406 public:
407 
408 
410 
417  string identifyType(string input_line);
418 
419 
421 
428  *string identifyTypeImpl(string input_line);
429 
430 
432 
436  bool checkTransition(*string from, *string to);
437 
438 };
439 
442 
443 public:
445 
450 
451 
453 
489  constructor(Qore::InputStream input, string encoding = "UTF-8", hash spec, *hash opts) ;
490 
491 };
492 
494 
536 
537 public:
538  private :
540  string m_file_path;
541 
542 public:
543 
545 
550  constructor(string path, hash spec, *hash opts) ;
551 
552 
554  string getEncoding();
555 
556 
558  string getFileName();
559 
560 
562  hash<Qore::StatInfo> hstat();
563 
564 
566  list stat();
567 
568 };
569 
571 
607 
608 public:
609 
611 
644  constructor(string data, hash spec, *hash opts) ;
645 
646 };
647 
650 
651 public:
652  private :
653  hash m_specs;
654  string m_state;
655  int m_linescount = 0;
656  *hash m_opts;
657 
658 public:
659 
661 
665  constructor(hash specs, *hash opts);
666 
667 
668 
669 private:
670  *hash checkOptions(*hash opts);
671 public:
672 
673 
675  int linesCount();
676 
677 
679 
689  string formatLine(hash line);
690 
691 
693 
697  bool checkTransition(*string from, *string to);
698 
699 };
700 
702 
741 
742 public:
743  private :
745  StreamWriter output;
746 
747 public:
748 
750 
755  constructor(Qore::OutputStream output, hash specs, *hash opts) ;
756 
757 
759 
788  write(hash line);
789 
790 
792 
806  write(list lines);
807 
808 
810 
824  write(Qore::AbstractIterator lines);
825 
826 };
827 
829 
870 
871 public:
872  private :
874  string file;
876  File m_file();
877 
878 public:
879 
881 
886  constructor(string file_name, hash specs, *hash opts) ;
887 
888 
890  string getFileName();
891 
892 
894 
923  write(hash line);
924 
925 
927 
941  write(list lines);
942 
943 
945 
959  write(Qore::AbstractIterator lines);
960 
961 };
962 
964 
994 
995 public:
997 
1001  constructor(hash specs, *hash opts) ;
1002 
1003 
1005 
1021  string write(list lines);
1022 
1023 
1025 
1056  string write(hash line);
1057 
1058 
1060 
1076  string write(Qore::AbstractIterator lines);
1077 
1078 };
auto transform(auto value, hash type)
parses the input value based on global configuration and the current field definition ...
Structured line iterator for abstract data allowing efficient "pipelined" processing.
Definition: FixedLengthUtil.qm.dox.h:339
const EOL_UNIX
Unix end of line character sequence (for new OS X too)
Definition: FixedLengthUtil.qm.dox.h:324
const EOL_WIN
MS DOS/Windows end of line character sequence.
Definition: FixedLengthUtil.qm.dox.h:326
*list stat(string path)
StreamWriter output
the output stream for the fixed-length data
Definition: FixedLengthUtil.qm.dox.h:745
string file
file name
Definition: FixedLengthUtil.qm.dox.h:874
Writer class for fixed-length line string data.
Definition: FixedLengthUtil.qm.dox.h:993
Structured line iterator for fixed-length line strings allowing efficient "pipelined" processing...
Definition: FixedLengthUtil.qm.dox.h:606
*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...
Structured line iterator for fixed-length line files allowing efficient "pipelined" processing...
Definition: FixedLengthUtil.qm.dox.h:535
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...
list list(...)
*hash< StatInfo > hstat(string path)
const EOL_MACINTOSH
Old (pre-OSX) Macintosh end of line character sequence.
Definition: FixedLengthUtil.qm.dox.h:328
bool next()
Moves the current line / record position to the next line / record; returns False if there are no mor...
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:347
The FixedLengthIterator class allows CSV sources to be iterated on a record basis. The source of the input data is an AbstractLineIterator object or an InputStream.
Definition: FixedLengthUtil.qm.dox.h:441
The FixedLengthUtil namespace contains all the definitions in the FixedLengthUtil module...
Definition: FixedLengthUtil.qm.dox.h:322
string type(auto arg)
Structured abstract writer for fixed-length lines.
Definition: FixedLengthUtil.qm.dox.h:649
Writer for fixed-length line output data.
Definition: FixedLengthUtil.qm.dox.h:740
constructor(AbstractLineIterator li, hash spec, *hash opts)
Instantiates the FixedLengthAbstractIterator object.
hash hash(object obj)
Writer for fixed-length line output files.
Definition: FixedLengthUtil.qm.dox.h:869
string m_file_path
the path of the file being iterated
Definition: FixedLengthUtil.qm.dox.h:540
*hash checkOptions(*hash opts)
Validate and prepare global fixed-length options.