Qore CsvUtil Module Reference  1.7.2
AbstractCsvWriter.qc.dox.h
1 // -*- mode: c++; indent-tabs-mode: nil -*-
2 // Qore AbstractCsvWriter class definition
3 
4 /* AbstractCsvWriter.qc Copyright 2012 - 2020 Qore Technologies, s.r.o.
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 // assume local var scope, do not use "$" for vars, members, and method calls
26 
28 namespace CsvUtil {
30 
139 class AbstractCsvWriter : protected CsvHelper {
140 
141 public:
142 protected:
144  const Options = ...;
145 
146 
148  string encoding;
149 
151  string separator = ",";
152 
154  string quote = "\"";
155 
157  string m_quoteEscapeChar = "\\";
158 
160  string eol = EOL_UNIX;
161 
164 
166  int lineNo = 0;
167 
169  int block = 1000;
170 
172  string baseTemplate;
173 
176 
179 
181  *code info_log;
182 
185 
188 
189 public:
190 
192 
198  constructor(string n_errname, *hash<auto> n_opts);
199 
200 
202 
210  constructor(string n_errname, hash<auto> spec, hash<auto> n_opts);
211 
212 
214  *hash<string, AbstractDataField> getRecordType();
215 
216 
218 protected:
219  processCommonOptions(*hash<auto> n_opts, int C_OPTx);
220 public:
221 
222 
224 protected:
225  processSpec();
226 public:
227 
228 
230 protected:
231  writeHeaders();
232 public:
233 
234 
236 
241  writeLine(list<auto> values);
242 
243 
245 
250  writeLine(hash<auto> values);
251 
252 
254 
260  writeLine(string type, list<auto> values);
261 
262 
264 
270  writeLine(string type, hash<auto> values);
271 
272 
274 
281  write(Qore::AbstractIterator iterator);
282 
283 
285 
292  write(Qore::SQL::SQLStatement iterator);
293 
294 
296 
303  write(list<auto> l);
304 
305 
307 protected:
308  abstract writeRawLine(list<auto> values);
309 public:
310 
312 
317 protected:
318  string prepareRawLine(list<auto> values);
319 public:
320 
321 
322 protected:
323  string prepareRawLineIntern(list<auto> values);
324 public:
325 
326 
327  }; // AbstractCsvWriter class
328 }; // CsvUtil namespace
bool write_headers
this flag determines if any stored headers are output
Definition: AbstractCsvWriter.qc.dox.h:175
abstract writeRawLine(list< auto > values)
This method must be overridden in child classes to provide the output implementation.
hash m_out_by_name
mapping output field by name
Definition: AbstractCsvWriter.qc.dox.h:184
writeHeaders()
Write csv headers.
string prepareRawLine(list< auto > values)
Prepare a string (line with EOF) with formatting and escaping.
const True
hash m_out_by_idx
mapping output field by index
Definition: AbstractCsvWriter.qc.dox.h:187
bool checkElementCounts
verify the column count for every row; if a row does not match, then throw a CSVFILEITERATOR-DATA-ERR...
Definition: AbstractCsvWriter.qc.dox.h:163
const False
string m_quoteEscapeChar
quote escape character
Definition: AbstractCsvWriter.qc.dox.h:157
*code info_log
a closure/call reference for informational logging when using write(SQLStatement) ...
Definition: AbstractCsvWriter.qc.dox.h:181
const Options
valid options for the object (a hash for quick lookups of valid keys)
Definition: AbstractCsvWriter.qc.dox.h:144
write(Qore::AbstractIterator iterator)
Stream an iterator into the output.
string eol
end of line sequence
Definition: AbstractCsvWriter.qc.dox.h:160
string separator
field separator
Definition: AbstractCsvWriter.qc.dox.h:151
string quote
field content delimiter
Definition: AbstractCsvWriter.qc.dox.h:154
processCommonOptions(*hash< auto > n_opts, int C_OPTx)
Process options and set internal variables.
processSpec()
Process specification and set internal variable for mapping.
The AbstractCsvWriter class provides a parent for all CSV writers.
Definition: AbstractCsvWriter.qc.dox.h:139
*hash< string, AbstractDataField > getRecordType()
Returns the description of the record type, if any.
string baseTemplate
base template for value format
Definition: AbstractCsvWriter.qc.dox.h:172
const EOL_UNIX
Unix end of line character sequence (for new OS X too)
Definition: CsvUtil.qm.dox.h:325
int lineNo
the latest line number
Definition: AbstractCsvWriter.qc.dox.h:166
string type(auto arg)
hash< auto > hash(object obj)
int block
block size for bulk DML
Definition: AbstractCsvWriter.qc.dox.h:169
bool optimal_quotes
stores the optimal quotes option
Definition: AbstractCsvWriter.qc.dox.h:178
string encoding
output file character encoding
Definition: AbstractCsvWriter.qc.dox.h:148
the CsvUtil namespace. All classes used in the CsvUtil module should be inside this namespace ...
Definition: AbstractCsvIterator.qc.dox.h:28
writeLine(list< auto > values)
Write a line with a list of values; data are checked against column rules.
constructor(string n_errname, *hash< auto > n_opts)
Creates the AbstractCsvWriter in single-type mode.