| Qore CsvUtil Module Reference 1.10

CsvWriteDataProvider.qc.dox.h
1 // -*- mode: c++; indent-tabs-mode: nil -*-
2 // Qore CsvWriteDataProvider class definition
3
4 /* CsvWriteDataProvider.qc Copyright 2012 - 2022 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 class CsvWriteDataProvider : public DataProvider::AbstractDataProvider {
31
32 public:
34 const ProviderInfo = <DataProviderInfo>{
35 "type": "CsvWriteDataProvider",
36 "supports_create": True,
37 "has_record": True,
38 "constructor_options": ConstructorOptions,
39 };
40
42 const ConstructorOptions = {
43 "path": <DataProviderOptionInfo>{
44 "type": AbstractDataProviderType::get(StringType),
45 "desc": "the location for the output CSV data file; mutually exclusive with \"stream\"; the output "
46 "location is handled by a call to FileLocationHandler::getOutputStreamForLocation()",
47 },
48 "stream": <DataProviderOptionInfo>{
49 "type": AbstractDataProviderType::get(new Type("OutputStream")),
50 "desc": "an output stream for CSV data; mutually exclusive with \"path\"",
51 },
52 "block": <DataProviderOptionInfo>{
53 "type": AbstractDataProviderType::get(SoftIntType),
54 "desc": "the block size when generating bulk output",
55 },
56 "datamap": <DataProviderOptionInfo>{
57 "type": AbstractDataProviderType::get(AutoHashType),
58 "desc": "a hash mapping actual data key names to the output field names, for use in case the data "
59 "field names differ; does not have to include every data or output key; keys not present will be "
60 "assumed to be mapped 1:1",
61 },
62 "date_format": <DataProviderOptionInfo>{
63 "type": AbstractDataProviderType::get(StringType),
64 "desc": "the default mask for date value formatting",
65 },
66 "encoding": <DataProviderOptionInfo>{
67 "type": AbstractDataProviderType::get(StringType),
68 "desc": "the character encoding for the data",
69 },
70 "eol": <DataProviderOptionInfo>{
71 "type": AbstractDataProviderType::get(StringType),
72 "desc": "the end of line / record character(s)",
73 },
74 "fields": <DataProviderOptionInfo>{
75 "type": AbstractDataProviderType::get(AutoHashType),
76 "desc": "describes the data to be output",
77 },
78 "headers": <DataProviderOptionInfo>{
79 "type": AbstractDataProviderType::get(new Type("softlist<string>")),
80 "desc": "list of field header / column names for the data iterated",
81 },
82 "header_reorder": <DataProviderOptionInfo>{
83 "type": AbstractDataProviderType::get(SoftBoolType),
84 "desc": "if `true` (the default) then if `headers` are provided, then data fields are reordered to "
85 "follow headers",
86 },
87 "optimal_quotes": <DataProviderOptionInfo>{
88 "type": AbstractDataProviderType::get(SoftBoolType),
89 "desc": "set to `false` to disable optimal quoting; when optimal quoting is disabled, all fields are "
90 "quoted regardless of type or content, when it is enabled, then fields are quoted only if they "
91 "require quoting (i.e. they contain a quote or separator character); the default is `true`",
92 },
93 "quote": <DataProviderOptionInfo>{
94 "type": AbstractDataProviderType::get(StringType),
95 "desc": "the quote character to quote fields (default: `\"`)",
96 },
97 "quote_escape": <DataProviderOptionInfo>{
98 "type": AbstractDataProviderType::get(StringType),
99 "desc": "escape character(s) used for `quote` (default: `\\`)",
100 },
101 "separator": <DataProviderOptionInfo>{
102 "type": AbstractDataProviderType::get(StringType),
103 "desc": "string separating fields in the data (default: `,`)",
104 },
105 "verify_columns": <DataProviderOptionInfo>{
106 "type": AbstractDataProviderType::get(SoftBoolType),
107 "desc": "if `true` (the default is `false`) then if a line is parsed with a different column count "
108 "than other lines, a `CSVFILEWRITER-DATA-ERROR` exception is thrown",
109 },
110 "write_headers": <DataProviderOptionInfo>{
111 "type": AbstractDataProviderType::get(SoftBoolType),
112 "desc": "set to `false` to suppress the output of headers; the default is `true`, meaning to output "
113 "headers if they are present",
114 },
115 };
116
118 const CsvGenerationOptionList = keys (ConstructorOptions - ("path", "stream"));
119
120 protected:
122 AbstractCsvWriter writer;
123
124 public:
125
127
132 constructor(string path, *hash<auto> opts);
133
134
136
141 constructor(OutputStream stream, *hash<auto> opts);
142
143
145 string getName();
146
147
149 constructor(*hash<auto> options);
150
151
153 protected:
154 *hash<string, AbstractDataField> getRecordTypeImpl(*hash<auto> search_options);
155 public:
156
157
159
164 protected:
165 *hash<auto> createRecordImpl(hash<auto> rec, *hash<auto> create_options);
166 public:
167
168
170 protected:
171 hash<DataProviderInfo> getStaticInfoImpl();
172 public:
173
174 };
175 }; // CsvUtil namespace
CsvUtil::AbstractCsvWriter
The AbstractCsvWriter class provides a parent for all CSV writers.
Definition: AbstractCsvWriter.qc.dox.h:139
CsvUtil::CsvWriteDataProvider
Provides a data provider for reading CSV files.
Definition: CsvWriteDataProvider.qc.dox.h:30
CsvUtil::CsvWriteDataProvider::ConstructorOptions
const ConstructorOptions
Constructor options.
Definition: CsvWriteDataProvider.qc.dox.h:42
CsvUtil::CsvWriteDataProvider::ProviderInfo
const ProviderInfo
Provider info.
Definition: CsvWriteDataProvider.qc.dox.h:34
CsvUtil::CsvWriteDataProvider::writer
AbstractCsvWriter writer
the writer object
Definition: CsvWriteDataProvider.qc.dox.h:122
CsvUtil::CsvWriteDataProvider::createRecordImpl
*hash< auto > createRecordImpl(hash< auto > rec, *hash< auto > create_options)
Creates the given record to the data provider.
CsvUtil::CsvWriteDataProvider::getStaticInfoImpl
hash< DataProviderInfo > getStaticInfoImpl()
Returns data provider static info.
CsvUtil::CsvWriteDataProvider::constructor
constructor(OutputStream stream, *hash< auto > opts)
Creates the CsvWriteDataProvider with the output data stream where data will be writeen and an option...
CsvUtil::CsvWriteDataProvider::getRecordTypeImpl
*hash< string, AbstractDataField > getRecordTypeImpl(*hash< auto > search_options)
Returns the description of the record type, if any.
CsvUtil::CsvWriteDataProvider::CsvGenerationOptionList
const CsvGenerationOptionList
CSV generation option list.
Definition: CsvWriteDataProvider.qc.dox.h:118
CsvUtil::CsvWriteDataProvider::constructor
constructor(*hash< auto > options)
Creates the object from constructor options.
CsvUtil::CsvWriteDataProvider::getName
string getName()
Returns the object name.
CsvUtil::CsvWriteDataProvider::constructor
constructor(string path, *hash< auto > opts)
Creates the CsvWriteDataProvider with the output path and optionally an option hash.
True
const True
CsvUtil
the CsvUtil namespace. All classes used in the CsvUtil module should be inside this namespace
Definition: AbstractCsvIterator.qc.dox.h:28