TreeFrogFramework  2.8
Namespaces | Macros | Functions | Variables
tglobal.h File Reference
#include <QMetaType>
#include <QIODevice>
#include <QtGlobal>
#include "tfexception.h"
#include "tfnamespace.h"
#include "tdeclexport.h"
#include <TDebug>
#include <cstdint>
#include <cstring>
#include <functional>
#include <algorithm>
Include dependency graph for tglobal.h:

Go to the source code of this file.

Namespaces

 Tf
 

Macros

#define T_DEFINE_CONTROLLER(TYPE)   T_DEFINE_TYPE(TYPE)
 
#define T_DEFINE_VIEW(TYPE)   T_DEFINE_TYPE(TYPE)
 
#define T_DEFINE_TYPE(TYPE)
 
#define T_REGISTER_STREAM_OPERATORS(TYPE)
 
#define T_DEFINE_PROPERTY(TYPE, PROPERTY)
 
#define T_ATTRIBUTE_FORMAT(A, B)
 
#define T_EXPORT(VAR)
 
#define texport(VAR)   T_EXPORT(VAR)
 
#define T_EXPORT_UNLESS(VAR)
 
#define texportUnless(VAR)   T_EXPORT_UNLESS(VAR)
 
#define T_FETCH(TYPE, VAR)   TYPE VAR = variant(QLatin1String(#VAR)).value<TYPE>()
 
#define tfetch(TYPE, VAR)   T_FETCH(TYPE, VAR)
 
#define T_FETCH_V(TYPE, VAR, DEFAULT)   TYPE VAR = (hasVariant(QLatin1String(#VAR))) ? (variant(QLatin1String(#VAR)).value<TYPE>()) : (DEFAULT)
 
#define tfetchv(TYPE, VAR, DEFAULT)   T_FETCH_V(TYPE, VAR, DEFAULT)
 
#define T_EHEX(VAR)
 
#define tehex(VAR)   T_EHEX(VAR)
 
#define T_EHEX_V(VAR, DEFAULT)
 
#define tehexv(VAR, DEFAULT)   T_EHEX_V(VAR, DEFAULT)
 
#define T_EHEX2(VAR, DEFAULT)   T_EHEX_V(VAR, DEFAULT)
 
#define tehex2(VAR, DEFAULT)   T_EHEX2(VAR, DEFAULT)
 
#define T_ECHOEX(VAR)
 
#define techoex(VAR)   T_ECHOEX(VAR)
 
#define T_ECHOEX_V(VAR, DEFAULT)
 
#define techoexv(VAR, DEFAULT)   T_ECHOEX_V(VAR, DEFAULT)
 
#define T_ECHOEX2(VAR, DEFAULT)   T_ECHOEX_V(VAR, DEFAULT)
 
#define techoex2(VAR, DEFAULT)   T_ECHOEX2(VAR, DEFAULT)
 
#define T_FLASH(VAR)
 
#define tflash(VAR)   T_FLASH(VAR)
 
#define T_VARIANT(VAR)   (variant(QLatin1String(#VAR)).toString())
 
#define tFatal   TDebug(Tf::FatalLevel).fatal
 
#define tError   TDebug(Tf::ErrorLevel).error
 
#define tWarn   TDebug(Tf::WarnLevel).warn
 
#define tInfo   TDebug(Tf::InfoLevel).info
 
#define tDebug   TDebug(Tf::DebugLevel).debug
 
#define tTrace   TDebug(Tf::TraceLevel).trace
 

Functions

T_CORE_EXPORT TWebApplicationTf::app () noexcept
 
T_CORE_EXPORT TAppSettings * Tf::appSettings () noexcept
 
T_CORE_EXPORT const QVariantMap & Tf::conf (const QString &configName) noexcept
 
T_CORE_EXPORT void Tf::msleep (int64_t msecs) noexcept
 
T_CORE_EXPORT int64_t Tf::getMSecsSinceEpoch ()
 
T_CORE_EXPORT uint32_t Tf::rand32_r () noexcept
 
T_CORE_EXPORT uint64_t Tf::rand64_r () noexcept
 
T_CORE_EXPORT uint64_t Tf::random (uint64_t min, uint64_t max) noexcept
 
T_CORE_EXPORT uint64_t Tf::random (uint64_t max) noexcept
 
T_CORE_EXPORT TCacheTf::cache () noexcept
 
T_CORE_EXPORT TAbstractControllerTf::currentController ()
 
const TAbstractControllerTf::constCurrentController ()
 
T_CORE_EXPORT TDatabaseContextTf::currentDatabaseContext ()
 
T_CORE_EXPORT QSqlDatabase & Tf::currentSqlDatabase (int id) noexcept
 
T_CORE_EXPORT QMap< QByteArray, std::function< QObject *()> > * Tf::objectFactories () noexcept
 
T_CORE_EXPORT QByteArray Tf::lz4Compress (const char *data, int nbytes, int compressionLevel=1) noexcept
 
