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

/* datamodelimport.h
 *
 * Copyright 2007 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/object.h>
#include <libgdamm/datamodel.h>
#include <libgdamm/set.h>

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

namespace Gnome
{

namespace Gda
{


/** Importing data from a string or a file.
 *
 * This data model imports data from a string or a file. The data can either be in a CSV (comma separated values) 
 * format or in an XML format as described by the libgda-array.dtd DTD (It is also possible to import 
 * data from an already-build XML tree validated against that DTD).
 * The caller must decide, upon construction, if the new DataModelImport must support random access or simply  
 * cursor based access. Random access makes it easier to use the resulting data model but consumes more memory as all 
 * the data is copied in memory, and this is thus not suitable for large data sets. Note that importing from an 
 * already-built XML tree will always result in a random access data model.
 *
 * Various import options can be specified using parameters in a Set object. The available options depend 
 * on the format of the imported data listed here:
 * - "SEPARATOR" (string, CVS import only): specifies the separator to consider.
 * - "ESCAPE_CHAR" (string, CVS import only): specifies the character used to "escape" the strings contained between two separators.
 * - "ENCODING" (string, CVS import only): specifies the character set used in the imported data.
 * - "TITLE_AS_FIRST_LINE" (boolean, CVS import only): TRUE to specify that the first line of the imported data contains the column names.
 * - "GDA_TYPE_<col number>" (gda type, CVS import only): specifies the requested GDA type for the column numbered "col number".
 * - "DBMS_TYPE_<col number>" (string, CVS import only): specifies the requested DBMS type for the column numbered "col number"; if the DBMS type is listed in the dictionary used by the created model, then the GDA type is set in accordance.
 *
 * @ingroup DataModels
 */
class DataModelImport
 : public Glib::Object,
   public DataModel
{
  _CLASS_GOBJECT(DataModelImport, GdaDataModelImport, GDA_DATA_MODEL_IMPORT, Glib::Object, GObject)
  _IMPLEMENTS_INTERFACE(DataModel)
protected:
  DataModelImport(const std::string& filename, bool random_access, const Glib::RefPtr<const Set>& options);
  _IGNORE(gda_data_model_import_new_file)

  //Note: data is a null-terminated string, not copied, so the instance must stay alive as long as this model.
  DataModelImport(const gchar* data, bool random_access, const Glib::RefPtr<const Set>& options);
  _IGNORE(gda_data_model_import_new_mem)

  explicit DataModelImport(xmlNodePtr node);
  _IGNORE(gda_data_model_import_new_xml_node)

public:
  //TODO: Documentation:
  _WRAP_CREATE(const std::string& filename, bool random_access, const Glib::RefPtr<const Set>& options)
  _WRAP_CREATE(const gchar* data, bool random_access, const Glib::RefPtr<const Set>& options)
  _WRAP_CREATE(xmlNodePtr node)


  //TODO: Use std::vector:
  _WRAP_METHOD(GSList* get_errors(), gda_data_model_import_get_errors)

  _WRAP_METHOD(void clean_errors(), gda_data_model_import_clean_errors)

  _WRAP_PROPERTY("data-string", Glib::ustring)
  _WRAP_PROPERTY("filename", std::string)
  _WRAP_PROPERTY("options", Glib::RefPtr<Set>)
  _WRAP_PROPERTY("random-access", bool)
  #m4 _EQUAL(gpointer, xmlNodePtr)
  _WRAP_PROPERTY("xml-node", xmlNodePtr)
};

} // namespace Gda
} // namespace Gnome

