/* sql-operator.c generated by valac 0.40.8, the Vala compiler
 * generated from sql-operator.vala, do not modify */

/*
 * Copyright (C) 2010 Jens Georg <mail@jensge.org>.
 *
 * Author: Jens Georg <mail@jensge.org>
 *
 * This file is part of Rygel.
 *
 * Rygel 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.
 *
 * Rygel 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */


#include <glib.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <libgupnp-av/gupnp-av.h>


#define RYGEL_DATABASE_TYPE_SQL_OPERATOR (rygel_database_sql_operator_get_type ())
#define RYGEL_DATABASE_SQL_OPERATOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), RYGEL_DATABASE_TYPE_SQL_OPERATOR, RygelDatabaseSqlOperator))
#define RYGEL_DATABASE_SQL_OPERATOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), RYGEL_DATABASE_TYPE_SQL_OPERATOR, RygelDatabaseSqlOperatorClass))
#define RYGEL_DATABASE_IS_SQL_OPERATOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), RYGEL_DATABASE_TYPE_SQL_OPERATOR))
#define RYGEL_DATABASE_IS_SQL_OPERATOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), RYGEL_DATABASE_TYPE_SQL_OPERATOR))
#define RYGEL_DATABASE_SQL_OPERATOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), RYGEL_DATABASE_TYPE_SQL_OPERATOR, RygelDatabaseSqlOperatorClass))

typedef struct _RygelDatabaseSqlOperator RygelDatabaseSqlOperator;
typedef struct _RygelDatabaseSqlOperatorClass RygelDatabaseSqlOperatorClass;
typedef struct _RygelDatabaseSqlOperatorPrivate RygelDatabaseSqlOperatorPrivate;
enum  {
	RYGEL_DATABASE_SQL_OPERATOR_0_PROPERTY,
	RYGEL_DATABASE_SQL_OPERATOR_NUM_PROPERTIES
};
static GParamSpec* rygel_database_sql_operator_properties[RYGEL_DATABASE_SQL_OPERATOR_NUM_PROPERTIES];
#define _g_free0(var) (var = (g_free (var), NULL))

struct _RygelDatabaseSqlOperator {
	GObject parent_instance;
	RygelDatabaseSqlOperatorPrivate * priv;
	gchar* name;
	gchar* arg;
	gchar* collate;
};

struct _RygelDatabaseSqlOperatorClass {
	GObjectClass parent_class;
	gchar* (*to_string) (RygelDatabaseSqlOperator* self);
};


static gpointer rygel_database_sql_operator_parent_class = NULL;

GType rygel_database_sql_operator_get_type (void) G_GNUC_CONST;
RygelDatabaseSqlOperator* rygel_database_sql_operator_new (const gchar* name,
                                                           const gchar* arg,
                                                           const gchar* collate);
RygelDatabaseSqlOperator* rygel_database_sql_operator_construct (GType object_type,
                                                                 const gchar* name,
                                                                 const gchar* arg,
                                                                 const gchar* collate);
RygelDatabaseSqlOperator* rygel_database_sql_operator_new_from_search_criteria_op (GUPnPSearchCriteriaOp op,
                                                                                   const gchar* arg,
                                                                                   const gchar* collate);
RygelDatabaseSqlOperator* rygel_database_sql_operator_construct_from_search_criteria_op (GType object_type,
                                                                                         GUPnPSearchCriteriaOp op,
                                                                                         const gchar* arg,
                                                                                         const gchar* collate);
gchar* rygel_database_sql_operator_to_string (RygelDatabaseSqlOperator* self);
static gchar* rygel_database_sql_operator_real_to_string (RygelDatabaseSqlOperator* self);
static void rygel_database_sql_operator_finalize (GObject * obj);


RygelDatabaseSqlOperator*
rygel_database_sql_operator_construct (GType object_type,
                                       const gchar* name,
                                       const gchar* arg,
                                       const gchar* collate)
{
	RygelDatabaseSqlOperator * self = NULL;
	gchar* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	g_return_val_if_fail (name != NULL, NULL);
	g_return_val_if_fail (arg != NULL, NULL);
	g_return_val_if_fail (collate != NULL, NULL);
	self = (RygelDatabaseSqlOperator*) g_object_new (object_type, NULL);
	_tmp0_ = g_strdup (name);
	_g_free0 (self->name);
	self->name = _tmp0_;
	_tmp1_ = g_strdup (arg);
	_g_free0 (self->arg);
	self->arg = _tmp1_;
	_tmp2_ = g_strdup (collate);
	_g_free0 (self->collate);
	self->collate = _tmp2_;
	return self;
}


RygelDatabaseSqlOperator*
rygel_database_sql_operator_new (const gchar* name,
                                 const gchar* arg,
                                 const gchar* collate)
{
	return rygel_database_sql_operator_construct (RYGEL_DATABASE_TYPE_SQL_OPERATOR, name, arg, collate);
}


