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

/* metastore.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.
 */

#include <libgdamm/value.h>
#include <libgda/gda-meta-struct.h>

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

namespace Gnome
{

namespace Gda
{

/** Exception class for Gda MetaStruct errors.
 */
_WRAP_GERROR(MetaStructError, GdaMetaStructError, GDA_META_STRUCT_ERROR)

_WRAP_ENUM(MetaStructFeature, GdaMetaStructFeature)
_WRAP_ENUM(MetaDbObjectType, GdaMetaDbObjectType)
_WRAP_ENUM(MetaSortType, GdaMetaSortType)
_WRAP_ENUM(MetaGraphInfo, GdaMetaGraphInfo) 

class MetaStore;

/** In-memory representation of some database objects.
 *
 * The Gda::MetaStruct object reads data from a Gda::MetaStore object and creates 
 * an easy to use in memory representation for some database objects. For example
 * one can easily analyse the columns of a table (or its foreign keys) using a 
 * Gda::MetaStruct.
 *
 * When created, the new Gda::MetaStruct object is empty (it does not have any 
 * information about any database object). Information about database objects is 
 * computed upon request using the gda_meta_struct_complement() method. Information 
 * about individual database objects is represented by GdaMetaDbObject structures, 
 * which can be obtained using get_db_object() or get_all_db_objects().
 * 
 * Note that the Gda::MetaDbObject structures may change or may be removed or 
 * replaced by others, so it not advised to keep pointers to these structures: 
 * pointers to these structures should be considered valid as long as 
 * complement() and other similar functions have not been called. 
 *
 * @ingroup Connection
 */
class MetaStruct : public Glib::Object
{
  _CLASS_GOBJECT(MetaStruct, GdaMetaStruct, GDA_META_STRUCT, Glib::Object, GObject)
protected:
  _WRAP_CTOR(MetaStruct(const Glib::RefPtr<MetaStore>& meta_store, MetaStructFeature features), gda_meta_struct_new)

public:
  _WRAP_CREATE(const Glib::RefPtr<MetaStore>& store, MetaStructFeature features = META_STRUCT_FEATURE_ALL)
  
  //TODO: Wrap GdaMetaDbObject?
  _WRAP_METHOD(GdaMetaDbObject* complement(MetaDbObjectType type, const Value& catalog, const Value& schema, const Value& name), gda_meta_struct_complement, errthrow)
  _WRAP_METHOD(bool complement_schema(const Value& catalog, const Value& schema), gda_meta_struct_complement_schema, errthrow)
  _WRAP_METHOD(bool complement_default(), gda_meta_struct_complement_default, errthrow)
  _IGNORE(gda_meta_struct_complement_depend) // private API   

  _WRAP_METHOD(bool sort_db_object(MetaSortType sort_type), gda_meta_struct_sort_db_objects, errthrow)
    _WRAP_METHOD(GdaMetaDbObject* get_db_object(const Value& catalog, const Value& schema, const Value& name), gda_meta_struct_get_db_object)

  //TODO: Wrap GdaMetaTable and GdaMetaDbObject? They seem to be bare C structs.
  //http://library.gnome.org/devel/libgda/unstable/GdaMetaStruct.html#GdaMetaTable
  _WRAP_METHOD(GdaMetaTableColumn* get_table_column(GdaMetaTable* table, const Value& col_name), gda_meta_struct_get_table_column)
  _WRAP_METHOD(Glib::ustring dump_as_graph(MetaGraphInfo info), gda_meta_struct_dump_as_graph, errthrow)
  
  _WRAP_METHOD(bool complement_all(), gda_meta_struct_complement_all, errthrow)
    
  // TODO: Use C++ type.
  // See http://bugzilla.gnome.org/show_bug.cgi?id=574740
  _WRAP_METHOD(GSList* get_all_db_objects(), gda_meta_struct_get_all_db_objects)
    
  //Ignore private functions.
  _IGNORE(gda_meta_struct_load_from_xml_file, gda_meta_struct_add_db_object)
  
  _WRAP_PROPERTY("features", guint)
};

} // namespace Gda
} // namespace Gnome

