sficl  Current version
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
SfiDelimitedRecordSTD Class Reference

A record consisting of string fields separated by a delimiter. More...

#include <SfiDelimitedRecordSTD.h>

Collaboration diagram for SfiDelimitedRecordSTD:
Collaboration graph
[legend]

Public Member Functions

 SfiDelimitedRecordSTD (const char *str=0, char delimiter= ',')
 
 SfiDelimitedRecordSTD (const SfiDelimitedRecordSTD &rec)
 
 ~SfiDelimitedRecordSTD ()
 
SfiDelimitedRecordSTDoperator= (const SfiDelimitedRecordSTD &rec)
 Copies all data from rec. More...
 
SfiDelimitedRecordSTDoperator= (const char *str)
 Sets the record to a new string (makes a copy). More...
 
int size () const
 Returns the number of fields in the record. More...
 
const char * operator[] (int i) const
 Returns a pointer to the i-th field or an empty string if there are fewer than i fields. More...
 
int length (int n) const
 Returns the length of the n-th field (zero-based) or -1 if there is no such field. More...
 
void setDelimiter (char delim)
 Sets the delimiter character and re-splits the string. More...
 
int offset (int n) const
 Returns the offset of the n-th field (zero-based) in the original string or -1 if there is no such field. More...
 
int split (char *buf, int n)
 Splits the buf in-place, overwriting delimiters with null characters. More...
 
const char * get (int i) const
 Returns a pointer to the i-th field of a split string - for use with split(char*, int) only!!! If the index i is outside the range of valid fields, a pointer to an empty string is returned. More...
 

Protected Member Functions

int split ()
 Returns the number of fields in the record. Delimiters inside double quotes are ignored. More...
 
void clear ()
 Clears the record. More...
 

Protected Attributes

string m_buffer
 Buffer with a modified string for fast retrieval. More...
 
char m_delimiter
 
SfiVectorLite< int > m_offsets
 
SfiVectorLite< int > m_lengths
 
char * m_sptr
 
const char m_nullChar
 

Detailed Description

A record consisting of string fields separated by a delimiter.

The functionality is similar to the split() function in Perl or the way awk treats lines. There are two ways of using this class. The first makes a copy of the string. In this case, the class should be initialized with a string and the resulting fields should be accessed by the operator[]. The second way is to pass the line to the class as a writable buffer in the split function and access the resulting fields via the get() method. In this case, the split occurs in-place, i.e., without a copy or memory allocation, but the delimiters in the buffer are overwritten with null characters. The get() method should not be called after the buffer was subsequently changed by the caller.

Definition at line 52 of file SfiDelimitedRecordSTD.h.

Constructor & Destructor Documentation

SfiDelimitedRecordSTD::SfiDelimitedRecordSTD ( const char *  str = 0,
char  delimiter = ',' 
)
inlineexplicit

Definition at line 64 of file SfiDelimitedRecordSTD.h.

References m_lengths, m_offsets, and SfiVectorLite< T >::reserve().

SfiDelimitedRecordSTD::SfiDelimitedRecordSTD ( const SfiDelimitedRecordSTD rec)
inline

Definition at line 70 of file SfiDelimitedRecordSTD.h.

SfiDelimitedRecordSTD::~SfiDelimitedRecordSTD ( )
inline

Definition at line 74 of file SfiDelimitedRecordSTD.h.

Member Function Documentation

void SfiDelimitedRecordSTD::clear ( )
inlineprotected

Clears the record.

Definition at line 218 of file SfiDelimitedRecordSTD.h.

References SfiVectorLite< T >::clear(), m_buffer, m_lengths, m_offsets, and m_sptr.

Referenced by operator=(), and split().

const char* SfiDelimitedRecordSTD::get ( int  i) const
inline

Returns a pointer to the i-th field of a split string - for use with split(char*, int) only!!! If the index i is outside the range of valid fields, a pointer to an empty string is returned.

Definition at line 178 of file SfiDelimitedRecordSTD.h.

References m_nullChar, m_offsets, m_sptr, SfiVectorLite< T >::size(), and size().

int SfiDelimitedRecordSTD::length ( int  n) const
inline