RygelDatabaseSqlOperator*
rygel_database_sql_operator_construct_from_search_criteria_op (GType object_type,
                                                               GUPnPSearchCriteriaOp op,
                                                               const gchar* arg,
                                                               const gchar* collate)
{
	RygelDatabaseSqlOperator * self = NULL;
	gchar* sql = NULL;
	const gchar* _tmp6_;
	g_return_val_if_fail (arg != NULL, NULL);
	g_return_val_if_fail (collate != NULL, NULL);
	sql = NULL;
	switch (op) {
		case GUPNP_SEARCH_CRITERIA_OP_EQ:
		{
			gchar* _tmp0_;
			_tmp0_ = g_strdup ("=");
			_g_free0 (sql);
			sql = _tmp0_;
			break;
		}
		case GUPNP_SEARCH_CRITERIA_OP_NEQ:
		{
			gchar* _tmp1_;
			_tmp1_ = g_strdup ("!=");
			_g_free0 (sql);
			sql = _tmp1_;
			break;
		}
		case GUPNP_SEARCH_CRITERIA_OP_LESS:
		{
			gchar* _tmp2_;
			_tmp2_ = g_strdup ("<");
			_g_free0 (sql);
			sql = _tmp2_;
			break;
		}
		case GUPNP_SEARCH_CRITERIA_OP_LEQ:
		{
			gchar* _tmp3_;
			_tmp3_ = g_strdup ("<=");
			_g_free0 (sql);
			sql = _tmp3_;
			break;
		}
		case GUPNP_SEARCH_CRITERIA_OP_GREATER:
		{
			gchar* _tmp4_;
			_tmp4_ = g_strdup (">");
			_g_free0 (sql);
			sql = _tmp4_;
			break;
		}
		case GUPNP_SEARCH_CRITERIA_OP_GEQ:
		{
			gchar* _tmp5_;
			_tmp5_ = g_strdup (">=");
			_g_free0 (sql);
			sql = _tmp5_;
			break;
		}
		default:
		{
			g_assert_not_reached ();
		}
	}
	_tmp6_ = sql;
	self = (RygelDatabaseSqlOperator*) rygel_database_sql_operator_construct (object_type, _tmp6_, arg, collate);
	_g_free0 (sql);
	return self;
}


RygelDatabaseSqlOperator*
rygel_database_sql_operator_new_from_search_criteria_op (GUPnPSearchCriteriaOp op,
                                                         const gchar* arg,
                                                         const gchar* collate)
{
	return rygel_database_sql_operator_construct_from_search_criteria_op (RYGEL_DATABASE_TYPE_SQL_OPERATOR, op, arg, collate);
}


static gchar*
rygel_database_sql_operator_real_to_string (RygelDatabaseSqlOperator* self)
{
	gchar* result = NULL;
	const gchar* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	gchar* _tmp3_;
	_tmp0_ = self->arg;
	_tmp1_ = self->name;
	_tmp2_ = self->collate;
	_tmp3_ = g_strdup_printf ("(%s %s ? %s)", _tmp0_, _tmp1_, _tmp2_);
	result = _tmp3_;
	return result;
}


gchar*
rygel_database_sql_operator_to_string (RygelDatabaseSqlOperator* self)
{
	g_return_val_if_fail (self != NULL, NULL);
	return RYGEL_DATABASE_SQL_OPERATOR_GET_CLASS (self)->to_string (self);
}


static void
rygel_database_sql_operator_class_init (RygelDatabaseSqlOperatorClass * klass)
{
	rygel_database_sql_operator_parent_class = g_type_class_peek_parent (klass);
	((RygelDatabaseSqlOperatorClass *) klass)->to_string = (gchar* (*) (RygelDatabaseSqlOperator *)) rygel_database_sql_operator_real_to_string;
	G_OBJECT_CLASS (klass)->finalize = rygel_database_sql_operator_finalize;
}


static void
rygel_database_sql_operator_instance_init (RygelDatabaseSqlOperator * self)
{
}


static void
rygel_database_sql_operator_finalize (GObject * obj)
{
	RygelDatabaseSqlOperator * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, RYGEL_DATABASE_TYPE_SQL_OPERATOR, RygelDatabaseSqlOperator);
	_g_free0 (self->name);
	_g_free0 (self->arg);
	_g_free0 (self->collate);
	G_OBJECT_CLASS (rygel_database_sql_operator_parent_class)->finalize (obj);
}


GType
rygel_database_sql_operator_get_type (void)
{
	static volatile gsize rygel_database_sql_operator_type_id__volatile = 0;
	if (g_once_init_enter (&rygel_database_sql_operator_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (RygelDatabaseSqlOperatorClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) rygel_database_sql_operator_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (RygelDatabaseSqlOperator), 0, (GInstanceInitFunc) rygel_database_sql_operator_instance_init, NULL };
		GType rygel_database_sql_operator_type_id;
		rygel_database_sql_operator_type_id = g_type_register_static (G_TYPE_OBJECT, "RygelDatabaseSqlOperator", &g_define_type_info, 0);
		g_once_init_leave (&rygel_database_sql_operator_type_id__volatile, rygel_database_sql_operator_type_id);
	}
	return rygel_database_sql_operator_type_id__volatile;
}



