/* sql-operator.c generated by valac 0.32.1, 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;
#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;
enum  {
	RYGEL_DATABASE_SQL_OPERATOR_DUMMY_PROPERTY
};
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;
	const gchar* _tmp0_ = NULL;
	gchar* _tmp1_ = NULL;
	const gchar* _tmp2_ = NULL;
	gchar* _tmp3_ = NULL;
	const gchar* _tmp4_ = NULL;
	gchar* _tmp5_ = NULL;
	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_ = name;
	_tmp1_ = g_strdup (_tmp0_);
	_g_free0 (self->name);
	self->name = _tmp1_;
	_tmp2_ = arg;
	_tmp3_ = g_strdup (_tmp2_);
	_g_free0 (self->arg);
	self->arg = _tmp3_;
	_tmp4_ = collate;
	_tmp5_ = g_strdup (_tmp4_);
	_g_free0 (self->collate);
	self->collate = _tmp5_;
	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;
	GUPnPSearchCriteriaOp _tmp0_ = 0;
	const gchar* _tmp7_ = NULL;
	const gchar* _tmp8_ = NULL;
	const gchar* _tmp9_ = NULL;
	g_return_val_if_fail (arg != NULL, NULL);
	g_return_val_if_fail (collate != NULL, NULL);
	sql = NULL;
	_tmp0_ = op;
	switch (_tmp0_) {
		case GUPNP_SEARCH_CRITERIA_OP_EQ:
		{
			gchar* _tmp1_ = NULL;
			_tmp1_ = g_strdup ("=");
			_g_free0 (sql);
			sql = _tmp1_;
			break;
		}
		case GUPNP_SEARCH_CRITERIA_OP_NEQ:
		{
			gchar* _tmp2_ = NULL;
			_tmp2_ = g_strdup ("!=");
			_g_free0 (sql);
			sql = _tmp2_;
			break;
		}
		case GUPNP_SEARCH_CRITERIA_OP_LESS:
		{
			gchar* _tmp3_ = NULL;
			_tmp3_ = g_strdup ("<");
			_g_free0 (sql);
			sql = _tmp3_;
			break;
		}
		case GUPNP_SEARCH_CRITERIA_OP_LEQ:
		{
			gchar* _tmp4_ = NULL;
			_tmp4_ = g_strdup ("<=");
			_g_free0 (sql);
			sql = _tmp4_;
			break;
		}
		case GUPNP_SEARCH_CRITERIA_OP_GREATER:
		{
			gchar* _tmp5_ = NULL;
			_tmp5_ = g_strdup (">");
			_g_free0 (sql);
			sql = _tmp5_;
			break;
		}
		case GUPNP_SEARCH_CRITERIA_OP_GEQ:
		{
			gchar* _tmp6_ = NULL;
			_tmp6_ = g_strdup (">=");
			_g_free0 (sql);
			sql = _tmp6_;
			break;
		}
		default:
		{
			g_assert_not_reached ();
		}
	}
	_tmp7_ = sql;
	_tmp8_ = arg;
	_tmp9_ = collate;
	self = (RygelDatabaseSqlOperator*) rygel_database_sql_operator_construct (object_type, _tmp7_, _tmp8_, _tmp9_);
	_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_ = NULL;
	const gchar* _tmp1_ = NULL;
	const gchar* _tmp2_ = NULL;
	gchar* _tmp3_ = NULL;
	_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 = 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;
}



