00001 #ifndef SXPACKETCONTENT_H_INCLUDED
00002 #define SXPACKETCONTENT_H_INCLUDED
00003
00004 #include <QDataStream>
00005 #include "sxGlobal.h"
00006
00013 class SX_SDKEXPORT sxPacketContent
00014 {
00015 public:
00016 virtual ~sxPacketContent();
00017 virtual sx::DataType Type() const = 0;
00018 virtual sxPacketContent * Clone(size_t cnt = 0) const = 0;
00019 virtual sxPacketContent * Split(size_t chanCount) = 0;
00020 virtual void Assign(const sxPacketContent * content) = 0;
00021 virtual void Assign(const sxPacketContent * content, size_t cnt) = 0;
00022 virtual void PushBackCircular(sxPacketContent * content) = 0;
00023
00024
00025 virtual bool GetBool(size_t idx) const = 0;
00026 virtual bool GetBool(size_t chNo, size_t idx) const = 0;
00027 virtual char GetChar(size_t idx) const = 0;
00028 virtual char GetChar(size_t chNo, size_t idx) const = 0;
00029 virtual unsigned char GetUChar(size_t idx) const = 0;
00030 virtual unsigned char GetUChar(size_t chNo, size_t idx) const = 0;
00031 virtual short GetShort(size_t idx) const = 0;
00032 virtual short GetShort(size_t chNo, size_t idx) const = 0;
00033 virtual unsigned short GetUShort(size_t idx) const = 0;
00034 virtual unsigned short GetUShort(size_t chNo, size_t idx) const = 0;
00035 virtual int GetInt(size_t idx) const = 0;
00036 virtual int GetInt(size_t chNo, size_t idx) const = 0;
00037 virtual unsigned int GetUInt(size_t idx) const = 0;
00038 virtual unsigned int GetUInt(size_t chNo, size_t idx) const = 0;
00039 virtual qint64 GetInt64(size_t idx) const = 0;
00040 virtual qint64 GetInt64(size_t chNo, size_t idx) const = 0;
00041 virtual quint64 GetUInt64(size_t idx) const = 0;
00042 virtual quint64 GetUInt64(size_t chNo, size_t idx) const = 0;
00043 virtual float GetFloat(size_t idx) const = 0;
00044 virtual float GetFloat(size_t chNo, size_t idx) const = 0;
00045 virtual double GetDouble(size_t idx) const = 0;
00046 virtual double GetDouble(size_t chNo, size_t idx) const = 0;
00047 virtual sxint_t GetSxInt(size_t idx) const = 0;
00048 virtual sxint_t GetSxInt(size_t chNo, size_t idx) const = 0;
00049
00050
00051 virtual void Set(size_t idx, bool val) = 0;
00052 virtual void Set(size_t chNo, size_t idx, bool val) = 0;
00053 virtual void Set(size_t idx, char val) = 0;
00054 virtual void Set(size_t chNo, size_t idx, char val) = 0;
00055 virtual void Set(size_t idx, unsigned char val) = 0;
00056 virtual void Set(size_t chNo, size_t idx, unsigned char val) = 0;
00057 virtual void Set(size_t idx, short val) = 0;
00058 virtual void Set(size_t chNo, size_t idx, short val) = 0;
00059 virtual void Set(size_t idx, unsigned short val) = 0;
00060 virtual void Set(size_t chNo, size_t idx, unsigned short val) = 0;
00061 virtual void Set(size_t idx, int val) = 0;
00062 virtual void Set(size_t chNo, size_t idx, int val) = 0;
00063 virtual void Set(size_t idx, unsigned int val) = 0;
00064 virtual void Set(size_t chNo, size_t idx, unsigned int val) = 0;
00065 virtual void Set(size_t idx, float val) = 0;
00066 virtual void Set(size_t chNo, size_t idx, float val) = 0;
00067 virtual void Set(size_t idx, double val) = 0;
00068 virtual void Set(size_t chNo, size_t idx, double val) = 0;
00069 virtual void Set(size_t idx, qint64 val) = 0;
00070 virtual void Set(size_t chNo, size_t idx, qint64 val) = 0;
00071 virtual void Set(size_t idx, quint64 val) = 0;
00072 virtual void Set(size_t chNo, size_t idx, quint64 val) = 0;
00073 virtual void SetSxInt(size_t idx, sxint_t val) = 0;
00074 virtual void SetSxInt(size_t chNo, size_t idx, sxint_t val) = 0;
00075
00076
00077 virtual void Multiply(double val) = 0;
00078 virtual void Divide(double val) = 0;
00079 virtual void Add(double val) = 0;
00080 virtual void Subtract(double val) = 0;
00081 virtual void ConstSubtract(double val) = 0;
00082 virtual void Multiply(size_t idx, double val) = 0;
00083 virtual void Divide(size_t idx, double val) = 0;
00084 virtual void Add(size_t idx, double val) = 0;
00085 virtual void Subtract(size_t idx, double val) = 0;
00086 virtual void ConstSubtract(size_t idx, double val) = 0;
00087
00088 virtual void Transpose() = 0;
00089
00090
00091 virtual void Serialize(QDataStream & ds) const;
00092 virtual void Deserialize(QDataStream & ds);
00093
00094 protected:
00095 virtual bool MergeType(const sxPacketContent * content) = 0;
00096 virtual bool MergeType(const sxPacketContent * content, size_t cnt) = 0;
00097 virtual bool AppendType(const sxPacketContent * content) = 0;
00098
00099 public:
00100
00101
00102 size_t CopyTo(bool * data, size_t sz) const;
00103 size_t CopyTo(bool * data, size_t chNo, size_t cnt) const;
00104 size_t CopyTo(char * data, size_t sz) const;
00105 size_t CopyTo(char * data, size_t chNo, size_t cnt) const;
00106 size_t CopyTo(unsigned char * data, size_t sz) const;
00107 size_t CopyTo(unsigned char * data, size_t chNo, size_t cnt) const;
00108 size_t CopyTo(short * data, size_t sz) const;
00109 size_t CopyTo(short * data, size_t chNo, size_t cnt) const;
00110 size_t CopyTo(unsigned short * data, size_t sz) const;
00111 size_t CopyTo(unsigned short * data, size_t chNo, size_t cnt) const;
00112 size_t CopyTo(int * data, size_t sz) const;
00113 size_t CopyTo(int * data, size_t chNo, size_t cnt) const;
00114 size_t CopyTo(unsigned int * data, size_t sz) const;
00115 size_t CopyTo(unsigned int * data, size_t chNo, size_t cnt) const;
00116 size_t CopyTo(qint64 * data, size_t sz) const;
00117 size_t CopyTo(qint64 * data, size_t chNo, size_t cnt) const;
00118 size_t CopyTo(quint64 * data, size_t sz) const;
00119 size_t CopyTo(quint64 * data, size_t chNo, size_t cnt) const;
00120 size_t CopyTo(float * data, size_t sz) const;
00121 size_t CopyTo(float * data, size_t chNo, size_t cnt) const;
00122 size_t CopyTo(double * data, size_t sz) const;
00123 size_t CopyTo(double * data, size_t chNo, size_t cnt) const;
00124 size_t CopyToSxInt(sxint_t * data, size_t sz) const;
00125 size_t CopyToSxInt(sxint_t * data, size_t chNo, size_t cnt) const;
00126 size_t CopyTo(sxPacketContent * pc, size_t from, size_t cnt) const;
00127
00128 size_t CopyPartTo(bool * data, size_t from, size_t sz) const;
00129 size_t CopyPartTo(bool * data, size_t chNo, size_t from, size_t cnt) const;
00130 size_t CopyPartTo(char * data, size_t from, size_t sz) const;
00131 size_t CopyPartTo(char * data, size_t chNo, size_t from, size_t cnt) const;
00132 size_t CopyPartTo(unsigned char * data, size_t from, size_t sz) const;
00133 size_t CopyPartTo(unsigned char * data, size_t chNo, size_t from, size_t cnt) const;
00134 size_t CopyPartTo(short * data, size_t from, size_t sz) const;
00135 size_t CopyPartTo(short * data, size_t chNo, size_t from, size_t cnt) const;
00136 size_t CopyPartTo(unsigned short * data, size_t from, size_t sz) const;
00137 size_t CopyPartTo(unsigned short * data, size_t chNo, size_t from, size_t cnt) const;
00138 size_t CopyPartTo(int * data, size_t from, size_t sz) const;
00139 size_t CopyPartTo(int * data, size_t chNo, size_t from, size_t cnt) const;
00140 size_t CopyPartTo(unsigned int * data, size_t from, size_t sz) const;
00141 size_t CopyPartTo(unsigned int * data, size_t chNo, size_t from, size_t cnt) const;
00142 size_t CopyPartTo(qint64 * data, size_t from, size_t sz) const;
00143 size_t CopyPartTo(qint64 * data, size_t chNo, size_t from, size_t cnt) const;
00144 size_t CopyPartTo(quint64 * data, size_t from, size_t sz) const;
00145 size_t CopyPartTo(quint64 * data, size_t chNo, size_t from, size_t cnt) const;
00146 size_t CopyPartTo(float * data, size_t from, size_t sz) const;
00147 size_t CopyPartTo(float * data, size_t chNo, size_t from, size_t cnt) const;
00148 size_t CopyPartTo(double * data, size_t from, size_t sz) const;
00149 size_t CopyPartTo(double * data, size_t chNo, size_t from, size_t cnt) const;
00150
00151 void CopyDimension(const sxPacketContent * pc);
00152 bool HasEqualDimension(const sxPacketContent * pc) const;
00153 size_t BytesCapacity() const;
00154 size_t Capacity() const;
00155 size_t TotalBytesLength() const;
00156 size_t TotalLength() const;
00157 size_t Count() const;
00158 size_t BytesCount() const;
00159 size_t BlockLength() const;
00160 size_t ChannelCount() const;
00161 char * RawData();
00162 char * RawData(size_t ch);
00163 const char * ConstRawData() const;
00164 const char * ConstRawData(size_t ch) const;
00165 bool IsEmpty() const;
00166 void Resize(size_t chCount,size_t cnt);
00167 void Trim(size_t cnt, sx::Position pos);
00168 void ReduceTo1Ch(size_t chfrom);
00169 void ExpandTo(size_t ncnt);
00170 void Reserve(size_t chCount, size_t cnt, bool copy = false);
00171 void Zeros();
00172
00173 bool Append(const sxPacketContent * content);
00174 bool Merge(const sxPacketContent * content);
00175 bool Merge(const sxPacketContent * content, size_t cnt);
00176 protected:
00177 char * xData;
00178 size_t xBlockLength;
00179 size_t xCapacity;
00180 size_t xChannelCount;
00181 size_t xCount;
00183 sxPacketContent(size_t cnt, size_t chanCnt, size_t blocklen);
00184 private:
00185 SX_DISABLE_COPY(sxPacketContent)
00186 };
00187
00188 #define SX_DECLARE_PACKET_CONTENT(Class) \
00189 class SX_SDKEXPORT Class : public sxPacketContent \
00190 { \
00191 protected: \
00192 bool MergeType(const sxPacketContent * content); \
00193 bool MergeType(const sxPacketContent * content, size_t cnt); \
00194 bool AppendType(const sxPacketContent * content); \
00195 public: \
00196 Class(size_t cnt = 0, size_t chanCnt = 1); \
00197 ~Class(); \
00198 sxPacketContent * Clone(size_t cnt = 0) const; \
00199 sxPacketContent * Split(size_t chanCount); \
00200 sx::DataType Type() const; \
00201 void Assign(const sxPacketContent * content); \
00202 void Assign(const sxPacketContent * content, size_t cnt); \
00203 void PushBackCircular(sxPacketContent * content); \
00204 bool GetBool(size_t idx) const; \
00205 bool GetBool(size_t chNo, size_t idx) const; \
00206 char GetChar(size_t idx) const; \
00207 char GetChar(size_t chNo, size_t idx) const; \
00208 unsigned char GetUChar(size_t idx) const; \
00209 unsigned char GetUChar(size_t chNo, size_t idx) const; \
00210 short GetShort(size_t idx) const; \
00211 short GetShort(size_t chNo, size_t idx) const; \
00212 unsigned short GetUShort(size_t idx) const; \
00213 unsigned short GetUShort(size_t chNo, size_t idx) const; \
00214 int GetInt(size_t idx) const; \
00215 int GetInt(size_t chNo, size_t idx) const; \
00216 unsigned int GetUInt(size_t idx) const; \
00217 unsigned int GetUInt(size_t chNo, size_t idx) const; \
00218 qint64 GetInt64(size_t idx) const; \
00219 qint64 GetInt64(size_t chNo, size_t idx) const; \
00220 quint64 GetUInt64(size_t idx) const; \
00221 quint64 GetUInt64(size_t chNo, size_t idx) const; \
00222 float GetFloat(size_t idx) const; \
00223 float GetFloat(size_t chNo, size_t idx) const; \
00224 double GetDouble(size_t idx) const; \
00225 double GetDouble(size_t chNo, size_t idx) const; \
00226 sxint_t GetSxInt(size_t idx) const; \
00227 sxint_t GetSxInt(size_t chNo, size_t idx) const; \
00228 void Set(size_t idx, bool val); \
00229 void Set(size_t chNo, size_t idx, bool val); \
00230 void Set(size_t idx, char val); \
00231 void Set(size_t chNo, size_t idx, char val); \
00232 void Set(size_t idx, unsigned char val); \
00233 void Set(size_t chNo, size_t idx, unsigned char val); \
00234 void Set(size_t idx, short val); \
00235 void Set(size_t chNo, size_t idx, short val); \
00236 void Set(size_t idx, unsigned short val); \
00237 void Set(size_t chNo, size_t idx, unsigned short val); \
00238 void Set(size_t idx, int val); \
00239 void Set(size_t chNo, size_t idx, int val); \
00240 void Set(size_t idx, unsigned int val); \
00241 void Set(size_t chNo, size_t idx, unsigned int val); \
00242 void Set(size_t idx, float val); \
00243 void Set(size_t chNo, size_t idx, float val); \
00244 void Set(size_t idx, double val); \
00245 void Set(size_t chNo, size_t idx, double val); \
00246 void Set(size_t idx, qint64 val); \
00247 void Set(size_t chNo, size_t idx, qint64 val); \
00248 void Set(size_t idx, quint64 val); \
00249 void Set(size_t chNo, size_t idx, quint64 val); \
00250 void SetSxInt(size_t idx, sxint_t val); \
00251 void SetSxInt(size_t chNo, size_t idx, sxint_t val); \
00252 void Multiply(double val); \
00253 void Divide(double val); \
00254 void Add(double val); \
00255 void Subtract(double val); \
00256 void ConstSubtract(double val); \
00257 void Multiply(size_t idx, double val); \
00258 void Divide(size_t idx, double val); \
00259 void Add(size_t idx, double val); \
00260 void Subtract(size_t idx, double val); \
00261 void ConstSubtract(size_t idx, double val); \
00262 void Transpose(); \
00263 };
00264
00265
00266 #define SX_IMPLEMENT_PACKET_CONTENT(Class, __TypeId__, __Type__) \
00267 Class::Class(size_t cnt, size_t chanCnt) : sxPacketContent(cnt, chanCnt, sizeof(__Type__)) \
00268 { \
00269 } \
00270 Class::~Class() \
00271 { \
00272 } \
00273 bool Class::MergeType(const sxPacketContent * content) \
00274 { \
00275 Q_ASSERT(xCount == content->Count()); \
00276 size_t tb1 = TotalBytesLength(); \
00277 size_t tb2 = content->TotalBytesLength(); \
00278 if ( (tb1 + tb2) > BytesCapacity()) \
00279 { \
00280 char * data = new char[tb1 + tb2]; \
00281 memcpy(data, xData, tb1); \
00282 __Type__ * typedPtr = (__Type__ *)(data + tb1); \
00283 content->CopyTo(typedPtr, content->TotalLength()); \
00284 delete [] xData; \
00285 xData = data; \
00286 xCapacity = TotalLength() + content->TotalLength(); \
00287 } \
00288 else \
00289 { \
00290 __Type__ * typedPtr = (__Type__ *)(xData + tb1); \
00291 content->CopyTo(typedPtr, content->TotalLength()); \
00292 } \
00293 xChannelCount += content->ChannelCount(); \
00294 return true; \
00295 } \
00296 bool Class::MergeType(const sxPacketContent * content, size_t cnt) \
00297 { \
00298 size_t tb1 = TotalBytesLength(); \
00299 size_t tb2 = content->BlockLength() * cnt * content->ChannelCount(); \
00300 if ( (tb1 + tb2) > BytesCapacity()) \
00301 { \
00302 char * data = new char[tb1 + tb2]; \
00303 memcpy(data, xData, tb1); \
00304 __Type__ * typedPtr = (__Type__ *)(data + tb1); \
00305 for (size_t ch = 0; ch < content->ChannelCount(); ch++) \
00306 { \
00307 content->CopyTo(typedPtr, ch, cnt); \
00308 typedPtr += cnt; \
00309 } \
00310 delete [] xData; \
00311 xData = data; \
00312 xCapacity = TotalLength() + cnt * content->ChannelCount(); \
00313 } \
00314 else \
00315 { \
00316 __Type__ * typedPtr = (__Type__ *)(xData + tb1); \
00317 for (size_t ch = 0; ch < content->ChannelCount(); ch++) \
00318 { \
00319 content->CopyTo(typedPtr, ch, cnt); \
00320 typedPtr += cnt; \
00321 } \
00322 } \
00323 xChannelCount += content->ChannelCount(); \
00324 return true; \
00325 } \
00326 bool Class::AppendType(const sxPacketContent * pc) \
00327 { \
00328 Q_ASSERT(ChannelCount() == pc->ChannelCount()); \
00329 size_t ncap = (TotalLength() + pc->TotalLength()); \
00330 char * pdata = new char[ncap * xBlockLength]; \
00331 register __Type__ * p = (__Type__ *)pdata; \
00332 size_t cnt1 = Count(); \
00333 size_t cnt2 = pc->Count(); \
00334 size_t cntTot = cnt1 + cnt2; \
00335 for (size_t ch = 0; ch < xChannelCount; ch++) \
00336 { \
00337 CopyTo(p, ch, cnt1); \
00338 pc->CopyTo(p + cnt1, ch, cnt2); \
00339 p += cntTot; \
00340 } \
00341 xCapacity = ncap; \
00342 delete [] xData; \
00343 xData = pdata; \
00344 xCount += pc->Count(); \
00345 return true; \
00346 } \
00347 sx::DataType Class::Type() const \
00348 { \
00349 return __TypeId__; \
00350 } \
00351 sxPacketContent * Class::Clone(size_t cnt) const \
00352 { \
00353 Class * pc; \
00354 if (cnt == 0 || cnt >= Count()) \
00355 { \
00356 pc = new Class(xCount, xChannelCount); \
00357 memcpy(pc->xData, xData, TotalBytesLength()); \
00358 return pc; \
00359 } \
00360 else \
00361 { \
00362 pc = new Class(cnt, xChannelCount); \
00363 register char * pcdata = pc->xData; \
00364 register char * data = xData; \
00365 cnt = cnt * xBlockLength; \
00366 size_t bytescnt = BytesCount(); \
00367 for (size_t ch = 0; ch < xChannelCount; ch++) \
00368 { \
00369 memcpy(pcdata, data, cnt); \
00370 pcdata += cnt; \
00371 data += bytescnt; \
00372 } \
00373 } \
00374 return pc; \
00375 } \
00376 sxPacketContent * Class::Split(size_t chanCount) \
00377 { \
00378 sxPacketContent * pc; \
00379 if (chanCount >= ChannelCount()) \
00380 { \
00381 pc = Clone(); \
00382 xCount = 0; \
00383 return pc; \
00384 } \
00385 pc = new Class(xCount, chanCount); \
00386 memcpy(pc->RawData(), xData + (xChannelCount - chanCount) * xCount * xBlockLength, pc->TotalBytesLength()); \
00387 xChannelCount -= chanCount; \
00388 return pc; \
00389 } \
00390 void Class::Assign(const sxPacketContent * content) \
00391 { \
00392 Resize(content->ChannelCount(), content->Count()); \
00393 __Type__ * typedData = (__Type__ *)xData; \
00394 content->CopyTo(typedData, TotalLength()); \
00395 } \
00396 void Class::Assign(const sxPacketContent * content, size_t cnt) \
00397 { \
00398 Q_ASSERT(content->Count() >= cnt); \
00399 Resize(content->ChannelCount(), cnt); \
00400 __Type__ * typedData = (__Type__ *)xData; \
00401 for (size_t ch = 0; ch < xChannelCount; ch++) \
00402 { \
00403 content->CopyTo(typedData, ch, cnt); \
00404 typedData += cnt; \
00405 } \
00406 } \
00407 void Class::PushBackCircular(sxPacketContent * content) \
00408 { \
00409 Q_ASSERT( content->ChannelCount() == ChannelCount() ); \
00410 size_t ch, diff; \
00411 size_t bcount = BytesCount(); \
00412 size_t bcount2 = content->BytesCount(); \
00413 char * rdata = content->RawData(); \
00414 if (content->Type() == Type()) { \
00415 if (content->Count() == Count()) { \
00416 memcpy(xData, content->RawData(), TotalBytesLength()); \
00417 } else if (content->Count() > Count()) { \
00418 diff = content->BytesCount() - BytesCount(); \
00419 for (ch = 0; ch < xChannelCount; ch++) { \
00420 memcpy(xData + ch*bcount, rdata + bcount2*ch + diff, bcount); \
00421 } \
00422 } else { \
00423 diff = BytesCount() - content->BytesCount(); \
00424 char * pp; \
00425 for (ch = 0; ch < xChannelCount; ch++) { \
00426 pp = xData + ch * bcount; \
00427 memmove(pp, pp + bcount2, diff); \
00428 memcpy(pp + diff, rdata + ch*bcount2, bcount2); \
00429 } \
00430 } \
00431 } else { \
00432 __Type__ * typedPtr = (__Type__ *)(xData); \
00433 if (content->Count() == Count()) { \
00434 content->CopyTo(typedPtr, Count()); \
00435 } else if (content->Count() > Count()) { \
00436 diff = content->BytesCount() - BytesCount(); \
00437 for (ch = 0; ch < xChannelCount; ch++) { \
00438 content->CopyPartTo(typedPtr+xCount*ch, ch, diff, xCount); \
00439 } \
00440 } else { \
00441 diff = BytesCount() - content->BytesCount(); \
00442 char * pp; \
00443 for (ch = 0; ch < xChannelCount; ch++) { \
00444 pp = xData + ch * bcount; \
00445 memmove(pp, pp + bcount2, diff); \
00446 typedPtr = (__Type__ *)(pp+diff); \
00447 content->CopyTo(typedPtr, ch, content->Count()); \
00448 } \
00449 } \
00450 }\
00451 }\
00452 bool Class::GetBool(size_t idx) const \
00453 { \
00454 Q_ASSERT(idx < TotalLength()); \
00455 register __Type__ * p = (__Type__ *)xData; \
00456 return (bool)p[idx]; \
00457 } \
00458 bool Class::GetBool(size_t chNo, size_t idx) const \
00459 { \
00460 Q_ASSERT( (chNo * xCount + idx) < TotalLength() ); \
00461 register __Type__ * p = (__Type__ *)xData; \
00462 return (bool)( * (p + chNo * xCount + idx) ); \
00463 } \
00464 char Class::GetChar(size_t idx) const \
00465 { \
00466 Q_ASSERT(idx < TotalLength()); \
00467 register __Type__ * p = (__Type__ *)xData; \
00468 return (char)p[idx]; \
00469 } \
00470 char Class::GetChar(size_t chNo, size_t idx) const \
00471 { \
00472 Q_ASSERT( (chNo * xCount + idx) < TotalLength() ); \
00473 register __Type__ * p = (__Type__ *)xData; \
00474 return (char)( * (p + chNo * xCount + idx) ); \
00475 } \
00476 unsigned char Class::GetUChar(size_t idx) const \
00477 { \
00478 Q_ASSERT(idx < TotalLength()); \
00479 register __Type__ * p = (__Type__ *)xData; \
00480 return (unsigned char)p[idx]; \
00481 } \
00482 unsigned char Class::GetUChar(size_t chNo, size_t idx) const \
00483 { \
00484 Q_ASSERT( (chNo * xCount + idx) < TotalLength() ); \
00485 register __Type__ * p = (__Type__ *)xData; \
00486 return (unsigned char)( * (p + chNo * xCount + idx) ); \
00487 } \
00488 short Class::GetShort(size_t idx) const \
00489 { \
00490 Q_ASSERT(idx < TotalLength()); \
00491 register __Type__ * p = (__Type__ *)xData; \
00492 return (short)p[idx]; \
00493 } \
00494 short Class::GetShort(size_t chNo, size_t idx) const \
00495 { \
00496 Q_ASSERT( (chNo * xCount + idx) < TotalLength() ); \
00497 register __Type__ * p = (__Type__ *)xData; \
00498 return (short)( * (p + chNo * xCount + idx) ); \
00499 } \
00500 unsigned short Class::GetUShort(size_t idx) const \
00501 { \
00502 Q_ASSERT(idx < TotalLength()); \
00503 register __Type__ * p = (__Type__ *)xData; \
00504 return (unsigned short)p[idx]; \
00505 } \
00506 unsigned short Class::GetUShort(size_t chNo, size_t idx) const \
00507 { \
00508 Q_ASSERT( (chNo * xCount + idx) < TotalLength() ); \
00509 register __Type__ * p = (__Type__ *)xData; \
00510 return (unsigned short)( * (p + chNo * xCount + idx) ); \
00511 } \
00512 int Class::GetInt(size_t idx) const \
00513 { \
00514 Q_ASSERT(idx < TotalLength()); \
00515 register __Type__ * p = (__Type__ *)xData; \
00516 return (int)p[idx]; \
00517 } \
00518 int Class::GetInt(size_t chNo, size_t idx) const \
00519 { \
00520 Q_ASSERT( (chNo * xCount + idx) < TotalLength() ); \
00521 register __Type__ * p = (__Type__ *)xData; \
00522 return (int)( * (p + chNo * xCount + idx) ); \
00523 } \
00524 unsigned int Class::GetUInt(size_t idx) const \
00525 { \
00526 Q_ASSERT(idx < TotalLength()); \
00527 register __Type__ * p = (__Type__ *)xData; \
00528 return (unsigned int)p[idx]; \
00529 } \
00530 unsigned int Class::GetUInt(size_t chNo, size_t idx) const \
00531 { \
00532 Q_ASSERT( (chNo * xCount + idx) < TotalLength() ); \
00533 register __Type__ * p = (__Type__ *)xData; \
00534 return (unsigned int)( * (p + chNo * xCount + idx) ); \
00535 } \
00536 qint64 Class::GetInt64(size_t idx) const \
00537 { \
00538 Q_ASSERT(idx < TotalLength()); \
00539 register __Type__ * p = (__Type__ *)xData; \
00540 return (qint64)p[idx]; \
00541 } \
00542 qint64 Class::GetInt64(size_t chNo, size_t idx) const \
00543 { \
00544 Q_ASSERT( (chNo * xCount + idx) < TotalLength() ); \
00545 register __Type__ * p = (__Type__ *)xData; \
00546 return (qint64)( * (p + chNo * xCount + idx) ); \
00547 } \
00548 quint64 Class::GetUInt64(size_t idx) const \
00549 { \
00550 Q_ASSERT(idx < TotalLength()); \
00551 register __Type__ * p = (__Type__ *)xData; \
00552 return (quint64)p[idx]; \
00553 } \
00554 quint64 Class::GetUInt64(size_t chNo, size_t idx) const \
00555 { \
00556 Q_ASSERT( (chNo * xCount + idx) < TotalLength() ); \
00557 register __Type__ * p = (__Type__ *)xData; \
00558 return (quint64)( * (p + chNo * xCount + idx) ); \
00559 } \
00560 float Class::GetFloat(size_t idx) const \
00561 { \
00562 Q_ASSERT(idx < TotalLength()); \
00563 register __Type__ * p = (__Type__ *)xData; \
00564 return (float)p[idx]; \
00565 } \
00566 float Class::GetFloat(size_t chNo, size_t idx) const \
00567 { \
00568 Q_ASSERT( (chNo * xCount + idx) < TotalLength() ); \
00569 register __Type__ * p = (__Type__ *)xData; \
00570 return (float)( * (p + chNo * xCount + idx) ); \
00571 } \
00572 double Class::GetDouble(size_t idx) const \
00573 { \
00574 Q_ASSERT(idx < TotalLength()); \
00575 register __Type__ * p = (__Type__ *)xData; \
00576 return (double)p[idx]; \
00577 } \
00578 double Class::GetDouble(size_t chNo, size_t idx) const \
00579 { \
00580 Q_ASSERT( (chNo * xCount + idx) < TotalLength() ); \
00581 register __Type__ * p = (__Type__ *)xData; \
00582 return (double)( * (p + chNo * xCount + idx) ); \
00583 } \
00584 sxint_t Class::GetSxInt(size_t idx) const \
00585 { \
00586 Q_ASSERT(idx < TotalLength()); \
00587 register __Type__ * p = (__Type__ *)xData; \
00588 return (sxint_t)p[idx]; \
00589 } \
00590 sxint_t Class::GetSxInt(size_t chNo, size_t idx) const \
00591 { \
00592 Q_ASSERT( (chNo * xCount + idx) < TotalLength() ); \
00593 register __Type__ * p = (__Type__ *)xData; \
00594 return (sxint_t)( * (p + chNo * xCount + idx) ); \
00595 } \
00596 void Class::Set(size_t idx, bool val) \
00597 { \
00598 Q_ASSERT(idx < TotalLength()); \
00599 register __Type__ * p = (__Type__ *)xData; \
00600 p[idx] = (__Type__)val; \
00601 } \
00602 void Class::Set(size_t chNo, size_t idx, bool val) \
00603 { \
00604 Q_ASSERT( (chNo * xCount + idx) < TotalLength() ); \
00605 register __Type__ * p = (__Type__ *)xData; \
00606 * (p + chNo * xCount + idx) = (__Type__)val; \
00607 } \
00608 void Class::Set(size_t idx, char val) \
00609 { \
00610 Q_ASSERT(idx < TotalLength()); \
00611 register __Type__ * p = (__Type__ *)xData; \
00612 p[idx] = (__Type__)val; \
00613 } \
00614 void Class::Set(size_t chNo, size_t idx, char val) \
00615 { \
00616 Q_ASSERT( (chNo * xCount + idx) < TotalLength() ); \
00617 register __Type__ * p = (__Type__ *)xData; \
00618 * (p + chNo * xCount + idx) = (__Type__)val; \
00619 } \
00620 void Class::Set(size_t idx, unsigned char val) \
00621 { \
00622 Q_ASSERT(idx < TotalLength()); \
00623 register __Type__ * p = (__Type__ *)xData; \
00624 p[idx] = (__Type__)val; \
00625 } \
00626 void Class::Set(size_t chNo, size_t idx, unsigned char val) \
00627 { \
00628 Q_ASSERT( (chNo * xCount + idx) < TotalLength() ); \
00629 register __Type__ * p = (__Type__ *)xData; \
00630 * (p + chNo * xCount + idx) = (__Type__)val; \
00631 } \
00632 void Class::Set(size_t idx, short val) \
00633 { \
00634 Q_ASSERT(idx < TotalLength()); \
00635 register __Type__ * p = (__Type__ *)xData; \
00636 p[idx] = (__Type__)val; \
00637 } \
00638 void Class::Set(size_t chNo, size_t idx, short val) \
00639 { \
00640 Q_ASSERT( (chNo * xCount + idx) < TotalLength() ); \
00641 register __Type__ * p = (__Type__ *)xData; \
00642 * (p + chNo * xCount + idx) = (__Type__)val; \
00643 } \
00644 void Class::Set(size_t idx, unsigned short val) \
00645 { \
00646 Q_ASSERT(idx < TotalLength()); \
00647 register __Type__ * p = (__Type__ *)xData; \
00648 p[idx] = (__Type__)val; \
00649 } \
00650 void Class::Set(size_t chNo, size_t idx, unsigned short val) \
00651 { \
00652 Q_ASSERT( (chNo * xCount + idx) < TotalLength() ); \
00653 register __Type__ * p = (__Type__ *)xData; \
00654 * (p + chNo * xCount + idx) = (__Type__)val; \
00655 } \
00656 void Class::Set(size_t idx, int val) \
00657 { \
00658 Q_ASSERT(idx < TotalLength()); \
00659 register __Type__ * p = (__Type__ *)xData; \
00660 p[idx] = (__Type__)val; \
00661 } \
00662 void Class::Set(size_t chNo, size_t idx, int val) \
00663 { \
00664 Q_ASSERT( (chNo * xCount + idx) < TotalLength() ); \
00665 register __Type__ * p = (__Type__ *)xData; \
00666 * (p + chNo * xCount + idx) = (__Type__)val; \
00667 } \
00668 void Class::Set(size_t idx, unsigned int val) \
00669 { \
00670 Q_ASSERT(idx < TotalLength()); \
00671 register __Type__ * p = (__Type__ *)xData; \
00672 p[idx] = (__Type__)val; \
00673 } \
00674 void Class::Set(size_t chNo, size_t idx, unsigned int val) \
00675 { \
00676 Q_ASSERT( (chNo * xCount + idx) < TotalLength() ); \
00677 register __Type__ * p = (__Type__ *)xData; \
00678 * (p + chNo * xCount + idx) = (__Type__)val; \
00679 } \
00680 void Class::Set(size_t idx, qint64 val) \
00681 { \
00682 Q_ASSERT(idx < TotalLength()); \
00683 register __Type__ * p = (__Type__ *)xData; \
00684 p[idx] = (__Type__)val; \
00685 } \
00686 void Class::Set(size_t chNo, size_t idx, qint64 val) \
00687 { \
00688 Q_ASSERT( (chNo * xCount + idx) < TotalLength() ); \
00689 register __Type__ * p = (__Type__ *)xData; \
00690 * (p + chNo * xCount + idx) = (__Type__)val; \
00691 } \
00692 void Class::Set(size_t idx, quint64 val) \
00693 { \
00694 Q_ASSERT(idx < TotalLength()); \
00695 register __Type__ * p = (__Type__ *)xData; \
00696 p[idx] = (__Type__)val; \
00697 } \
00698 void Class::Set(size_t chNo, size_t idx, quint64 val) \
00699 { \
00700 Q_ASSERT( (chNo * xCount + idx) < TotalLength() ); \
00701 register __Type__ * p = (__Type__ *)xData; \
00702 * (p + chNo * xCount + idx) = (__Type__)val; \
00703 } \
00704 void Class::Set(size_t idx, float val) \
00705 { \
00706 Q_ASSERT(idx < TotalLength()); \
00707 register __Type__ * p = (__Type__ *)xData; \
00708 p[idx] = (__Type__)val; \
00709 } \
00710 void Class::Set(size_t chNo, size_t idx, float val) \
00711 { \
00712 Q_ASSERT( (chNo * xCount + idx) < TotalLength() ); \
00713 register __Type__ * p = (__Type__ *)xData; \
00714 * (p + chNo * xCount + idx) = (__Type__)val; \
00715 } \
00716 void Class::Set(size_t idx, double val) \
00717 { \
00718 Q_ASSERT(idx < TotalLength()); \
00719 register __Type__ * p = (__Type__ *)xData; \
00720 p[idx] = (__Type__)val; \
00721 } \
00722 void Class::Set(size_t chNo, size_t idx, double val) \
00723 { \
00724 Q_ASSERT( (chNo * xCount + idx) < TotalLength() ); \
00725 register __Type__ * p = (__Type__ *)xData; \
00726 * (p + chNo * xCount + idx) = (__Type__)val; \
00727 } \
00728 void Class::SetSxInt(size_t idx, sxint_t val) \
00729 { \
00730 Q_ASSERT(idx < TotalLength()); \
00731 register __Type__ * p = (__Type__ *)xData; \
00732 p[idx] = (__Type__)val; \
00733 } \
00734 void Class::SetSxInt(size_t chNo, size_t idx, sxint_t val) \
00735 { \
00736 Q_ASSERT( (chNo * xCount + idx) < TotalLength() ); \
00737 register __Type__ * p = (__Type__ *)xData; \
00738 * (p + chNo * xCount + idx) = (__Type__)val; \
00739 } \
00740 void Class::Multiply(double val) \
00741 { \
00742 if (xCount == 0) return; \
00743 size_t totLen = TotalLength(); \
00744 register __Type__ * p = (__Type__ *)xData; \
00745 for (size_t idx = 0; idx < totLen; idx++) \
00746 p[idx] = (__Type__)(p[idx] * val); \
00747 } \
00748 void Class::Divide(double val) \
00749 { \
00750 if (xCount == 0 || val == 0) return; \
00751 size_t totLen = TotalLength(); \
00752 register __Type__ * p = (__Type__ *)xData; \
00753 for (size_t idx = 0; idx < totLen; idx++) \
00754 p[idx] = (__Type__)(p[idx] / val); \
00755 } \
00756 void Class::Add(double val) \
00757 { \
00758 if (xCount == 0) return; \
00759 size_t totLen = TotalLength(); \
00760 register __Type__ * p = (__Type__ *)xData; \
00761 for (size_t idx = 0; idx < totLen; idx++) \
00762 p[idx] = (__Type__)(p[idx] + val); \
00763 } \
00764 void Class::Subtract(double val) \
00765 { \
00766 if (xCount == 0) return; \
00767 size_t totLen = TotalLength(); \
00768 register __Type__ * p = (__Type__ *)xData; \
00769 for (size_t idx = 0; idx < totLen; idx++) \
00770 p[idx] = (__Type__)(p[idx] - val); \
00771 } \
00772 void Class::ConstSubtract(double val) \
00773 { \
00774 if (xCount == 0) return; \
00775 size_t totLen = TotalLength(); \
00776 register __Type__ * p = (__Type__ *)xData; \
00777 for (size_t idx = 0; idx < totLen; idx++) \
00778 p[idx] = (__Type__)(val - p[idx]); \
00779 } \
00780 void Class::Multiply(size_t idx, double val) \
00781 { \
00782 register __Type__ * p = (__Type__ *)xData; \
00783 p[idx] = (__Type__)(p[idx] * val); \
00784 } \
00785 void Class::Divide(size_t idx, double val) \
00786 { \
00787 register __Type__ * p = (__Type__ *)xData; \
00788 p[idx] = (__Type__)(p[idx] / val); \
00789 } \
00790 void Class::Add(size_t idx, double val) \
00791 { \
00792 register __Type__ * p = (__Type__ *)xData; \
00793 p[idx] = (__Type__)(p[idx] + val); \
00794 } \
00795 void Class::Subtract(size_t idx, double val) \
00796 { \
00797 register __Type__ * p = (__Type__ *)xData; \
00798 p[idx] = (__Type__)(p[idx] - val); \
00799 } \
00800 void Class::ConstSubtract(size_t idx, double val) \
00801 { \
00802 register __Type__ * p = (__Type__ *)xData; \
00803 p[idx] = (__Type__)(val - p[idx]); \
00804 } \
00805 void Class::Transpose() \
00806 { \
00807 if (xCount == 0) return; \
00808 size_t nch = xCount; \
00809 size_t ncnt = xChannelCount; \
00810 __Type__ * nd = new __Type__[nch * ncnt]; \
00811 __Type__ * p = nd; \
00812 register __Type__ * pOld = (__Type__ *)xData; \
00813 for (size_t cnt = 0; cnt < xCount; cnt++) \
00814 { \
00815 for (size_t ch = 0; ch < xChannelCount; ch++) \
00816 { \
00817 *p = * (pOld + ch * xCount + cnt); \
00818 p++; \
00819 } \
00820 } \
00821 delete [] xData; \
00822 xData = (char *)nd; \
00823 xCount = ncnt; \
00824 xChannelCount = nch; \
00825 }
00826
00827
00828 SX_DECLARE_PACKET_CONTENT(sxBoolPacketContent)
00829 SX_DECLARE_PACKET_CONTENT(sxCharPacketContent)
00830 SX_DECLARE_PACKET_CONTENT(sxUCharPacketContent)
00831 SX_DECLARE_PACKET_CONTENT(sxShortPacketContent)
00832 SX_DECLARE_PACKET_CONTENT(sxUShortPacketContent)
00833 SX_DECLARE_PACKET_CONTENT(sxIntPacketContent)
00834 SX_DECLARE_PACKET_CONTENT(sxUIntPacketContent)
00835 SX_DECLARE_PACKET_CONTENT(sxInt64PacketContent)
00836 SX_DECLARE_PACKET_CONTENT(sxUInt64PacketContent)
00837 SX_DECLARE_PACKET_CONTENT(sxFloatPacketContent)
00838 SX_DECLARE_PACKET_CONTENT(sxDoublePacketContent)
00839 SX_DECLARE_PACKET_CONTENT(sxSxIntPacketContent)
00840
00841 #endif // SXPACKETCONTENT_H_INCLUDED