00001
00005 #ifndef SXGLOBAL_H_INCLUDED
00006 #define SXGLOBAL_H_INCLUDED
00007
00008 #include <QtGlobal>
00009
00010
00011 #if defined(Q_OS_WIN)
00012 #ifdef SX_MAKE_DLL //build dll
00013 #ifdef SX_DLL
00014 #undef SX_DLL
00015 #endif
00016
00017
00018 #ifdef SX_BUILD_SDK
00019 #define SX_SDKEXPORT Q_DECL_EXPORT
00020 #else
00021 #define SX_SDKEXPORT Q_DECL_IMPORT
00022 #endif
00023
00024
00025 #ifdef SX_BUILD_GUISDK
00026 #define SX_GUISDKEXPORT Q_DECL_EXPORT
00027 #else
00028 #define SX_GUISDKEXPORT Q_DECL_IMPORT
00029 #endif
00030
00031 #define Q_TEMPLATEDLL
00032 #elif defined(SX_DLL) //using dll
00033 #define SX_SDKEXPORT Q_DECL_IMPORT
00034 #define SX_GUISDKEXPORT Q_DECL_IMPORT
00035 #define Q_TEMPLATEDLL
00036 #endif //make dll, SX_DLL
00037
00038 #endif //Q_OS_WIN
00039
00044 #if !defined(SX_SDKEXPORT)
00045 #define SX_SDKEXPORT
00046 #endif
00047
00048 #if !defined(SX_GUISDKEXPORT)
00049 #define SX_GUISDKEXPORT
00050 #endif
00051
00055 #if !defined(Q_NO_DECLARED_NOT_DEFINED) || !defined(SX_MAKE_DLL)
00056 #define SX_DISABLE_COPY(Class) \
00057 Class(const Class &); \
00058 Class &operator=(const Class &);
00059 #else
00060 #define SX_DISABLE_COPY(Class)
00061 #endif
00062
00063 #include <QString>
00064 #include <QList>
00065 #include <QVector>
00066 #include <QDomDocument>
00067 #include <QObject>
00068 #include <QRectF>
00069 #include <QFlags>
00070 #include <QStringList>
00071
00073 #define SXTR(s) QObject::tr((s))
00074
00079 #define SXIsPower2(num) ((num) != 0 && ((num) & ((num) - 1)) == 0)
00080
00084 #define SXDiffZero(n1, n2) ((n1) > (n2) ? (n1) - (n2) : 0)
00085
00093 #define SX_VERSION(sdk, major, minor) (((sdk) << 16) | ((major) << 8) | (minor))
00094
00098 #define SX_SDK_VERSION(ver) ((ver) >> 16)
00099
00102 #define SX_MAJOR_VERSION(ver) (((ver) >> 8) & 0x000000ff)
00103
00106 #define SX_MINOR_VERSION(ver) ((ver) & 0x000000ff)
00107
00109 typedef qptrdiff sxint_t;
00110
00115 namespace sx {
00116
00117 enum DataType
00118 {
00119 TypeInvalid = 0x00,
00120 TypeBool = 0x01,
00121 TypeChar = 0x02,
00122 TypeShort = 0x04,
00123 TypeInt = 0x08,
00124 TypeFloat = 0x10,
00125 TypeDouble = 0x20,
00126 TypeSxInt = 0x40,
00127 TypeInt64 = 0x80,
00128 TypeUChar = 0x100,
00129 TypeUShort = 0x200,
00130 TypeUInt = 0x400,
00131 TypeUInt64 = 0x800
00132 };
00133 Q_DECLARE_FLAGS(DataTypes, DataType)
00134
00135 enum Position
00136 {
00137 Front = 1,
00138 Back
00139 };
00140
00141 enum RunMode
00142 {
00143 RunOnce = 1,
00144 RunCounted,
00145 RunTimed,
00146 RunForever
00147 };
00148
00149 enum MessageType
00150 {
00151 RegularMessage = -1,
00152 InfoMessage,
00153 WarningMessage,
00154 ErrorMessage,
00155 CriticalMessage
00156 };
00157
00158
00159 enum
00160 {
00161 DecimalPrecission = 30
00162 };
00163
00177 template <typename Tx>
00178 QDomElement appendSettingText(QDomElement & pn,
00179 const QString& cap, const Tx& val)
00180 {
00181 QDomDocument doc = pn.ownerDocument();
00182 QDomElement e = doc.createElement(cap);
00183 e.appendChild( doc.createTextNode(QString("%1").arg(val)) );
00184 pn.appendChild(e);
00185
00186 return e;
00187 }
00188
00189 template<typename Tx>
00190 QDomElement appendSettingCDATA(QDomElement & pn,
00191 const QString& cap, const Tx& val)
00192 {
00193 QDomDocument doc = pn.ownerDocument();
00194 QDomElement e = doc.createElement(cap);
00195 e.appendChild( doc.createCDATASection(QString("%1").arg(val)) );
00196 pn.appendChild(e);
00197
00198 return e;
00199 }
00200
00215 template <typename Tx>
00216 QDomElement appendSettingAttribute(QDomElement & pn,
00217 const QString& cap, const QString& attr, const Tx& val)
00218 {
00219 QDomDocument doc = pn.ownerDocument();
00220 QDomElement e = doc.createElement(cap);
00221 e.setAttribute(attr, QString("%1").arg(val) );
00222 pn.appendChild(e);
00223
00224 return e;
00225 }
00226
00230 extern size_t SX_SDKEXPORT MaxBufferMemory;
00231
00235 extern size_t SX_SDKEXPORT InitialBufferSize;
00236
00240 extern unsigned long SX_SDKEXPORT MaxTimeout;
00241
00245 extern quintptr SX_SDKEXPORT MainThreadId;
00246
00250 bool SX_SDKEXPORT isInMainThread();
00251
00255 int SX_SDKEXPORT version();
00256
00261 size_t SX_SDKEXPORT nextPower2(size_t sz);
00262
00266 QString SX_SDKEXPORT rectfToString(const QRectF & r);
00267
00271 QRectF SX_SDKEXPORT stringToRectf(const QString& str);
00272
00276 QString SX_SDKEXPORT pointfToString(const QPointF & pt);
00277
00281 QPointF SX_SDKEXPORT stringToPointf(const QString& str);
00282
00286 QString SX_SDKEXPORT doubleToString(const double * db, int n, int precission = DecimalPrecission);
00287
00292 QVector<double> SX_SDKEXPORT stringToDouble(const QString& str);
00293
00297 QStringList SX_SDKEXPORT dataTypes();
00298
00302 QString SX_SDKEXPORT dataTypeToString(DataType tid);
00303
00307 DataType SX_SDKEXPORT dataTypeFromString(const QString& tstr);
00308
00309 }
00311 Q_DECLARE_OPERATORS_FOR_FLAGS(sx::DataTypes)
00312
00313
00314 template <typename Tx>
00315 class PrivateDataT
00316 {
00317 int xDCap;
00318 protected:
00319 inline PrivateDataT() : xDCap(0), xData(0) { qDebug("###PrivateDataT excecuted"); }
00320 public:
00321 Tx * xData;
00322 virtual ~PrivateDataT() { qDebug("####PRIVATE DATA#####"); delete [] xData; }
00323 inline void allocate(int cap) {
00324 if (cap > xDCap) {
00325 delete [] xData;
00326 xData = new Tx[cap];
00327 xDCap = cap;
00328 }
00329 }
00330 };
00331
00332 typedef PrivateDataT<double> PrivateDouble;
00333 typedef PrivateDataT<char> PrivateChar;
00334
00335
00336 #endif // SXGLOBAL_H_INCLUDED