![]() |
QxOrm
1.2.3
C++ Object Relational Mapping library
|
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_NEUTRAL_H_ 00027 #define _QX_DATE_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 QxDateNeutral 00056 { 00057 00058 friend class boost::serialization::access; 00059 00060 private: 00061 00062 QDate m_date; 00063 QString m_neutral; 00064 00065 public: 00066 00067 QxDateNeutral() { ; } 00068 explicit QxDateNeutral(const QDate & date) : m_date(date) { update(); } 00069 explicit QxDateNeutral(const QString & neutral) : m_neutral(neutral) { update(); } 00070 virtual ~QxDateNeutral() { ; } 00071 00072 inline QDate toDate() const { return m_date; } 00073 inline QString toNeutral() const { return m_neutral; } 00074 inline bool isValid() const { return m_date.isValid(); } 00075 00076 inline void setDate(const QDate & date) { m_neutral = ""; m_date = date; update(); } 00077 inline void setNeutral(const QString & neutral) { m_date = QDate(); m_neutral = neutral; update(); } 00078 00079 static QxDateNeutral fromDate(const QDate & date) { return QxDateNeutral(date); } 00080 static QxDateNeutral fromNeutral(const QString & neutral) { return QxDateNeutral(neutral); } 00081 00082 private: 00083 00084 static inline const char * format() { return "yyyyMMdd"; } 00085 00086 void update() 00087 { 00088 if (m_neutral.isEmpty() && ! m_date.isValid()) { return; } 00089 else if (m_date.isValid()) { m_neutral = m_date.toString(format()); } 00090 else { qAssert(m_neutral.size() == QString(format()).size()); m_date = QDate::fromString(m_neutral, format()); qAssert(m_date.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("date_neutral", m_neutral); 00098 if (Archive::is_loading::value) { m_date = QDate(); update(); } 00099 } 00100 00101 }; 00102 00103 } // namespace qx 00104 00105 QX_REGISTER_CLASS_NAME(qx::QxDateNeutral) 00106 00107 #endif // _QX_DATE_NEUTRAL_H_