Qore Mapper Module Reference 1.0

- Main Page
- Related Pages
- Namespaces
- Classes

All Classes Namespaces Functions Variables Groups Pages
Mapper.qm.dox.h
1 // -*- mode: c++; indent-tabs-mode: nil -*-
3
4 /* Mapper.qm Copyright 2014 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
32 /* Version History
33 * 2014-01-03 v1.0: David Nichols <david@qore.org>
34 + the initial version of the Mapper module
35 */
36
155 namespace Mapper {
158 class Mapper {
159
160 public:
161 // no public members
162 public :
163
164 public:
165
166 private :
168 hash map;
169
171 string enc = "utf-8";
172
174 *string name;
175
177 *code trunc;
178
180 *code input_log;
181
183 *code output_log;
184
186 *Qore::TimeZone timezone;
187
189 Qore::TimeZone input_timezone = TimeZone::get();
190
192 bool trunc_all = False;
193
195 bool allow_dot = False;
196
198 *hash crec;
199
201 int count = 0;
202
204 const OptionKeys = (
205 "enc": True,
206 "name": True,
207 "trunc": True,
208 "input_log": True,
209 "output_log": True,
210 "timezone": True,
211 "input_timezone": True,
212 "trunc_all": True,
213 "crec": True,
214 "date_format": True,
215 );
216
218 const ValidKeys = (
219 "name": True,
220 "struct": True,
221 "code": True,
222 "maxlen": True,
223 "trunc": True,
224 "mand": True,
225 "number": True,
226 "type": True,
227 "date_format": True,
228 );
229
231 const ValidTypes = (
232 "number": True,
233 "integer": True,
234 "int": True, // is an alias for "integer"
235 "date": True,
236 );
237
238 public:
239
241
264 constructor(hash map, *hash opts);
265
266
268 private constructor();
269
270
272 private setup(hash map, *hash opts);
273
274
276 private checkMap();
277
278
280 private convertToHash(int t, string k, reference fh);
281
282
284
287 private checkMapField(string k, reference fh, *hash th);
288
289
291 private bool hasMapping(hash fh);
292
293
295 private checkTimezoneOption(hash opts, string rn);
296
297
298 string getFieldName(string name);
299
300
302
304 hash validKeys();
305
306
308
310 hash validTypes();
311
312
314
316 hash optionKeys();
317
318
320
329 list mapAll(softlist recs);
330
331
333
343 hash mapData(hash rec);
344
345
347
349 int getCount();
350
351
353
355 resetCount();
356
357
359 private mapFieldType(string key, hash m, reference v, hash rec);
360
361
363 private error(string fmt);
364
365
367 private error2(string ex, string fmt);
368
369
371 private any mapSubclass(hash m, any v);
372
373 };
374
376 class AbstractMapperIterator : public Qore::AbstractIterator {
377
378 public:
379 public :
380
381 public:
382
383 private :
385 Qore::AbstractIterator i;
386
387 public:
388
390
393 constructor(Qore::AbstractIterator i);
394
395
397 bool next();
398
399
401 bool valid();
402
403 };
404
406 class MapperIterator : public Mapper::AbstractMapperIterator {
407
408 public:
409 public :
410
411 public:
412
413 private :
415 Mapper::Mapper map;
416
417 public:
418
420
426 constructor(Qore::AbstractIterator i, hash map, *hash opts);
427
428
430
433 constructor(Qore::AbstractIterator i, Mapper::Mapper map);
434
435
437 hash getValue();
438
439
441
443 int getCount();
444
445
447
449 resetCount();
450
451 };
452 };
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