Advertisement
Guest User

Untitled

a guest
Jul 5th, 2012
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 18.74 KB | None | 0 0
  1. #ifndef __SERIALIZATOR__
  2. #define __SERIALIZATOR__
  3.  
  4. #pragma bindfunc "int FloatToInt(float) -> Utils.dll FloatToInt"
  5. #pragma bindfunc "float IntToFloat(int) -> Utils.dll IntToFloat"
  6.  
  7. // Class data serializator
  8. // AnyData wrapper
  9. // Big Endian
  10. // Author: cvet
  11.  
  12. /*class Serializator
  13. {
  14.     Serializator();
  15.     Serializator(uint approxSize);
  16.     void GrowBuffer();
  17.     void GrowBuffer(uint length);
  18.     bool Save(string& name);
  19.     bool Load(string& name);
  20.     void Clear();
  21.     void SetCurPos(uint pos);
  22.     Serializator@ Fill(uint8 value, uint length);
  23.     Serializator@ Set(const int64& value);
  24.     Serializator@ Set(const int32& value);
  25.     Serializator@ Set(const int16& value);
  26.     Serializator@ Set(const int8& value);
  27.     Serializator@ Set(const uint64& value);
  28.     Serializator@ Set(const uint32& value);
  29.     Serializator@ Set(const uint16& value);
  30.     Serializator@ Set(const uint8& value);
  31.     Serializator@ Set(const bool& value);
  32.     Serializator@ Set(const string& value);
  33.     Serializator@ Set(const float& value);
  34.     Serializator@ Set(const int64[]& values);
  35.     Serializator@ Set(const int32[]& values);
  36.     Serializator@ Set(const int16[]& values);
  37.     Serializator@ Set(const int8[]& values);
  38.     Serializator@ Set(const uint64[]& values);
  39.     Serializator@ Set(const uint32[]& values);
  40.     Serializator@ Set(const uint16[]& values);
  41.     Serializator@ Set(const uint8[]& values);
  42.     Serializator@ Set(const bool[]& values);
  43.     Serializator@ Set(const string[]& values);
  44.     Serializator@ Set(const float[]& values);
  45.     Serializator@ Set(const Critter& cr);
  46.     Serializator@ Set(const Item& item);
  47.     Serializator@ Get(int64& value);
  48.     Serializator@ Get(int32& value);
  49.     Serializator@ Get(int16& value);
  50.     Serializator@ Get(int8& value);
  51.     Serializator@ Get(uint64& value);
  52.     Serializator@ Get(uint32& value);
  53.     Serializator@ Get(uint16& value);
  54.     Serializator@ Get(uint8& value);
  55.     Serializator@ Get(bool& value);
  56.     Serializator@ Get(string& value);
  57.     Serializator@ Get(float& value);
  58.     Serializator@ Get(int64[]& values);
  59.     Serializator@ Get(int32[]& values);
  60.     Serializator@ Get(int16[]& values);
  61.     Serializator@ Get(int8[]& values);
  62.     Serializator@ Get(uint64[]& values);
  63.     Serializator@ Get(uint32[]& values);
  64.     Serializator@ Get(uint16[]& values);
  65.     Serializator@ Get(uint8[]& values);
  66.     Serializator@ Get(bool[]& value);
  67.     Serializator@ Get(string[]& value);
  68.     Serializator@ Get(float[]& values);
  69.     Serializator@ Get(Critter@& value);
  70.     Serializator@ Get(Item@& value);
  71. }*/
  72.  
  73. #define DEFAULT_GROW         (128)
  74.  
  75. shared class Serializator
  76. {
  77.     Serializator()
  78.     {
  79.         CurPos=0;
  80.         BufSize=0;
  81.         DataSize=0;
  82.     }
  83.  
  84.     Serializator(uint approxSize)
  85.     {
  86.         CurPos=0;
  87.         BufSize=0;
  88.         DataSize=0;
  89.         GrowBuffer(approxSize);
  90.     }
  91.  
  92.     void GrowBuffer()
  93.     {
  94.         BufSize+=DEFAULT_GROW;
  95.         Array.resize(BufSize);
  96.     }
  97.  
  98.     void GrowBuffer(uint length)
  99.     {
  100.         BufSize+=length;
  101.         Array.resize(BufSize);
  102.     }
  103.  
  104.     bool Save(string& name)
  105.     {
  106.         if(DataSize==0) return false;
  107.         bool result=SetAnyData(name,Array,DataSize);
  108.         Clear();
  109.         return result;
  110.     }
  111.  
  112.     bool Load(string& name)
  113.     {
  114.         Clear();
  115.         if (!IsAnyData(name)) return false;
  116.         if(!GetAnyData(name,Array)) return false;
  117.         BufSize=Array.length();
  118.         DataSize=BufSize;
  119.         return true;
  120.     }
  121.  
  122.     void Clear()
  123.     {
  124.         CurPos=0;
  125.         BufSize=0;
  126.         DataSize=0;
  127.     }
  128.  
  129.     Serializator@ SetCurPos(uint pos)
  130.     {
  131.         if(pos>BufSize) GrowBuffer(pos-BufSize+DEFAULT_GROW);
  132.         CurPos=pos;
  133.         return this;
  134.     }
  135.  
  136.     Serializator@ Fill(uint8 value, uint length)
  137.     {
  138.         if(CurPos+length>BufSize) GrowBuffer(CurPos+length-BufSize+DEFAULT_GROW);
  139.         for(uint i=0;i<length;i++) Array[CurPos++]=value;
  140.         if(CurPos>DataSize) DataSize=CurPos;
  141.         return this;
  142.     }
  143.  
  144.     Serializator@ Set(const int64& value)
  145.     {
  146.         if(CurPos+8>BufSize) GrowBuffer();
  147.         Array[CurPos++]=(value>>56)&0xFF;
  148.         Array[CurPos++]=(value>>48)&0xFF;
  149.         Array[CurPos++]=(value>>40)&0xFF;
  150.         Array[CurPos++]=(value>>32)&0xFF;
  151.         Array[CurPos++]=(value>>24)&0xFF;
  152.         Array[CurPos++]=(value>>16)&0xFF;
  153.         Array[CurPos++]=(value>>8)&0xFF;
  154.         Array[CurPos++]=value&0xFF;
  155.         if(CurPos>DataSize) DataSize=CurPos;
  156.         return this;
  157.     }
  158.  
  159.     Serializator@ opShl(const int64& value)
  160.     {
  161.         return Set(value);
  162.     }
  163.  
  164.     Serializator@ Set(const int32& value)
  165.     {
  166.         if(CurPos+4>BufSize) GrowBuffer();
  167.         Array[CurPos++]=(value>>24)&0xFF;
  168.         Array[CurPos++]=(value>>16)&0xFF;
  169.         Array[CurPos++]=(value>>8)&0xFF;
  170.         Array[CurPos++]=value&0xFF;
  171.         if(CurPos>DataSize) DataSize=CurPos;
  172.         return this;
  173.     }
  174.  
  175.     Serializator@ opShl(const int32& value)
  176.     {
  177.         return Set(value);
  178.     }
  179.  
  180.     Serializator@ Set(const int16& value)
  181.     {
  182.         if(CurPos+2>BufSize) GrowBuffer();
  183.         Array[CurPos++]=(value>>8)&0xFF;
  184.         Array[CurPos++]=value&0xFF;
  185.         if(CurPos>DataSize) DataSize=CurPos;
  186.         return this;
  187.     }
  188.  
  189.     Serializator@ opShl(const int16& value)
  190.     {
  191.         return Set(value);
  192.     }
  193.  
  194.     Serializator@ Set(const int8& value)
  195.     {
  196.         if(CurPos+1>BufSize) GrowBuffer();
  197.         Array[CurPos++]=value;
  198.         if(CurPos>DataSize) DataSize=CurPos;
  199.         return this;
  200.     }
  201.  
  202.     Serializator@ opShl(const int8& value)
  203.     {
  204.         return Set(value);
  205.     }
  206.  
  207.     Serializator@ Set(const uint64& value)
  208.     {
  209.         if(CurPos+8>BufSize) GrowBuffer();
  210.         Array[CurPos++]=(value>>56)&0xFF;
  211.         Array[CurPos++]=(value>>48)&0xFF;
  212.         Array[CurPos++]=(value>>40)&0xFF;
  213.         Array[CurPos++]=(value>>32)&0xFF;
  214.         Array[CurPos++]=(value>>24)&0xFF;
  215.         Array[CurPos++]=(value>>16)&0xFF;
  216.         Array[CurPos++]=(value>>8)&0xFF;
  217.         Array[CurPos++]=value&0xFF;
  218.         if(CurPos>DataSize) DataSize=CurPos;
  219.         return this;
  220.     }
  221.  
  222.     Serializator@ opShl(const uint64& value)
  223.     {
  224.         return Set(value);
  225.     }
  226.  
  227.     Serializator@ Set(const uint32& value)
  228.     {
  229.         if(CurPos+4>BufSize) GrowBuffer();
  230.         Array[CurPos++]=(value>>24)&0xFF;
  231.         Array[CurPos++]=(value>>16)&0xFF;
  232.         Array[CurPos++]=(value>>8)&0xFF;
  233.         Array[CurPos++]=value&0xFF;
  234.         if(CurPos>DataSize) DataSize=CurPos;
  235.         return this;
  236.     }
  237.  
  238.     Serializator@ opShl(const uint32& value)
  239.     {
  240.         return Set(value);
  241.     }
  242.  
  243.     Serializator@ Set(const uint16& value)
  244.     {
  245.         if(CurPos+2>BufSize) GrowBuffer();
  246.         Array[CurPos++]=(value>>8)&0xFF;
  247.         Array[CurPos++]=value&0xFF;
  248.         if(CurPos>DataSize) DataSize=CurPos;
  249.         return this;
  250.     }
  251.  
  252.     Serializator@ opShl(const uint16& value)
  253.     {
  254.         return Set(value);
  255.     }
  256.  
  257.     Serializator@ Set(const uint8& value)
  258.     {
  259.         if(CurPos+1>BufSize) GrowBuffer();
  260.         Array[CurPos++]=value;
  261.         if(CurPos>DataSize) DataSize=CurPos;
  262.         return this;
  263.     }
  264.  
  265.     Serializator@ opShl(const uint8& value)
  266.     {
  267.         return Set(value);
  268.     }
  269.  
  270.     Serializator@ Set(const bool& value)
  271.     {
  272.         if(CurPos+1>BufSize) GrowBuffer();
  273.         Array[CurPos++]=value?1:0;
  274.         if(CurPos>DataSize) DataSize=CurPos;
  275.         return this;
  276.     }
  277.  
  278.     Serializator@ opShl(const bool& value)
  279.     {
  280.         return Set(value);
  281.     }
  282.  
  283.     Serializator@ Set(const string& value)
  284.     {
  285.         uint len=value.length();
  286.         if(CurPos+len+1>BufSize) GrowBuffer(CurPos+len+1-BufSize+DEFAULT_GROW);
  287.         for(uint i=0;i<len;i++) Array[CurPos++]=value[i];
  288.         Array[CurPos++]=0;
  289.         if(CurPos>DataSize) DataSize=CurPos;
  290.         return this;
  291.     }
  292.  
  293.     Serializator@ opShl(const string& value)
  294.     {
  295.         return Set(value);
  296.     }
  297.  
  298.     Serializator@ Set(const float& value)
  299.     {
  300.         int dummy=FloatToInt(value);
  301.         return Set(dummy);
  302.     }
  303.  
  304.     Serializator@ opShl(const float& value)
  305.     {
  306.         return Set(value);
  307.     }
  308.  
  309.     Serializator@ Set(const array<int64>& values)
  310.     {
  311.         uint valuesLen=values.length();
  312.         uint len=4+valuesLen*8;
  313.         if(CurPos+len>BufSize) GrowBuffer(CurPos+len-BufSize);
  314.         Set(valuesLen);
  315.         for(uint i=0,j=valuesLen;i<j;i++) Set(values[i]);
  316.         if(CurPos>DataSize) DataSize=CurPos;
  317.         return this;
  318.     }
  319.  
  320.     Serializator@ opShl(const array<int64>& values)
  321.     {
  322.         return Set(values);
  323.     }
  324.  
  325.     Serializator@ Set(const array<int32>& values)
  326.     {
  327.         uint valuesLen=values.length();
  328.         uint len=4+valuesLen*4;
  329.         if(CurPos+len>BufSize) GrowBuffer(CurPos+len-BufSize);
  330.         Set(valuesLen);
  331.         for(uint i=0,j=valuesLen;i<j;i++) Set(values[i]);
  332.         if(CurPos>DataSize) DataSize=CurPos;
  333.         return this;
  334.     }
  335.  
  336.     Serializator@ opShl(const array<int32>& values)
  337.     {
  338.         return Set(values);
  339.     }
  340.  
  341.     Serializator@ Set(const array<int16>& values)
  342.     {
  343.         uint valuesLen=values.length();
  344.         uint len=4+valuesLen*2;
  345.         if(CurPos+len>BufSize) GrowBuffer(CurPos+len-BufSize);
  346.         Set(valuesLen);
  347.         for(uint i=0,j=valuesLen;i<j;i++) Set(values[i]);
  348.         if(CurPos>DataSize) DataSize=CurPos;
  349.         return this;
  350.     }
  351.  
  352.     Serializator@ opShl(const array<int16>& values)
  353.     {
  354.         return Set(values);
  355.     }
  356.  
  357.     Serializator@ Set(const array<int8>& values)
  358.     {
  359.         uint valuesLen=values.length();
  360.         uint len=4+valuesLen;
  361.         if(CurPos+len>BufSize) GrowBuffer(CurPos+len-BufSize);
  362.         Set(valuesLen);
  363.         for(uint i=0,j=valuesLen;i<j;i++) Set(values[i]);
  364.         if(CurPos>DataSize) DataSize=CurPos;
  365.         return this;
  366.     }
  367.  
  368.     Serializator@ opShl(const array<int8>& values)
  369.     {
  370.         return Set(values);
  371.     }
  372.  
  373.     Serializator@ Set(const array<uint64>& values)
  374.     {
  375.         uint valuesLen=values.length();
  376.         uint len=4+valuesLen*8;
  377.         if(CurPos+len>BufSize) GrowBuffer(CurPos+len-BufSize);
  378.         Set(valuesLen);
  379.         for(uint i=0,j=valuesLen;i<j;i++) Set(values[i]);
  380.         if(CurPos>DataSize) DataSize=CurPos;
  381.         return this;
  382.     }
  383.  
  384.     Serializator@ opShl(const array<uint64>& values)
  385.     {
  386.         return Set(values);
  387.     }
  388.  
  389.     Serializator@ Set(const array<uint32>& values)
  390.     {
  391.         uint valuesLen=values.length();
  392.         uint len=4+valuesLen*4;
  393.         if(CurPos+len>BufSize) GrowBuffer(CurPos+len-BufSize);
  394.         Set(valuesLen);
  395.         for(uint i=0,j=valuesLen;i<j;i++) Set(values[i]);
  396.         if(CurPos>DataSize) DataSize=CurPos;
  397.         return this;
  398.     }
  399.  
  400.     Serializator@ opShl(const array<uint32>& values)
  401.     {
  402.         return Set(values);
  403.     }
  404.  
  405.     Serializator@ Set(const array<uint16>& values)
  406.     {
  407.         uint valuesLen=values.length();
  408.         uint len=4+valuesLen*2;
  409.         if(CurPos+len>BufSize) GrowBuffer(CurPos+len-BufSize);
  410.         Set(valuesLen);
  411.         for(uint i=0,j=valuesLen;i<j;i++) Set(values[i]);
  412.         if(CurPos>DataSize) DataSize=CurPos;
  413.         return this;
  414.     }
  415.  
  416.     Serializator@ opShl(const array<uint16>& values)
  417.     {
  418.         return Set(values);
  419.     }
  420.  
  421.     Serializator@ Set(const array<uint8>& values)
  422.     {
  423.         uint valuesLen=values.length();
  424.         uint len=4+valuesLen;
  425.         if(CurPos+len>BufSize) GrowBuffer(CurPos+len-BufSize);
  426.         Set(valuesLen);
  427.         for(uint i=0,j=valuesLen;i<j;i++) Set(values[i]);
  428.         if(CurPos>DataSize) DataSize=CurPos;
  429.         return this;
  430.     }
  431.  
  432.     Serializator@ opShl(const array<uint8>& values)
  433.     {
  434.         return Set(values);
  435.     }
  436.  
  437.     Serializator@ Set(const array<bool>& values)
  438.     {
  439.         uint valuesLen=values.length();
  440.         uint len=4+valuesLen;
  441.         if(CurPos+len>BufSize) GrowBuffer(CurPos+len-BufSize);
  442.         Set(valuesLen);
  443.         for(uint i=0,j=valuesLen;i<j;i++) Set(values[i]);
  444.         if(CurPos>DataSize) DataSize=CurPos;
  445.         return this;
  446.     }
  447.  
  448.     Serializator@ opShl(const array<bool>& values)
  449.     {
  450.         return Set(values);
  451.     }
  452.  
  453.     Serializator@ Set(const array<string>& values)
  454.     {
  455.         uint valuesLen=values.length();
  456.         uint len=4+valuesLen; // Length and zeros
  457.         for(uint i=0,j=valuesLen;i<j;i++) len+=values[i].length();
  458.         if(CurPos+len>BufSize) GrowBuffer(CurPos+len-BufSize);
  459.         Set(valuesLen);
  460.         for(uint i=0,j=valuesLen;i<j;i++) Set(values[i]);
  461.         if(CurPos>DataSize) DataSize=CurPos;
  462.         return this;
  463.     }
  464.  
  465.     Serializator@ opShl(const array<string>& values)
  466.     {
  467.         return Set(values);
  468.     }
  469.  
  470.     Serializator@ Set(const array<float>& values)
  471.     {
  472.         uint valuesLen=values.length();
  473.         uint len=4+valuesLen*4;
  474.         if(CurPos+len>BufSize) GrowBuffer(CurPos+len-BufSize);
  475.         Set(valuesLen);
  476.         for(uint i=0,j=valuesLen;i<j;i++) Set(FloatToInt(values[i]));
  477.         if(CurPos>DataSize) DataSize=CurPos;
  478.         return this;
  479.     }
  480.  
  481.     Serializator@ opShl(const array<float>& values)
  482.     {
  483.         return Set(values);
  484.     }
  485.  
  486.     Serializator@ Set(const Critter& cr)
  487.     {
  488.         if(CurPos+4>BufSize) GrowBuffer();
  489.         uint value=cr.Id;
  490.         Array[CurPos++]=(value>>24)&0xFF;
  491.         Array[CurPos++]=(value>>16)&0xFF;
  492.         Array[CurPos++]=(value>>8)&0xFF;
  493.         Array[CurPos++]=value&0xFF;
  494.         if(CurPos>DataSize) DataSize=CurPos;
  495.         return this;
  496.     }
  497.  
  498.     Serializator@ opShl(const Critter& cr)
  499.     {
  500.         return Set(cr);
  501.     }
  502.  
  503.     Serializator@ Set(const Item& item)
  504.     {
  505.         if(CurPos+4>BufSize) GrowBuffer();
  506.         uint value=item.Id;
  507.         Array[CurPos++]=(value>>24)&0xFF;
  508.         Array[CurPos++]=(value>>16)&0xFF;
  509.         Array[CurPos++]=(value>>8)&0xFF;
  510.         Array[CurPos++]=value&0xFF;
  511.         if(CurPos>DataSize) DataSize=CurPos;
  512.         return this;
  513.     }
  514.  
  515.     Serializator@ opShl(const Item& item)
  516.     {
  517.         return Set(item);
  518.     }
  519.  
  520.     Serializator@ Get(int64& value)
  521.     {
  522.         value=0;
  523.         if(CurPos+8>DataSize) return this;
  524.         value|=Array[CurPos++]<<56;
  525.         value|=Array[CurPos++]<<48;
  526.         value|=Array[CurPos++]<<40;
  527.         value|=Array[CurPos++]<<32;
  528.         value|=Array[CurPos++]<<24;
  529.         value|=Array[CurPos++]<<16;
  530.         value|=Array[CurPos++]<<8;
  531.         value|=Array[CurPos++];
  532.         return this;
  533.     }
  534.  
  535.     Serializator@ opShr(int64& value)
  536.     {
  537.         return Get(value);
  538.     }
  539.  
  540.     Serializator@ Get(int32& value)
  541.     {
  542.         value=0;
  543.         if(CurPos+4>DataSize) return this;
  544.         value|=Array[CurPos++]<<24;
  545.         value|=Array[CurPos++]<<16;
  546.         value|=Array[CurPos++]<<8;
  547.         value|=Array[CurPos++];
  548.         return this;
  549.     }
  550.  
  551.     Serializator@ opShr(int32& value)
  552.     {
  553.         return Get(value);
  554.     }
  555.  
  556.     Serializator@ Get(int16& value)
  557.     {
  558.         value=0;
  559.         if(CurPos+2>DataSize) return this;
  560.         value|=Array[CurPos++]<<8;
  561.         value|=Array[CurPos++];
  562.         return this;
  563.     }
  564.  
  565.     Serializator@ opShr(int16& value)
  566.     {
  567.         return Get(value);
  568.     }
  569.  
  570.     Serializator@ Get(int8& value)
  571.     {
  572.         value=0;
  573.         if(CurPos+1>DataSize) return this;
  574.         value=Array[CurPos++];
  575.         return this;
  576.     }
  577.  
  578.     Serializator@ opShr(int8& value)
  579.     {
  580.         return Get(value);
  581.     }
  582.  
  583.     Serializator@ Get(uint64& value)
  584.     {
  585.         value=0;
  586.         if(CurPos+8>DataSize) return this;
  587.         value|=Array[CurPos++]<<56;
  588.         value|=Array[CurPos++]<<48;
  589.         value|=Array[CurPos++]<<40;
  590.         value|=Array[CurPos++]<<32;
  591.         value|=Array[CurPos++]<<24;
  592.         value|=Array[CurPos++]<<16;
  593.         value|=Array[CurPos++]<<8;
  594.         value|=Array[CurPos++];
  595.         return this;
  596.     }
  597.  
  598.     Serializator@ opShr(uint64& value)
  599.     {
  600.         return Get(value);
  601.     }
  602.  
  603.     Serializator@ Get(uint32& value)
  604.     {
  605.         value=0;
  606.         if(CurPos+4>DataSize) return this;
  607.         value|=Array[CurPos++]<<24;
  608.         value|=Array[CurPos++]<<16;
  609.         value|=Array[CurPos++]<<8;
  610.         value|=Array[CurPos++];
  611.         return this;
  612.     }
  613.  
  614.     Serializator@ opShr(uint32& value)
  615.     {
  616.         return Get(value);
  617.     }
  618.  
  619.     Serializator@ Get(uint16& value)
  620.     {
  621.         value=0;
  622.         if(CurPos+2>DataSize) return this;
  623.         value|=Array[CurPos++]<<8;
  624.         value|=Array[CurPos++];
  625.         return this;
  626.     }
  627.  
  628.     Serializator@ opShr(uint16& value)
  629.     {
  630.         return Get(value);
  631.     }
  632.  
  633.     Serializator@ Get(uint8& value)
  634.     {
  635.         value=0;
  636.         if(CurPos+1>DataSize) return this;
  637.         value=Array[CurPos++];
  638.         return this;
  639.     }
  640.  
  641.     Serializator@ opShr(uint8& value)
  642.     {
  643.         return Get(value);
  644.     }
  645.  
  646.     Serializator@ Get(bool& value)
  647.     {
  648.         value=false;
  649.         if(CurPos+1>DataSize) return this;
  650.         value=Array[CurPos++]==1?true:false;
  651.         return this;
  652.     }
  653.  
  654.     Serializator@ opShr(bool& value)
  655.     {
  656.         return Get(value);
  657.     }
  658.  
  659.     Serializator@ Get(string& str)
  660.     {
  661.         uint len=0;
  662.         for(uint i=CurPos;;i++)
  663.         {
  664.             if(i==DataSize)
  665.             {
  666.                 str="";
  667.                 return this;
  668.             }
  669.             if(Array[i]==0)
  670.             {
  671.                 len=i-CurPos;
  672.                 break;
  673.             }
  674.         }
  675.         str.resize(len);
  676.         for(uint i=0;i<len;i++) str[i]=Array[CurPos++];
  677.         CurPos++; // Skip zero
  678.         return this;
  679.     }
  680.  
  681.     Serializator@ opShr(string& str)
  682.     {
  683.         return Get(str);
  684.     }
  685.  
  686.     Serializator@ Get(float& value)
  687.     {
  688.         int dummy=0;
  689.         Get(dummy);
  690.         value=IntToFloat(dummy);
  691.         return this;
  692.     }
  693.  
  694.     Serializator@ opShr(float& value)
  695.     {
  696.         return Get(value);
  697.     }
  698.  
  699.     Serializator@ Get(array<int64>& values)
  700.     {
  701.         uint valuesLen=0;
  702.         Get(valuesLen);
  703.         values.resize(valuesLen);
  704.         for(uint i=0;i<valuesLen;i++) Get(values[i]);
  705.         return this;
  706.     }
  707.  
  708.     Serializator@ opShr(array<int64>& values)
  709.     {
  710.         return Get(values);
  711.     }
  712.  
  713.     Serializator@ Get(array<int32>& values)
  714.     {
  715.         uint valuesLen=0;
  716.         Get(valuesLen);
  717.         values.resize(valuesLen);
  718.         for(uint i=0;i<valuesLen;i++) Get(values[i]);
  719.         return this;
  720.     }
  721.  
  722.     Serializator@ opShr(array<int32>& values)
  723.     {
  724.         return Get(values);
  725.     }
  726.  
  727.     Serializator@ Get(array<float>& values)
  728.     {
  729.         uint valuesLen=0;
  730.         Get(valuesLen);
  731.         values.resize(valuesLen);
  732.         for(uint i=0;i<valuesLen;i++)
  733.         {
  734.             int dummy=0;
  735.             Get(dummy);
  736.             values[i]=IntToFloat(dummy);
  737.         }
  738.         return this;
  739.     }
  740.  
  741.     Serializator@ opShr(array<float>& values)
  742.     {
  743.         return Get(values);
  744.     }
  745.  
  746.     Serializator@ Get(array<int16>& values)
  747.     {
  748.         uint valuesLen=0;
  749.         Get(valuesLen);
  750.         values.resize(valuesLen);
  751.         for(uint i=0;i<valuesLen;i++) Get(values[i]);
  752.         return this;
  753.     }
  754.  
  755.     Serializator@ opShr(array<int16>& values)
  756.     {
  757.         return Get(values);
  758.     }
  759.  
  760.     Serializator@ Get(array<int8>& values)
  761.     {
  762.         uint valuesLen=0;
  763.         Get(valuesLen);
  764.         values.resize(valuesLen);
  765.         for(uint i=0;i<valuesLen;i++) Get(values[i]);
  766.         return this;
  767.     }
  768.  
  769.     Serializator@ opShr(array<int8>& values)
  770.     {
  771.         return Get(values);
  772.     }
  773.  
  774.     Serializator@ Get(array<uint64>& values)
  775.     {
  776.         uint valuesLen=0;
  777.         Get(valuesLen);
  778.         values.resize(valuesLen);
  779.         for(uint i=0;i<valuesLen;i++) Get(values[i]);
  780.         return this;
  781.     }
  782.  
  783.     Serializator@ opShr(array<uint64>& values)
  784.     {
  785.         return Get(values);
  786.     }
  787.  
  788.     Serializator@ Get(array<uint32>& values)
  789.     {
  790.         uint valuesLen=0;
  791.         Get(valuesLen);
  792.         values.resize(valuesLen);
  793.         for(uint i=0;i<valuesLen;i++) Get(values[i]);
  794.         return this;
  795.     }
  796.  
  797.     Serializator@ opShr(array<uint32>& values)
  798.     {
  799.         return Get(values);
  800.     }
  801.  
  802.     Serializator@ Get(array<uint16>& values)
  803.     {
  804.         uint valuesLen=0;
  805.         Get(valuesLen);
  806.         values.resize(valuesLen);
  807.         for(uint i=0;i<valuesLen;i++) Get(values[i]);
  808.         return this;
  809.     }
  810.  
  811.     Serializator@ opShr(array<uint16>& values)
  812.     {
  813.         return Get(values);
  814.     }
  815.  
  816.     Serializator@ Get(array<uint8>& values)
  817.     {
  818.         uint valuesLen=0;
  819.         Get(valuesLen);
  820.         values.resize(valuesLen);
  821.         for(uint i=0;i<valuesLen;i++) Get(values[i]);
  822.         return this;
  823.     }
  824.  
  825.     Serializator@ opShr(array<uint8>& values)
  826.     {
  827.         return Get(values);
  828.     }
  829.  
  830.     Serializator@ Get(array<bool>& values)
  831.     {
  832.         uint valuesLen=0;
  833.         Get(valuesLen);
  834.         values.resize(valuesLen);
  835.         for(uint i=0;i<valuesLen;i++) Get(values[i]);
  836.         return this;
  837.     }
  838.  
  839.     Serializator@ opShr(array<bool>& values)
  840.     {
  841.         return Get(values);
  842.     }
  843.  
  844.     Serializator@ Get(array<string>& values)
  845.     {
  846.         uint valuesLen=0;
  847.         Get(valuesLen);
  848.         values.resize(valuesLen);
  849.         for(uint i=0;i<valuesLen;i++) Get(values[i]);
  850.         return this;
  851.     }
  852.  
  853.     Serializator@ opShr(array<string>& values)
  854.     {
  855.         return Get(values);
  856.     }
  857.  
  858.     Serializator@ Get(Critter@& cr)
  859.     {
  860.         @cr=null;
  861.         if(CurPos+4>DataSize) return this;
  862.         uint id=0;
  863.         id|=Array[CurPos++]<<24;
  864.         id|=Array[CurPos++]<<16;
  865.         id|=Array[CurPos++]<<8;
  866.         id|=Array[CurPos++];
  867.         @cr=::GetCritter(id);
  868.         return this;
  869.     }
  870.  
  871.     Serializator@ opShr(Critter@& cr)
  872.     {
  873.         return Get(cr);
  874.     }
  875.  
  876.     Serializator@ Get(Item@& item)
  877.     {
  878.         @item=null;
  879.         if(CurPos+4>DataSize) return this;
  880.         uint id=0;
  881.         id|=Array[CurPos++]<<24;
  882.         id|=Array[CurPos++]<<16;
  883.         id|=Array[CurPos++]<<8;
  884.         id|=Array[CurPos++];
  885.         @item=::GetItem(id);
  886.         return this;
  887.     }
  888.  
  889.     Serializator@ opShr(Item@& item)
  890.     {
  891.         return Get(item);
  892.     }
  893.  
  894.     array<uint8> Array;
  895.     uint CurPos;
  896.     uint BufSize;
  897.     uint DataSize;
  898. };
  899.  
  900. #endif //__SERIALIZATOR__
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement