October 28, 2020, 06:20:09 AM

Author Topic: [bmx] StreamBank by N [ 1+ years ago ]  (Read 1182 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bmx] StreamBank by N [ 1+ years ago ]
« on: June 29, 2017, 12:28:42 AM »
Title : StreamBank
Author : N
Posted : 1+ years ago

Description : Basically, this lets you treat streams the same was as you would a bank.  It's surprisingly handy.

However, it should probably be noted that I do zero error checking in this code.  If you find yourself getting exceptions, you'll probably want to check that you're not reading from/writing to some offset into the stream that just doesn't exist.  I've never had any problems but I do realize there are people out there who expect bizarre things like the aforementioned to magically work.


Code :
Code: BlitzMax
  1. SuperStrict
  2.  
  3. Import Brl.Bank
  4. Import Brl.Stream
  5.  
  6. Public
  7. Type IStreamBank Extends TBank
  8.     Field _proxy:TStream
  9.    
  10.     Method Delete( )
  11.         _proxy = Null
  12.     End Method
  13.    
  14.     Method Resize( size% )
  15.         Throw "Cannot resize IStreamBanks"
  16.     End Method
  17.    
  18.     Method PeekByte%( idx% )
  19.         _proxy.Seek( idx )
  20.         Return _proxy.ReadByte( )
  21.     End Method
  22.    
  23.     Method PeekShort%( idx% )
  24.         _proxy.Seek( idx )
  25.         Return _proxy.ReadShort( )
  26.     End Method
  27.    
  28.     Method PeekInt%( idx% )
  29.         _proxy.Seek( idx )
  30.         Return _proxy.ReadInt( )
  31.     End Method
  32.    
  33.     Method PeekLong:Long( idx% )
  34.         _proxy.Seek( idx )
  35.         Return _proxy.ReadLong( )
  36.     End Method
  37.    
  38.     Method PeekFloat#( idx% )
  39.         _proxy.Seek( idx )
  40.         Return _proxy.ReadFloat( )
  41.     End Method
  42.    
  43.     Method PeekDouble!( idx% )
  44.         _proxy.Seek( idx )
  45.         Return _proxy.ReadDouble( )
  46.     End Method
  47.    
  48.     Method PokeByte( idx%, value% )
  49.         _proxy.Seek( idx )
  50.         _proxy.WriteByte( value )
  51.     End Method
  52.    
  53.     Method PokeShort( idx%, value% )
  54.         _proxy.Seek( idx )
  55.         _proxy.WriteShort( value )
  56.     End Method
  57.    
  58.     Method PokeInt( idx%, value% )
  59.         _proxy.Seek( idx )
  60.         _proxy.WriteInt( value )
  61.     End Method
  62.    
  63.     Method PokeLong( idx%, value:Long )
  64.         _proxy.Seek( idx )
  65.         _proxy.WriteLong( value )
  66.     End Method
  67.    
  68.     Method PokeFloat( idx%, value# )
  69.         _proxy.Seek( idx )
  70.         _proxy.WriteFloat( value )
  71.     End Method
  72.    
  73.     Method PokeDouble( idx%, value! )
  74.         _proxy.Seek( idx )
  75.         _proxy.WriteDouble( value )
  76.     End Method
  77.    
  78.     Method Size%( )
  79.         Return _proxy.Size( )
  80.     End Method
  81.    
  82.     Method PeekBytes@ Ptr( into@ Ptr, off%, size% )
  83.         _proxy.Seek( off )
  84.         _proxy.ReadBytes( into, size )
  85.     End Method
  86.    
  87.     Method PokeBytes( from@ Ptr, off%, size% )
  88.         _proxy.Seek( off )
  89.         _proxy.WriteBytes( from, size )
  90.     End Method
  91.    
  92.     Method Buf@ Ptr( )
  93.         Return Null
  94.     End Method
  95. End Type
  96.  
  97. Function CreateStreamBank:TBank( stream:TStream )
  98.     Local o:IStreamBank = New IStreamBank
  99.     o._proxy = stream
  100.     Return o
  101. End Function


Comments : none...

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal