CVS File. More...
#include <rcsvfile.h>
Public Member Functions | |
RCSVFile (const RURI &uri, RChar sep=',', bool quotes=true, const RCString &encoding="utf-8") | |
const RURI | GetURI (void) const |
virtual void | Open (RIO::ModeType mode=RIO::Read) |
virtual void | Open (const RURI &uri, RChar sep=',', bool quotes=true, RIO::ModeType mode=RIO::Read, const RCString &encoding="utf-8") |
virtual void | Close (void) |
bool | End (void) const |
unsigned long | GetLineNb (void) const |
void | SetPrintDebug (bool debug) |
void | Read (void) |
RString | Get (size_t idx) const |
size_t | GetSizeT (size_t idx, bool zero=true) const |
double | GetDouble (size_t idx, bool zero=true) const |
size_t | GetNbValues (void) const |
bool | HasValue (size_t idx) const |
virtual | ~RCSVFile (void) |
Static Public Member Functions | |
static RString | CSVValue (const RString val) |
Private Member Functions | |
void | NewValue (void) |
void | AddBuffer (void) |
void | AddToBuffer (void) |
void | NextChar (void) |
bool | IsEol (void) |
Private Member Functions inherited from RTextFile | |
RTextFile (void) | |
RTextFile (const RURI &uri, const RCString &encoding="Latin1") | |
RTextFile (RIOFile &file, const RCString &encoding="Latin1") | |
void | Open (const RURI &uri, RIO::ModeType mode=RIO::Read, const RCString &encoding="Latin1") |
virtual void | Seek (off_t pos) |
virtual void | SeekRel (off_t pos) |
RChar | GetNextChar (void) const |
RChar | GetChar (void) |
const RChar | GetCur (void) const |
RString | GetChars (size_t size) |
RString | GetUntilEnd (void) |
void | SkipEol (void) |
bool | CurString (const RString &str, bool CaseSensitive=true, bool skip=true) |
void | SkipComments (void) |
void | SkipSpaces (void) |
size_t | SkipCountSpaces (RChar car) |
virtual void | SetEncoding (const RCString &name) |
RCString | GetEncoding (void) const |
void | SetRemStyle (RemType style) |
void | SetParseSpace (ParseSpaceType parse) |
ParseSpaceType | GetParseSpace (void) const |
void | SetRem (const RString &c) |
void | SetRem (const RString &b, const RString &e) |
bool | MustAddSeparator (void) const |
void | SetAddSeparator (bool add) |
RString | GetWord (void) |
RString | GetToken (const RString &endingchar) |
RString | GetTokenString (const RString &endingstr) |
RString | GetLine (bool skipempty=true) |
long | GetInt (void) |
unsigned long | GetUInt (void) |
RTextFile & | operator>> (RString &str) |
RTextFile & | operator>> (char &nb) |
RTextFile & | operator>> (unsigned char &nb) |
RTextFile & | operator>> (short &nb) |
RTextFile & | operator>> (unsigned short &nb) |
RTextFile & | operator>> (int &nb) |
RTextFile & | operator>> (unsigned int &nb) |
RTextFile & | operator>> (long &nb) |
RTextFile & | operator>> (unsigned long &nb) |
RTextFile & | operator>> (float &nb) |
RTextFile & | operator>> (double &nb) |
RTextFile & | operator>> (long double &nb) |
void | WriteLine (void) |
void | WriteStr (const RString &str, bool invalid=false) |
void | WriteStr (const char *c, bool invalid=false) |
void | WriteStr (const char *c, size_t l, bool invalid=false) |
RTextFile & | operator<< (const char *c) |
RTextFile & | operator<< (const RString &str) |
void | WriteLong (const long nb) |
RTextFile & | operator<< (const char nb) |
RTextFile & | operator<< (const short nb) |
RTextFile & | operator<< (const int nb) |
RTextFile & | operator<< (const long nb) |
void | WriteULong (const unsigned long nb) |
RTextFile & | operator<< (const unsigned char nb) |
RTextFile & | operator<< (const unsigned int nb) |
RTextFile & | operator<< (const unsigned long nb) |
void | WriteBool (const bool b) |
RTextFile & | operator<< (const bool b) |
void | WriteChar (const char c) |
void | WriteFloat (const float nb) |
RTextFile & | operator<< (const float nb) |
void | WriteDouble (const double nb) |
RTextFile & | operator<< (const double nb) |
void | WriteLongDouble (const long double nb) |
RTextFile & | operator<< (const long double nb) |
void | WriteTime (void) |
void | WriteLog (const RString &entry, bool invalid) |
unsigned long | GetLineNb (void) const |
unsigned long | GetLastLine (void) const |
void | SetSeparator (const RString &str) |
void | SetSeparator (const char *str) |
virtual | ~RTextFile (void) |
void | Next (void) |
RString | GetRealNb (void) |
void | WriteSeparator (void) |
Private Member Functions inherited from RIOFile | |
RIOFile (void) | |
RIOFile (const RURI &uri) | |
RIOFile (RIOFile &file) | |
RURI | GetRealName (void) const |
void | Open (const RURI &uri, RIO::ModeType mode) |
bool | IsOpen (void) const |
size_t | Read (char *buffer, size_t nb, bool move=true) |
void | Write (const char *buffer, size_t nb) |
virtual void | SeekToEnd (void) |
void | Truncate (off_t newsize) |
bool | End (void) const |
off_t | GetSize (void) const |
off_t | GetPos (void) const |
virtual | ~RIOFile (void) |
Private Member Functions inherited from RFile | |
RFile (void) | |
RFile (const RURI &uri) | |
RFile (const RFile &file) | |
void | Open (const RURI &uri, RIO::ModeType mode) |
int | Compare (const RFile &file) const |
int | Compare (const RFile *file) const |
int | Compare (const RString &uri) const |
const RURI & | GetURI (void) const |
void | SetURI (const RURI &uri) |
const RString | GetFileName (void) const |
virtual | ~RFile (void) |
Private Attributes | |
RChar | Sep |
bool | Quotes |
RChar | Escape |
RContainer< RString, true, false > | Values |
size_t | NbValues |
RChar * | Internal |
size_t | SizeBuffer |
RChar * | Buffer |
RString * | CurValue |
int | CurCol |
RChar | CurChar |
bool | ReadValue |
RChar | EndValueChar |
bool | Debug |
Private Attributes inherited from RIOFile | |
bool | CanWrite |
bool | CanRead |
Private Attributes inherited from RFile | |
RIO::ModeType | Mode |
RURI | URI |
Additional Inherited Members | |
Private Types inherited from RTextFile | |
enum | RemType { NoComment, SingleLineComment, MultiLineComment, SingleMultiLineComment } |
enum | ParseSpaceType { LeaveSpaces, SkipAllSpaces } |
Static Private Member Functions inherited from RTextFile | |
static bool | Eol (RChar car) |
Static Private Member Functions inherited from RFile | |
static RChar | GetDirSeparator (void) |
static void | RemoveFile (const RURI &uri) |
static void | RenameFile (const RURI &olduri, const RURI &newuri) |
static RURI | GetTempFile (void) |
static bool | Exists (const RURI &uri) |
static bool | IsDir (const RURI &uri) |
Detailed Description
CVS File.
The RCSVFile provides a class for manipulating CSV text files. Currently, these files can only be opened. When the file is opened, the fist "CSV line" is read. An end of line character inside a field delimited by quotes are part of the value and not the end of a "CSV line"
Here is an example of use:
- Remarks
- If this first line contains the headers, the programmer should called the method 'Read' before reading the first values.
Constructor & Destructor Documentation
RCSVFile | ( | const RURI & | uri, |
RChar | sep = ',' , |
||
bool | quotes = true , |
||
const RCString & | encoding = "utf-8" |
||
) |
Constructor of the CSV file.
- Parameters
-
uri URI of the file. sep Separator (comma by default). quotes Can columns be delimited by quotes ? encoding The encoding scheme of the file.
- Returns
|
virtual |
Destruct the file.
Member Function Documentation
const RURI GetURI | ( | void | ) | const |
Return the URI of the file including.
|
virtual |
|
virtual |
Open the file.
- Parameters
-
uri URI of the file. sep Separator (comma by default). quotes Can columns be delimited by quotes ? mode The open mode for the file. encoding The encoding scheme of the file.
|
virtual |
Close the file.
Reimplemented from RTextFile.
bool End | ( | void | ) | const |
- Returns
- true if the end of the file is reached.
unsigned long GetLineNb | ( | void | ) | const |
Get the number of the current line.
- Returns
- current line.
void SetPrintDebug | ( | bool | debug | ) |
Specify if information must be printed during the treatment of a line.
- Parameters
-
debug If true, information is printed.
Transform a string to be used in a csv file (add quotes before and after, double quotes inside the string).
- Parameters
-
val String containing the value.
- Returns
- a RString.
|
private |
Create a new value to read and assign it the CurValue.
|
private |
Add the content of the buffer to CurValue and reset the buffer.
|
private |
Add the current character to the buffer.
|
private |
Read the current character in CurChar and increment CurCol.
|
private |
Look if there is some values to read at thr current column. In practice, the method is called at the beginning and after a separation.
- Returns
- true if the end of line is reached.
void Read | ( | void | ) |
Read and analyze a line.
RString Get | ( | size_t | idx | ) | const |
- Returns
- a RString corresponding to a given value of the current line.
- Parameters
-
idx Index of the value.
size_t GetSizeT | ( | size_t | idx, |
bool | zero = true |
||
) | const |
- Returns
- a size_t corresponding to a given value of the current line. if the value is not an integer, an exception is generated.
- Parameters
-
idx Index of the value. zero Specify if an empty field must be considered as a zero (true) or generate an exception (false).
double GetDouble | ( | size_t | idx, |
bool | zero = true |
||
) | const |
- Returns
- a double corresponding to a given value of the current line. if the value is not an number, an exception is generated.
- Parameters
-
idx Index of the value. zero Specify if an empty field must be considered as a zero (true) or generate an exception (false).
size_t GetNbValues | ( | void | ) | const |
- Returns
- the number of values at the last line read.
bool HasValue | ( | size_t | idx | ) | const |
Verify if the current line has a value for a given index.
- Parameters
-
idx Index to verify.
- Returns
- true if a value exists.
Field Documentation
|
private |
Separator of the values.
|
private |
Can the columns be delimited by quotes.
|
private |
Escape character
|
private |
Current values.
|
private |
Number of values on a line.
|
private |
Internal Buffer.
|
private |
Number of characters in the buffer.
|
private |
Current position in the buffer.
|
private |
Current value read.
|
private |
Current column.
|
private |
Current character.
|
private |
Is a value currently read?
|
private |
Character that will represent the end of a value.
|
private |
Debug characters read.