Add properties

svn path=/trunk/; revision=6006
This commit is contained in:
Matthias Clasen 2007-12-01 05:25:40 +00:00
parent 650c65e892
commit d8266ffb8f
2 changed files with 51 additions and 24 deletions

View File

@ -1,3 +1,7 @@
2007-12-01 Matthias Clasen <mclasen@redhat.com>
* gbufferedoutputstream.c: Add properties
2007-11-30 Matthias Clasen <mclasen@redhat.com>
* *.c: Unify the capitalization of section headings.

View File

@ -39,19 +39,17 @@
*
* By default, #GBufferedOutputStream's buffer size is set at 4 kilobytes.
*
* To create a buffered output stream, use g_buffered_output_stream_new(), or
* g_buffered_output_stream_new_sized() to specify the buffer's size at construction.
* To create a buffered output stream, use g_buffered_output_stream_new(),
* or g_buffered_output_stream_new_sized() to specify the buffer's size
* at construction.
*
* To get the size of a buffer within a buffered input stream, use
* g_buffered_output_stream_get_buffer_size(). To change the size of a
* buffered output stream's buffer, use g_buffered_output_stream_set_buffer_size().
* Note: the buffer's size cannot be reduced below the size of the data within the
* buffer.
*
* buffered output stream's buffer, use
* g_buffered_output_stream_set_buffer_size(). Note that the buffer's
* size cannot be reduced below the size of the data within the buffer.
**/
#define DEFAULT_BUFFER_SIZE 4096
struct _GBufferedOutputStreamPrivate {
@ -63,7 +61,8 @@ struct _GBufferedOutputStreamPrivate {
enum {
PROP_0,
PROP_BUFSIZE
PROP_BUFSIZE,
PROP_AUTO_GROW
};
static void g_buffered_output_stream_set_property (GObject *object,
@ -157,6 +156,15 @@ g_buffered_output_stream_class_init (GBufferedOutputStreamClass *klass)
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB));
g_object_class_install_property (object_class,
PROP_AUTO_GROW,
g_param_spec_boolean ("auto-grow",
P_("Auto-grow"),
P_("Whether the buffer should automatically grow"),
FALSE,
G_PARAM_READWRITE|
G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB));
}
/**
@ -193,6 +201,9 @@ g_buffered_output_stream_set_buffer_size (GBufferedOutputStream *stream,
priv = stream->priv;
if (size == priv->len)
return;
if (priv->buffer)
{
size = MAX (size, priv->pos);
@ -210,6 +221,8 @@ g_buffered_output_stream_set_buffer_size (GBufferedOutputStream *stream,
priv->len = size;
priv->pos = 0;
}
g_object_notify (G_OBJECT (stream), "buffer-size");
}
/**
@ -240,9 +253,15 @@ void
g_buffered_output_stream_set_auto_grow (GBufferedOutputStream *stream,
gboolean auto_grow)
{
GBufferedOutputStreamPrivate *priv;
g_return_if_fail (G_IS_BUFFERED_OUTPUT_STREAM (stream));
stream->priv->auto_grow = auto_grow;
priv = stream->priv;
auto_grow = auto_grow != FALSE;
if (priv->auto_grow != auto_grow)
{
priv->auto_grow = auto_grow;
g_object_notify (G_OBJECT (stream), "auto-grow");
}
}
static void
@ -251,17 +270,18 @@ g_buffered_output_stream_set_property (GObject *object,
const GValue *value,
GParamSpec *pspec)
{
GBufferedOutputStream *buffered_stream;
GBufferedOutputStreamPrivate *priv;
GBufferedOutputStream *stream;
buffered_stream = G_BUFFERED_OUTPUT_STREAM (object);
priv = buffered_stream->priv;
stream = G_BUFFERED_OUTPUT_STREAM (object);
switch (prop_id)
{
case PROP_BUFSIZE:
g_buffered_output_stream_set_buffer_size (buffered_stream, g_value_get_uint (value));
g_buffered_output_stream_set_buffer_size (stream, g_value_get_uint (value));
break;
case PROP_AUTO_GROW:
g_buffered_output_stream_set_auto_grow (stream, g_value_get_boolean (value));
break;
default:
@ -285,11 +305,14 @@ g_buffered_output_stream_get_property (GObject *object,
switch (prop_id)
{
case PROP_BUFSIZE:
g_value_set_uint (value, priv->len);
break;
case PROP_AUTO_GROW:
g_value_set_boolean (value, priv->auto_grow);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;