Qore Mapper Module Reference  1.1
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 */
34 
170 namespace Mapper {
172  // private function, added in qore 0.8.12
173  number parse_number(string str, string fmt);
174 
175 
177  class Mapper {
178 
179 public:
180  public :
182  const ConstantConflictList = ("name", "struct", "code", "default");
183 
184 public:
185 
186  private :
189 
191  string enc = "utf-8";
192 
194  *string name;
195 
197  *code trunc;
198 
200  *code input_log;
201 
203  *code output_log;
204 
207 
209  Qore::TimeZone input_timezone = TimeZone::get();
210 
212  bool trunc_all = False;
213 
215  bool allow_dot = False;
216 
218  bool allow_output_dot = False;
219 
221  *string date_format;
222 
224  *string number_format;
225 
228 
230  int count = 0;
231 
233  const OptionKeys = (
234  "enc": True,
235  "name": True,
236  "trunc": True,
237  "input_log": True,
238  "output_log": True,
239  "timezone": True,
240  "input_timezone": True,
241  "trunc_all": True,
242  "crec": True,
243  "date_format": True,
244  "number_format": True,
245  );
246 
248  const ValidKeys = (
249  "name": True,
250  "struct": True,
251  "constant": True,
252  "code": True,
253  "default": True,
254  "maxlen": True,
255  "trunc": True,
256  "mand": True,
257  "number": True,
258  "type": True,
259  "date_format": True,
260  "number_format": True,
261  );
262 
264  const ValidTypes = (
265  "number": True,
266  "integer": True,
267  "int": True, // is an alias for "integer"
268  "date": True,
269  );
270 
271 public:
272 
274 
297  constructor(hash map, *hash opts);
298 
299 
301  private constructor();
302 
303 
305  private setup(hash map, *hash opts);
306 
307 
309  private checkMap();
310 
311 
313  private convertToHash(int t, string k, reference fh);
314 
315 
317 
320  private checkMapField(string k, reference fh, *hash th);
321 
322 
324  private bool hasMapping(hash fh);
325 
326 
328  private checkTimezoneOption(hash opts, string rn);
329 
330 
331  string getFieldName(string name);
332 
333 
335 
337  hash validKeys();
338 
339 
341 
343  hash validTypes();
344 
345 
347 
349  hash optionKeys();
350 
351 
353 
362  list mapAll(softlist recs);
363 
364 
366 
376  hash mapData(hash rec);
377 
378 
380 
382  int getCount();
383 
384 
386 
388  resetCount();
389 
390 
392  private mapFieldType(string key, hash m, reference v, hash rec);
393 
394 
396  private error(string fmt);
397 
398 
400  private error2(string ex, string fmt);
401 
402 
404  private any mapSubclass(hash m, any v);
405 
406  };
407 
410 
411 public:
412  public :
413 
414 public:
415 
416  private :
419 
420 public:
421 
423 
427 
428 
430  bool next();
431 
432 
434  bool valid();
435 
436  };
437 
440 
441 public:
442  public :
443 
444 public:
445 
446  private :
449 
450 public:
451 
453 
460 
461 
463 
467 
468 
470  hash getValue();
471 
472 
474 
476  int getCount();
477 
478 
480 
482  resetCount();
483 
484  };
485 };
Qore::AbstractIterator i
input iterator; AbstractIterator::getValue() must return a hash
Definition: Mapper.qm.dox.h:418
*string date_format
the global date format for parsing dates
Definition: Mapper.qm.dox.h:221
Mapper::Mapper mapc
data mapper
Definition: Mapper.qm.dox.h:448
constructor(Qore::AbstractIterator i)
creates the iterator from the arguments passed
bool next()
Moves the current position of the input iterator to the next element; returns False if there are no m...
const True
*code output_log
an optional output data logging callback; must accept a hash giving the output data hash ...
Definition: Mapper.qm.dox.h:203
provides a hash iterator based on a mapper object and an iterator input source
Definition: Mapper.qm.dox.h:439
number number(softnumber n)
const False
this class is a base class for mapping data; see Mapper Examples for usage examples ...
Definition: Mapper.qm.dox.h:177
list list(...)
hash mapc
the hash providing output field names and mappings
Definition: Mapper.qm.dox.h:188
hash getValue()
returns the current row transformed with the mapper
constructor(Qore::AbstractIterator i, hash map, *hash opts)
creates the iterator from the arguments passed
*string number_format
the global number format for parsing numbers
Definition: Mapper.qm.dox.h:224
abstract base class for hash iterator mappping classes based on a mapper object and an iterator input...
Definition: Mapper.qm.dox.h:409
*Qore::TimeZone timezone
an optional timezone for output date fields
Definition: Mapper.qm.dox.h:206
*hash crec
(deprecated) constant hash value for output mappings
Definition: Mapper.qm.dox.h:227
*code trunc
an optional field truncation callback
Definition: Mapper.qm.dox.h:197
the Mapper namespace contains all the definitions in the Mapper module
Definition: Mapper.qm.dox.h:171
*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:194
int getCount()
returns the internal record count
*code input_log
an optional input data logging callback; must accept a hash giving the input data hash ...
Definition: Mapper.qm.dox.h:200
hash hash(object obj)
bool valid()
returns True if the input iterator is currently pointing at a valid element, False if not ...
resetCount()
resets the internal record count