// This may look like C code, but it's really -*- C++ -*-
/*
 * Copyright (C) 2008 Emweb bvba, Kessel-Lo, Belgium.
 *
 * See the LICENSE file for terms of use.
 */
#ifndef WMODEL_INDEX_H_
#define WMODEL_INDEX_H_

#include <vector>
#include <boost/any.hpp>
#include <Wt/WDllDefs.h>

namespace Wt {

class WAbstractItemModel;

/*! \class WModelIndex Wt/WModelIndex Wt/WModelIndex
 *  \brief An index to a data item of a data model.
 *
 * An index is immutable, and a \link isValid() valid\endlink index
 * can only be created using the WAbstractItemModel::index(int row,
 * int column) method.
 *
 * \sa WAbstractItemModel
 */
class WT_API WModelIndex
{
public:
  /*! \brief Create a new (invalid) WModelIndex.
   *
   * Returns a model index for which isValid() return false.
   */
  WModelIndex();

  /*! \brief Get the column for this model index.
   */
  int column() const { return column_; }

  /*! \brief Get the row for this model index.
   */
  int row() const { return row_; }

  /*! \brief Get the data in the model at this index.
   */
  boost::any data() const;

  /*! \brief Return if this index points to anything.
   */
  bool isValid() const { return model_ != 0; }

  /*! \brief Return the abstract item model to which this (valid) index is
   *         bound.
   */
  const WAbstractItemModel *model() const { return model_; }

private:
  const WAbstractItemModel *model_;
  int row_, column_;

  WModelIndex(int row, int column, const WAbstractItemModel *model);

  friend class WAbstractItemModel;
};

typedef std::vector<WModelIndex> WModelIndexList;

}

#endif // WMODEL_INDEX_H_
