/* $Id$ */

/* Copyright (C) 2002-2009 The gtkmm Development Team
 *
 * 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., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

_DEFS(glibmm,glib)

#include <glib-object.h>
#include <glibmm/value.h>
#include <sigc++/functors/slot.h>

namespace Glib
{

/** A container structure to maintain an array of generic values.
 * The prime purpose of a ValueArray is for it to be used as an object property
 * that holds an array of values. A ValueArray wraps an array of ValueBase
 * elements.
 *
 * @newin{2,22}
 */
class ValueArray
{
  _CLASS_BOXEDTYPE(ValueArray, GValueArray, NONE, g_value_array_copy, g_value_array_free)
  _IGNORE(g_value_array_copy, g_value_array_free)
  _CUSTOM_DEFAULT_CTOR

public:
  /** For example,
   *  int on_compare(const Glib::ValueBase& v1, const Glib::ValueBase& v2);.
   *  The compare function should return -1 if v1 < v2, 0 if v1 == v2, and 1 if
   *  v1 > v2.
   */
  typedef sigc::slot<int, const Glib::ValueBase&, const Glib::ValueBase&> SlotCompare;

  /** Default constructor.  Constructs a new array with no pre-allocation.
   */
  ValueArray();

  /** Constructs a new array with pre-allocation.
   */
  ValueArray(guint n_preallocated);

  /** Return the value at @a index contained in the value array.
   * @param index Index of the value of interest.
   * @param value An uninitialized ValueBase in which to store the result.  If
   * the get is successful, @a value will be valid, otherwise it will remain
   * uninitialized.
   * @return whether the get was successful or not.
   */
  bool get_nth(guint index, Glib::ValueBase& value);
  _IGNORE(g_value_array_get_nth)

  _WRAP_METHOD_DOCS_ONLY(g_value_array_append)
  Glib::ValueArray& append(const Glib::ValueBase& value);

  _WRAP_METHOD_DOCS_ONLY(g_value_array_prepend)
  Glib::ValueArray& prepend(const Glib::ValueBase& value);

  _WRAP_METHOD_DOCS_ONLY(g_value_array_insert)
  Glib::ValueArray& insert(guint index, const Glib::ValueBase& value);

  _WRAP_METHOD_DOCS_ONLY(g_value_array_remove)
  Glib::ValueArray& remove(guint index);

  _WRAP_METHOD_DOCS_ONLY(g_value_array_sort)
  Glib::ValueArray& sort(const SlotCompare& compare_func);
  _IGNORE(g_value_array_sort_with_data)
};

} //namespace Glib
