Tianchi  v0.0.2 build 20130701
C++ library for Qt with VC & mingW
tccommon.h
1 // **************************************************************************
2 // Tianchi C++ library for Qt (open source)
3 // 天池共享源码库
4 // 版权所有 (C) 天池共享源码库开发组
5 // 授权协议:请阅读天池共享源码库附带的授权协议
6 // **************************************************************************
7 // 文档说明:公共单元,此单元不使用 namespace Tianchi
8 // ==========================================================================
9 // 开发日志:
10 // 日期 人员 说明
11 // --------------------------------------------------------------------------
12 // 2013.04.15 圣域天子 建立
13 //
14 // ==========================================================================
16 #ifndef TIANCHI_TCCOMMON_H
17 #define TIANCHI_TCCOMMON_H
18 
19 #include <tianchi/tcglobal.h>
20 
21 #include <QTextCodec>
22 #include <QDateTime>
23 
24 #ifdef QT_WIDGETS_LIB
25  #include <QMessageBox>
26 #endif
27 
28 #if defined(QT_DEBUG)
29  #include <iostream>
30  using namespace std;
31 #endif
32 
33 
34 
35 
36 
37 
38 
39 
40 
41 
42 
43 
44 
45 
46 
47 
48 
49 
50 
51 
52 
53 
54 QTextCodec* initQS(const QByteArray& name="GBK");
55 
78 inline QString QS(const char* s)
79 {
80  return QTextCodec::codecForLocale()->toUnicode(s);
81 }
82 
84 #define max(a,b) (((a) > (b)) ? (a) : (b))
85 
86 #define min(a,b) (((a) < (b)) ? (a) : (b))
87 
88 inline int iif(bool logic, int v1, int v2=0) { return logic ? v1 : v2; }
90 inline QString iif(bool logic, const QString& v1, const QString& v2="") { return logic ? v1 : v2; }
91 
92 #ifdef QT_WIDGETS_LIB
93 
94 
95 
96 inline void MsgBox(const QString& s)
97 {
98  QMessageBox::information(NULL, "", s);
99 }
100 #endif
101 #define TC_FREE(x) {delete x; x=NULL;}
102 #if defined(QT_DEBUG)
103 
104 
105 
106 
107  inline void debug_out(const char* file, int line, const QString& text="")
108  {
109  cout<<QDateTime::currentDateTime().toString("yyyy/MM/dd HH:mm:ss->").toLocal8Bit().data()<<file<<"("<<line<<"): "<<text.toLocal8Bit().data()<<endl;
110  }
115  inline void debug_out(const char* file, int line, int value)
116  {
117  debug_out(file, line, QString::number(value));
118  }
119 
121  #define DEBUG_STEP debug_out(__FILE__, __LINE__);
122 
123  #define DEBUG_OUT(x) debug_out(__FILE__, __LINE__, x);
124 #else
125 
126  #define DEBUG_STEP
127 
128  #define DEBUG_OUT(x)
129 #endif
130 
132 QString YYYY_MM_DD_HH_MM_SS_ZZZ();
134 QString YYYY_MM_DD_HH_MM_SS();
135 
136 #endif // TIANCHI_COMMON_H