Qore Mapper Module Reference  1.4
Mapper.qm.dox.h
1 // -*- mode: c++; indent-tabs-mode: nil -*-
3 
4 /* Mapper.qm Copyright 2014 - 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 // require type definitions everywhere
28 
29 // enable all warnings
30 
31 // do not use "$" for vars
32 
33 
34 /* Version History
35 */
36 
248 namespace Mapper {
251  class Mapper {
252 
253 public:
254  public :
256  const ConstantConflictList = ("name", "struct", "code", "default");
257 
259  const OptionKeys = (
260  "allow_dot": "allows input fields to have a dot in their name without implying a structured format",
261  "allow_output_dot": "allows output fields to have a dot in their name without implying a structured format",
262  "date_format": "gives the default format for parsing dates from strings; ex: \"MM/DD/YYYY HH:mm:SS\"",
263  "encoding": "gives the default output character encoding for string fields",
264  "info_log": "a call reference / closure for informational logging",
265  "input": "a hash describing the input record",
266  "input_log": "a call reference / closure for input record logging",
267  "input_timezone": "the default timezone to assume when parsing input dates",
268  "name": "the name of the Mapper object",
269  "number_format": "the default number format when parsing number fields from strings; ex: \".,\"",
270  "output": "a hash describing the output record",
271  "output_log": "a call reference / closure for input record logging",
272  "timezone": "the default output timezone for date/time values",
273  "runtime": "runtime options as a hash (see also setRuntime(), replaceRuntime())",
274  "empty_strings_to_nothing": "converts out record's empty strings and into NOTHING - actually the value is deleted",
275  );
276 
278  const ValidKeys = (
279  "name": True,
280  "struct": True,
281  "constant": True,
282  "index" : True,
283  "code": True,
284  "default": True,
285  "maxlen": True,
286  "trunc": True,
287  "mand": True,
288  "number": True,
289  "type": True,
290  "date_format": True,
291  "number_format": True,
292  "runtime" : True,
293  "empty_strings_to_nothing" : True,
294  );
295 
297  const ValidTypes = (
298  "number": True,
299  "integer": True,
300  "int": True, // is an alias for "integer"
301  "date": True,
302  "string": True,
303  );
304 
306  const OutputKeys = (
307  "desc": True,
308  "mand": True,
309  "maxlen": True,
310  "type": True,
311  );
312 
313 public:
314 
315  private :
318 
321 
324 
326  string encoding = "utf-8";
327 
329  *string name;
330 
332  *code info_log;
333 
335  *code input_log;
336 
338  *code output_log;
339 
342 
344  Qore::TimeZone input_timezone = TimeZone::get();
345 
347  bool trunc_all = False;
348 
350  bool allow_dot = False;
351 
353  bool allow_output_dot = False;
354 
356  *string date_format;
357 
359  *string number_format;
360 
363 
366 
368  int count = 0;
369 
371 
374 
376 
378  bool m_empty_strings_to_nothing = False;
379 
382 
385 
388 
391 
392 public:
393 
395 
418  constructor(hash mapv, *hash opts);
419 
420 
422 
423 private:
424  constructor();
425 public:
426 
427 
429 
430 private:
431  setup(hash mapv, *hash opts);
432 public:
433 
434 
436 
437 private:
438  checkMap();
439 public:
440 
441 
443 
444 private:
445  convertToHash(int t, string k, reference<any> fh);
446 public:
447 
448 
450 
451 private:
452  checkInputField(string k, string name);
453 public:
454 
455 
457 
461 private:
462  checkMapField(string k, reference<any> fh);
463 public:
464 
465 
467 
468 private:
469  checkTimezoneOption(hash opts, string rn);
470 public:
471 
472 
474 
492  setRuntime(string key, auto value);
493 
494 
496 
514  setRuntime(hash runtime);
515 
516 
518 
536  replaceRuntime(*hash runtime);
537 
538 
540 
551  auto getRuntime(string key);
552 
553 
555  string getFieldName(string fname);
556 
557 
559 
561  hash validKeys();
562 
563 
565 
567  hash validTypes();
568 
569 
571 
573  hash optionKeys();
574 
575 
577  *hash getInputRecord();
578 
579 
581  *hash getOutputRecord();
582 
583 
585 
594  list<hash> mapAll(list recs);
595 
596 
598 
607  list<hash> mapAll(hash recs);
608 
609 
611 
623  hash mapData(hash rec);
624 
625 
627 
640 private:
641  hash mapDataIntern(hash rec);
642 public:
643 
644 
646 
673 private:
674  nothing mapFieldIntern(reference<hash> h, string key, hash rec, bool do_list, int list_size);
675 public:
676 
677 
679 
680 private:
681  string truncateField(string k, string val, int ix, int sze, int maxlen);
682 public:
683 
684 
686 
687 private:
688  fieldLengthError(string k, string val, int ix, int sze, int maxlen, hash rc);
689 public:
690 
691 
693  logOutput(hash h);
694 
695 
697 
699  int getCount();
700 
701 
703 
705  resetCount();
706 
707 
709 
710 private:
711  mapFieldType(string key, hash m, reference<any> v, hash rec);
712 public:
713 
714 
716 
719 private:
720  error(string fmt);
721 public:
722 
723 
725 
726 private:
727  error2(string ex, string fmt);
728 public:
729 
730 
732 
733 private:
734  auto mapSubclass(hash m, auto v);
735 public:
736 
737  };
738 
741 
742 public:
743  public :
744 
745 public:
746 
747  private :
750 
751 public:
752 
754 
757 
758 
760  bool next();
761 
762 
764  bool valid();
765 
766 
768  bool hasBulk();
769 
770 
772 
776  list<hash> mapBulk(int size);
777 
778  };
779 
782 
783 public:
784  public :
785 
786 public:
787 
788  private :
791 
792 public:
793 
795 
802 
803 
805 
809 
810 
812  hash getValue();
813 
814 
816 
818  int getCount();
819 
820 
822 
824  resetCount();
825 
826  };
827 };
Qore::AbstractIterator i
input iterator; AbstractIterator::getValue() must return a hash
Definition: Mapper.qm.dox.h:749
abstract any getValue()
*string date_format
the global date format for parsing dates
Definition: Mapper.qm.dox.h:356
Mapper::Mapper mapc
data mapper
Definition: Mapper.qm.dox.h:790
hash mapd
the hash with a subset of the mappings used dynamically
Definition: Mapper.qm.dox.h:320
bool next()
Moves the current position of the iterator to the next element; returns False if there are no more el...
const True
hash consth
map of constant fields
Definition: Mapper.qm.dox.h:387
*code output_log
an optional output data logging callback; must accept a hash giving the output data hash ...
Definition: Mapper.qm.dox.h:338
*code info_log
an optional info logging callback; must accept a sprintf()-style format specifier and optional argume...
Definition: Mapper.qm.dox.h:332
provides a hash iterator based on a mapper object and an iterator input source
Definition: Mapper.qm.dox.h:781
const False
this class is a base class for mapping data; see Mapper Examples for usage examples ...
Definition: Mapper.qm.dox.h:251
list list(...)
hash mapc
the hash providing output field names and mappings
Definition: Mapper.qm.dox.h:317
hash mapo
the hash of output records for key order
Definition: Mapper.qm.dox.h:323
list< hash > mapBulk(int size)
performs bulk mapping; if the iterator does not support bulk mapping then it is simulated in this met...
*string number_format
the global number format for parsing numbers
Definition: Mapper.qm.dox.h:359
abstract base class for hash iterator mappping classes based on a mapper object and an iterator input...
Definition: Mapper.qm.dox.h:740
*list identl
list of fields to be mapped 1:1 input -> output
Definition: Mapper.qm.dox.h:384
hash identh
map of fields to be mapped 1:1 input -> output
Definition: Mapper.qm.dox.h:381
*Qore::TimeZone timezone
an optional timezone for output date fields
Definition: Mapper.qm.dox.h:341
constructor(Qore::AbstractIterator iter)
creates the iterator from the arguments passed
*hash output
an optional description of the output data structure
Definition: Mapper.qm.dox.h:365
the Mapper namespace contains all the definitions in the Mapper module
Definition: Mapper.qm.dox.h:249
bool hasBulk()
returns True if the iterator supports bulk mode; this method returns False (the default) ...
*string name
the optional name for the object (for example a table name); will be prepended to field names in erro...
Definition: Mapper.qm.dox.h:329
*hash input
an optional description of possible input hash keys
Definition: Mapper.qm.dox.h:362
*code input_log
an optional input data logging callback; must accept a hash giving the input data hash ...
Definition: Mapper.qm.dox.h:335
hash hash(object obj)
hash rconsth
map of constant runtime fields
Definition: Mapper.qm.dox.h:390
bool valid()
returns True if the iterator is currently pointing at a valid element, False if not ...
*hash m_runtime
current runtime values
Definition: Mapper.qm.dox.h:373