Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

FBase.h

Go to the documentation of this file.
00001 #ifndef FBASE_H_FILE
00002 #define FBASE_H_FILE
00003 
00004 
00005 #include <iostream>
00006 #include <vector>
00007 #include <math.h>
00008 
00009 /*static unsigned long arr1[] = {
00010                 0x0, 0x1, 0x3, 0x7, 0xf, 0x1f, 0x3f, 0x7f, 0xff,
00011         0x1ff, 0x3ff, 0x7ff, 0xfff, 0x1fff, 0x3fff, 0x7fff, 0xffff,
00012         0x1ffff, 0x3ffff, 0x7ffff, 0xfffff, 0x1fffff, 0x3fffff, 0x7fffff, 0xffffff,
00013         0x1ffffff, 0x3ffffff, 0x7ffffff, 0xfffffff, 0x1fffffff, 0x3fffffff, 0x7fffffff, 0xffffffff
00014 };*/
00015 
00016 class FlashImporter;
00017 
00018 typedef unsigned char UBYTE;
00019 typedef char SBYTE;
00020 
00021 typedef unsigned short UWORD;
00022 typedef short SWORD;
00023 
00024 typedef unsigned int UDWORD;
00025 typedef int SDWORD;
00026 
00027 #define WRITE_UBYTE(x) { UBYTE s = (x); out.write((char*)&s,1); }
00028 #define WRITE_SBYTE(x) { SBYTE s = (x); out.write((char*)&s,1); }
00029 
00030 #define WRITE_UWORD(x) { UWORD s = (x); out.write((char*)&s,2); }
00031 #define WRITE_SWORD(x) { SWORD s = (x); out.write((char*)&s,2); }
00032 
00033 #define WRITE_UDWORD(x) { UDWORD s = (x); out.write((char*)&s,4); }
00034 #define WRITE_SDWORD(x) { SDWORD s = (x); out.write((char*)&s,4); }
00035 
00036 #define WRITE_UBYTE2(x,f) { UBYTE s = (x); f.write((char*)&s,1); }
00037 #define WRITE_SBYTE2(x,f) { SBYTE s = (x); f.write((char*)&s,1); }
00038 
00039 #define WRITE_UWORD2(x,f) { UWORD s = (x); f.write((char*)&s,2); }
00040 #define WRITE_SWORD2(x,f) { SWORD s = (x); f.write((char*)&s,2); }
00041 
00042 #define WRITE_UDWORD2(x,f) { UDWORD s = (x); f.write((char*)&s,4); }
00043 #define WRITE_SDWORD2(x,f) { SDWORD s = (x); f.write((char*)&s,4); }
00044 
00045 #define READ_UBYTE(x) { in.read((char*)&x,1); }
00046 #define READ_SBYTE(x) { in.read((char*)&x,1); }
00047 
00048 #define READ_UWORD(x) { in.read((char*)&x,2); }
00049 #define READ_SWORD(x) { in.read((char*)&x,2); }
00050 
00051 #define READ_UDWORD(x) { in.read((char*)&x,4); }
00052 #define READ_SDWORD(x) { in.read((char*)&x,4); }
00053 
00054 #define READ_UBYTE2(x,f) { f.read((char*)&x,1); }
00055 #define READ_SBYTE2(x,f) { f.read((char*)&x,1); }
00056 
00057 #define READ_UWORD2(x,f) { f.read((char*)&x,2); }
00058 #define READ_SWORD2(x,f) { f.read((char*)&x,2); }
00059 
00060 #define READ_UDWORD2(x,f) { f.read((char*)&x,4); }
00061 #define READ_SDWORD2(x,f) { f.read((char*)&x,4); }
00062 
00063 #define DEFINE_RW_INTERFACE                                                             \
00064 public:                                                                                                 \
00065 virtual void Write(std::ostream &out) { out << *this; } \
00066 virtual void Read(std::istream &in) { in >> *this; }    \
00067 
00068 template <class T> T max(T a, T b)  {return (((a) > (b)) ? (a) : (b)); } 
00069 template <class T> T min(T a, T b)  {return (((a) < (b)) ? (a) : (b)); } 
00070 
00071 template<class T, class U>
00072     struct flash_pair {
00073     typedef T first_type;
00074     typedef U second_type;
00075     T first;
00076     U second;
00077     flash_pair() {}
00078     flash_pair(const T& x, const U& y) : first(x), second(y) {}
00079     template<class V, class W>
00080         flash_pair(const flash_pair<V, W>& pr) : first(pr.first), second(pr.second) {}
00081     };
00082 
00083 class FlashVersionEnabled
00084 {
00085 public:
00086     FlashVersionEnabled() : version(1) {}
00087     virtual void SetTagVersion(int v) { version = v; }
00088     virtual int GetTagVersion(void) const { return version; }
00089 private:
00090     int version;
00091 };
00092 
00093 template<class T> T LSHR(T x, int num);
00094 
00095 template<class T> int GetBitSize(T x)
00096 {
00097     int size=0;
00098     while(x > 0)
00099     {
00100       x=LSHR(x,1);
00101       size++;
00102     } 
00103     return size;
00104 }
00105 
00106 template<class T> int GetBitSizeSigned(T x)
00107 {
00108     int size=0;
00109     int sign = (long(x) < 0);
00110     T tmp=x;
00111     if(sign) tmp = tmp*(-1);
00112     size = GetBitSize(tmp);
00113     return (size+1);
00114 }
00115 
00116 template<class T> T PackBitsSigned(T x)
00117 {    
00118     UDWORD v=0x0;
00119     int sign = (long(x) < 0);
00120     if(sign) x=~x + 1;
00121 
00122     int i = GetBitSizeSigned(x);
00123 //    v = arr1[i];
00124     for(int b=0; b < i; b++)
00125     {
00126         v = (v << 1) | 0x01;
00127     }
00128     v = (x & v) | (GetBit(x,sizeof(T)*8-1));
00129     if(sign) return (T)(~v + 1);
00130     return (v); 
00131 }
00132 
00133 template<class T> T UnPackBitsSigned(T x, int size)
00134 {
00135     int sign = GetBit(x,size-1);
00136     
00137     x = GetIsolatedBits(x,0,size);
00138     
00139     T v = 0;
00140     if(sign == 1) 
00141     {
00142         int bit1 = size;
00143         int bit2 = sizeof(T)*8;
00144 //              v = arr1[bit2-bit1];
00145         for(int b=0; b < bit2-bit1; b++)
00146                   {
00147             v = (v << 1) | 0x01;
00148         }
00149 //              v <<= bit1;
00150         for(int b2=0; b2 < bit1; b2++)
00151         {
00152             v = (v << 1);
00153         }
00154 
00155     }
00156     return (x | v); 
00157 }
00158 
00159 template<class T> char GetBit(T x, int bit)
00160 {   
00161     T y = 1 << bit;
00162     if((x & y)==0) return (char)0;
00163     return((char)1);
00164 }
00165 
00166 template<class T> T IsolateBits(T x, int bit1, int bit2)
00167 {
00168     T v=0;
00169     //v = arr1[bit2-bit1];
00170     for(int b=0; b < bit2-bit1; b++)
00171     {
00172         v = (v << 1) | 0x01;
00173     }
00174         //v <<= bit1;
00175     for(int b2=0; b2 < bit1; b2++)
00176     {
00177         v = (v << 1);
00178     }   
00179     return (x & v);
00180 }
00181 template<class T> T LSHR(T x, int num)
00182 {
00183     char sign = (GetBit(x,sizeof(T)*8-1));
00184     T v = IsolateBits(x, 0, sizeof(T)*8-1);
00185     v >>= num;
00186     if(sign==1) 
00187     {
00188         v |= (((T)0x1) << (sizeof(T)*8-1));
00189     }
00190     return v;
00191 }
00192 
00193 template<class T> T GetIsolatedBits(T x, int bit1, int bit2)
00194 {
00195     T r = IsolateBits(x,bit1,bit2);
00196     return ((T)(LSHR(r, bit1)));
00197 }
00198 
00199 
00200 
00201 class BitStreamIn
00202 {
00203 public:
00204     BitStreamIn(std::istream *i, int off=0) :
00205       in(i), offset(off) {}
00206     ~BitStreamIn()
00207     {
00208         Align();
00209     }
00210     //TODO Add Exception handling for nbits > bitsizeof()
00211     template <class T> void Read(T &r, int nbits)
00212     {
00213         if (nbits == 0) return;
00214                 std::vector<int> tmp;
00215 
00216         int count   = 0;
00217         int read     = 0-offset;
00218         int to_go    = nbits;
00219         int last;
00220         do
00221         {       
00222             last = in->get();
00223             tmp.push_back(last);
00224             read += 8;
00225             count++;
00226         } while(read < to_go);
00227         
00228         
00229         UDWORD bits=0;
00230 
00231         int bitsleft = (count*8)-(offset+nbits);
00232         int bitsright = (count*8)-offset;
00233         
00234         int count2 = 0;
00235         for(std::vector<int>::iterator i = tmp.begin(); i != tmp.end(); i++)
00236         {
00237 
00238             count2++;
00239             int shift = 8*(count-(count2));
00240 
00241             int b1 = max(bitsleft-shift,0);
00242             int b2 = min(bitsright-shift,8);
00243             
00244             int c = GetIsolatedBits(*i, b1, b2);
00245             
00246             bits = bits << (b2-b1);
00247             bits |= (T)(c & 0xff);
00248             
00249         }
00250         offset = (offset+nbits)%8;
00251         
00252         if(offset != 0)
00253         {       
00254             in->putback(last);      
00255         }
00256         r = (T)bits;
00257     }
00258     
00259     void Align() { if(offset != 0) in->get(); }
00260         std::istream &GetStream() { return *in; }
00261 private:
00262     std::istream *in;
00263     int offset;
00264 };
00265 
00266 class BitStreamOut
00267 {
00268 
00269 public:
00270     
00271 
00272     BitStreamOut(std::ostream *o) :
00273       out (o), displace(0), curchar(0), remaining(false){ }
00274     ~BitStreamOut() 
00275     { 
00276         if(remaining) (*out).put(curchar); 
00277     }
00278     
00279     std::ostream *out;
00280 public:
00281     template <class T>
00282     void Write(T data, int bitsize)
00283     {
00284 
00285         for(int i = 0; i < bitsize; i++)
00286         {           
00287             remaining = true;
00288             int offset = 7-(displace%8);
00289 
00290             unsigned char val = GetBit(data, (bitsize)-1-i);        
00291             unsigned char set = 0x01 << (offset);
00292 
00293             curchar = (curchar & ~set) | (val << (offset));
00294             displace++;         
00295             
00296             offset = 7-(displace%8);
00297             if(offset%8==7)
00298             {
00299                 (*out).put((char)curchar);
00300                 curchar=0;
00301                 remaining=false;
00302                 displace=0;
00303             }
00304 
00305         }
00306 
00307     }
00308     void Align()
00309     {
00310         int offset = 7-(displace%8);
00311         displace+=offset;
00312         (*out).put((char)curchar);
00313         curchar=0;      
00314         remaining=false;
00315         displace=0;
00316     }
00317     
00318 private:
00319     int displace;
00320     char curchar;
00321     bool remaining; 
00322 };
00323 
00324 template<class T> BitStreamOut &operator<< (BitStreamOut &o, const T t)
00325 {
00326     o.Write(t,sizeof(T)*8);
00327 }
00328 
00329 class BitBuffer
00330 {
00331 public:
00332     BitBuffer() : displace(0) {}
00333     ~BitBuffer() {}
00334 
00335     void WriteBytes(char *c, int numbytes)
00336     {
00337         for(int i=0; i < numbytes; i++)
00338         {
00339             Write(c[i],8);
00340         }
00341     }
00342     void Write(UDWORD data, int bitsize)
00343     {
00344         for(int i = 0; i < bitsize; i++)
00345         {
00346             int pos    = displace/8;
00347             int offset = 7-(displace%8);
00348 
00349             if(offset==7)
00350             {
00351                 v.push_back(0);
00352             }
00353             unsigned char val = GetBit(data, (bitsize)-1-i);        
00354             unsigned char set = 0x01 << (offset);
00355 
00356             v[pos] = (v[pos] & ~set) | (val << (offset));
00357             displace++;         
00358         }
00359     }
00360     void Align()
00361     {
00362         int offset = 8-(displace%8);
00363 
00364         displace+=offset;
00365     }
00366 
00367 private:
00368     long displace;
00369     std::vector<char> v;
00370     
00371     friend BitStreamOut &operator<< (BitStreamOut &out, BitBuffer &data);
00372     friend std::ostream &operator<< (std::ostream &out, BitBuffer &data);
00373     friend std::istream &operator>> (std::istream &in,  BitBuffer &data);
00374 };
00375 
00376 class FlashFixed
00377 {
00378 //private:
00379 public:
00380     SWORD upperval;
00381     UWORD lowerval;
00382 public: 
00383     FlashFixed(void); 
00384     FlashFixed(SWORD u, UWORD l); 
00385     FlashFixed(double f); 
00386 
00387     UDWORD ConvertToRaw () const
00388     {
00389         UDWORD r = ((SDWORD)upperval)<<16;
00390         r |= lowerval;
00391         return r;
00392     }
00393     void GetFromRaw(SDWORD raw)
00394     {
00395         upperval = raw >> 16;
00396         lowerval = (raw & 0xffff);
00397     }
00398     double ConvertToDouble() const
00399     {
00400         return upperval + double(lowerval) / 0x10000;
00401     }
00402     void GetFromDouble(double x)
00403     {
00404         upperval = (UWORD)floor(x);
00405         lowerval = (UWORD)((x-floor(x))*0x10000);
00406     }
00407     
00408     friend std::ostream &operator<< (std::ostream &out, const FlashFixed &data);
00409     friend std::istream &operator>> (std::istream &in,  FlashFixed &data);
00410 
00411 };
00412 
00413 class FlashFixed16
00414 {
00415 //private
00416 public:
00417     SBYTE upperval;
00418     UBYTE lowerval;
00419 public: 
00420     FlashFixed16(void); 
00421     FlashFixed16(SBYTE u, UBYTE l); 
00422     FlashFixed16(double f); 
00423     
00424     UWORD ConvertToRaw() const
00425     {
00426         UWORD r = ((SWORD)upperval)<<8;
00427         r |= lowerval;
00428         return r;
00429     }
00430     void GetFromRaw(SWORD raw)
00431     {
00432         upperval = raw >> 8;
00433         lowerval = (raw & 0xff);
00434     }
00435     double ConvertToDouble()
00436     {
00437         return upperval + double(lowerval) / 0x100;
00438     }
00439     void GetFromDouble(double x)
00440     {
00441         upperval = (UBYTE)floor(x);
00442         lowerval = (UBYTE)((x-floor(x))*0x100);
00443     }
00444     
00445     friend std::ostream &operator<< (std::ostream &out, const FlashFixed16 &data);
00446     friend std::istream &operator>> (std::istream &in,  FlashFixed16 &data);    
00447 };
00448 
00449 class FlashMatrix
00450 {
00451 public:
00452     FlashMatrix() : scale(false), scalex(0), scaley(0),
00453                   rotate(false), rotatex(0), rotatey(0),
00454                   translatex(0), translatey(0)
00455     {
00456     }
00457     FlashMatrix(bool _scale, FlashFixed _scalex, FlashFixed _scaley,
00458                 bool _rotate, FlashFixed _rotatex, FlashFixed _rotatey,
00459                 SWORD _translatex, SWORD _translatey)
00460                 : scale(_scale), scalex(_scalex), scaley(_scaley),
00461                   rotate(_rotate), rotatex(_rotatex), rotatey(_rotatey),
00462                   translatex(_translatex), translatey(_translatey)
00463     {
00464     }
00465     
00466     void SetScale(FlashFixed _scalex, FlashFixed _scaley) { scalex=_scalex; scaley=_scaley; scale=true;}
00467     void SetRotate(FlashFixed _rotatex, FlashFixed _rotatey) { rotatex=_rotatex; rotatey=_rotatey; rotate = true;}
00468     void SetTranslate(SWORD _translatex, SWORD _translatey) { translatex=_translatex; translatey=_translatey;}
00469 
00470     bool HasScale() const { return scale; }
00471     bool HasRotate() const { return rotate; }
00472 
00473     FlashFixed GetRotateX() const { return rotatex; }
00474     FlashFixed GetRotateY() const { return rotatey; }
00475 
00476     FlashFixed GetScaleX() const { return scalex; }
00477     FlashFixed GetScaleY() const { return scaley; }
00478 
00479     FlashFixed GetTranslateX() const { return translatex; }
00480     FlashFixed GetTranslateY() const { return translatey; }
00481 
00482 private:
00483     bool scale;
00484     FlashFixed scalex;
00485     FlashFixed scaley;
00486     bool rotate;
00487     FlashFixed rotatex;
00488     FlashFixed rotatey;
00489     SWORD translatex;
00490     SWORD translatey;
00491 
00492     friend std::ostream &operator<< (std::ostream &out, const FlashMatrix &data);
00493     friend std::istream &operator>> (std::istream &in,  FlashMatrix &data);
00494 };
00495 
00496 class FlashMatrixScale : public FlashMatrix
00497 {
00498     FlashMatrixScale(FlashFixed _scalex, FlashFixed _scaley) : 
00499         FlashMatrix(true, _scalex, _scaley, false, 0, 0, 0, 0)
00500     {
00501         
00502     }       
00503 };
00504 
00505 class FlashMatrixRotate : public FlashMatrix
00506 {
00507     FlashMatrixRotate(FlashFixed _rotatex, FlashFixed _rotatey) : 
00508         FlashMatrix(false, 0, 0, true, _rotatex, _rotatey, 0, 0)
00509     {
00510         
00511     }       
00512 };
00513 
00514 class FlashMatrixTranslate : public FlashMatrix
00515 {
00516     FlashMatrixTranslate(SWORD x, SWORD y) : 
00517         FlashMatrix(false, 0, 0, false, 0, 0, x, y)
00518     {
00519         
00520     }       
00521 };
00522 
00523 class FlashRGB
00524 {
00525 public: 
00526     FlashRGB() : r(0), g(0), b(0), a(0xff), alpha(false) { }
00527     FlashRGB(SWORD _r, SWORD _g, SWORD _b) : r(_r), g(_g), b(_b), a(0xff), alpha(false){ }
00528     FlashRGB(SWORD _r, SWORD _g, SWORD _b, SWORD _a) : r(_r), g(_g), b(_b), a(_a), alpha(true){ }
00529 
00530     void Write(BitBuffer &out, int num=-1);
00531     
00532     void Read(BitStreamIn &in, int num=-1);
00533 
00534     bool GetAlphaWriteMode(void)   { return (alpha); }
00535     void SetAlphaWriteMode(bool a) { alpha=a; }
00536 
00537     int GetNumBits() 
00538     { 
00539         if(alpha) return max(max(GetBitSizeSigned(a),GetBitSizeSigned(b)),max(GetBitSizeSigned(r),GetBitSizeSigned(g)));
00540         return max(GetBitSizeSigned(b),max(GetBitSizeSigned(r),GetBitSizeSigned(g)));
00541     }
00542     
00543     SWORD GetR() { return r; }
00544     SWORD GetG() { return g; }
00545     SWORD GetB() { return b; }
00546     SWORD GetA() { return a; }
00547     void SetR(SWORD _r) {r = _r; }
00548     void SetG(SWORD _g) {g = _g; }
00549     void SetB(SWORD _b) {b = _b; }
00550     void SetA(SWORD _a) {a = _a; }
00551     void SetRGBA(SWORD _r, SWORD _g, SWORD _b, SWORD _a)
00552     {
00553         r = _r;
00554         g = _g;
00555         b = _b;
00556         a = _a;
00557     }
00558     void SetRGB(SWORD _r, SWORD _g, SWORD _b)
00559     {
00560         r = _r;
00561         g = _g;
00562         b = _b;
00563     }
00564 
00565 private:    
00566     bool alpha;
00567 
00568     SWORD r;
00569     SWORD g;
00570     SWORD b;
00571     SWORD a;
00572 
00573     friend std::ostream &operator<< (std::ostream &out, const FlashRGB &data);
00574     friend std::istream &operator>> (std::istream &in,  FlashRGB &data);
00575 };
00576 
00577 class FlashColorTransform : public FlashVersionEnabled
00578 {
00579 public:
00580         FlashColorTransform() : add(false), mult(false){}
00581         
00582         FlashColorTransform(bool _add, FlashRGB& _addFlashRGB, bool _mult, FlashRGB& _multFlashRGB)
00583                 : add(_add), mult(_mult), addFlashRGB(_addFlashRGB), multFlashRGB(_multFlashRGB){}
00584             
00585     friend std::ostream& operator<<(std::ostream& out, FlashColorTransform &data);
00586     friend std::istream& operator>>(std::istream& in, FlashColorTransform &data);
00587 
00588     bool HasAdd() const { return add; }
00589     bool HasMult() const { return mult; }
00590     
00591     FlashRGB GetAddRGB() const { return addFlashRGB; }
00592     FlashRGB GetMultRGB() const { return multFlashRGB; }
00593 
00594         void SetAddRGB(FlashRGB _addFlashRGB) 
00595         {
00596                 addFlashRGB = _addFlashRGB;
00597                 add = true;
00598         }
00599         void SetMultRGB(FlashRGB _multFlashRGB) 
00600         {
00601                 multFlashRGB = _multFlashRGB;
00602                 mult = true;
00603         }
00604 
00605         void SetAdd(short _addFlashR, short _addFlashG, short _addFlashB) 
00606         {
00607                 addFlashRGB = FlashRGB(_addFlashR, _addFlashG, _addFlashB);
00608                 add = true;
00609         }
00610         void SetMult(FlashFixed16 _multFlashR, FlashFixed16 _multFlashG, FlashFixed16 _multFlashB) 
00611         {
00612                 multFlashRGB = FlashRGB(_multFlashR.ConvertToRaw(), _multFlashG.ConvertToRaw(), _multFlashB.ConvertToRaw());
00613                 mult = true;
00614         }
00615 
00616 private:
00617     bool add;
00618     bool mult;
00619     FlashRGB addFlashRGB;
00620     FlashRGB multFlashRGB;
00621 };
00622 
00623 class FlashRect
00624 {
00625 public:
00626     FlashRect(int _x1, int _y1, int _x2, int _y2) : 
00627       x1(_x1), y1(_y1), x2(_x2), y2(_y2), defined(true) {}
00628     
00629     FlashRect() : x1(0), y1(0), x2(0), y2(0), defined(false) {}
00630     
00631     ~FlashRect() {}
00632 
00633     bool IsDefined() { return(defined); }
00634     
00635     void SetRect(int _x1, int _y1, int _x2, int _y2)
00636     {
00637       x1 = _x1;
00638       y1 = _y1;
00639       x2 = _x2;
00640       y2 = _y2;
00641     }
00642     
00643     SWORD GetX1() const { return x1; }
00644     SWORD GetX2() const { return x2; }
00645     SWORD GetY1() const { return y1; }
00646     SWORD GetY2() const { return y2; }
00647 
00648     void BoundWith(const FlashRect &r) { x1 = min(x1,r.x1); x2 = max(x2, r.x2); y1 = min(y1,r.y1); y2 = max(y2, r.y2); };
00649 private:
00650     int x1; 
00651     int y1;
00652     int x2;
00653     int y2;
00654     bool defined;
00655 
00656     friend std::ostream &operator<< (std::ostream &out, const FlashRect &data);
00657     friend std::istream &operator>> (std::istream &in,  FlashRect &data);
00658 };
00659 
00660 
00661 class FlashHeader
00662 {
00663 public:
00664     FlashHeader(UBYTE _version, UDWORD _filesize, int width, int height, UWORD _framerate, UWORD _framecount);
00665     FlashHeader(UBYTE _version, UDWORD _filesize, int width, int height, double _framerate, UWORD _framecount);
00666 
00667     ~FlashHeader() {}
00668 
00669     UBYTE  GetVersion(void) { return version; }
00670     UDWORD GetFilesize(void) { return filesize; }
00671     FlashRect GetScreenSize(void) { return size; }
00672     FlashFixed16 GetFrameRate(void) { return frameRate; }
00673     UWORD GetFrameCount(void) { return frameCount; }
00674 
00675 private:
00676     
00677     friend std::ostream &operator << (std::ostream &out, const FlashHeader &data);
00678     friend std::istream &operator >> (std::istream &in,  FlashHeader &data);
00679 
00680     UBYTE  version;
00681     UDWORD filesize;
00682     FlashRect size;
00683     FlashFixed16 frameRate;
00684     UWORD frameCount;
00685 protected:
00686     FlashHeader() {};
00687     friend class FlashImporter;
00688 
00689 };
00690 
00691 class FlashTagHeader
00692 {
00693 DEFINE_RW_INTERFACE
00694 public:
00695     FlashTagHeader(UWORD _tagID, UDWORD _length) : tagID(_tagID), length(_length) {}
00696     ~FlashTagHeader(void) {}
00697 
00698     UWORD GetTagID(void) { return tagID; }
00699     UDWORD GetTagLength(void) { return length; }
00700 
00701 private:
00702     UWORD  tagID;
00703     UDWORD length;
00704 
00705     friend std::ostream &operator << (std::ostream &out, const FlashTagHeader &data);
00706     friend std::istream &operator >> (std::istream &in,  FlashTagHeader &data);
00707 protected:
00708     FlashTagHeader() {}
00709     friend class FlashImporter;
00710 };
00711 
00712 
00713 class FlashTag
00714 {
00715 DEFINE_RW_INTERFACE
00716 public:
00717     FlashTag() {}
00718     ~FlashTag() {}
00719 
00720     void SetImportSize(UDWORD i) { importsize = i; }    
00721 protected:
00722     UDWORD importsize;
00723 private:        
00724         friend std::ostream &operator << (std::ostream &out, const FlashTag &data);
00725     friend std::istream &operator >> (std::istream &in,  FlashTag &data);
00726 };
00727 
00728 class FlashSpriteEnabled : public FlashTag
00729 {
00730 public:
00731     FlashSpriteEnabled() {}
00732     ~FlashSpriteEnabled() {}
00733         virtual bool isFrame() { return false; }
00734 
00735 };
00736 
00737 class FlashIDFactory
00738 {
00739 public: 
00740     FlashIDFactory() {};
00741 
00742     UWORD GetCharacterID() 
00743     { 
00744         UWORD _IDCharacter = IDCharacter; 
00745         IDCharacter++; 
00746         return (_IDCharacter); 
00747     }
00748     static void ResetCount()
00749     {
00750         IDCharacter=0;
00751     }
00752 private:    
00753     static UWORD IDCharacter;
00754 };
00755 
00756 class FlashIDEnabled
00757 {
00758 public:
00759     FlashIDEnabled(bool count=true) { if(count) charID = idFactory.GetCharacterID(); }
00760     
00761     void SetID(UWORD i) { charID=i; }
00762     UWORD GetID(void) const { return (charID); }
00763 private:
00764     FlashIDFactory idFactory;
00765     UWORD charID;
00766 };
00767 
00768 #define DEFINE_SIMPLE_TAG(x, n) \
00769 std::ostream &operator << (std::ostream &out, const x &data) \
00770 { \
00771     return (out << FlashTagHeader(n,0)); \
00772 } \
00773 std::istream &operator >> (std::istream &in,  x &data) \
00774 { \
00775     return in; \
00776 }
00777 
00778 #define DECLARE_SIMPLE_TAG(x) \
00779 class x : public FlashTag \
00780 {                               \
00781         DEFINE_RW_INTERFACE                     \
00782 public:                         \
00783     x() {} \
00784     ~x() {} \
00785     friend std::ostream &operator << (std::ostream &out, const x &data); \
00786     friend std::istream &operator >> (std::istream &in,  x &data); \
00787 };
00788 
00789 #define DECLARE_SIMPLE_TAG2(x) \
00790 class x : public FlashSpriteEnabled \
00791 {                               \
00792         DEFINE_RW_INTERFACE                     \
00793 public:                         \
00794     x() {} \
00795     ~x() {} \
00796     friend std::ostream &operator << (std::ostream &out, const x &data); \
00797     friend std::istream &operator >> (std::istream &in,  x &data); \
00798 };
00799 
00800 #define DECLARE_SIMPLE_TAG3(x) \
00801 class x : public FlashSpriteEnabled \
00802 {                               \
00803         DEFINE_RW_INTERFACE                     \
00804 public:                         \
00805     x() {} \
00806     ~x() {} \
00807         virtual bool isFrame() { return true; }\
00808     friend std::ostream &operator << (std::ostream &out, const x &data); \
00809     friend std::istream &operator >> (std::istream &in,  x &data); \
00810 };
00811 
00812 template<class T> class gc_vector: public std::vector<T>
00813 {
00814 public: 
00815         gc_vector() {}
00816         gc_vector(const gc_vector &c) {}
00817         ~gc_vector() { for(std::vector<T>::iterator i = begin(); i != end(); i++) { delete *i; }}
00818 };
00819 
00820 FlashMatrix CreateMatrix(FlashRect bounds,float scaleX,float scaleY,float rotation,float translateX,float translateY,bool bScale, bool bRotate);
00821 
00822 #endif

Generated at Wed Aug 1 13:33:50 2001 for SWFSource by doxygen1.2.9 written by Dimitri van Heesch, © 1997-2001