src/sources/writer.cpp
// Write data to csv-file
// @input:
// - filePath - string with absolute path to csv-file
// - data - not empty AbstractData object that contains information that should
// be written to csv-file
// - separator - string or character that would separate values in a row
// (line) in csv-file
// - textDelimeter - string or character that enclose each element in a row
// - mode - write mode of the file
// - header - strings that will be written at the beginning of the file in
// one line. separator will be used as delimiter character.
// - footer - strings that will be written at the end of the file in
// one line. separator will be used as delimiter character.
// - codec - pointer to codec object that would be used for file writing
// @output:
// - bool - True if data was written to the file, otherwise False
Write data to csv-file
Write data to csv - file
bool Writer::write(const QString& filePath,
                   const AbstractData& data,
                   const QString& separator,
                   const QString& textDelimeter,
                   const WriteMode& mode,
                   const QStringList& header,
                   const QStringList& footer,
                   QTextCodec* codec)
{
    if ( true == filePath.isEmpty() || true == data.isEmpty() )
    {
        qDebug() << __FUNCTION__ << "Error - invalid arguments";
        return false;
    }
    if ( false == CheckFile(filePath) )
    {
        qDebug() << __FUNCTION__ << "Error - wrong file path/name:" << filePath;
        return false;
    }
    ContentIterator content(data, separator, textDelimeter, header, footer);
    bool result = false;
    switch (mode)
    {
        case APPEND:
            result = WriterPrivate::appendToFile(filePath, content, codec);
            break;
        case REWRITE:
        default:
            result = WriterPrivate::overwriteFile(filePath, content, codec);
    }
    return result;
}
bool Writer :: write ( const QString & filePath , const AbstractData & data , const QString & separator , const QString & textDelimeter , const WriteMode & mode , const QStringList & header , const QStringList & footer , QTextCodec * codec ) { if ( true == filePath . isEmpty ( ) || true == data . isEmpty ( ) ) { qDebug ( ) << __FUNCTION__ << " " ; return false ; } if ( false == CheckFile ( filePath ) ) { qDebug ( ) << __FUNCTION__ << " " << filePath ; return false ; } ContentIterator content ( data , separator , textDelimeter , header , footer ) ; bool result = false ; switch ( mode ) { case APPEND : result = WriterPrivate :: appendToFile ( filePath , content , codec ) ; break ; case REWRITE : default : result = WriterPrivate :: overwriteFile ( filePath , content , codec ) ; } return result ; }
Write data to csv-file
Write data to csv - file