/*
 * 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: CharArray.h,v 1.4 2003/01/08 17:45:04 florian Exp $
 */


#ifndef INCLUDE_JAKELIB2_UTIL_CHARARRAY_H
# define INCLUDE_JAKELIB2_UTIL_CHARARRAY_H

namespace jakelib {
  namespace util {

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

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

	void copyTo(jchar* dest);

	jchar* getChars();
  
        /**
         * @brief Returns a string representation of this \c CharArray.
         */
        jakelib::lang::String* toString();

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

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

	JAKELIB_DECLARE_CLASS(CharArray);
      };

  }
}

#endif