T_CORE_EXPORT QByteArray Tf::lz4Compress (const QByteArray &data, int compressionLevel=1) noexcept
 
T_CORE_EXPORT QByteArray Tf::lz4Uncompress (const char *data, int nbytes) noexcept
 
T_CORE_EXPORT QByteArray Tf::lz4Uncompress (const QByteArray &data) noexcept
 
bool Tf::strcmp (const QByteArray &str1, const QByteArray &str2)
 

Variables

constexpr auto TF_VERSION_STR = "2.8.0"
 
constexpr auto TF_VERSION_NUMBER = 0x020800
 
constexpr auto TF_SRC_REVISION = 2834
 
constexpr auto Tf::ReadOnly = QIODeviceBase::ReadOnly
 
constexpr auto Tf::WriteOnly = QIODeviceBase::WriteOnly
 
constexpr auto Tf::CR = "\x0d"
 
constexpr auto Tf::LF = "\x0a"
 
constexpr auto Tf::CRLF = "\x0d\x0a"
 
constexpr auto Tf::CRLFCRLF = "\x0d\x0a\x0d\x0a"
 

Macro Definition Documentation

◆ T_ATTRIBUTE_FORMAT

#define T_ATTRIBUTE_FORMAT (   A,
 
)

◆ T_DEFINE_CONTROLLER

#define T_DEFINE_CONTROLLER (   TYPE)    T_DEFINE_TYPE(TYPE)

◆ T_DEFINE_PROPERTY

#define T_DEFINE_PROPERTY (   TYPE,
  PROPERTY 
)
Value:
inline void set##PROPERTY(const TYPE &v__) noexcept { PROPERTY = v__; } \
inline TYPE get##PROPERTY() const noexcept { return PROPERTY; }

◆ T_DEFINE_TYPE

