gda-holder.h 5.82 KB
Newer Older
1
/*
2
 * Copyright (C) 2008 Massimo Cora <maxcvs@email.it>
3
 * Copyright (C) 2008 - 2012 Vivien Malerba <malerba@gnome-db.org>
4
 *
5 6 7 8
 * 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 of the License, or (at your option) any later version.
9
 *
10
 * This library is distributed in the hope that it will be useful,
11 12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
 * Lesser General Public License for more details.
14
 *
15 16 17 18
 * 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 St, Fifth Floor,
 * Boston, MA  02110-1301, USA.
19 20 21 22 23 24 25
 */


#ifndef __GDA_HOLDER_H_
#define __GDA_HOLDER_H_

#include <libgda/gda-decl.h>
26
#include <libgda/gda-data-handler.h>
27 28 29 30 31 32 33 34 35
#include "gda-value.h"

G_BEGIN_DECLS

/* error reporting */
extern GQuark gda_holder_error_quark (void);
#define GDA_HOLDER_ERROR gda_holder_error_quark ()

typedef enum {
36 37 38
	GDA_HOLDER_STRING_CONVERSION_ERROR,
	GDA_HOLDER_VALUE_TYPE_ERROR,
	GDA_HOLDER_VALUE_NULL_ERROR
39 40
} GdaHolderError;

41 42
#define GDA_TYPE_HOLDER          (gda_holder_get_type())
G_DECLARE_DERIVABLE_TYPE(GdaHolder, gda_holder, GDA, HOLDER, GObject)
43 44 45 46 47 48 49 50


/* struct for the object's class */
struct _GdaHolderClass
{
	GObjectClass               parent_class;
	void                     (*changed)          (GdaHolder *holder);
	void                     (*source_changed)   (GdaHolder *holder);
51
	GError                  *(*validate_change)  (GdaHolder *holder, const GValue *new_value);
52
	void                     (*att_changed)      (GdaHolder *holder, const gchar *att_name, const GValue *att_value);
53

54
	/*< private >*/
55 56 57 58 59
	/* Padding for future expansion */
	void (*_gda_reserved1) (void);
	void (*_gda_reserved2) (void);
	void (*_gda_reserved3) (void);
	void (*_gda_reserved4) (void);
60 61
};

62 63 64 65 66 67 68 69 70 71 72 73
/**
 * SECTION:gda-holder
 * @short_description: Container for a single #GValue
 * @title: GdaHolder
 * @stability: Stable
 * @see_also: The #GdaSet object which "groups" several #GdaHolder objects 
 *
 * The #GdaHolder is a container for a single #GValue value. It also specifies various attributes
 * of the contained value (default value, ...)
 *
 * The type of a #GdaHolder has to be set and cannot be modified, except if it's initialized
 * with a GDA_TYPE_NULL GType (representing NULL values) where it can be changed once to a real GType.
74 75
 *
 * Each GdaHolder object is thread safe.
76 77
 */

78
GdaHolder          *gda_holder_new                     (GType type, const gchar *id);
79 80 81 82 83
GdaHolder          *gda_holder_new_inline              (GType type, const gchar *id, ...);
GdaHolder          *gda_holder_copy                    (GdaHolder *orig);

GType               gda_holder_get_g_type              (GdaHolder *holder);
const gchar        *gda_holder_get_id                  (GdaHolder *holder);
84 85
gchar *             gda_holder_get_alphanum_id         (GdaHolder *holder);

86

Vivien Malerba's avatar
Vivien Malerba committed
87
/**
88
 * gda_holder_new_string:
Vivien Malerba's avatar
Vivien Malerba committed
89 90 91 92 93 94 95 96
 * @id: a string
 * @str: a string
 * 
 * Creates a new boolean #GdaHolder object with an ID set to @id, and a value initialized to 
 * @str.
 *
 * Returns: a new #GdaHolder
 */
97
#define gda_holder_new_string(id,str) gda_holder_new_inline (G_TYPE_STRING, (id), (str))
Vivien Malerba's avatar
Vivien Malerba committed
98 99

/**
100
 * gda_holder_new_boolean:
Vivien Malerba's avatar
Vivien Malerba committed
101 102 103 104 105 106 107 108
 * @id: a string
 * @abool: a boolean value
 * 
 * Creates a new boolean #GdaHolder object with an ID set to @id, and a value initialized to 
 * @abool.
 *
 * Returns: a new #GdaHolder
 */
109
#define gda_holder_new_boolean(id,abool) gda_holder_new_inline (G_TYPE_BOOLEAN, (id), (abool))
Vivien Malerba's avatar
Vivien Malerba committed
110 111

/**
112
 * gda_holder_new_int:
Vivien Malerba's avatar
Vivien Malerba committed
113 114 115 116 117 118 119 120
 * @id: a string
 * @anint: an int value
 * 
 * Creates a new boolean #GdaHolder object with an ID set to @id, and a value initialized to 
 * @anint.
 *
 * Returns: a new #GdaHolder
 */
121 122 123
#define gda_holder_new_int(id,anint) gda_holder_new_inline (G_TYPE_INT, (id), (anint))

const GValue       *gda_holder_get_value               (GdaHolder *holder);
124
gchar              *gda_holder_get_value_str           (GdaHolder *holder, GdaDataHandler *dh);
125 126
gboolean            gda_holder_set_value               (GdaHolder *holder, const GValue *value, GError **error);
gboolean            gda_holder_take_value              (GdaHolder *holder, GValue *value, GError **error);
127
GValue             *gda_holder_take_static_value       (GdaHolder *holder, const GValue *value, gboolean *value_changed, GError **error);
128
gboolean            gda_holder_set_value_str           (GdaHolder *holder, GdaDataHandler *dh, const gchar *value, GError **error);
129 130 131 132 133 134 135

const GValue       *gda_holder_get_default_value       (GdaHolder *holder);
void                gda_holder_set_default_value       (GdaHolder *holder, const GValue *value);
gboolean            gda_holder_set_value_to_default    (GdaHolder *holder);
gboolean            gda_holder_value_is_default        (GdaHolder *holder);

void                gda_holder_force_invalid           (GdaHolder *holder);
136
void                gda_holder_force_invalid_e         (GdaHolder *holder, GError *error);
137
gboolean            gda_holder_is_valid                (GdaHolder *holder);
138
gboolean            gda_holder_is_valid_e              (GdaHolder *holder, GError **error);
139 140 141 142 143 144 145 146 147


void                gda_holder_set_not_null            (GdaHolder *holder, gboolean not_null);
gboolean            gda_holder_get_not_null            (GdaHolder *holder);

gboolean            gda_holder_set_source_model         (GdaHolder *holder, GdaDataModel *model,
							 gint col, GError **error);
GdaDataModel       *gda_holder_get_source_model         (GdaHolder *holder, gint *col);

148
gboolean            gda_holder_set_bind                 (GdaHolder *holder, GdaHolder *bind_to, GError **error);
149 150 151 152 153
GdaHolder          *gda_holder_get_bind                 (GdaHolder *holder);

G_END_DECLS

#endif