// -*- C++ -*- //

/* datacomparator.h
 *
 * Copyright 2006 libgdamm 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(libgdamm,libgda)
_PINCLUDE(glibmm/private/object_p.h)

#include <libgdamm/datamodel.h>
#include <libgda/gda-data-comparator.h>

namespace Gnome
{

namespace Gda
{

//TODO: Document and/or wrap this:
typedef GdaDiff Diff;
	
/** Simple data model's contents comparison.
 *
 * The DataComparator is a simple object which takes two DataModel objects
 * and compare them. Actual comparison is performed when the 
 * compute_diff() is called; for each difference found, the diff-computed signal
 * is emitted (any user installed signal handler which returns FALSE stops 
 * the computing process).
 *
 * After the differences have been computed, they can each be accessed using 
 * gda_data_comparator_get_diff(), the number of differences found being 
 * returned by gda_data_comparator_get_n_diffs().
 * There are some limitations to this object:
 * <ul>
 *   <li>The data models compared must have the same number and type of columns</li>
 *   <li>The comparison is done column-for-column: one cannot omit columns in the comparison,
 * nor compare columns with different positions</li>
 * </ul>
 *
 * @ingroup DataHandlers
 */
class DataComparator
 : public Glib::Object,
   public DataModel
{
  _CLASS_GOBJECT(DataComparator, GdaDataComparator, GDA_DATA_COMPARATOR, Glib::Object, GObject)
  _IMPLEMENTS_INTERFACE(DataModel)
protected:
  _WRAP_CTOR(DataComparator (const Glib::RefPtr<DataModel>& old_model, const Glib::RefPtr<DataModel>& new_model), gda_data_comparator_new)

public:
  _WRAP_CREATE(const Glib::RefPtr<DataModel>& old_model, const Glib::RefPtr<DataModel>& new_model)

  //TODO: The nb_cols parmetetr is unnecessary:
  //TODO: Documentation
  void set_key_for_columns(const std::vector<int>& col_numbers);
  _IGNORE(gda_data_comparator_set_key_columns)

  _WRAP_METHOD(bool compute_diff(), gda_data_comparator_compute_diff, errthrow)
  _WRAP_METHOD(int get_n_diffs() const, gda_data_comparator_get_n_diffs)
  _WRAP_METHOD(const Diff* get_diff(int pos), gda_data_comparator_get_diff)
		
  _WRAP_PROPERTY("old-model", Glib::RefPtr<DataModel>)
  _WRAP_PROPERTY("new-model", Glib::RefPtr<DataModel>)

//TODO: Register the type in libgda properly?
#m4 _CONVERSION(`gpointer',`Diff*',`(Diff*)($3)')
#m4 _CONVERSION(`Diff*',`gpointer',`(gpointer)($3)')
    _WRAP_SIGNAL(bool diff_computed(Diff* diff), "diff-computed", no_default_handler)
};

} // namespace Gda
} // namespace Gnome
