| QxOrm 1.2.1 C++ Object Relational Mapping library

- Main Page
- Modules
- Namespaces
- Classes
- Files
- Directories

- File List
- File Members

QxDateTimeNeutral.h
Go to the documentation of this file.

    00001 /****************************************************************************
    00002 **
    00003 ** http://www.qxorm.com/
    00004 ** http://sourceforge.net/projects/qxorm/
    00005 ** Original file by Lionel Marty
    00006 **
    00007 ** This file is part of the QxOrm library
    00008 **
    00009 ** This software is provided 'as-is', without any express or implied
    00010 ** warranty. In no event will the authors be held liable for any
    00011 ** damages arising from the use of this software.
    00012 **
    00013 ** GNU Lesser General Public License Usage
    00014 ** This file must be used under the terms of the GNU Lesser
    00015 ** General Public License version 2.1 as published by the Free Software
    00016 ** Foundation and appearing in the file 'license.lgpl.txt' included in the
    00017 ** packaging of this file.  Please review the following information to
    00018 ** ensure the GNU Lesser General Public License version 2.1 requirements
    00019 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    00020 **
    00021 ** If you have questions regarding the use of this file, please contact :
    00022 ** contact@qxorm.com
    00023 **
    00024 ****************************************************************************/
    00025
    00026 #ifndef _QX_DATE_TIME_NEUTRAL_H_
    00027 #define _QX_DATE_TIME_NEUTRAL_H_
    00028
    00029 #ifdef _MSC_VER
    00030 #pragma once
    00031 #endif
    00032
    00040 #include <boost/serialization/serialization.hpp>
    00041 #include <boost/serialization/nvp.hpp>
    00042
    00043 #include <QtCore/qdatetime.h>
    00044
    00045 #include <QxSerialize/Qt/QxSerialize_QString.h>
    00046
    00047 #include <QxTraits/get_class_name.h>
    00048
    00049 namespace qx {
    00050
    00055 class QxDateTimeNeutral
    00056 {
    00057
    00058    friend class boost::serialization::access;
    00059
    00060 private:
    00061
    00062    QDateTime m_dt;
    00063    QString m_neutral;
    00064
    00065 public:
    00066
    00067    QxDateTimeNeutral() { ; }
    00068    explicit QxDateTimeNeutral(const QDateTime & dt) : m_dt(dt) { update(); }
    00069    explicit QxDateTimeNeutral(const QString & neutral) : m_neutral(neutral) { update(); }
    00070    virtual ~QxDateTimeNeutral() { ; }
    00071
    00072    inline QDateTime toDateTime() const    { return m_dt; }
    00073    inline QString toNeutral() const       { return m_neutral; }
    00074    inline bool isValid() const            { return m_dt.isValid(); }
    00075
    00076    inline void setDateTime(const QDateTime & dt)      { m_neutral = ""; m_dt = dt; update(); }
    00077    inline void setNeutral(const QString & neutral)    { m_dt = QDateTime(); m_neutral = neutral; update(); }
    00078
    00079    static QxDateTimeNeutral fromDateTime(const QDateTime & dt)    { return QxDateTimeNeutral(dt); }
    00080    static QxDateTimeNeutral fromNeutral(const QString & neutral)  { return QxDateTimeNeutral(neutral); }
    00081
    00082 private:
    00083
    00084    static inline const char * format() { return "yyyyMMddhhmmss"; }
    00085
    00086    void update()
    00087    {
    00088       if (m_neutral.isEmpty() && ! m_dt.isValid()) { return; }
    00089       else if (m_dt.isValid()) { m_neutral = m_dt.toString(format()); }
    00090       else { qAssert(m_neutral.size() == QString(format()).size()); m_dt = QDateTime::fromString(m_neutral, format()); qAssert(m_dt.isValid()); }
    00091    }
    00092
    00093    template <class Archive>
    00094    void serialize(Archive & ar, const unsigned int file_version)
    00095    {
    00096       Q_UNUSED(file_version);
    00097       ar & boost::serialization::make_nvp("dt_neutral", m_neutral);
    00098       if (Archive::is_loading::value) { m_dt = QDateTime(); update(); }
    00099    }
    00100
    00101 };
    00102
    00103 } // namespace qx
    00104
    00105 QX_REGISTER_CLASS_NAME(qx::QxDateTimeNeutral)
    00106
    00107 #endif // _QX_DATE_TIME_NEUTRAL_H_

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines