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::AbstractMapperIterator::i
Qore::AbstractIterator i
input iterator; AbstractIterator::getValue() must return a hash
Definition: Mapper.qm.dox.h:612
Mapper::Mapper::date_format
*string date_format
the global date format for parsing dates
Definition: Mapper.qm.dox.h:337
Mapper::MapperIterator::mapc
Mapper::Mapper mapc
data mapper
Definition: Mapper.qm.dox.h:654
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::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
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:240
list
list list(...)
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::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::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::timezone
*Qore::TimeZone timezone
an optional timezone for output date fields
Definition: Mapper.qm.dox.h:322
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
the Mapper namespace contains all the definitions in the Mapper module
Definition: Mapper.qm.dox.h:238
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::MapperIterator::getCount
int getCount()
returns the internal record count
Mapper::Mapper::input
*hash input
an optional description of possible input hash keys
Definition: Mapper.qm.dox.h:343
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
hash
hash hash(object obj)
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