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