|
LSSTApplications
1.1.2+25,10.0+13,10.0+132,10.0+133,10.0+224,10.0+41,10.0+8,10.0-1-g0f53050+14,10.0-1-g4b7b172+19,10.0-1-g61a5bae+98,10.0-1-g7408a83+3,10.0-1-gc1e0f5a+19,10.0-1-gdb4482e+14,10.0-11-g3947115+2,10.0-12-g8719d8b+2,10.0-15-ga3f480f+1,10.0-2-g4f67435,10.0-2-gcb4bc6c+26,10.0-28-gf7f57a9+1,10.0-3-g1bbe32c+14,10.0-3-g5b46d21,10.0-4-g027f45f+5,10.0-4-g86f66b5+2,10.0-4-gc4fccf3+24,10.0-40-g4349866+2,10.0-5-g766159b,10.0-5-gca2295e+25,10.0-6-g462a451+1
LSSTDataManagementBasePackage
|
#include <Csv.h>
Public Member Functions | |
| CsvReader (std::string const &path, CsvControl const &control, bool namesInFirstRecord=false) | |
| CsvReader (std::istream &in, CsvControl const &control, bool namesInFirstRecord=false) | |
| ~CsvReader () | |
| CsvControl const & | getControl () const |
| size_t | getNumLines () const |
| size_t | getNumRecords () const |
| std::vector< std::string > const & | getFieldNames () const |
| void | setFieldNames (std::vector< std::string > const &names) |
| void | setFieldNames (std::string const &names, std::string const ®ex, bool stripWhitespace=true) |
| bool | isDone () const |
| void | nextRecord () |
| int | getIndexOf (std::string const &name) const |
| int | getIndexOf (char const *name) const |
Access fields in the current record | |
| int | getNumFields () const |
| bool | isNull (int i) const |
| bool | isNull (std::string const &name) const |
| const More... | |
| bool | isNull (char const *name) const |
| const More... | |
| std::string const | get (int i) const |
| std::string const | get (std::string const &name) const |
| const More... | |
| std::string const | get (char const *name) const |
| const More... | |
| template<typename T > | |
| T const | get (int i) const |
| template<typename T > | |
| T const | get (std::string const &name) const |
| template<typename T > | |
| T const | get (char const *name) const |
Private Types | |
| enum | State { START_RECORD = 0, START_FIELD, IN_FIELD, IN_QUOTED_FIELD, INITIAL_ESCAPE, ESCAPE, EMBEDDED_QUOTE } |
| typedef std::tr1::unordered_map < std::string, int > | FieldIndexes |
Private Member Functions | |
| CsvReader (CsvReader const &) | |
| CsvReader & | operator= (CsvReader const &) |
| void | _ioError (char const *msg) const |
| void | _runtimeError (char const *msg) const |
| bool | _readLine (int offset) |
| void | _readRecord () |
| void | _checkWhitespace (char const *s, char const *msg) const |
| template<typename T > | |
| T | _get (char const *value) const |
| template<> | |
| bool | _get (char const *field) const |
| template<> | |
| char | _get (char const *field) const |
| template<> | |
| signed char | _get (char const *field) const |
| template<> | |
| short | _get (char const *field) const |
| template<> | |
| int | _get (char const *field) const |
| template<> | |
| long | _get (char const *field) const |
| template<> | |
| long long | _get (char const *field) const |
| template<> | |
| unsigned char | _get (char const *field) const |
| template<> | |
| unsigned short | _get (char const *field) const |
| template<> | |
| unsigned int | _get (char const *field) const |
| template<> | |
| unsigned long | _get (char const *field) const |
| template<> | |
| unsigned long long | _get (char const *field) const |
| template<> | |
| float | _get (char const *field) const |
| template<> | |
| double | _get (char const *field) const |
| template<> | |
| long double | _get (char const *field) const |
| template<> | |
| char const * | _null () |
| template<> | |
| bool | _null () |
| template<> | |
| char | _null () |
| template<> | |
| signed char | _null () |
| template<> | |
| short | _null () |
| template<> | |
| int | _null () |
| template<> | |
| long | _null () |
| template<> | |
| long long | _null () |
| template<> | |
| unsigned char | _null () |
| template<> | |
| unsigned short | _null () |
| template<> | |
| unsigned int | _null () |
| template<> | |
| unsigned long | _null () |
| template<> | |
| unsigned long long | _null () |
| template<> | |
| float | _null () |
| template<> | |
| double | _null () |
| template<> | |
| long double | _null () |
| template<> | |
| char const * | _get (char const *field) const |
Static Private Member Functions | |
| template<typename T > | |
| static T | _null () |
Private Attributes | |
| std::string | _path |
| File name. More... | |
| CsvControl | _control |
| File format. More... | |
| std::vector< std::string > | _names |
| Field names in order of occurence. More... | |
| FieldIndexes | _indexes |
| Field name to index map. More... | |
| boost::scoped_ptr< std::ifstream > | _stream |
| File stream. More... | |
| std::istream * | _in |
| Input stream. More... | |
| size_t | _numLines |
| 1-based index of current line. More... | |
| size_t | _numRecords |
| 1-based index of current record. More... | |
| boost::scoped_array< char > | _record |
| Data for a single record. More... | |
| int | _capacity |
| Capacity of _record. More... | |
| bool | _done |
| Finished reading file? More... | |
| std::vector< int > | _fields |
Static Private Attributes | |
| static std::string const | WHITESPACE |
| static int const | MAX_RECORD_LENGTH = 4*1024*1024 |
| static int const | DEFAULT_CAPACITY = 128*1024 |
A class for reading records from Character-Separated-Value files in sequential order.
Fields may be accessed either by name or by index - performance sensitive code should favor the latter. Values can be retrieved as std::string objects via get(int) const . Alternatively, to avoid the cost of memory allocation, they can be retrieved via get<char const *>(int) const, which returns a null-terminated C string. But beware: the C string is located in the readers internal decoded character buffer and is invalidated by the next call to nextRecord()!
get<T>(int) const method can be used to retrieve and cast a field value simultaneously. The supported types are: true. Case insensitive matches to "n", "f", "no", "false", "0" are mapped to false. Any other value results in an exception. Leading and trailing whitespace is permitted. When a field is recognized as a database NULL (e.g. \N with the CsvControl::standardEscapes == true), the field access methods return the following values:
false '\0'
To distinguish between a NULL field and one which happens to take one of values above, use the isNull(int) const method.
All methods provide the strong exception safety guarantee, except for nextRecord() - see the documentation of that method for details.
|
private |
|
private |
| lsst::ap::utils::CsvReader::CsvReader | ( | std::string const & | path, |
| CsvControl const & | control, | ||
| bool | namesInFirstRecord = false |
||
| ) |
Creates a new CsvReader for a file and reads the first record.
| path | Input file name. |
| control | CSV format of the input file. |
| namesInFirstRecord | Set field names to the strings in the first record of the input file? |
Definition at line 76 of file Csv.cc.
| lsst::ap::utils::CsvReader::CsvReader | ( | std::istream & | in, |
| CsvControl const & | control, | ||
| bool | namesInFirstRecord = false |
||
| ) |
Creates a new CsvReader from an std::istream and reads the first record.
This std::istream must be kept alive for the life-time of the CsvReader. If it is externally modified while the reader is alive (e.g. its exception mask is changed, or external reads are performed from it) then the behaviour of the reader is undefined.
| in | Input stream |
| control | CSV format of the input stream |
| namesInFirstRecord | Set field names to the strings in the first record read from the input stream? |
Definition at line 118 of file Csv.cc.
|
private |
|
private |
Throws an exception if the given string contains anything but whitespace.
Definition at line 533 of file Csv.cc.
|
private |
|
inlineprivate |
|
private |
Definition at line 540 of file Csv.cc.
|
private |
Definition at line 589 of file Csv.cc.
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
inlineprivate |
|
inlineprivate |
|
inlineprivate |
|
inlinestaticprivate |
|
inlineprivate |
|
inlineprivate |
|
inlineprivate |
|
inlineprivate |
|
inlineprivate |
|
inlineprivate |
|
inlineprivate |
|
inlineprivate |
|
inlineprivate |
|
inlineprivate |
|
inlineprivate |
|
inlineprivate |
|
inlineprivate |
|
private |
|
private |
Reads a single CSV record from the underlying stream.
Definition at line 295 of file Csv.cc.
|
private |
|
inline |
|
inline |
|
inline |
|
inline |
Returns the number of fields in the current record, or 0 if there is no current record.
|
inline |
Returns the number of fields in the current record, or 0 if there is no current record.
|
inline |
Returns the number of fields in the current record, or 0 if there is no current record.
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Advances to the next record in the file. If all records have been read, the function has no effect.
| lsst::pex::exception::RuntimeError | If this exception is thrown, it is because the input file did not conform to the readers format. The current record will contain the fields succesfully read-in, but the last field may be incomplete or otherwise incorrectly decoded. The next call to nextRecord() will resume reading at the beginning of the next line in the file. If fields contain new-lines, this will not necessarily be at the start of a record! |
| lsst::pex::exception::IoError | A system I/O call failed - one cannot recover in any general way. |
| lsst::pex::exception::LogicError | There is a serious bug in the internal CSV parser. File a ticket! |
Definition at line 110 of file Csv.cc.
| void lsst::ap::utils::CsvReader::setFieldNames | ( | std::vector< std::string > const & | names | ) |
Associates field names with field indexes. The i-th field name in the list corresponds to the i-th field in a record. Once field names have been set, they can be used in lieu of field indexes to look up field values.
Definition at line 167 of file Csv.cc.
| void lsst::ap::utils::CsvReader::setFieldNames | ( | std::string const & | names, |
| std::string const & | regex, | ||
| bool | stripWhitespace = true |
||
| ) |
Splits a string containing a delimited list of field names using the given regular expression and associates the resulting field names with field indexes.
| names | Delimited list of field names. |
| regex | Regular expression matching delimiter. |
| stripWhitespace | Strip whitespace from field names? |
Definition at line 202 of file Csv.cc.
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
staticprivate |
|
staticprivate |
|
staticprivate |
1.8.5