CSVArchive Class Reference
[Public API]

Implementation of Archive interface for csv file format. More...

#include <csv.h>

Inheritance diagram for CSVArchive:

Inheritance graph
[legend]
Collaboration diagram for CSVArchive:

Collaboration graph
[legend]
List of all members.

Public Member Functions

void addMapping (const char *pCSVField, const char *pTable, const char *pField)
 Add mapping using column name.
void addMapping (int pCSVField, const char *pTable, const char *pField)
 Add mapping using column number.
void clearMappings ()
 Clear all mappings created by addMapping methods.
virtual IStreamgetInputStream ()
 Create input stream.
CSVIStream getIStream ()
 create and return input stream
CSVOStream getOStream ()
 create and return output stream
virtual OStreamgetOutputStream ()
 Create output stream.
bool hasColumnNames () const
 This flag tells archive if file contains column names as first row or not.
void hasColumnNames (bool pFlag)
 This flag tells archive if file contains column names as first row or not.
void ignoreEmptyLines (bool pFlag)
 This flag tells internal CSVParser to ignore lines with no data.
virtual bool isOpen () const
 Check if archive is open.
virtual void open (const char *pOpenStr)
 Open archive.
void setFieldSeparator (char pSep)
 Set field separator.
virtual ~CSVArchive ()
 Destructor.

Detailed Description

Implementation of Archive interface for csv file format.

To fetch data or objects from csv files before opening archive you have to set mappings. Mappings are used to make relation between object fields or binded vars and columns in CSV file.

Mappings can be done automatically or manually (see hasColumnNames()). Automatic mapping occurs always when:

  • archive has column names
  • addMapping was not called before open()

Automatic mapping is estabilished between store table entry or binded var and column that have the same name as field. It is not possibile to manually add mappings after automatic mapping was done

Binded Vars.

When binding variables to output stream with automatic mapping order of binding is sigincfant. For example for this bindings:

int a,b;
stream.bind(a,"test","a")
stream.bind(b,"test","b")

first data for "a" column will be written and then data for "b".

You can add multiple bindings for the same column name - this will result in multiple column names in cvs file in order that variables were binded.

Mappings.

If there is no mapping for column that is not last on list (for example there are mappings for column 1,2,3 and 5 only) that column will be written as empty one if archive does not have setColnames() set to true. In that case DataException will be thrown - driver don't know what column name to write because there is no mapping for it.

You should not create multiple streams from one CSVArchive at one time. Every call to a CSVOStream::open will overwrite existing file. Reading data from a file using a CSVIStream and writing data to it using a CSVOStream simultaneously is not a good idea and can give weird results


Member Function Documentation

void addMapping const char *  pCSVField,
const char *  pTable,
const char *  pField
 

Add mapping using column name.

This function will map pTable and pFiled from object's store tables to particular column name.

Parameters:
pCSVField column name from csv file
pTable relation name from store table
pField field name from store table

void addMapping int  pCSVField,
const char *  pTable,
const char *  pField
 

Add mapping using column number.

This function will map pTable and pField to n-th column in cvs file (columns are numbered from 0). It can be called for archives with or without names. Don't use this function if you want to bind variables to fields - in this case only named mappings works.

Parameters:
pCSVField column index from csv file
pTable relation name from store table
pField field name from store table

virtual IStream* getInputStream  )  [virtual]
 

Create input stream.

Returned value must be deleted

Returns:
IStream

Implements Archive.

CSVIStream getIStream  ) 
 

create and return input stream

Returns:
IStream derived class

CSVOStream getOStream  ) 
 

create and return output stream

Returns:
OStream derived class

virtual OStream* getOutputStream  )  [virtual]
 

Create output stream.

Returned value must be deleted

Returns:
IStream

Implements Archive.

bool hasColumnNames  )  const
 

This flag tells archive if file contains column names as first row or not.

Returns:
true if hasColumnNames was set, false otherwise

void hasColumnNames bool  pFlag  ) 
 

This flag tells archive if file contains column names as first row or not.

Parameters:
pFlag true if archive should read/create column names in first line of csv file

void ignoreEmptyLines bool  pFlag  ) 
 

This flag tells internal CSVParser to ignore lines with no data.

Parameters:
pFlag true if input stream should ignore empty lines, false otherwise

virtual bool isOpen  )  const [virtual]
 

Check if archive is open.

Returns:
true if archive is open, false otherwise

Implements Archive.

virtual void open const char *  pOpenStr  )  [virtual]
 

Open archive.

Parameters:
pOpenStr path to csv file.

Implements Archive.

void setFieldSeparator char  pSep  ) 
 

Set field separator.

Default is comma

Parameters:
pSep new field separator char

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

Documentation
Quick start
Examples
Search

API Documentation
Class hierarchy
Member index
API Reference
Store filters
Store table macros
Back

Generated by doxygen at Sun Nov 9 02:08:17 2008