WARNING: USE THIS SOFTWARE AT YOUR OWN RISK! THIS IS EXPERIMENTAL SOFTWARE NOT INTENDED FOR PRODUCTION USE! Zuble is currently an early stage prototype. As such Zuble is minimally tested and inherently unstable. It is provided for experimental, development, and demonstration purposes only. Zuble QML Types   |  Zuble C++ Classes   |  Zuble Overview
Zuble  0.1
Zuble Framework C++/QML extension API
zglobal.h
Go to the documentation of this file.
1 /*
2  * Zuble - A run-time system for QML/Javascript applications
3  * Copyright (C) 2013, 2014 Bob Dinitto
4  *
5  * zglobal.h
6  *
7  * Created on: 15-Feb, 2013
8  * Author: Bob Dinitto bob@ninzo.com
9  *
10  * Zuble is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Lesser General Public
12  * License as published by the Free Software Foundation; either
13  * version 2.1 of the License, or (at your option) any later version.
14  *
15  * This library is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  * Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public
21  * License along with this library; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23  *
24 */
25 
26 #ifndef ZGLOBAL_H
27 #define ZGLOBAL_H
28 
29 #include <QtCore/qglobal.h>
30 #include <QSharedPointer>
31 #include <QThread>
32 #include "ZblException.h"
33 #include "ZblThreadErr.h"
34 #include "ZblLogCategory.h"
35 
36 class QFile;
37 class QIODevice;
38 class QByteArray;
39 class QSqlQuery;
40 class QProcess;
41 
42 
43 namespace Zbl
44 {
45 
49 #define cStr(qStr) qStr.toUtf8().constData()
50 
54 #define ptrStr(ptr) ptrToString(static_cast<void*>(ptr))
55 
56 inline QString ptrToString(void* ptr)
57 {
58  return QString::asprintf("%p", ptr);
59 }
60 
64 inline bool fromLiterallyTrue(const QString& value)
65 {
66  const QString lc = value.toLower();
67 
68  if(lc == "true")
69  return true;
70  else
71  return false;
72 }
73 
76 inline QString toLiterallyTrue(bool value)
77 {
78  if(value)
79  return QString("true");
80  else
81  return QString("false");
82 }
83 
88 // TDB: make object name user definable ie: m_log
89 
90 
91 
92 #define ZBL_DECLARE_LOGGED_CATEGORY(category) static ZblLogCategory category;
93 
94 #define ZBL_DECLARE_LOGGED_OBJECT ZBL_DECLARE_LOGGED_CATEGORY(m_log)
95 
96 #define ZBL_DEFINE_LOGGED_CATEGORY(category_name, variable_name) \
97  ZblLogCategory variable_name(#category_name);
98 
99 #define ZBL_DEFINE_LOGGED_OBJECT(class_name) \
100  ZblLogCategory class_name::m_log(#class_name);
101 
102 #define ZBL_REGISTER_LOGGED_CATEGORY(variable_name) variable_name.registerCategory();
103 
104 #define ZBL_REGISTER_LOGGED_OBJECT ZBL_REGISTER_LOGGED_CATEGORY(m_log)
105 
106 
107 #define zCWarning(category) qCWarning(category())
108 #define zCCritical(category) qCCritical(category())
109 #define zCDebug(category) qCDebug(category())
110 
111 #define zWarning() zCWarning(m_log)
112 #define zCritical() zCCritical(m_log)
113 #define zDebug() zCDebug(m_log)
114 
115 #define LOCK_ZLOGCATEGORIES \
116  QStringList& zLogCategories(ZblLogCategory::m_categories); \
117  QMutexLocker categoryLock(&ZblLogCategory::m_categorylock);
118 
123 #define Z_FAC_JS ZJS
124 
128 #define ZBL_SLOT_BEGIN_TRY try{zThreadErr.clearError();
129 
134 #define ZBL_SLOT_END_VOID(facility,code,error_message) \
135 }catch(Zbl::ZblException ze){ \
136 QString msg(#error_message); \
137 msg.append(", source exception: ").append(ze.what( )); \
138 zThreadErr.raiseError(#facility,#code,msg);} \
139 catch(...){zThreadErr.raiseError(#facility,#code,#error_message);}
140 
141 #define ZBL_SLOT_END_RETURN(return_success,return_failed,facility,code,error_message) \
142  return return_success; \
143  ZBL_SLOT_END_VOID(facility,code,error_message) \
144  return return_failed;
145 
146 #define Z_CONSTANT_DEF(propName, dataType) \
147  Q_PROPERTY(dataType propName READ propName CONSTANT) \
148  dataType propName();
149 
150 #define Z_CONSTANT_IMPL(className, readMethodName, dataType, constantExp) \
151 dataType className::readMethodName(){return constantExp;}
152 
153 #define Z_PROPGET_DEF(propName, propType) \
154  Q_PROPERTY(propType propName READ propName) \
155  propType propName();
156 
157 #define Z_PROPGET_IMPL(className, propName, propType, failedValue) \
158 propType className::propName(){ \
159  ZBL_SLOT_BEGIN_TRY \
160  ZBL_SLOT_END_RETURN(m_fi.at(m_i).propName(), failedValue, \
161  Z_FAC_JS, className::propName, propName failed) \
162 
163 typedef QSharedPointer<QFile> ZqFilePtr;
164 typedef QSharedPointer<QIODevice> ZqIODevicePtr;
165 typedef QSharedPointer<QString> ZqStringPtr;
166 typedef QSharedPointer<QByteArray> ZqByteArrayPtr;
167 typedef QSharedPointer<QProcess> ZqProcessPtr;
168 
169 typedef QList<QString> zMetaRow;
170 typedef QList<QList<QString> > zStringTable;
171 typedef QList<QList<QVariant> > zVariantTable;
172 
173 inline bool inObjectThread(const QObject& object)
174 {
175  //return QThread::currentThread() == object.thread();
176 
177  QThread* objThread = object.thread();
178 
179  QThread* thisThread = QThread::currentThread();
180 
181  return objThread == thisThread ? true : false;
182 }
183 
184 inline bool inObjectThread(const QObject* object)
185 {
186  if(!object)
187  return false;
188  else
189  return inObjectThread(*object);
190 }
191 
195 #if 1
196 // save text instead
197 typedef enum logFileFormat
198 {
202 } LogFileFormat;
203 #endif
204 
210 {
213 };
214 
222 inline textSearchType zValidateSearchType(int searchType)
223 {
224  if(searchType < SearchCaseSensitive || searchType > SearchCaseInsensitive)
225  return SearchCaseInsensitive;
226  else
227  return static_cast<textSearchType>(searchType);
228 }
229 
230 
231 } // Zbl
232 
233 
234 #endif // ZGLOBAL_H
QList< QString > zMetaRow
Definition: zglobal.h:169
QList< QList< QString > > zStringTable
Definition: zglobal.h:170
QString ptrToString(void *ptr)
Definition: zglobal.h:56
QString toLiterallyTrue(bool value)
Definition: zglobal.h:76
QSharedPointer< QProcess > ZqProcessPtr
Definition: zglobal.h:167
enum Zbl::logFileFormat LogFileFormat
Specifies the output format for Zuble log files.
QList< QList< QVariant > > zVariantTable
Definition: zglobal.h:171
bool fromLiterallyTrue(const QString &value)
Definition: zglobal.h:64
QSharedPointer< QString > ZqStringPtr
Definition: zglobal.h:165
QSharedPointer< QFile > ZqFilePtr
Definition: zglobal.h:163
logFileFormat
Specifies the output format for Zuble log files.
Definition: zglobal.h:197
Definition: ZAndGate.cpp:6
textSearchType
Specifies search case sensitivity.
Definition: zglobal.h:209
QSharedPointer< QByteArray > ZqByteArrayPtr
Definition: zglobal.h:166
bool inObjectThread(const QObject &object)
Definition: zglobal.h:173
textSearchType zValidateSearchType(int searchType)
Validates an integer value to be type textSearchType and returns it or a valid default value if out o...
Definition: zglobal.h:222
QSharedPointer< QIODevice > ZqIODevicePtr
Definition: zglobal.h:164