/*
 * Jakelib2 - General purpose C++ library
 * Copyright (C) 2001 Florian Wolff  (florian@donuz.de)
 *
 * 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
 *
 * $Id: ByteArray.h,v 1.6 2003/01/08 17:45:04 florian Exp $
 */


#ifndef INCLUDE_JAKELIB2_UTIL_BYTEARRAY_H
# define INCLUDE_JAKELIB2_UTIL_BYTEARRAY_H

namespace jakelib {
  namespace util {

    /**
     *
     * @class ByteArray
     * @version $Id: ByteArray.h,v 1.6 2003/01/08 17:45:04 florian Exp $
     * @author Florian 'Overflo' Wolff (florian@donuz.de)
     */
    class ByteArray : public jakelib::lang::Object
      {
      public:
	/**
	 * Constructs an empty \c ByteArray with the specified initial capacity.
	 *
	 * @param initialCapacity The initial capacity of the \c ByteArray.
	 */
	ByteArray(int initialCapacity = 256);

	/**
	 * Constructs a \c ByteArray filled with the given byte sequence.
	 *
	 * @param bytes Pointer to the byte sequence
	 * @param size Number of bytes
	 */
	ByteArray(jbyte* bytes, int size);

	~ByteArray();
  
	int add(jbyte b);
  
	void ensureCapacity(int minCapacity);
  
	jbyte get(int index);
  
	/**
	 * Returns the number of bytes stored in the \c ByteArray.
	 *
	 * @return Number of elements.
	 */
	int size();
  
	/**
	 * Determines whether the \c ByteArray is empty.
	 *
	 * @return <tt>TRUE</tt> if the <tt>ByteArray</tt> is empty, <tt>FALSE</tt> if it contains at least one item.
	 */
	jboolean isEmpty();
  
	/**
	 * Remove all bytes from the \c ByteArray, i.e. set \c size to zero.
	 */
	void clear();
  
	void set(int index, jbyte b);
  
	void insert(int index, jbyte b);
  
	int indexOf(jakelib::lang::Object* object);
  
	void removeLastElement();
  
	void remove(int index);

	void copyTo(jbyte* dest);

	jbyte* getBytes();
  
        /**
         * @brief Returns a string representation of this \c ByteArray.
         */
        jakelib::lang::String* toString();

        /**
         * Frees all resources. Don't use the \c ByteArray afterwards!
         */
        void destroy();

      protected:
	jbyte* elementData;
  
	int elementCount;
  
	int capacity;

	JAKELIB_DECLARE_CLASS(ByteArray);
      };

  }
}

#endif

