AbstractCsvIterator.qc.dox.h
// -*- mode: c++; indent-tabs-mode: nil -*-
// Qore AbstractCsvIterator class definition
/* AbstractCsvIterator.qc Copyright 2012 - 2020 Qore Technologies, s.r.o.
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.
*/
// assume local var scope, do not use "$" for vars, members, and method calls
namespace CsvUtil {
class AbstractCsvIterator : public Qore::AbstractIterator, protected CsvHelper {
public:
protected:
const Options = ...;
// field separator
string separator = ",";
// field content delimiter
string quote = "\"";
// number of header lines
softint headerLines = 0;
// flag to use string names from the first header row if possible
bool headerNames = False;
// True if empty lines should be ignored
bool ignoreEmptyLines = True;
// Flag to trim the field content (trim leading and trailing whitespace) from unquoted fields
bool ignoreWhitespace = True;
// the @ref Qore::TimeZone to use when parsing dates (default: current time zone)
*TimeZone timezone;
// verify the column count for every row; if a row does not match, then throw a \c CSVFILEITERATOR-DATA-ERROR exception
bool checkElementCounts = False;
// getRecord/getValue returns extended hash
bool extendedRecord = False;
// force "*string" fields with no value to return an empty string rather than @ref nothing for backwards compatibility with very early versions of CsvUtil
bool compat_force_empty_string = False;
// read ahead flag
bool read_ahead;
// column count for verifying column counts
int cc;
// current record count for the index() method
int rc = 0;
// to resolve record type by rules
hash<string, hash<string, list<hash<auto>>>> m_resolve_by_rule;
// to resolve record type by number of fields
hash<string, list<string>> m_resolve_by_count;
// list of idx to field transformarions, in order of spec
hash<string, list<string>> m_resolve_by_idx;
// fake specs based on the first non-header row
bool fakeHeaderNames;
*string eol;
// data source iterator
AbstractLineIterator lineIterator;
public:
constructor(AbstractLineIterator li, *hash<auto> opts);
// NOTE: when declared as *hash then always calls this constructor
constructor(AbstractLineIterator li, hash<auto> spec, hash<auto> opts);
protected:
processCommonOptions(*hash<auto> opts, int C_OPTx);
public:
protected:
processSpec(hash<auto> spec);
public:
protected:
prepareFieldsFromHeaders(*list<auto> headers);
public:
bool valid();
bool next();
peek();
auto memberGate(string name);
hash<auto> getValue();
hash<auto> getRecord(bool extended);
hash<auto> getRecord();
auto getRecordList();
string getSeparator();
string getQuote();
*hash<string, AbstractDataField> getRecordType();
*list<string> getHeaders();
*list<string> getHeaders(string type);
int index();
int lineNumber();
string getRawLine();
list<*string> getRawLineValues();
protected:
auto handleType(hash<auto> fh, *string val);
public:
protected:
list<*string> getLineAndSplit();
public:
string identifyType(list<auto> rec);
protected:
*string identifyTypeImpl(list<auto> rec);
public:
protected:
hash<auto> parseLine();
public:
}; // AbstractCsvIterator class
}; // CsvUtil namespace
CsvUtil::AbstractCsvIterator
the AbstractCsvIterator class is an abstract base class that allows abstract CSV data to be iterated
Definition: AbstractCsvIterator.qc.dox.h:285
CsvUtil::AbstractCsvIterator::prepareFieldsFromHeaders
prepareFieldsFromHeaders(*list< auto > headers)
match headers provided at csv header or in options, never called for multi-type because header_names ...
CsvUtil::AbstractCsvIterator::getRecordType
*hash< string, AbstractDataField > getRecordType()
Returns the description of the record type, if any.
CsvUtil::AbstractCsvIterator::getQuote
string getQuote()
Returns the current quote string.
CsvUtil::AbstractCsvIterator::processSpec
processSpec(hash< auto > spec)
process specification and assing internal data for resolving
CsvUtil::AbstractCsvIterator::eol
*string eol
the eol marker, if any
Definition: AbstractCsvIterator.qc.dox.h:345
CsvUtil::AbstractCsvIterator::memberGate
auto memberGate(string name)
Returns the given column value for the current row.
CsvUtil::AbstractCsvIterator::getLineAndSplit
list< *string > getLineAndSplit()
Read line split by separator/quote into list.
CsvUtil::AbstractCsvIterator::getRecord
hash< auto > getRecord()
Returns the current record as a hash.
CsvUtil::AbstractCsvIterator::constructor
constructor(AbstractLineIterator li, *hash< auto > opts)
creates the AbstractCsvIterator with an option hash in single-type mode
CsvUtil::AbstractCsvIterator::getRawLine
string getRawLine()
Returns the current line 'as it is', i.e. the original string.
CsvUtil::AbstractCsvIterator::Options
const Options
valid options for the object (a hash for quick lookups of valid keys)
Definition: AbstractCsvIterator.qc.dox.h:290
CsvUtil::AbstractCsvIterator::peek
peek()
Reads a single row without moving the index position.
CsvUtil::AbstractCsvIterator::getValue
hash< auto > getValue()
Returns the current record as a hash.
CsvUtil::AbstractCsvIterator::identifyType
string identifyType(list< auto > rec)
Identify a fixed-length line type using identifyTypeImpl(); may be overridden if necessary.
CsvUtil::AbstractCsvIterator::index
int index()
Returns the row index being iterated, which does not necessarily correspond to the line number when t...
CsvUtil::AbstractCsvIterator::identifyTypeImpl
*string identifyTypeImpl(list< auto > rec)
Identify a input record, given the raw line string. This method performs a lookup to a precalculated ...
CsvUtil::AbstractCsvIterator::lineNumber
int lineNumber()
Returns the current iterator line number in the file (the first line is line 1) or 0 if not pointing ...
CsvUtil::AbstractCsvIterator::parseLine
hash< auto > parseLine()
Parses a line in the file and returns a processed list of the fields.
CsvUtil::AbstractCsvIterator::getRawLineValues
list< *string > getRawLineValues()
Returns the list of raw string values of the current line.
CsvUtil::AbstractCsvIterator::getRecord
hash< auto > getRecord(bool extended)
Returns the current record as a hash.
CsvUtil::AbstractCsvIterator::processCommonOptions
processCommonOptions(*hash< auto > opts, int C_OPTx)
process common options and and assing internal fields
CsvUtil::AbstractCsvIterator::getHeaders
*list< string > getHeaders()
Returns the current record headers or NOTHING if no headers have been detected or saved yet.
CsvUtil::AbstractCsvIterator::constructor
constructor(AbstractLineIterator li, hash< auto > spec, hash< auto > opts)
creates the AbstractCsvIterator with an option hash in multi-type mode
CsvUtil::AbstractCsvIterator::getHeaders
*list< string > getHeaders(string type)
Returns a list of headers for the given record or NOTHING if the record is not recognized.
CsvUtil::AbstractCsvIterator::getRecordList
auto getRecordList()
Returns the current record as a list.
CsvUtil::AbstractCsvIterator::getSeparator
string getSeparator()
Returns the current separator string.
CsvUtil::AbstractCsvIterator::next
bool next()
Moves the current line / record position to the next line / record; returns False if there are no mor...
Qore::AbstractIterator
True
const True
False
const False
type
string type(auto arg)
CsvUtil
the CsvUtil namespace. All classes used in the CsvUtil module should be inside this namespace
Definition: AbstractCsvIterator.qc.dox.h:28