All Classes Namespaces Functions Variables Groups Pages
Mapper.qm.dox.h
// -*- mode: c++; indent-tabs-mode: nil -*-
/* Mapper.qm Copyright 2014 - 2016 Qore Technologies, sro
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/
// minimum required Qore version
// require type definitions everywhere
// enable all warnings
// do not use "$" for vars
/* Version History
*/
namespace Mapper {
class Mapper {
public:
public :
const ConstantConflictList = ("name", "struct", "code", "default");
const OptionKeys = (
"date_format": "gives the default format for parsing dates from strings; ex: \"MM/DD/YYYY HH:mm:SS\"",
"encoding": "gives the default output character encoding for string fields",
"info_log": "a call reference / closure for informational logging",
"input": "a hash describing the input record",
"input_log": "a call reference / closure for input record logging",
"input_timezone": "the default timezone to assume when parsing input dates",
"name": "the name of the Mapper object",
"number_format": "the default number format when parsing number fields from strings; ex: \".,\"",
"output": "a hash describing the output record",
"output_log": "a call reference / closure for input record logging",
"timezone": "the default output timezone for date/time values",
"runtime": "runtime options as a hash (see also setRuntime(), replaceRuntime())",
"empty_strings_to_nothing": "converts out record's empty strings and into NOTHING - actually the value is deleted",
);
const ValidKeys = (
"name": True,
"struct": True,
"constant": True,
"index" : True,
"code": True,
"default": True,
"maxlen": True,
"trunc": True,
"mand": True,
"number": True,
"type": True,
"date_format": True,
"number_format": True,
"runtime" : True,
"empty_strings_to_nothing" : True,
);
const ValidTypes = (
"number": True,
"integer": True,
"int": True, // is an alias for "integer"
"date": True,
"string": True,
);
const OutputKeys = (
"desc": True,
"mand": True,
"maxlen": True,
"type": True,
);
public:
private :
hash mapc;
string encoding = "utf-8";
*string name;
*code info_log;
*code input_log;
*code output_log;
*Qore::TimeZone timezone;
Qore::TimeZone input_timezone = TimeZone::get();
bool trunc_all = False;
bool allow_dot = False;
bool allow_output_dot = False;
*string date_format;
*string number_format;
*hash input;
*hash output;
int count = 0;
*hash m_runtime;
bool m_empty_strings_to_nothing = False;
public:
constructor(hash mapv, *hash opts);
private constructor();
private setup(hash mapv, *hash opts);
private checkMap();
private convertToHash(int t, string k, reference fh);
private checkInputField(string k, string name);
private checkMapField(string k, reference fh, *hash th);
private checkTimezoneOption(hash opts, string rn);
setRuntime(string key, any value);
setRuntime(hash runtime);
replaceRuntime(*hash runtime);
any getRuntime(string key);
string getFieldName(string fname);
hash validKeys();
hash validTypes();
hash optionKeys();
*hash getInputRecord();
*hash getOutputRecord();
list mapAll(list recs);
list mapAll(hash recs);
hash mapData(hash rec);
private hash mapDataIntern(hash rec);
logOutput(hash h);
int getCount();
resetCount();
private mapFieldType(string key, hash m, reference v, hash rec);
private error(string fmt);
private error2(string ex, string fmt);
private any mapSubclass(hash m, any v);
};
class AbstractMapperIterator : public Qore::AbstractIterator {
public:
public :
public:
private :
Qore::AbstractIterator i;
public:
constructor(Qore::AbstractIterator iter);
bool next();
bool valid();
bool hasBulk();
list mapBulk(int size);
};
class MapperIterator : public Mapper::AbstractMapperIterator {
public:
public :
public:
private :
Mapper::Mapper mapc;
public:
constructor(Qore::AbstractIterator i, hash mapv, *hash opts) ;
constructor(Qore::AbstractIterator i, Mapper::Mapper mapv) ;
hash getValue();
int getCount();
resetCount();
};
};
Mapper::Mapper::mapFieldType
private mapFieldType(string key, hash m, reference v, hash rec)
performs type handling
Mapper::AbstractMapperIterator::i
Qore::AbstractIterator i
input iterator; AbstractIterator::getValue() must return a hash
Definition: Mapper.qm.dox.h:612
Mapper::Mapper::getCount
int getCount()
returns the internal record count
Mapper::Mapper::getOutputRecord
*hash getOutputRecord()
returns the value of the &quot;output&quot; option
Mapper::Mapper::ConstantConflictList
const ConstantConflictList
field keys that conflict with &quot;constant&quot; and &quot;index&quot;
Definition: Mapper.qm.dox.h:245
Mapper::Mapper::date_format
*string date_format
the global date format for parsing dates
Definition: Mapper.qm.dox.h:337
Mapper::Mapper::validTypes
hash validTypes()
returns a list of valid field types for this class (can be overridden in subclasses) ...
Mapper::Mapper::setup
private setup(hash mapv, *hash opts)
sets up the mapper object before checking the mapper hash
Mapper::Mapper::checkInputField
private checkInputField(string k, string name)
raises an error if an invalid input field name is declared; only call this if &quot;input&quot; is defined ...
Mapper::MapperIterator::mapc
Mapper::Mapper mapc
data mapper
Definition: Mapper.qm.dox.h:654
Mapper::Mapper::mapSubclass
private any mapSubclass(hash m, any v)
to be overridden as necessary in subclasses
Mapper::AbstractMapperIterator::next
bool next()
Moves the current position of the iterator to the next element; returns False if there are no more el...
True
const True
Mapper::AbstractMapperIterator::mapBulk
list mapBulk(int size)
performs bulk mapping; if the iterator does not support bulk mapping then it is simulated in this met...
Mapper::Mapper::getFieldName
string getFieldName(string fname)
returns a descriptive name of the given field if possible, otherwise returns the field name itself ...
Mapper::Mapper::m_empty_strings_to_nothing
bool m_empty_strings_to_nothing
flag to enforce deletion of the empty string in the output record
Definition: Mapper.qm.dox.h:359
Mapper::Mapper::OptionKeys
const OptionKeys
constructor option keys (can be extended by subclassing and reimplementing optionKeys()) ...
Definition: Mapper.qm.dox.h:248
Mapper::Mapper::output_log
*code output_log
an optional output data logging callback; must accept a hash giving the output data hash ...
Definition: Mapper.qm.dox.h:319
Mapper::Mapper::info_log
*code info_log
an optional info logging callback; must accept a sprintf()-style format specifier and optional argume...
Definition: Mapper.qm.dox.h:313
Mapper::MapperIterator
provides a hash iterator based on a mapper object and an iterator input source
Definition: Mapper.qm.dox.h:645
Mapper::Mapper::convertToHash
private convertToHash(int t, string k, reference fh)
convert a field definition to a hash if possible
Mapper::Mapper::checkMapField
private checkMapField(string k, reference fh, *hash th)
perform per-field pre-processing on the passed map in the constructor
False
const False
Mapper::Mapper::allow_dot
bool allow_dot
do not assume struct when field names have a &quot;.&quot; in them; instead allow input field names to have a &quot;...
Definition: Mapper.qm.dox.h:331
Mapper::Mapper
this class is a base class for mapping data; see Mapper Examples for usage examples ...
Definition: Mapper.qm.dox.h:240
list
list list(...)
Mapper::Mapper::setRuntime
setRuntime(string key, any value)
set the runtime option with &quot;key&quot; to value &quot;value&quot;
Mapper::Mapper::mapc
hash mapc
the hash providing output field names and mappings
Definition: Mapper.qm.dox.h:304
Mapper::MapperIterator::getValue
hash getValue()
returns the current row transformed with the mapper
Mapper::Mapper::count
int count
count of records mapped
Definition: Mapper.qm.dox.h:349
Mapper::Mapper::resetCount
resetCount()
resets the internal record count
Mapper::MapperIterator::constructor
constructor(Qore::AbstractIterator i, hash mapv, *hash opts)
creates the iterator from the arguments passed
Mapper::Mapper::number_format
*string number_format
the global number format for parsing numbers
Definition: Mapper.qm.dox.h:340
Qore::TimeZone
Mapper::Mapper::input_timezone
Qore::TimeZone input_timezone
the timezone for input fields in case of parsing text values; if not set defaults to the current Time...
Definition: Mapper.qm.dox.h:325
Mapper::Mapper::error2
private error2(string ex, string fmt)
throws the given exception; prepends the map name to the description if known
Mapper::AbstractMapperIterator
abstract base class for hash iterator mappping classes based on a mapper object and an iterator input...
Definition: Mapper.qm.dox.h:603
Mapper::Mapper::validKeys
hash validKeys()
returns a list of valid field keys for this class (can be overridden in subclasses) ...
Mapper::Mapper::allow_output_dot
bool allow_output_dot
do not assume structured/hash output when output field names have a &quot;.&quot; in them; instead allow output...
Definition: Mapper.qm.dox.h:334
Mapper::Mapper::ValidKeys
const ValidKeys
default known mapper hash field keys (can be extended by subclassing and reimplementing validKeys()) ...
Definition: Mapper.qm.dox.h:265
Mapper::Mapper::checkMap
private checkMap()
verifies the input map in the constructor
Mapper::Mapper::error
private error(string fmt)
throws a MAP-ERROR exception; prepends the map name to the description if known
Mapper::Mapper::timezone
*Qore::TimeZone timezone
an optional timezone for output date fields
Definition: Mapper.qm.dox.h:322
Mapper::Mapper::logOutput
logOutput(hash h)
calls the output logging closure or call reference (if any) to log the output record ...
Mapper::Mapper::trunc_all
bool trunc_all
truncate all option
Definition: Mapper.qm.dox.h:328
Mapper::Mapper::ValidTypes
const ValidTypes
default known field types (can be extended by subclassing and reimplementing validTypes() and mapFiel...
Definition: Mapper.qm.dox.h:284
Mapper::Mapper::mapData
hash mapData(hash rec)
processes the input record and returns a hash of the mapped values where the keys in the hash returne...
Mapper::AbstractMapperIterator::constructor
constructor(Qore::AbstractIterator iter)
creates the iterator from the arguments passed
Mapper::Mapper::output
*hash output
an optional description of the output data structure
Definition: Mapper.qm.dox.h:346
Mapper::Mapper::checkTimezoneOption
private checkTimezoneOption(hash opts, string rn)
verifies a timezone constructor option
Mapper::Mapper::constructor
private constructor()
private constructor for subclasses
Mapper::Mapper::mapDataIntern
private hash mapDataIntern(hash rec)
processes the input record and returns a hash of the mapped values where the keys in the hash returne...
Mapper::AbstractMapperIterator::hasBulk
bool hasBulk()
returns True if the iterator supports bulk mode; this method returns False (the default) ...
Mapper::Mapper::name
*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
Mapper::Mapper::encoding
string encoding
the output character encoding; if not given then the output encoding is assumed to be UTF-8 ...
Definition: Mapper.qm.dox.h:307
Mapper::MapperIterator::getCount
int getCount()
returns the internal record count
Mapper::Mapper::optionKeys
hash optionKeys()
returns a list of valid constructor options for this class (can be overridden in subclasses) ...
Mapper::Mapper::input
*hash input
an optional description of possible input hash keys
Definition: Mapper.qm.dox.h:343
Mapper::Mapper::getInputRecord
*hash getInputRecord()
returns the value of the &quot;input&quot; option
Mapper::Mapper::mapAll
list mapAll(list recs)
maps all input records and returns the mapped data as a list of output records
Mapper::Mapper::input_log
*code input_log
an optional input data logging callback; must accept a hash giving the input data hash ...
Definition: Mapper.qm.dox.h:316
Mapper::Mapper::replaceRuntime
replaceRuntime(*hash runtime)
replaces runtime options
hash
hash hash(object obj)
Mapper::Mapper::getRuntime
any getRuntime(string key)
get current runtime option value for a key
Mapper::Mapper::OutputKeys
const OutputKeys
output option keys
Definition: Mapper.qm.dox.h:293
Mapper::AbstractMapperIterator::valid
bool valid()
returns True if the iterator is currently pointing at a valid element, False if not ...
Mapper::Mapper::m_runtime
*hash m_runtime
current runtime values
Definition: Mapper.qm.dox.h:354
Qore::AbstractIterator
Mapper::MapperIterator::resetCount
resetCount()
resets the internal record count