NO FRAMES

Class IloCsvReader

Definition file: ilconcert/ilocsvreader.h
Reads a formatted csv file.

An instance of IloCsvReader reads a file of comma-separated values of a specified format. The csv file can be a multitable or a single table file. Empty lines and commented lines are allowed everywhere in the file.

Format of multitable files

The first column of the table must contain the name of the table.

Each table can begin with a line containing column headers, the first field of this line must have this format: tableName|NAMES

The keys can be specified in the data file by adding a line at the beginning of the table. This line is formatted as follows:

If this line doesn't exist, all columns form a key. If you need to get a line having a specific value for a field, you must add the key line in which you specify that this field is a key for the table.

Any line containing '|' in its first field is ignored by the reader.

A table can be split in several parts in the file (for example, you have a part of table TA, then table TB, then the end of table TA).

Example

 NODES|NAMES,node_type,node_name,xcoord,ycoord
 NODES|KEYS,1,1,0,0
 NODES,1,node1,0,1
 NODES,1,node2,0,2
 NODES,2,node1,0,4
 

Format of single table files

The line containing the column headers, if it exists, must have a first field of the following format: Field|NAMES.

Table keys can be specified by adding a line at the beginning of the table. This line must have a first field with this format: tableName|KEYS. If this line doesn't exist, all columns form a key.

Example

 Field|NAMES,nodeName,xCoord,yCoord
 Field|KEYS,1,0,0
 node1,0,1
 node2,0,2
 
Constructor and Destructor Summary
public IloCsvReader()
public IloCsvReader(IloCsvReaderI * impl)
public IloCsvReader(const IloCsvReader & csv)
public IloCsvReader(IloEnv env, const char * problem, IloBool multiTable=IloFalse, IloBool allowTableSplitting=IloFalse, const char * separator=",;\t", const char decimalp='.', const char quote='\"', const char comment='#')
Method Summary
public voidend()
public IloNumgetCsvFormat()
public IloCsvLinegetCurrentLine() const
public IloEnvgetEnv() const
public IloNumgetFileVersion()
public IloCsvReaderI *getImpl() const
public IloCsvLinegetLineByKey(IloInt numberOfKeys, const char *, ...)
public IloCsvLinegetLineByNumber(IloInt i)
public IloIntgetNumberOfColumns()
public IloIntgetNumberOfItems()
public IloIntgetNumberOfKeys() const
public IloIntgetNumberOfTables()
public IloIntgetPosition(const char * headingName) const
public IloCsvTableReadergetReaderForUniqueTableFile() const
public const char *getRequiredBy()
public IloCsvTableReadergetTable()
public IloCsvTableReadergetTableByName(const char * name)
public IloCsvTableReadergetTableByNumber(IloInt i)
public IloBoolisHeadingExists(const char * headingName) const
public voidoperator=(const IloCsvReader & csv)
public IloBoolprintKeys() const
Inner Class
IloCsvReader::IloColumnHeaderNotFoundException Exception thrown for unfound header.
IloCsvReader::TableIterator Table-iterator of csv readers.
IloCsvReader::LineIterator Line-iterator for csv readers.
IloCsvReader::IloFileNotFoundException Exception thrown when file is not found.
IloCsvReader::IloFieldNotFoundException Exception thrown for field not found.
IloCsvReader::IloCsvReaderParameterException Exception thrown for incorrect arguments in constructor.
IloCsvReader::IloDuplicatedTableException Exception thrown for tables of same name in csv file.
IloCsvReader::IloTableNotFoundException Exception thrown for unfound table.
IloCsvReader::IloIncorrectCsvReaderUseException Exception thrown for call to inappropriate csv reader.
IloCsvReader::IloLineNotFoundException Exception thrown for unfound line.
Constructor and Destructor Detail

IloCsvReader

public IloCsvReader()

This constructor creates a csv reader object whose handle pointer is null. This object must be assigned before it can be used.


IloCsvReader

public IloCsvReader(IloCsvReaderI * impl)

This constructor creates a handle object (an instance of IloCsvReader) from a pointer to an implementation object (an instance of the class IloCsvReaderI).


IloCsvReader

public IloCsvReader(const IloCsvReader & csv)

This copy constructor creates a handle from a reference to a csv reader object. Both the csv reader object and csv point to the same implementation object.


IloCsvReader

public IloCsvReader(IloEnv env, const char * problem, IloBool multiTable=IloFalse, IloBool allowTableSplitting=IloFalse, const char * separator=",;\t", const char decimalp='.', const char quote='\"', const char comment='#')

This constructor creates a csv reader object for the file problem in the environment env. If the argument isCached has the value IloTrue, the data of the file will be stored in the memory.

The cached mode is useful only if you need to read lines by keys. It needs consequent memory consumption and takes time to load data according to the csv file size.

If the argument isMultiTable has the value IloTrue, the file problem is read as a multitable file. The default value is IloFalse.

If the argument allowTableSplitting has the value IloFalse, splitting the table into several parts in the file is not permitted. The default value is IloFalse.

The string separator represents the characters used as separator in the data file. The default values are , ; \t.

The character decimal represents the character used to write decimal numbers in the data file. The default value is . (period).

The character quote represents the character used to quote expressions.

The character comment represents the character used at the beginning of each commented line. The default value is #.


Method Detail

end

public void end()

This member function deallocates the memory used by the csv reader. If you no longer need a csv reader, you can reduce memory consumption by calling this member function.


getCsvFormat

public IloNum getCsvFormat()

This member function returns the format of the csv data file. This format is identified in the data file by ILOG_CSV_FORMAT.

Example

ILOG_CSV_FORMAT;1

getCsvFormat() returns 1.

Note
This member function can be used only if isMultiTable has the value IloTrue.

getCurrentLine

public IloCsvLine getCurrentLine() const

This member function returns the last line read by getLineByKey or getLineByNumber.

Note
This member function can be used only if isMultiTable has the value IloFalse.

getEnv

public IloEnv getEnv() const

This member function returns the environment object corresponding to the invoking csv reader.


getFileVersion

public IloNum getFileVersion()

This member function returns the version of the csv data file. This information is identified in the data file by ILOG_DATA_SCHEMA.

Example

ILOG_DATA_SCHEMA;PROJECTNAME;0.9

getFileVersion() returns 0.9.

Note
This member function can be used only if isMultiTable has the value IloTrue.

getImpl

public IloCsvReaderI * getImpl() const

This member function returns a pointer to the implementation object corresponding to the invoking csv reader.


getLineByKey

public IloCsvLine getLineByKey(IloInt numberOfKeys, const char *, ...)

This member function takes numberOfKeys arguments; these arguments are used as one key to identify a line. It returns an instance of IloCsvLine representing the line having (key1, key2, ...) in the data file. If the number of keys specified is less than the number of keys in the table, this member function throws an exception. Each time getLineByNumber or getLineByKey is called, the previous line read by one of these methods is deleted.

Note
This member function can be used only if isMultiTable has the value IloFalse.

getLineByNumber

public IloCsvLine getLineByNumber(IloInt i)

This member function returns an instance of IloCsvLine representing the line numbered i in the data file. If i does not exist, this member function throws an exception. Each time getLineByNumber or getLineByKey is called, the previous line read by one of these methods is deleted.

Note
This member function can be used only if isMultiTable has the value IloFalse.

getNumberOfColumns

public IloInt getNumberOfColumns()

This member function returns the number of columns in the table. If the first column contains the name of the table it is ignored.

Note
This member function can be used only if isMultiTable has the value IloFalse.

getNumberOfItems

public IloInt getNumberOfItems()

This member function returns the number of lines of the table excluding blank lines, commented lines, and the header line.

Note
This member function can be used only if isMultiTable has the value IloFalse.

getNumberOfKeys

public IloInt getNumberOfKeys() const

This member function returns the number of keys for the table.

Note
This member function can be used only if isMultiTable has the value IloFalse.

getNumberOfTables

public IloInt getNumberOfTables()

This member function returns the number of tables in the data file.


getPosition

public IloInt getPosition(const char * headingName) const

This member function returns the position (column number) of the headingName in the file.

Note
This member function can be used only if isMultiTable has the value IloFalse.

getReaderForUniqueTableFile

public IloCsvTableReader getReaderForUniqueTableFile() const

This member function returns an IloCsvTableReader for the unique table contained in the csv data file.

Note
This member function can be used only if isMultiTable has the value IloFalse.

getRequiredBy

public const char * getRequiredBy()

This member function returns the name of the project that uses the csv data file. This information is identified in the data file by ILOG_DATA_SCHEMA.

Example

ILOG_DATA_SCHEMA;PROJECTNAME;0.9

getRequiredBy() returns PROJECTNAME.

Note
This member function can be used only if isMultiTable has the value IloTrue.

getTable

public IloCsvTableReader getTable()

This member function returns an instance of IloCsvTableReader representing the unique table in the data file.

Note
This member function can be used only if isMultiTable has the value IloFalse.

getTableByName

public IloCsvTableReader getTableByName(const char * name)

This member function returns an instance of IloCsvTableReader representing the table named name in the data file.

Note
This member function can be used only if isMultiTable has the value IloTrue.

getTableByNumber

public IloCsvTableReader getTableByNumber(IloInt i)

This member function returns an instance of IloCsvTableReader representing the table numbered i in the data file.

Note
This member function can be used only if isMultiTable has the value IloTrue.

isHeadingExists

public IloBool isHeadingExists(const char * headingName) const

This member function returns IloTrue if the column header headingName exists. Otherwise, it returns IloFalse.

Note
This member function can be used only if isMultiTable has the value IloFalse.

operator=

public void operator=(const IloCsvReader & csv)

This operator assigns an address to the handle pointer of the invoking csv reader. This address is the location of the implementation object of the argument csv.

After execution of this operator, both the invoking csv reader and csv point to the same implementation object.


printKeys

public IloBool printKeys() const

This member function prints the column header of keys if the header exists. Otherwise, it prints the column numbers of keys.

Note
This member function can be used only if isMultiTable has the value IloFalse.