All Classes Namespaces Functions Variables Groups Pages
Mapper.qm.dox.h
// -*- mode: c++; indent-tabs-mode: nil -*-
/* Mapper.qm Copyright 2014 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.
*/
// this module requires Qore 0.8.9 or better
// require type definitions everywhere
// enable all warnings
/* Version History
* 2014-01-03 v1.0: David Nichols <david@qore.org>
+ the initial version of the Mapper module
*/
namespace Mapper {
class Mapper {
public:
// no public members
public :
public:
private :
hash map;
string enc = "utf-8";
*string name;
*code trunc;
*code input_log;
*code output_log;
*Qore::TimeZone timezone;
Qore::TimeZone input_timezone = TimeZone::get();
bool trunc_all = False;
bool allow_dot = False;
*hash crec;
int count = 0;
const OptionKeys = (
"enc": True,
"name": True,
"trunc": True,
"input_log": True,
"output_log": True,
"timezone": True,
"input_timezone": True,
"trunc_all": True,
"crec": True,
"date_format": True,
);
const ValidKeys = (
"name": True,
"struct": True,
"code": True,
"maxlen": True,
"trunc": True,
"mand": True,
"number": True,
"type": True,
"date_format": True,
);
const ValidTypes = (
"number": True,
"integer": True,
"int": True, // is an alias for "integer"
"date": True,
);
public:
constructor(hash map, *hash opts);
private constructor();
private setup(hash map, *hash opts);
private checkMap();
private convertToHash(int t, string k, reference fh);
private checkMapField(string k, reference fh, *hash th);
private bool hasMapping(hash fh);
private checkTimezoneOption(hash opts, string rn);
string getFieldName(string name);
hash validKeys();
hash validTypes();
hash optionKeys();
list mapAll(softlist recs);
hash mapData(hash rec);
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 i);
bool next();
bool valid();
};
class MapperIterator : public Mapper::AbstractMapperIterator {
public:
public :
public:
private :
Mapper::Mapper map;
public:
constructor(Qore::AbstractIterator i, hash map, *hash opts);
constructor(Qore::AbstractIterator i, Mapper::Mapper map);
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:385
Mapper::Mapper::mapAll
list mapAll(softlist recs)
maps all input records and returns the mapped data as a list of output records
Mapper::Mapper::getCount
int getCount()
returns the internal record count
Mapper::Mapper::setup
private setup(hash map, *hash opts)
sets up the mapper object before checking the mapper hash
Mapper::Mapper::validTypes
hash validTypes()
returns a list of valid field types for this class (can be overridden in subclasses) ...
Mapper::Mapper::mapSubclass
private any mapSubclass(hash m, any v)
to be overridden as necessary in subclasses
Mapper::AbstractMapperIterator::constructor
constructor(Qore::AbstractIterator i)
creates the iterator from the arguments passed
Mapper::AbstractMapperIterator::next
bool next()
Moves the current position of the input iterator to the next element; returns False if there are no m...
True
const True
Mapper::Mapper::OptionKeys
const OptionKeys
constructor option keys (can be extended by subclassing and reimplementing optionKeys()) ...
Definition: Mapper.qm.dox.h:204
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:183
Mapper::MapperIterator
provides a hash iterator based on a mapper object and an iterator input source
Definition: Mapper.qm.dox.h:406
Mapper::Mapper::enc
string enc
the output character encoding; if not given then the output encoding is assumed to be UTF-8 ...
Definition: Mapper.qm.dox.h:171
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:195
Mapper::Mapper
this class is a base class for mapping data; see Mapper Examples for usage examples ...
Definition: Mapper.qm.dox.h:158
list
list list(...)
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:201
Mapper::Mapper::resetCount
resetCount()
resets the internal record count
Mapper::MapperIterator::constructor
constructor(Qore::AbstractIterator i, hash map, *hash opts)
creates the iterator from the arguments passed
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:189
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:376
Mapper::Mapper::validKeys
hash validKeys()
returns a list of valid field keys for this class (can be overridden in subclasses) ...
Mapper::Mapper::ValidKeys
const ValidKeys
default known mapper hash field keys (can be extended by subclassing and reimplementing validKeys()) ...
Definition: Mapper.qm.dox.h:218
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:186
Mapper::Mapper::trunc_all
bool trunc_all
truncate all option
Definition: Mapper.qm.dox.h:192
Mapper::Mapper::ValidTypes
const ValidTypes
default known field types (can be extended by subclassing and reimplementing validTypes() and mapFiel...
Definition: Mapper.qm.dox.h:231
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::Mapper::crec
*hash crec
constant hash value for output mappings
Definition: Mapper.qm.dox.h:198
Mapper::Mapper::trunc
*code trunc
an optional field truncation callback
Definition: Mapper.qm.dox.h:177
Mapper::Mapper::checkTimezoneOption
private checkTimezoneOption(hash opts, string rn)
verifies a timezone constructor option
Mapper::MapperIterator::map
Mapper::Mapper map
data mapper
Definition: Mapper.qm.dox.h:415
Mapper::Mapper::constructor
private constructor()
private constructor for subclasses
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:174
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::map
hash map
the hash providing output field names and mappings
Definition: Mapper.qm.dox.h:168
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:180
hash
hash hash(object obj)
Mapper::AbstractMapperIterator::valid
bool valid()
returns True if the input iterator is currently pointing at a valid element, False if not ...
Mapper::Mapper::hasMapping
private bool hasMapping(hash fh)
returns True if the field has a mapping, False if not
Qore::AbstractIterator
Mapper::MapperIterator::resetCount
resetCount()
resets the internal record count