/*  libhrel - Holyrel library

    Copyright (C) 2005 Chong Kai Xiong <descender@phreaker.net>

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 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
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public
    License along with this library; if not, write to the
    Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    Boston, MA  02111-1307  USA.
*/

#ifndef H_RELATION_H
#define H_RELATION_H

#include <glib.h>
#include <glib-object.h>
#include <libhrel/tuple.h>
#include <libhrel/attr_map.h>

G_BEGIN_DECLS

#define H_TYPE_RELATION            (h_relation_get_type ())
#define H_RELATION(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), H_TYPE_RELATION, HRelation))
#define H_RELATION_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST    ((klass), H_TYPE_RELATION, HRelationClass))
#define H_IS_RELATION(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), H_TYPE_RELATION))
#define H_IS_RELATION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE    ((klass), H_TYPE_RELATION))
#define H_RELATION_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS  ((obj), H_TYPE_RELATION, HRelationClass))

typedef struct _HRelation      HRelation;
typedef struct _HRelationClass HRelationClass;

typedef void (*HTupleFunc) (HTuple   *tuple,
                            gpointer  user_data);

struct _HRelation
{
  GObject   gobject;

  gchar    *name;
  gchar    *description;
};

struct _HRelationClass
{
  GObjectClass parent_class;

  void        (*print)          (HRelation *self);
  HAttribute *(*get_attr)       (HRelation *self, const gchar *name);
  guint       (*get_degree)     (HRelation *self);
  guint       (*get_size)       (HRelation *self);
  void        (*for_each_attr)  (HRelation *self, HAttrFunc  func, gpointer user_data);
  void        (*for_each_tuple) (HRelation *self, HTupleFunc func, gpointer user_data);
  void        (*insert_tuple)   (HRelation *self, HTuple *tuple);
  void        (*delete_tuple)   (HRelation *self, HTuple *tuple);
};

#define h_relation_get_n_attrs(relation) h_relation_get_degree (relation)
#define h_relation_ref(relation)         g_object_ref (relation)
#define h_relation_unref(relation)       g_object_unref (relation)

GType       h_relation_get_type       (void);
void        h_relation_set_name       (HRelation   *relation,
                                       const gchar *name);
void        h_relation_set_desc       (HRelation   *relation,
                                       const gchar *desc);
gchar      *h_relation_get_name       (HRelation   *relation);
gchar      *h_relation_get_desc       (HRelation   *relation);
HAttribute *h_relation_get_attr       (HRelation   *relation,
                                       const gchar *name);
void        h_relation_print          (HRelation   *relation);
void        h_relation_for_each_attr  (HRelation   *relation,
                                       HAttrFunc    func,
                                       gpointer     user_data);
void        h_relation_for_each_tuple (HRelation   *relation,
                                       HTupleFunc   func,
                                       gpointer     user_data);
guint       h_relation_get_size       (HRelation   *relation);
guint       h_relation_get_degree     (HRelation   *relation);

G_END_DECLS

#include <libhrel/relation_base.h>
#include <libhrel/relation_sort.h>
#include <libhrel/relation_restrict.h>
#include <libhrel/relation_project.h>

#endif /* #ifndef H_RELATION_H */