Returns the length of the n-th field (zero-based) or -1 if there is no such field.

Definition at line 121 of file SfiDelimitedRecordSTD.h.

References m_lengths, m_offsets, and SfiVectorLite< T >::size().

int SfiDelimitedRecordSTD::offset ( int  n) const
inline

Returns the offset of the n-th field (zero-based) in the original string or -1 if there is no such field.

Definition at line 133 of file SfiDelimitedRecordSTD.h.

References m_offsets, and SfiVectorLite< T >::size().

SfiDelimitedRecordSTD& SfiDelimitedRecordSTD::operator= ( const SfiDelimitedRecordSTD rec)
inline

Copies all data from rec.

Definition at line 77 of file SfiDelimitedRecordSTD.h.

References m_buffer, m_delimiter, m_lengths, m_offsets, and m_sptr.

SfiDelimitedRecordSTD& SfiDelimitedRecordSTD::operator= ( const char *  str)
inline

Sets the record to a new string (makes a copy).

Access to the resulting split string is via the operator[].

Definition at line 89 of file SfiDelimitedRecordSTD.h.

References clear(), m_buffer, and split().

const char* SfiDelimitedRecordSTD::operator[] ( int  i) const
inline

Returns a pointer to the i-th field or an empty string if there are fewer than i fields.

Definition at line 110 of file SfiDelimitedRecordSTD.h.

References m_buffer, m_nullChar, m_offsets, SfiVectorLite< T >::size(), and size().

void SfiDelimitedRecordSTD::setDelimiter ( char  delim)
inline

Sets the delimiter character and re-splits the string.

Definition at line 127 of file SfiDelimitedRecordSTD.h.

References m_delimiter.

int SfiDelimitedRecordSTD::size ( ) const
inline

Returns the number of fields in the record.

Definition at line 104 of file SfiDelimitedRecordSTD.h.

References m_offsets, and SfiVectorLite< T >::size().

Referenced by get(), and operator[]().

int SfiDelimitedRecordSTD::split ( char *  buf,
int  n 
)
inline

Splits the buf in-place, overwriting delimiters with null characters.

Returns the number of fields in the buf. Delimiters inside double quotes are ignored. n is the size of string in buf, excluding the terminating null. Access to fields is provided by get(int).

Definition at line 142 of file SfiDelimitedRecordSTD.h.

References SfiVectorLite< T >::clear(), clear(), m_delimiter, m_lengths, m_offsets, m_sptr, SfiVectorLite< T >::push_back(), and SfiVectorLite< T >::size().

int SfiDelimitedRecordSTD::split ( )
inlineprotected

Returns the number of fields in the record. Delimiters inside double quotes are ignored.

Definition at line 191 of file SfiDelimitedRecordSTD.h.

References SfiVectorLite< T >::clear(), m_buffer, m_delimiter, m_lengths, m_offsets, SfiVectorLite< T >::push_back(), and SfiVectorLite< T >::size().

Referenced by operator=().

Member Data Documentation

string SfiDelimitedRecordSTD::m_buffer
protected

Buffer with a modified string for fast retrieval.

Definition at line 56 of file SfiDelimitedRecordSTD.h.

Referenced by clear(), operator=(), operator[](), and split().

char SfiDelimitedRecordSTD::m_delimiter
protected

Definition at line 57 of file SfiDelimitedRecordSTD.h.

Referenced by operator=(), setDelimiter(), and split().

SfiVectorLite<int> SfiDelimitedRecordSTD::m_lengths
protected

Definition at line 59 of file SfiDelimitedRecordSTD.h.

Referenced by clear(), length(), operator=(), SfiDelimitedRecordSTD(), and split().

const char SfiDelimitedRecordSTD::m_nullChar
protected

Definition at line 61 of file SfiDelimitedRecordSTD.h.

Referenced by get(), and operator[]().

SfiVectorLite<int> SfiDelimitedRecordSTD::m_offsets
protected
char* SfiDelimitedRecordSTD::m_sptr
protected

Definition at line 60 of file SfiDelimitedRecordSTD.h.

Referenced by clear(), get(), operator=(), and split().


The documentation for this class was generated from the following file: