Overview | Group | Tree | Graph | Index | Concepts |
An instance of IloCsvReader
reads a csv file 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:
tableName|KEYS
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 *) |
public | IloCsvReader(const IloCsvReader &) |
public | IloCsvReader(IloEnv, const char *, IloBool, IloBool, const char *, const char, const char, const char, IloBool) |
Method Summary | |
---|---|
public void | end() |
public IloNum | getCsvFormat() |
public IloCsvLine | getCurrentLine() |
public IloEnv | getEnv() |
public IloNum | getFileVersion() |
public IloCsvReaderI * | getImpl() |
public IloCsvLine | getLineByKey(IloInt, const char *, ...) |
public IloCsvLine | getLineByNumber(IloInt) |
public IloInt | getNumberOfColumns() |
public IloInt | getNumberOfItems() |
public IloInt | getNumberOfKeys() |
public IloInt | getNumberOfTables() |
public IloInt | getPosition(const char *) |
public IloCsvTableReader | getReaderForUniqueTableFile() |
public const char * | getRequiredBy() |
public IloCsvTableReader | getTable() |
public IloCsvTableReader | getTableByName(const char *) |
public IloCsvTableReader | getTableByNumber(IloInt) |
public IloBool | isHeadingExists(const char *) |
public void | operator=(const IloCsvReader &) |
public IloBool | printKeys() |
Inner Class |
---|
IloCsvReader::TableIterator |
IloCsvReader::LineIterator |
Constructor and Destructor Detail |
---|
This constructor creates a csv reader object whose handle pointer is null. This object must be assigned before it can be used.
This constructor creates a handle object (an instance of
IloCsvReader
) from a pointer to an implementation object (an
instance of the class IloCsvReaderI
).
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.
This constructor creates a csv reader object for the file
problem
in the environment env
. If the parameter
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 parameter isMultiTable
has the value
IloTrue
, the file problem
is read as a multitable
file. The default value is IloFalse
.
If the parameter 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 |
---|
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.
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
.
isMultiTable
has the value IloTrue
.This member function returns the last line read by
getLineByKey
or getLineByNumber
.
isMultiTable
has the value IloFalse
.This member function returns the environment object corresponding to the invoking csv reader.
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
.
isMultiTable
has the value IloTrue
.This member function returns a pointer to the implementation object corresponding to the invoking csv reader.
This member function takes numberOfKeys
as parameters;
these parameters 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.
isMultiTable
has the value IloFalse
.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.
isMultiTable
has the value IloFalse
.This member function returns the number of columns in the table. If the first column contains the name of the table it is ignored.
isMultiTable
has the value IloFalse
.This member function returns the number of lines of the table excluding blank lines, commented lines, and the header line.
isMultiTable
has the value IloFalse
.This member function returns the number of keys for the table.
isMultiTable
has the value IloFalse
.This member function returns the number of tables in the data file.
This member function returns the position (column number) of the
headingName
in the file.
isMultiTable
has the value IloFalse
.This member function returns an IloCsvTableReader
for the
unique table contained in the csv data file.
isMultiTable
has the value IloFalse
.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
.
isMultiTable
has the value IloTrue
.This member function returns an instance of
IloCsvTableReader
representing the unique
table in the data file.
isMultiTable
has the value IloFalse
.This member function returns an instance of
IloCsvTableReader
representing the table
named name
in the data file.
isMultiTable
has the value IloTrue
.This member function returns an instance of
IloCsvTableReader
representing the table
numbered i
in the data file.
isMultiTable
has the value IloTrue
.This member function returns IloTrue
if the column header
headingName
exists. Otherwise, it returns
IloFalse
.
isMultiTable
has the value IloFalse
.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.
This member function prints the column header of keys if the header exists. Otherwise, it prints the column numbers of keys.
isMultiTable
has the value IloFalse
.