Mapper.qm.dox.h
// -*- mode: c++; indent-tabs-mode: nil -*-
/* Mapper.qm Copyright 2014 - 2017 Qore Technologies, s.r.o.
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 = (
"allow_dot": "allows input fields to have a dot in their name without implying a structured format",
"allow_output_dot": "allows output fields to have a dot in their name without implying a structured format",
"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;
hash mapd;
hash mapo;
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;
hash identh;
*list identl;
hash consth;
hash rconsth;
public:
constructor(hash mapv, *hash opts);
private:
constructor();
public:
private:
setup(hash mapv, *hash opts);
public:
private:
checkMap();
public:
private:
convertToHash(int t, string k, reference<any> fh);
public:
private:
checkInputField(string k, string name);
public:
private:
checkMapField(string k, reference<any> fh);
public:
private:
checkTimezoneOption(hash opts, string rn);
public:
setRuntime(string key, auto value);
setRuntime(hash runtime);
replaceRuntime(*hash runtime);
auto getRuntime(string key);
string getFieldName(string fname);
hash validKeys();
hash validTypes();
hash optionKeys();
*hash getInputRecord();
*hash getOutputRecord();
list<hash> mapAll(list recs);
list<hash> mapAll(hash recs);
hash mapData(hash rec);
private:
hash mapDataIntern(hash rec);
public:
private:
nothing mapFieldIntern(reference<hash> h, string key, hash rec, bool do_list, int list_size);
public:
private:
string truncateField(string k, string val, int ix, int sze, int maxlen);
public:
private:
fieldLengthError(string k, string val, int ix, int sze, int maxlen, hash rc);
public:
logOutput(hash h);
int getCount();
resetCount();
private:
mapFieldType(string key, hash m, reference<any> v, hash rec);
public:
private:
error(string fmt);
public:
private:
error2(string ex, string fmt);
public:
private:
auto mapSubclass(hash m, auto v);
public:
};
class AbstractMapperIterator : public Qore::AbstractIterator {
public:
public :
public:
private :
Qore::AbstractIterator i;
public:
constructor(Qore::AbstractIterator iter);
bool next();
bool valid();
bool hasBulk();
list<hash> 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::AbstractMapperIterator::i
Qore::AbstractIterator i
input iterator; AbstractIterator::getValue() must return a hash
Definition: Mapper.qm.dox.h:750
Qore::AbstractIterator::getValue
abstract any getValue()
Mapper::Mapper::date_format
*string date_format
the global date format for parsing dates
Definition: Mapper.qm.dox.h:357
Mapper::MapperIterator::mapc
Mapper::Mapper mapc
data mapper
Definition: Mapper.qm.dox.h:791
Mapper::Mapper::mapd
hash mapd
the hash with a subset of the mappings used dynamically
Definition: Mapper.qm.dox.h:321
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::Mapper::consth
hash consth
map of constant fields
Definition: Mapper.qm.dox.h:388
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:339
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:333
Mapper::MapperIterator
provides a hash iterator based on a mapper object and an iterator input source
Definition: Mapper.qm.dox.h:782
False
const False
Mapper::Mapper
this class is a base class for mapping data; see Mapper Examples for usage examples ...
Definition: Mapper.qm.dox.h:252
list
list list(...)
Mapper::Mapper::mapc
hash mapc
the hash providing output field names and mappings
Definition: Mapper.qm.dox.h:318
Mapper::Mapper::mapo
hash mapo
the hash of output records for key order
Definition: Mapper.qm.dox.h:324
Mapper::AbstractMapperIterator::mapBulk
list< hash > mapBulk(int size)
performs bulk mapping; if the iterator does not support bulk mapping then it is simulated in this met...
Mapper::Mapper::number_format
*string number_format
the global number format for parsing numbers
Definition: Mapper.qm.dox.h:360
Qore::TimeZone
Mapper::AbstractMapperIterator
abstract base class for hash iterator mappping classes based on a mapper object and an iterator input...
Definition: Mapper.qm.dox.h:741
Mapper::Mapper::identl
*list identl
list of fields to be mapped 1:1 input -> output
Definition: Mapper.qm.dox.h:385
Mapper::Mapper::identh
hash identh
map of fields to be mapped 1:1 input -> output
Definition: Mapper.qm.dox.h:382
Mapper::Mapper::timezone
*Qore::TimeZone timezone
an optional timezone for output date fields
Definition: Mapper.qm.dox.h:342
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:366
Mapper
the Mapper namespace contains all the definitions in the Mapper module
Definition: Mapper.qm.dox.h:250
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:330
Mapper::Mapper::input
*hash input
an optional description of possible input hash keys
Definition: Mapper.qm.dox.h:363
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:336
hash
hash hash(object obj)
Mapper::Mapper::rconsth
hash rconsth
map of constant runtime fields
Definition: Mapper.qm.dox.h:391
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:374
Qore::AbstractIterator