#define T_DEFINE_TYPE (   TYPE)
Value:
class Static##TYPE##Definition { \
public: \
Static##TYPE##Definition() noexcept \
{ \
Tf::objectFactories()->insert(QByteArray(#TYPE).toLower(), []() { return new TYPE(); }); \
} \
}; \
static Static##TYPE##Definition _static##TYPE##Definition;
T_CORE_EXPORT QMap< QByteArray, std::function< QObject *()> > * objectFactories() noexcept
Definition: tglobal.cpp:183

◆ T_DEFINE_VIEW

#define T_DEFINE_VIEW (   TYPE)    T_DEFINE_TYPE(TYPE)

◆ T_ECHOEX

#define T_ECHOEX (   VAR)
Value:
do { \
auto ___##VAR##_ = variant(QLatin1String(#VAR)); \
int ___##VAR##_type = (___##VAR##_).typeId(); \
switch (___##VAR##_type) { \
case QMetaType::QJsonValue: \
echo((___##VAR##_).toJsonValue()); \
break; \
case QMetaType::QJsonObject: \
echo((___##VAR##_).toJsonObject()); \
break; \
case QMetaType::QJsonArray: \
echo((___##VAR##_).toJsonArray()); \
break; \
case QMetaType::QJsonDocument: \
echo((___##VAR##_).toJsonDocument()); \
break; \
case QMetaType::QVariantMap: \
echo((___##VAR##_).toMap()); \
break; \
default: \
echo(___##VAR##_); \
} \
} while (0)

◆ T_ECHOEX2

#define T_ECHOEX2 (   VAR,
  DEFAULT 
)    T_ECHOEX_V(VAR, DEFAULT)

◆ T_ECHOEX_V

#define T_ECHOEX_V (   VAR,
  DEFAULT 
)
Value:
do { \
auto ___##VAR##_ = variant(QLatin1String(#VAR)); \
if ((___##VAR##_).isNull()) { \
echo(DEFAULT); \
} else { \
T_ECHOEX(VAR); \
} \
} while (0)

◆ T_EHEX

#define T_EHEX (   VAR)
Value:
do { \
auto ___##VAR##_ = variant(QLatin1String(#VAR)); \
int ___##VAR##_type = (___##VAR##_).typeId(); \
switch (___##VAR##_type) { \
case QMetaType::QJsonValue: \
eh((___##VAR##_).toJsonValue()); \
break; \
case QMetaType::QJsonObject: \
eh((___##VAR##_).toJsonObject()); \
break; \
case QMetaType::QJsonArray: \
eh((___##VAR##_).toJsonArray()); \
break; \
case QMetaType::QJsonDocument: \
eh((___##VAR##_).toJsonDocument()); \
break; \
case QMetaType::QVariantMap: \
eh((___##VAR##_).toMap()); \
break; \
default: \
eh(___##VAR##_); \
} \
} while (0)

◆ T_EHEX2

#define T_EHEX2 (   VAR,
  DEFAULT 
)    T_EHEX_V(VAR, DEFAULT)

◆ T_EHEX_V

#define T_EHEX_V (   VAR,
  DEFAULT 
)
Value:
do { \
auto ___##VAR##_ = variant(QLatin1String(#VAR)); \
if ((___##VAR##_).isNull()) { \
eh(DEFAULT); \
} else { \
T_EHEX(VAR); \
} \
} while (0)

◆ T_EXPORT

#define T_EXPORT (   VAR)
Value:
do { \
QVariant ___##VAR##_; \
___##VAR##_.setValue(VAR); \
Tf::currentController()->exportVariant(QLatin1String(#VAR), (___##VAR##_), true); \
} while (0)
void exportVariant(const QString &name, const QVariant &value, bool overwrite=true)
Exports a new variable with the name name and a value of value for views.
Definition: tabstractcontroller.cpp:30
T_CORE_EXPORT TAbstractController * currentController()
Definition: tglobal.cpp:122

Exports the current value of a local variable named VAR from the controller context to view contexts.

See also
T_FETCH(TYPE,VAR)

◆ T_EXPORT_UNLESS

#define T_EXPORT_UNLESS (   VAR)
Value:
do { \
QVariant ___##VAR##_; \
___##VAR##_.setValue(VAR); \
Tf::currentController()->exportVariant(QLatin1String(#VAR), (___##VAR##_), false); \
} while (0)

Exports the current value of a local variable named VAR from the controller context to view contexts only if a local variable named VAR isn't exported.

See also
T_EXPORT(VAR)

◆ T_FETCH

#define T_FETCH (   TYPE,
  VAR 
)    TYPE VAR = variant(QLatin1String(#VAR)).value<TYPE>()

Creates a local variable named VAR with the type TYPE on the view and fetches the value of a variable named VAR exported in a controller context.

See also
T_EXPORT(VAR)

◆ T_FETCH_V

#define T_FETCH_V (   TYPE,
  VAR,
  DEFAULT 
)    TYPE VAR = (hasVariant(QLatin1String(#VAR))) ? (variant(QLatin1String(#VAR)).value<TYPE>()) : (DEFAULT)

◆ T_FLASH

#define T_FLASH (   VAR)
Value:
do { \
QVariant ___##VAR##_; \
___##VAR##_.setValue(VAR); \
Tf::currentController()->setFlash(QLatin1String(#VAR), (___##VAR##_)); \
} while (0)
virtual void setFlash(const QString &name, const QVariant &value)
Definition: tabstractcontroller.cpp:93

◆ T_REGISTER_STREAM_OPERATORS

#define T_REGISTER_STREAM_OPERATORS (   TYPE)

◆ T_VARIANT

#define T_VARIANT (   VAR)    (variant(QLatin1String(#VAR)).toString())

◆ tDebug

#define tDebug   TDebug(Tf::DebugLevel).debug

◆ techoex

#define techoex (   VAR)    T_ECHOEX(VAR)

◆ techoex2

#define techoex2 (   VAR,
  DEFAULT 
)    T_ECHOEX2(VAR, DEFAULT)

◆ techoexv

#define techoexv (   VAR,
  DEFAULT 
)    T_ECHOEX_V(VAR, DEFAULT)

◆ tehex

#define tehex (   VAR)    T_EHEX(VAR)

◆ tehex2

#define tehex2 (   VAR,
  DEFAULT 
)    T_EHEX2(VAR, DEFAULT)

◆ tehexv

#define tehexv (   VAR,
  DEFAULT 
)    T_EHEX_V(VAR, DEFAULT)

◆ tError

#define tError   TDebug(Tf::ErrorLevel).error

◆ texport

#define texport (   VAR)    T_EXPORT(VAR)

Exports the current value of a local variable named VAR from the controller context to view contexts.

See also
tfetch(TYPE,VAR)

◆ texportUnless

#define texportUnless (   VAR)    T_EXPORT_UNLESS(VAR)

Exports the current value of a local variable named VAR from the controller context to view contexts only if a local variable named VAR isn't exported.

See also
texport(VAR)

◆ tFatal

#define tFatal   TDebug(Tf::FatalLevel).fatal

◆ tfetch

#define tfetch (   TYPE,
  VAR 
)    T_FETCH(TYPE, VAR)

Creates a local variable named VAR with the type TYPE on the view and fetches the value of a variable named VAR exported in a controller context.

See also
texport(VAR)

◆ tfetchv

#define tfetchv (   TYPE,
  VAR,
  DEFAULT 
)    T_FETCH_V(TYPE, VAR, DEFAULT)

◆ tflash

#define tflash (   VAR)    T_FLASH(VAR)

◆ tInfo

#define tInfo   TDebug(Tf::InfoLevel).info

◆ tTrace

#define tTrace   TDebug(Tf::TraceLevel).trace

◆ tWarn

#define tWarn   TDebug(Tf::WarnLevel).warn

Variable Documentation

◆ TF_SRC_REVISION

constexpr auto TF_SRC_REVISION = 2834
constexpr

◆ TF_VERSION_NUMBER

constexpr auto TF_VERSION_NUMBER = 0x020800
constexpr

◆ TF_VERSION_STR

constexpr auto TF_VERSION_STR = "2.8.0"
constexpr