/***********************************************************************
 * FXRuby -- the Ruby language bindings for the FOX GUI toolkit.
 * Copyright (c) 2001-2003 by J. Lyle Johnson. All Rights Reserved.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * For further information please contact the author by e-mail
 * at "lyle@users.sourceforge.net".
 ***********************************************************************/

/***********************************************************************
 * $Id: FXMemoryBuffer.i,v 1.1.2.4 2003/03/19 17:28:32 lyle Exp $
 ***********************************************************************/

%ignore FXMemoryBuffer::FXMemoryBuffer(FXuchar *data,FXuint size);
%ignore FXMemoryBuffer::getData() const;

class FXMemoryBuffer {
public:
  // Create an memory buffer object
  FXMemoryBuffer(FXuchar *data,FXuint size);
  
  // Returns a pointer to the data
  FXuchar* getData() const;
  
  // Returns the size (in bytes)
  FXuint getSize() const;
  
  %extend {
    // Indexed access
    FXuchar __getitem__(FXuint i) const {
      return self->getData()[i];
      }
    
    FXuchar __setitem__(FXuint i,FXuchar value){
      self->getData()[i] = value;
      return value;
      }
      
    // Convert it to a Ruby string
    VALUE to_s() const {
      if(self->getSize()>0){
        const char *str=const_cast<const char*>(reinterpret_cast<char*>(self->getData()));
	long len=static_cast<long>(self->getSize());
        return rb_str_new(str,len);
	}
      else{
        return rb_str_new2("");
	}
      }
  }
  
  // Destructor
  ~FXMemoryBuffer();
  };
