Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //////////////////////////////////////////////////////////////////////////
- #pragma mark helper functions
- #pragma mark -
- //////////////////////////////////////////////////////////////////////////
- /**********************************************************************************************/
- long ReadLong( wchar_t*& ch, const wchar_t* end )
- {
- long res;
- ++ch;
- wchar_t* start = ch;
- for( ; ch < end ; ++ch )
- {
- if( *ch == '\n' )
- {
- res = wcstol( start, &ch, 10 );
- break;
- }
- }
- return res;
- }
- ...
- /**********************************************************************************************/
- inline LDCPlayerItem ReadClipItem( wchar_t*& ch, const wchar_t* end )
- {
- LDCPlayerItem item;
- item.type = kPlayerItemClip;
- item.pos.x = ReadLong( ch, end );
- item.pos.y = ReadLong( ch, end );
- item.size.x = ReadLong( ch, end );
- item.size.y = ReadLong( ch, end );
- return item;
- }
- ...
- //////////////////////////////////////////////////////////////////////////
- #pragma mark methods
- #pragma mark -
- //////////////////////////////////////////////////////////////////////////
- /**********************************************************************************************/
- void LDCPlayer::LoadData( const LString& data )
- {
- mIsLoaded = true;
- mItems.Clear();
- bool first = true;
- wchar_t* start = &data[ 0 ];
- wchar_t* end = start + data.Len();
- long wlen;
- // Parse string with format:
- // %LRecordDC
- // /<item_type>
- // [param1]
- // [param2]
- // ...
- // /<item_type>
- // ...
- for( wchar_t* ch = start ; ch < end ; ++ch )
- {
- if( *ch == '\n' )
- {
- if( first )
- {
- *ch = 0;
- first = false;
- // First line must be "%LRecordDC"
- if( wcscmp( start, L"%LRecordDC" ) )
- return;
- start = ch + 1;
- continue;
- }
- // Item description must have atleast two chars
- wlen = ch - start - 1;
- if( wlen < 1 )
- break;
- // We can optimize search for items that have unique first char
- switch( *( start + 1 ) )
- {
- // "/brush"
- case 'b': mItems += ReadBrushItem( ch, end ); break;
- // "/clip"
- case 'c': mItems += ReadClipItem( ch, end ); break;
- // "/ellipse"
- case 'e': mItems += ReadEllipseItem( ch, end ); break;
- ...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement