Advertisement
Guest User

Untitled

a guest
Jul 19th, 2010
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.63 KB | None | 0 0
  1. //////////////////////////////////////////////////////////////////////////
  2. #pragma mark helper functions
  3. #pragma mark -
  4. //////////////////////////////////////////////////////////////////////////
  5.  
  6. /**********************************************************************************************/
  7. long ReadLong( wchar_t*& ch, const wchar_t* end )
  8. {
  9.     long res;
  10.  
  11.     ++ch;
  12.     wchar_t* start = ch;
  13.  
  14.     for( ; ch < end ; ++ch )
  15.     {
  16.         if( *ch == '\n' )
  17.         {
  18.             res = wcstol( start, &ch, 10 );
  19.             break;
  20.         }
  21.     }
  22.  
  23.     return res;
  24. }
  25.  
  26. ...
  27.  
  28. /**********************************************************************************************/
  29. inline LDCPlayerItem ReadClipItem( wchar_t*& ch, const wchar_t* end )
  30. {
  31.     LDCPlayerItem item;
  32.     item.type   = kPlayerItemClip;
  33.     item.pos.x  = ReadLong( ch, end );
  34.     item.pos.y  = ReadLong( ch, end );
  35.     item.size.x = ReadLong( ch, end );
  36.     item.size.y = ReadLong( ch, end );
  37.  
  38.     return item;
  39. }
  40.  
  41. ...
  42.  
  43. //////////////////////////////////////////////////////////////////////////
  44. #pragma mark methods
  45. #pragma mark -
  46. //////////////////////////////////////////////////////////////////////////
  47.  
  48. /**********************************************************************************************/
  49. void LDCPlayer::LoadData( const LString& data )
  50. {
  51.     mIsLoaded = true;
  52.     mItems.Clear();
  53.  
  54.     bool      first  = true;
  55.     wchar_t*  start  = &data[ 0 ];
  56.     wchar_t*  end    = start + data.Len();
  57.     long      wlen;
  58.  
  59.     // Parse string with format:
  60.     // %LRecordDC
  61.     // /<item_type>
  62.     // [param1]
  63.     // [param2]
  64.     // ...
  65.     // /<item_type>
  66.     // ...
  67.     for( wchar_t* ch = start ; ch < end ; ++ch )
  68.     {
  69.         if( *ch == '\n' )
  70.         {
  71.             if( first )
  72.             {
  73.                 *ch   = 0;
  74.                 first = false;
  75.  
  76.                 // First line must be "%LRecordDC"
  77.                 if( wcscmp( start, L"%LRecordDC" ) )
  78.                     return;
  79.  
  80.                 start = ch + 1;
  81.                 continue;
  82.             }
  83.  
  84.             // Item description must have atleast two chars
  85.             wlen = ch - start - 1;
  86.             if( wlen < 1 )
  87.                 break;
  88.  
  89.             // We can optimize search for items that have unique first char
  90.             switch( *( start + 1 ) )
  91.             {
  92.                 // "/brush"
  93.                 case 'b': mItems += ReadBrushItem( ch, end ); break;
  94.  
  95.                 // "/clip"
  96.                 case 'c': mItems += ReadClipItem( ch, end ); break;
  97.  
  98.                 // "/ellipse"
  99.                 case 'e': mItems += ReadEllipseItem( ch, end ); break;
  100.  
  101. ...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement