QxOrm 1.1.8
C++ Object Relational Mapping library
QxBool.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_BOOL_H_
00027 #define _QX_BOOL_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 <QxSerialize/Qt/QxSerialize_QString.h>
00044 
00045 #include <QxTraits/get_class_name.h>
00046 
00047 namespace qx {
00048 
00053 class QxBool
00054 {
00055 
00056    friend class boost::serialization::access;
00057 
00058 private:
00059 
00060    bool m_bValue;    
00061    long m_lCode;     
00062    QString m_sDesc;  
00063 
00064 public:
00065 
00066    QxBool() : m_bValue(false), m_lCode(0) { ; }
00067    QxBool(bool b) : m_bValue(b), m_lCode(0) { qAssert(checkInitialized(b)); }
00068    QxBool(long lCode, const QString & sDesc) : m_bValue(false), m_lCode(lCode), m_sDesc(sDesc) { ; }
00069    QxBool(bool bValue, long lCode, const QString & sDesc) : m_bValue(bValue), m_lCode(lCode), m_sDesc(sDesc) { qAssert(checkInitialized(bValue)); }
00070    QxBool(const QxBool & other) : m_bValue(other.getValue()), m_lCode(other.getCode()), m_sDesc(other.getDesc()) { ; }
00071    ~QxBool() { ; }
00072 
00073    inline bool getValue() const                          { return m_bValue; }
00074    inline long getCode() const                           { return m_lCode; }
00075    inline QString getDesc() const                        { return m_sDesc; }
00076 
00077    inline void setValue(bool bValue)                     { m_bValue = bValue; qAssert(checkInitialized(bValue)); }
00078    inline void setCode(long lCode)                       { m_lCode = lCode; }
00079    inline void setDesc(const QString & sDesc)            { m_sDesc = sDesc; }
00080 
00081    inline QxBool & operator=(const QxBool & other)       { m_bValue = other.getValue(); m_lCode = other.getCode(); m_sDesc = other.getDesc(); return (* this); }
00082    inline QxBool & operator=(const bool b)               { m_bValue = b; qAssert(checkInitialized(b)); return (* this); }
00083 
00084    inline operator bool() const                          { return (m_bValue != false); }
00085    inline bool operator!() const                         { return (m_bValue == false); }
00086 
00087    inline bool operator==(const QxBool & other) const    { return ((m_bValue == other.getValue()) && (m_lCode == other.getCode()) && (m_sDesc == other.getDesc())); }
00088    inline bool operator==(const bool b) const            { qAssert(checkInitialized(b)); return (m_bValue == b); }
00089    inline bool operator!=(const QxBool & other) const    { return ((m_bValue != other.getValue()) || (m_lCode != other.getCode()) || (m_sDesc != other.getDesc())); }
00090    inline bool operator!=(const bool b) const            { qAssert(checkInitialized(b)); return (m_bValue != b); }
00091    inline bool operator&&(const QxBool & other) const    { return (m_bValue && other.getValue()); }
00092    inline bool operator&&(const bool b) const            { qAssert(checkInitialized(b)); return (m_bValue && b); }
00093    inline bool operator||(const QxBool & other) const    { return (m_bValue || other.getValue()); }
00094    inline bool operator||(const bool b) const            { qAssert(checkInitialized(b)); return (m_bValue || b); }
00095 
00096 private:
00097 
00098    template <class Archive>
00099    void serialize(Archive & ar, const unsigned int file_version)
00100    {
00101       Q_UNUSED(file_version);
00102       ar & boost::serialization::make_nvp("value", m_bValue);
00103       ar & boost::serialization::make_nvp("code", m_lCode);
00104       ar & boost::serialization::make_nvp("desc", m_sDesc);
00105    }
00106 
00107    inline bool checkInitialized(const bool b) const { return ((static_cast<int>(b) == 0) || (static_cast<int>(b) == 1)); }
00108 
00109 };
00110 
00111 } // namespace qx
00112 
00113 /*
00114 inline bool operator==(const bool b1, const qx::QxBool & b2) { return (b1 == b2.getValue()); }
00115 inline bool operator!=(const bool b1, const qx::QxBool & b2) { return (b1 != b2.getValue()); }
00116 inline bool operator&&(const bool b1, const qx::QxBool & b2) { return (b1 && b2.getValue()); }
00117 inline bool operator||(const bool b1, const qx::QxBool & b2) { return (b1 || b2.getValue()); }
00118 */
00119 
00120 typedef qx::QxBool qx_bool;
00121 QX_REGISTER_CLASS_NAME(qx_bool)
00122 
00123 #endif // _QX_BOOL_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines