Qore Mapper Module Reference  1.1
Mapper.qm.dox.h
1 // -*- mode: c++; indent-tabs-mode: nil -*-
3 
4 /* Mapper.qm Copyright 2014 - 2016 Qore Technologies, sro
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 
237 namespace Mapper {
240  class Mapper {
241 
242 public:
243  public :
245  const ConstantConflictList = ("name", "struct", "code", "default");
246 
248  const OptionKeys = (
249  "date_format": "gives the default format for parsing dates from strings; ex: \"MM/DD/YYYY HH:mm:SS\"",
250  "encoding": "gives the default output character encoding for string fields",
251  "info_log": "a call reference / closure for informational logging",
252  "input": "a hash describing the input record",
253  "input_log": "a call reference / closure for input record logging",
254  "input_timezone": "the default timezone to assume when parsing input dates",
255  "name": "the name of the Mapper object",
256  "number_format": "the default number format when parsing number fields from strings; ex: \".,\"",
257  "output": "a hash describing the output record",
258  "output_log": "a call reference / closure for input record logging",
259  "timezone": "the default output timezone for date/time values",
260  "runtime": "runtime options as a hash (see also setRuntime(), replaceRuntime())",
261  "empty_strings_to_nothing": "converts out record's empty strings and into NOTHING - actually the value is deleted",
262  );
263 
265  const ValidKeys = (
266  "name": True,
267  "struct": True,
268  "constant": True,
269  "index" : True,
270  "code": True,
271  "default": True,
272  "maxlen": True,
273  "trunc": True,
274  "mand": True,
275  "number": True,
276  "type": True,
277  "date_format": True,
278  "number_format": True,
279  "runtime" : True,
280  "empty_strings_to_nothing" : True,
281  );
282 
284  const ValidTypes = (
285  "number": True,
286  "integer": True,
287  "int": True, // is an alias for "integer"
288  "date": True,
289  "string": True,
290  );
291 
293  const OutputKeys = (
294  "desc": True,
295  "mand": True,
296  "maxlen": True,
297  "type": True,
298  );
299 
300 public:
301 
302  private :
305 
307  string encoding = "utf-8";
308 
310  *string name;
311 
313  *code info_log;
314 
316  *code input_log;
317 
319  *code output_log;
320 
323 
325  Qore::TimeZone input_timezone = TimeZone::get();
326 
328  bool trunc_all = False;
329 
331  bool allow_dot = False;
332 
334  bool allow_output_dot = False;
335 
337  *string date_format;
338 
340  *string number_format;
341 
344 
347 
349  int count = 0;
350 
352 
355 
357 
359  bool m_empty_strings_to_nothing = False;
360 
361 public:
362 
364 
387  constructor(hash mapv, *hash opts);
388 
389 
391  private constructor();
392 
393 
395  private setup(hash mapv, *hash opts);
396 
397 
399  private checkMap();
400 
401 
403  private convertToHash(int t, string k, reference fh);
404 
405 
407  private checkInputField(string k, string name);
408 
409 
411 
414  private checkMapField(string k, reference fh, *hash th);
415 
416 
418  private checkTimezoneOption(hash opts, string rn);
419 
420 
422 
433  setRuntime(string key, any value);
434 
435 
437 
447  setRuntime(hash runtime);
448 
449 
451 
461  replaceRuntime(*hash runtime);
462 
463 
465 
476  any getRuntime(string key);
477 
478 
480  string getFieldName(string fname);
481 
482 
484 
486  hash validKeys();
487 
488 
490 
492  hash validTypes();
493 
494 
496 
498  hash optionKeys();
499 
500 
502  *hash getInputRecord();
503 
504 
506  *hash getOutputRecord();
507 
508 
510 
519  list mapAll(list recs);
520 
521 
523 
532  list mapAll(hash recs);
533 
534 
536 
548  hash mapData(hash rec);
549 
550 
552 
564  private hash mapDataIntern(hash rec);
565 
566 
568  logOutput(hash h);
569 
570 
572 
574  int getCount();
575 
576 
578 
580  resetCount();
581 
582 
584  private mapFieldType(string key, hash m, reference v, hash rec);
585 
586 
588 
590  private error(string fmt);
591 
592 
594  private error2(string ex, string fmt);
595 
596 
598  private any mapSubclass(hash m, any v);
599 
600  };
601 
604 
605 public:
606  public :
607 
608 public:
609 
610  private :
613 
614 public:
615 
617 
621 
622 
624  bool next();
625 
626 
628  bool valid();
629 
630 
632  bool hasBulk();
633 
634 
636 
640  list mapBulk(int size);
641 
642  };
643 
646 
647 public:
648  public :
649 
650 public:
651 
652  private :
655 
656 public:
657 
659 
666 
667 
669 
673 
674 
676  hash getValue();
677 
678 
680 
682  int getCount();
683 
684 
686 
688  resetCount();
689 
690  };
691 };
Qore::AbstractIterator i
input iterator; AbstractIterator::getValue() must return a hash
Definition: Mapper.qm.dox.h:612
*string date_format
the global date format for parsing dates
Definition: Mapper.qm.dox.h:337
Mapper::Mapper mapc
data mapper
Definition: Mapper.qm.dox.h:654
bool next()
Moves the current position of the iterator to the next element; returns False if there are no more el...
const True
list mapBulk(int size)
performs bulk mapping; if the iterator does not support bulk mapping then it is simulated in this met...
*code output_log
an optional output data logging callback; must accept a hash giving the output data hash ...
Definition: Mapper.qm.dox.h:319
*code info_log
an optional info logging callback; must accept a sprintf()-style format specifier and optional argume...
Definition: Mapper.qm.dox.h:313
provides a hash iterator based on a mapper object and an iterator input source
Definition: Mapper.qm.dox.h:645
const False
this class is a base class for mapping data; see Mapper Examples for usage examples ...
Definition: Mapper.qm.dox.h:240
list list(...)
hash mapc
the hash providing output field names and mappings
Definition: Mapper.qm.dox.h:304
hash getValue()
returns the current row transformed with the mapper
constructor(Qore::AbstractIterator i, hash mapv, *hash opts)
creates the iterator from the arguments passed
*string number_format
the global number format for parsing numbers
Definition: Mapper.qm.dox.h:340
abstract base class for hash iterator mappping classes based on a mapper object and an iterator input...
Definition: Mapper.qm.dox.h:603
*Qore::TimeZone timezone
an optional timezone for output date fields
Definition: Mapper.qm.dox.h:322
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:346
the Mapper namespace contains all the definitions in the Mapper module
Definition: Mapper.qm.dox.h:238
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:310
int getCount()
returns the internal record count
*hash input
an optional description of possible input hash keys
Definition: Mapper.qm.dox.h:343
*code input_log
an optional input data logging callback; must accept a hash giving the input data hash ...
Definition: Mapper.qm.dox.h:316
hash hash(object obj)
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:354
resetCount()
resets the internal record count