TreeFrogFramework  1.18
tglobal.h
Go to the documentation of this file.
1 #ifndef TGLOBAL_H
2 #define TGLOBAL_H
3 
4 #define TF_VERSION_STR "1.19.0"
5 #define TF_VERSION_NUMBER 0x011900
6 #define TF_SRC_REVISION 1549
7 
8 #include <QtGlobal>
9 #include <QMetaType>
10 
11 #define T_DECLARE_CONTROLLER(TYPE,NAME) \
12  typedef TYPE NAME; \
13  Q_DECLARE_METATYPE(NAME)
14 
15 // Deprecated
16 #define T_REGISTER_CONTROLLER(TYPE) T_REGISTER_METATYPE(TYPE)
17 #define T_REGISTER_VIEW(TYPE) T_REGISTER_METATYPE(TYPE)
18 #define T_REGISTER_METATYPE(TYPE) \
19  class Static##TYPE##Instance \
20  { \
21  public: \
22  Static##TYPE##Instance() \
23  { \
24  qRegisterMetaType<TYPE>(); \
25  } \
26  }; \
27  static Static##TYPE##Instance _static##TYPE##Instance;
28 
29 #define T_DEFINE_CONTROLLER(TYPE) T_DEFINE_VIEW(TYPE)
30 #define T_DEFINE_VIEW(TYPE) \
31  class Static##TYPE##Definition \
32  { \
33  public: \
34  Static##TYPE##Definition() \
35  { \
36  Tf::metaObjects()->insert(QByteArray(#TYPE).toLower(), &TYPE::staticMetaObject); \
37  } \
38  }; \
39  static Static##TYPE##Definition _static##TYPE##Definition;
40 
41 #define T_REGISTER_STREAM_OPERATORS(TYPE) \
42  class Static##TYPE##Instance \
43  { \
44  public: \
45  Static##TYPE##Instance() \
46  { \
47  qRegisterMetaTypeStreamOperators<TYPE>(#TYPE); \
48  } \
49  }; \
50  static Static##TYPE##Instance _static##TYPE##Instance;
51 
52 #define T_DEFINE_PROPERTY(TYPE,PROPERTY) \
53  inline void set##PROPERTY(const TYPE &v__) { PROPERTY = v__; } \
54  inline TYPE get##PROPERTY() const { return PROPERTY; }
55 
56 
57 //
58 // Create Treefrog DLL if TF_MAKEDLL is defined (Windows only)
59 //
60 #if defined(Q_OS_WIN)
61 # if defined(TF_MAKEDLL) // Create a Treefrog DLL
62 # define T_CORE_EXPORT Q_DECL_EXPORT
63 # define T_MODEL_EXPORT
64 # define T_VIEW_EXPORT
65 # define T_CONTROLLER_EXPORT
66 # define T_HELPER_EXPORT
67 # elif defined(TF_DLL) // Use a Treefrog DLL
68 # define T_CORE_EXPORT Q_DECL_IMPORT
69 # define T_MODEL_EXPORT Q_DECL_EXPORT
70 # define T_VIEW_EXPORT Q_DECL_EXPORT
71 # define T_CONTROLLER_EXPORT Q_DECL_EXPORT
72 # define T_HELPER_EXPORT Q_DECL_EXPORT
73 # else
74 # define T_CORE_EXPORT
75 # define T_MODEL_EXPORT
76 # define T_VIEW_EXPORT
77 # define T_CONTROLLER_EXPORT
78 # define T_HELPER_EXPORT
79 # endif
80 #else
81 # define T_CORE_EXPORT
82 # define T_MODEL_EXPORT
83 # define T_VIEW_EXPORT
84 # define T_CONTROLLER_EXPORT
85 # define T_HELPER_EXPORT
86 #endif
87 
88 #if defined(Q_CC_GNU) && !defined(__INSURE__)
89 # if defined(Q_CC_MINGW) && !defined(Q_CC_CLANG)
90 # define T_ATTRIBUTE_FORMAT(A,B) __attribute__((format(gnu_printf,(A),(B))))
91 # else
92 # define T_ATTRIBUTE_FORMAT(A,B) __attribute__((format(printf,(A),(B))))
93 # endif
94 #else
95 # define T_ATTRIBUTE_FORMAT(A,B)
96 #endif
97 
98 
99 #define T_EXPORT(VAR) do { QVariant ___##VAR##_; ___##VAR##_.setValue(VAR); exportVariant(QLatin1String(#VAR), (___##VAR##_), true); } while(0)
100 #define texport(VAR) T_EXPORT(VAR)
101 
102 #define T_EXPORT_UNLESS(VAR) do { QVariant ___##VAR##_; ___##VAR##_.setValue(VAR); exportVariant(QLatin1String(#VAR), (___##VAR##_), false); } while(0)
103 #define texportUnless(VAR) T_EXPORT_UNLESS(VAR)
104 
105 #define T_FETCH(TYPE,VAR) TYPE VAR = variant(QLatin1String(#VAR)).value<TYPE>()
106 #define tfetch(TYPE,VAR) T_FETCH(TYPE,VAR)
107 
108 #define T_FETCH_V(TYPE,VAR,DEFAULT) TYPE VAR = (hasVariant(QLatin1String(#VAR))) ? (variant(QLatin1String(#VAR)).value<TYPE>()) : (DEFAULT)
109 #define tfetchv(TYPE,VAR,DEFAULT) T_FETCH_V(TYPE,VAR,DEFAULT)
110 
111 #define T_EHEX(VAR) eh(variant(QLatin1String(#VAR)))
112 #define tehex(VAR) T_EHEX(VAR)
113 
114 #define T_EHEX_V(VAR,DEFAULT) do { QString ___##VAR##_ = variant(QLatin1String(#VAR)).toString(); if (___##VAR##_.isEmpty()) eh(DEFAULT); else eh(___##VAR##_); } while(0)
115 #define tehexv(VAR,DEFAULT) T_EHEX_V(VAR,DEFAULT)
116 
117 // alias of tehexv
118 #define T_EHEX2(VAR,DEFAULT) do { QString ___##VAR##_ = variant(QLatin1String(#VAR)).toString(); if (___##VAR##_.isEmpty()) eh(DEFAULT); else eh(___##VAR##_); } while(0)
119 #define tehex2(VAR,DEFAULT) T_EHEX2(VAR,DEFAULT)
120 
121 #define T_ECHOEX(VAR) echo(variant(QLatin1String(#VAR)))
122 #define techoex(VAR) T_ECHOEX(VAR)
123 
124 #define T_ECHOEX_V(VAR,DEFAULT) do { QString ___##VAR##_ = variant(QLatin1String(#VAR)).toString(); if (___##VAR##_.isEmpty()) echo(DEFAULT); else echo(___##VAR##_); } while(0)
125 #define techoexv(VAR,DEFAULT) T_ECHOEX_V(VAR,DEFAULT)
126 
127 // alias of techoexv
128 #define T_ECHOEX2(VAR,DEFAULT) do { QString ___##VAR##_ = variant(QLatin1String(#VAR)).toString(); if (___##VAR##_.isEmpty()) echo(DEFAULT); else echo(___##VAR##_); } while(0)
129 #define techoex2(VAR,DEFAULT) T_ECHOEX2(VAR,DEFAULT)
130 
131 #define T_FLASH(VAR) do { QVariant ___##VAR##_; ___##VAR##_.setValue(VAR); setFlash(QLatin1String(#VAR), (___##VAR##_)); } while(0)
132 #define tflash(VAR) T_FLASH(VAR)
133 
134 #define T_VARIANT(VAR) (variant(QLatin1String(#VAR)).toString())
135 
136 // Some classes do not permit copies and moves to be made of an object.
137 #define T_DISABLE_COPY(Class) \
138  Class(const Class &) = delete; \
139  Class &operator=(const Class &) = delete;
140 
141 #define T_DISABLE_MOVE(Class) \
142  Class(Class &&) = delete; \
143  Class &operator=(Class &&) = delete;
144 
145 
146 #define tFatal TDebug(Tf::FatalLevel).fatal
147 #define tError TDebug(Tf::ErrorLevel).error
148 #define tWarn TDebug(Tf::WarnLevel).warn
149 #define tInfo TDebug(Tf::InfoLevel).info
150 #define tDebug TDebug(Tf::DebugLevel).debug
151 #define tTrace TDebug(Tf::TraceLevel).trace
152 
153 #if QT_VERSION < 0x050000
154 # define TF_SET_CODEC_FOR_TR(codec) do { QTextCodec::setCodecForTr(codec); QTextCodec::setCodecForCStrings(codec); } while (0)
155 # ifndef Q_DECL_OVERRIDE
156 # define Q_DECL_OVERRIDE
157 # endif
158 #else
159 # define TF_SET_CODEC_FOR_TR(codec)
160 #endif
161 
162 
163 #include <TfNamespace>
164 #include <TDebug>
165 #include <TWebApplication>
166 #include "tfexception.h"
167 #include <cstdint>
168 
169 class TAppSettings;
170 class TActionContext;
171 class TDatabaseContext;
172 class QSqlDatabase;
173 
174 namespace Tf
175 {
177  T_CORE_EXPORT TAppSettings *appSettings();
178  T_CORE_EXPORT const QVariantMap &conf(const QString &configName);
179  T_CORE_EXPORT void msleep(unsigned long msecs);
180 
181  // Xorshift random number generator
182  T_CORE_EXPORT void srandXor128(quint32 seed); // obsolete
183  T_CORE_EXPORT quint32 randXor128(); // obsolete
184 
185  // Thread-safe std::random number generator
186  T_CORE_EXPORT uint32_t rand32_r();
187  T_CORE_EXPORT uint64_t rand64_r();
188  T_CORE_EXPORT uint64_t random(uint64_t min, uint64_t max);
189  T_CORE_EXPORT uint64_t random(uint64_t max);
190 
191  T_CORE_EXPORT TActionContext *currentContext();
193  T_CORE_EXPORT QSqlDatabase &currentSqlDatabase(int id);
194  T_CORE_EXPORT QMap<QByteArray, const QMetaObject*> *metaObjects();
195 }
196 
197 #endif // TGLOBAL_H
#define T_CORE_EXPORT
Definition: tglobal.h:81
T_CORE_EXPORT QSqlDatabase & currentSqlDatabase(int id)
Definition: tglobal.cpp:229
T_CORE_EXPORT quint32 randXor128()
Returns a value between 0 and UINT_MAX, the next number in the current sequence of xorshift random in...
Definition: tglobal.cpp:107
The TDatabaseContext class is the base class of contexts for database access.
Definition: tdatabasecontext.h:11
T_CORE_EXPORT uint32_t rand32_r()
Definition: tglobal.cpp:125
The Tf namespace contains miscellaneous identifiers used throughout the library of TreeFrog Framework...
Definition: tdebug.h:8
T_CORE_EXPORT TWebApplication * app()
Returns a global pointer referring to the unique application object.
Definition: tglobal.cpp:28
T_CORE_EXPORT const QVariantMap & conf(const QString &configName)
Returns the map associated with config file configName in &#39;conf&#39; directory.
Definition: tglobal.cpp:45
T_CORE_EXPORT QMap< QByteArray, const QMetaObject * > * metaObjects()
Definition: tglobal.cpp:235
T_CORE_EXPORT uint64_t random(uint64_t min, uint64_t max)
Random number generator in the range from min to max.
Definition: tglobal.cpp:145
T_CORE_EXPORT uint64_t rand64_r()
Definition: tglobal.cpp:134
T_CORE_EXPORT TAppSettings * appSettings()
Returns a global pointer referring to the unique application settings object.
Definition: tglobal.cpp:36
T_CORE_EXPORT void msleep(unsigned long msecs)
Causes the current thread to sleep for msecs milliseconds.
Definition: tglobal.cpp:53
T_CORE_EXPORT void srandXor128(quint32 seed)
Sets the argument seed to be used to generate a new random number sequence of xorshift random integer...
Definition: tglobal.cpp:94
The TWebApplication class provides an event loop for TreeFrog applications.
Definition: twebapplication.h:19
T_CORE_EXPORT TActionContext * currentContext()
Definition: tglobal.cpp:163
T_CORE_EXPORT TDatabaseContext * currentDatabaseContext()
Definition: tglobal.cpp:193