Classes | Public Member Functions

Writer Class Reference

Used by Exporter to write a file. More...

#include <exporter.h>

Collaboration diagram for Writer:
Collaboration graph
[legend]

List of all members.

Classes

class  TemporaryTextFile
 Used by Writer as a device for writing. More...

Public Member Functions

 Writer ()
 Writer (const Writer &original)
template<class T >
Writeroperator<< (const T &t)
Writeroperator<< (const QVariant &v)
Writeroperator<< (const QDateTime &dt)
const QDateTimemin ()
const QDateTimemax ()
QString filePath () const

Detailed Description

Used by Exporter to write a file.


Constructor & Destructor Documentation

Writer::Writer (  ) 

               : m_file(new TemporaryTextFile()), m_stream(new QTextStream())
{
    if (!GlobalConst::TEMP_DIR.exists())
        if (!GlobalConst::TEMP_DIR.mkpath(GlobalConst::TEMP_DIR.absolutePath()))
            Q_ASSERT(false);
    m_file->setFileTemplate(GlobalConst::TEMP_DIR.path() + QDir::separator() + "tmp_writer");
    if (!m_file->open())
        qCritical() << "Cannot create the file " << m_file->fileName();
    m_stream->setDevice(m_file.data());
}

Writer::Writer ( const Writer original  ) 

{
    m_file = original.m_file;
    m_stream = original.m_stream;
    m_min = original.m_min;
    m_max = original.m_max;
}


Member Function Documentation

QString Writer::filePath (  )  const

{
    return QFileInfo(*m_file.data()).filePath();
}

const QDateTime & Writer::max (  ) 

{
    return m_max;
}

const QDateTime & Writer::min (  ) 

{
    return m_min;
}

Writer & Writer::operator<< ( const QVariant v  )  [inline]

{
    if (v.isNull()){
        QVariant::Type type = v.type();
        if (type > QVariant::Invalid && type <= QVariant::Double) {
            // Volgens de enum QVariant::Type betekent dan dat type een built-in numeric is.
            // Daar de QVaraint null is, is de numeric "not a number"
            // Note: QVariant kan hierbij isValid() zijn en een 0 bij conversie outputten, maar toch isNull() zijn!
            *m_stream.data() << "NaN";
        } else
            Q_ASSERT_X(false, "problem in Writer", QString("Type ").append(QString::number(type)).append(" unhandled. Contact admin.").toAscii().data());
    } else
        *m_stream.data() << v.toString();

    return *this;
}

Writer & Writer::operator<< ( const QDateTime dt  )  [inline]

{
    // set min/max
    if (dt > m_max || m_max.isNull()) m_max = dt;
    if (dt < m_min || m_min.isNull()) m_min = dt;

    *m_stream.data() << dt.toString(Qt::ISODate);
    return *this;
}

template<class T >
Writer & Writer::operator<< ( const T &  t  )  [inline]

The non-template function takes precedence in overload resolution. (c.f. http://publib.boulder.ibm.com/infocenter/lnxpcomp/v8v101/index.jsp?topic=/com.ibm.xlcpp8l.doc/language/ref/overloading_function_templates.htm)

{
    *m_stream.data() << t;
    return *this;
}


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