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

/* datahandler.h
 *
 * Copyright 2003 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.
 */

#include <glibmm/interface.h>
#include <libgdamm/value.h>
#include <libgda/gda-data-handler.h>

_DEFS(libgdamm,libgda)
_PINCLUDE(glibmm/private/interface_p.h)

namespace Gnome
{

namespace Gda
{

/** @defgroup DataHandlers Data Handlers
 */

/** Base class which provides data handling capabilities.
 *
 * Because data types vary a lot from one DBMS to another, the DataHandler interface helps with designing modules 
 * which can handle very specific pieces of data through plugins. Each object which imlements the DataHandler interface 
 * is expected to handle a subset of the possible libgda defined data types.
 * 
 * The DataHandler object can convert a Value to and from both SQL and 'STR'. The SQL representation of a value is the 
 * actual string which would be used in an SQL statement (for example a string's SQL representation is surrounded by 
 * quotes such as 'that\'s a string'). The 'STR' representation is a human-readable representation of a value appropriate 
 * for the user's current locale. The 'STR' respresentation of a string is simply the original string without quotes but 
 * a numerical value or date, for instance, will be formatted according to the user's current locale.
 * 
 * Only one object which implements this interface is needed for any given data type, and it mainly contains some methods 
 * to manage values (as Value structures). The Gnome::Db::DataEntry interface is complementary to this one since it is 
 * implemented by widgets in which the user can enter or modify some data. 
 *
 * @ingroup DataHandlers
 */
class DataHandler : public Glib::Interface
{
  _CLASS_INTERFACE(DataHandler, GdaDataHandler, GDA_DATA_HANDLER, GdaDataHandlerIface)
public:

  _WRAP_METHOD(Glib::ustring get_sql_from_value(const Value& value) const, gda_data_handler_get_sql_from_value)
  _WRAP_METHOD(Glib::ustring get_str_from_value(const Value& value) const, gda_data_handler_get_str_from_value)

  _WRAP_METHOD(Value get_value_from_sql(const Glib::ustring& sql, GType type) const, gda_data_handler_get_value_from_sql)
  _WRAP_METHOD(Value get_value_from_str(const Glib::ustring& sql, GType type) const, gda_data_handler_get_value_from_str)
  _WRAP_METHOD(Value get_sane_init_value(GType type) const, gda_data_handler_get_sane_init_value)

  _WRAP_METHOD(bool accepts_g_type(GType type) const, gda_data_handler_accepts_g_type)
  _WRAP_METHOD(Glib::ustring get_descr() const, gda_data_handler_get_descr)

protected:

  //We don't wrap the vfuncs because they are only useful for implementation of libgda itself,
  //and they have a high code-size and per-object memory cost. murrayc
};

} // namespace Gda
} // namespace Gnome

