![]() |
QxOrm
1.3.2
C++ Object Relational Mapping library
|
00001 /**************************************************************************** 00002 ** 00003 ** http://www.qxorm.com/ 00004 ** Copyright (C) 2013 Lionel Marty (contact@qxorm.com) 00005 ** 00006 ** This file is part of the QxOrm library 00007 ** 00008 ** This software is provided 'as-is', without any express or implied 00009 ** warranty. In no event will the authors be held liable for any 00010 ** damages arising from the use of this software 00011 ** 00012 ** Commercial Usage 00013 ** Licensees holding valid commercial QxOrm licenses may use this file in 00014 ** accordance with the commercial license agreement provided with the 00015 ** Software or, alternatively, in accordance with the terms contained in 00016 ** a written agreement between you and Lionel Marty 00017 ** 00018 ** GNU General Public License Usage 00019 ** Alternatively, this file may be used under the terms of the GNU 00020 ** General Public License version 3.0 as published by the Free Software 00021 ** Foundation and appearing in the file 'license.gpl3.txt' included in the 00022 ** packaging of this file. Please review the following information to 00023 ** ensure the GNU General Public License version 3.0 requirements will be 00024 ** met : http://www.gnu.org/copyleft/gpl.html 00025 ** 00026 ** If you are unsure which license is appropriate for your use, or 00027 ** if you have questions regarding the use of this file, please contact : 00028 ** contact@qxorm.com 00029 ** 00030 ****************************************************************************/ 00031 00032 #ifndef _QX_TIME_NEUTRAL_H_ 00033 #define _QX_TIME_NEUTRAL_H_ 00034 00035 #ifdef _MSC_VER 00036 #pragma once 00037 #endif 00038 00046 #include <boost/serialization/serialization.hpp> 00047 #include <boost/serialization/nvp.hpp> 00048 00049 #include <QtCore/qdatetime.h> 00050 00051 #include <QxSerialize/Qt/QxSerialize_QString.h> 00052 00053 #include <QxTraits/get_class_name.h> 00054 00055 namespace qx { 00056 00061 class QxTimeNeutral 00062 { 00063 00064 friend class boost::serialization::access; 00065 00066 private: 00067 00068 QTime m_time; 00069 QString m_neutral; 00070 00071 public: 00072 00073 QxTimeNeutral() { ; } 00074 explicit QxTimeNeutral(const QTime & time) : m_time(time) { update(); } 00075 explicit QxTimeNeutral(const QString & neutral) : m_neutral(neutral) { update(); } 00076 virtual ~QxTimeNeutral() { ; } 00077 00078 inline QTime toTime() const { return m_time; } 00079 inline QString toNeutral() const { return m_neutral; } 00080 inline bool isValid() const { return m_time.isValid(); } 00081 00082 inline void setTime(const QTime & time) { m_neutral = ""; m_time = time; update(); } 00083 inline void setNeutral(const QString & neutral) { m_time = QTime(); m_neutral = neutral; update(); } 00084 00085 static QxTimeNeutral fromTime(const QTime & time) { return QxTimeNeutral(time); } 00086 static QxTimeNeutral fromNeutral(const QString & neutral) { return QxTimeNeutral(neutral); } 00087 00088 private: 00089 00090 static inline const char * format() { return "hhmmss"; } 00091 00092 void update() 00093 { 00094 if (m_neutral.isEmpty() && ! m_time.isValid()) { return; } 00095 else if (m_time.isValid()) { m_neutral = m_time.toString(format()); } 00096 else { qAssert(m_neutral.size() == QString(format()).size()); m_time = QTime::fromString(m_neutral, format()); qAssert(m_time.isValid()); } 00097 } 00098 00099 template <class Archive> 00100 void serialize(Archive & ar, const unsigned int file_version) 00101 { 00102 Q_UNUSED(file_version); 00103 ar & boost::serialization::make_nvp("time_neutral", m_neutral); 00104 if (Archive::is_loading::value) { m_time = QTime(); update(); } 00105 } 00106 00107 }; 00108 00109 } // namespace qx 00110 00111 QX_REGISTER_CLASS_NAME(qx::QxTimeNeutral) 00112 00113 #endif // _QX_TIME_NEUTRAL_H_