QxOrm 1.4.9
C++ Object Relational Mapping library
Loading...
Searching...
No Matches
QxBool.h
Go to the documentation of this file.
1/****************************************************************************
2**
3** https://www.qxorm.com/
4** Copyright (C) 2013 Lionel Marty (contact@qxorm.com)
5**
6** This file is part of the QxOrm library
7**
8** This software is provided 'as-is', without any express or implied
9** warranty. In no event will the authors be held liable for any
10** damages arising from the use of this software
11**
12** Commercial Usage
13** Licensees holding valid commercial QxOrm licenses may use this file in
14** accordance with the commercial license agreement provided with the
15** Software or, alternatively, in accordance with the terms contained in
16** a written agreement between you and Lionel Marty
17**
18** GNU General Public License Usage
19** Alternatively, this file may be used under the terms of the GNU
20** General Public License version 3.0 as published by the Free Software
21** Foundation and appearing in the file 'license.gpl3.txt' included in the
22** packaging of this file. Please review the following information to
23** ensure the GNU General Public License version 3.0 requirements will be
24** met : http://www.gnu.org/copyleft/gpl.html
25**
26** If you are unsure which license is appropriate for your use, or
27** if you have questions regarding the use of this file, please contact :
28** contact@qxorm.com
29**
30****************************************************************************/
31
32#ifndef _QX_BOOL_H_
33#define _QX_BOOL_H_
34
35#ifdef _MSC_VER
36#pragma once
37#endif
38
46#ifdef _QX_ENABLE_BOOST_SERIALIZATION
47#include <boost/serialization/serialization.hpp>
48#include <boost/serialization/nvp.hpp>
49#endif // _QX_ENABLE_BOOST_SERIALIZATION
50
51#include <QtCore/qdatastream.h>
52
54
56
57namespace qx {
58class QxBool;
59} // namespace qx
60
61QX_DLL_EXPORT QDataStream & operator<< (QDataStream & stream, const qx::QxBool & t) QX_USED;
62QX_DLL_EXPORT QDataStream & operator>> (QDataStream & stream, qx::QxBool & t) QX_USED;
63
64namespace qx {
65
70class QxBool
71{
72
73#ifdef _QX_ENABLE_BOOST_SERIALIZATION
75#endif // _QX_ENABLE_BOOST_SERIALIZATION
76
77 friend QX_DLL_EXPORT QDataStream & ::operator<< (QDataStream & stream, const qx::QxBool & t);
78 friend QX_DLL_EXPORT QDataStream & ::operator>> (QDataStream & stream, qx::QxBool & t);
79
80private:
81
82 bool m_bValue;
83 long m_lCode;
84 QString m_sDesc;
85
86public:
87
88 QxBool() : m_bValue(false), m_lCode(0) { ; }
90 QxBool(long lCode, const QString & sDesc) : m_bValue(false), m_lCode(lCode), m_sDesc(sDesc) { ; }
91 QxBool(bool bValue, long lCode, const QString & sDesc) : m_bValue(bValue), m_lCode(lCode), m_sDesc(sDesc) { qAssert(checkInitialized(bValue)); }
92 QxBool(const QxBool & other) : m_bValue(other.getValue()), m_lCode(other.getCode()), m_sDesc(other.getDesc()) { ; }
93 ~QxBool() { ; }
94
95 inline bool getValue() const { return m_bValue; }
96 inline long getCode() const { return m_lCode; }
97 inline QString getDesc() const { return m_sDesc; }
98
99 inline void setValue(bool bValue) { m_bValue = bValue; qAssert(checkInitialized(bValue)); }
100 inline void setCode(long lCode) { m_lCode = lCode; }
101 inline void setDesc(const QString & sDesc) { m_sDesc = sDesc; }
102
103 inline QxBool & operator=(const QxBool & other) { m_bValue = other.getValue(); m_lCode = other.getCode(); m_sDesc = other.getDesc(); return (* this); }
104 inline QxBool & operator=(const bool b) { m_bValue = b; qAssert(checkInitialized(b)); return (* this); }
105
106 inline operator bool() const { return (m_bValue != false); }
107 inline bool operator!() const { return (m_bValue == false); }
108
109 inline bool operator==(const QxBool & other) const { return ((m_bValue == other.getValue()) && (m_lCode == other.getCode()) && (m_sDesc == other.getDesc())); }
110 inline bool operator==(const bool b) const { qAssert(checkInitialized(b)); return (m_bValue == b); }
111 inline bool operator!=(const QxBool & other) const { return ((m_bValue != other.getValue()) || (m_lCode != other.getCode()) || (m_sDesc != other.getDesc())); }
112 inline bool operator!=(const bool b) const { qAssert(checkInitialized(b)); return (m_bValue != b); }
113 inline bool operator&&(const QxBool & other) const { return (m_bValue && other.getValue()); }
114 inline bool operator&&(const bool b) const { qAssert(checkInitialized(b)); return (m_bValue && b); }
115 inline bool operator||(const QxBool & other) const { return (m_bValue || other.getValue()); }
116 inline bool operator||(const bool b) const { qAssert(checkInitialized(b)); return (m_bValue || b); }
117
118 QString toString() const { return (QString(m_bValue ? "1" : "0") + "|" + QString::number(static_cast<qlonglong>(m_lCode)) + "|" + m_sDesc); }
119
120 void fromString(const QString & s)
121 {
122 if (s.trimmed().isEmpty()) { (* this) = QxBool(); return; }
123 bool bValue = s.startsWith("1");
124 int iPos = s.indexOf("|", 2);
125 if (iPos == -1) { (* this) = QxBool(bValue); return; }
126 long lCode = s.mid(2, (iPos - 2)).toLong();
127 QString sDesc = s.right(s.size() - (iPos + 1));
128 (* this) = QxBool(bValue, lCode, sDesc);
129 }
130
131private:
132
133#ifdef _QX_ENABLE_BOOST_SERIALIZATION
134 template <class Archive>
135 void serialize(Archive & ar, const unsigned int file_version)
136 {
137 Q_UNUSED(file_version);
138 ar & boost::serialization::make_nvp("value", m_bValue);
139 ar & boost::serialization::make_nvp("code", m_lCode);
140 ar & boost::serialization::make_nvp("desc", m_sDesc);
141 }
142#endif // _QX_ENABLE_BOOST_SERIALIZATION
143
144 inline bool checkInitialized(const bool b) const { return ((static_cast<int>(b) == 0) || (static_cast<int>(b) == 1)); }
145
146};
147
148} // namespace qx
149
152
153#endif // _QX_BOOL_H_
QX_DLL_EXPORT QDataStream & operator<<(QDataStream &stream, const qx::QxBool &t) QX_USED
qx::QxBool qx_bool
Definition QxBool.h:150
QX_DLL_EXPORT QDataStream & operator>>(QDataStream &stream, qx::QxBool &t) QX_USED
#define QX_USED
Definition QxMacro.h:244
#define qAssert(x)
Definition QxMacro.h:52
#define QX_DLL_EXPORT
Definition QxMacro.h:182
qx_bool : boolean type with code and description message when an error occured
Definition QxBool.h:71
long getCode() const
Definition QxBool.h:96
QxBool(long lCode, const QString &sDesc)
Definition QxBool.h:90
QString getDesc() const
Definition QxBool.h:97
bool m_bValue
Data boolean value.
Definition QxBool.h:82
void setDesc(const QString &sDesc)
Definition QxBool.h:101
QString toString() const
Definition QxBool.h:118
QxBool(const QxBool &other)
Definition QxBool.h:92
bool operator&&(const bool b) const
Definition QxBool.h:114
bool getValue() const
Definition QxBool.h:95
QString m_sDesc
Error description when value is false.
Definition QxBool.h:84
bool operator!=(const QxBool &other) const
Definition QxBool.h:111
bool operator==(const bool b) const
Definition QxBool.h:110
~QxBool()
Definition QxBool.h:93
void fromString(const QString &s)
Definition QxBool.h:120
bool operator||(const bool b) const
Definition QxBool.h:116
void serialize(Archive &ar, const unsigned int file_version)
Definition QxBool.h:135
bool checkInitialized(const bool b) const
Definition QxBool.h:144
QxBool & operator=(const QxBool &other)
Definition QxBool.h:103
long m_lCode
Error code when value is false.
Definition QxBool.h:83
bool operator&&(const QxBool &other) const
Definition QxBool.h:113
QxBool(bool bValue, long lCode, const QString &sDesc)
Definition QxBool.h:91
void setCode(long lCode)
Definition QxBool.h:100
bool operator||(const QxBool &other) const
Definition QxBool.h:115
friend class boost::serialization::access
Definition QxBool.h:74
bool operator!() const
Definition QxBool.h:107
bool operator!=(const bool b) const
Definition QxBool.h:112
QxBool & operator=(const bool b)
Definition QxBool.h:104
QxBool(bool b)
Definition QxBool.h:89
bool operator==(const QxBool &other) const
Definition QxBool.h:109
void setValue(bool bValue)
Definition QxBool.h:99
qx::trait::get_class_name<T>::get() : return class name of type T under const char * format,...
#define QX_REGISTER_CLASS_NAME(className)
Root namespace for all QxOrm library features.