[tepl] File loading: implement TeplFileContent private class
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tepl] File loading: implement TeplFileContent private class
- Date: Fri, 20 Oct 2017 14:50:01 +0000 (UTC)
commit b6f2f14c16f2949ce1a5f62648f1470c056bc363
Author: Sébastien Wilmet <swilmet gnome org>
Date: Fri Oct 20 14:12:07 2017 +0200
File loading: implement TeplFileContent private class
It'll permit to delegate some work to this class.
docs/reference/Makefile.am | 1 +
po/POTFILES.in | 1 +
tepl/Makefile.am | 2 +
tepl/tepl-file-content.c | 82 ++++++++++++++++++++++++++++++++++++++++++++
tepl/tepl-file-content.h | 65 ++++++++++++++++++++++++++++++++++
5 files changed, 151 insertions(+), 0 deletions(-)
---
diff --git a/docs/reference/Makefile.am b/docs/reference/Makefile.am
index 96ca0b7..ff8783e 100644
--- a/docs/reference/Makefile.am
+++ b/docs/reference/Makefile.am
@@ -29,6 +29,7 @@ IGNORE_HFILES = \
tepl-buffer-input-stream.h \
tepl-encoding-converter.h \
tepl-encoding-private.h \
+ tepl-file-content.h \
tepl-file-content-loader.h \
tepl-io-error-info-bar.h \
tepl-progress-info-bar.h \
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 07ab488..02a9bde 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -17,6 +17,7 @@ tepl/tepl-buffer-input-stream.c
tepl/tepl-encoding.c
tepl/tepl-encoding-converter.c
tepl/tepl-file.c
+tepl/tepl-file-content.c
tepl/tepl-file-content-loader.c
tepl/tepl-file-loader.c
tepl/tepl-file-metadata.c
diff --git a/tepl/Makefile.am b/tepl/Makefile.am
index f0b6b59..21423d7 100644
--- a/tepl/Makefile.am
+++ b/tepl/Makefile.am
@@ -64,6 +64,7 @@ tepl_private_headers = \
tepl-buffer-input-stream.h \
tepl-encoding-converter.h \
tepl-encoding-private.h \
+ tepl-file-content.h \
tepl-file-content-loader.h \
tepl-io-error-info-bar.h \
tepl-progress-info-bar.h \
@@ -72,6 +73,7 @@ tepl_private_headers = \
tepl_private_c_files = \
tepl-buffer-input-stream.c \
tepl-encoding-converter.c \
+ tepl-file-content.c \
tepl-file-content-loader.c \
tepl-io-error-info-bar.c \
tepl-progress-info-bar.c \
diff --git a/tepl/tepl-file-content.c b/tepl/tepl-file-content.c
new file mode 100644
index 0000000..74efdae
--- /dev/null
+++ b/tepl/tepl-file-content.c
@@ -0,0 +1,82 @@
+/*
+ * This file is part of Tepl, a text editor library.
+ *
+ * Copyright 2017 - Sébastien Wilmet <swilmet gnome org>
+ *
+ * Tepl 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.
+ *
+ * Tepl 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "tepl-file-content.h"
+
+struct _TeplFileContentPrivate
+{
+ /* List of GBytes*. */
+ GQueue *chunks;
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE (TeplFileContent, _tepl_file_content, G_TYPE_OBJECT)
+
+static void
+_tepl_file_content_finalize (GObject *object)
+{
+ TeplFileContent *content = TEPL_FILE_CONTENT (object);
+
+ if (content->priv->chunks != NULL)
+ {
+ g_queue_free_full (content->priv->chunks, (GDestroyNotify)g_bytes_unref);
+ content->priv->chunks = NULL;
+ }
+
+ G_OBJECT_CLASS (_tepl_file_content_parent_class)->finalize (object);
+}
+
+static void
+_tepl_file_content_class_init (TeplFileContentClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->finalize = _tepl_file_content_finalize;
+}
+
+static void
+_tepl_file_content_init (TeplFileContent *content)
+{
+ content->priv = _tepl_file_content_get_instance_private (content);
+
+ content->priv->chunks = g_queue_new ();
+}
+
+TeplFileContent *
+_tepl_file_content_new (void)
+{
+ return g_object_new (TEPL_TYPE_FILE_CONTENT, NULL);
+}
+
+void
+_tepl_file_content_add_chunk (TeplFileContent *content,
+ GBytes *chunk)
+{
+ g_return_if_fail (TEPL_IS_FILE_CONTENT (content));
+ g_return_if_fail (chunk != NULL);
+
+ g_queue_push_tail (content->priv->chunks, g_bytes_ref (chunk));
+}
+
+GQueue *
+_tepl_file_content_get_chunks (TeplFileContent *content)
+{
+ g_return_val_if_fail (TEPL_IS_FILE_CONTENT (content), NULL);
+
+ return content->priv->chunks;
+}
diff --git a/tepl/tepl-file-content.h b/tepl/tepl-file-content.h
new file mode 100644
index 0000000..a9ee7d2
--- /dev/null
+++ b/tepl/tepl-file-content.h
@@ -0,0 +1,65 @@
+/*
+ * This file is part of Tepl, a text editor library.
+ *
+ * Copyright 2017 - Sébastien Wilmet <swilmet gnome org>
+ *
+ * Tepl 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.
+ *
+ * Tepl 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef TEPL_FILE_CONTENT_H
+#define TEPL_FILE_CONTENT_H
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define TEPL_TYPE_FILE_CONTENT (_tepl_file_content_get_type ())
+#define TEPL_FILE_CONTENT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TEPL_TYPE_FILE_CONTENT,
TeplFileContent))
+#define TEPL_FILE_CONTENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TEPL_TYPE_FILE_CONTENT,
TeplFileContentClass))
+#define TEPL_IS_FILE_CONTENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TEPL_TYPE_FILE_CONTENT))
+#define TEPL_IS_FILE_CONTENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TEPL_TYPE_FILE_CONTENT))
+#define TEPL_FILE_CONTENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TEPL_TYPE_FILE_CONTENT,
TeplFileContentClass))
+
+typedef struct _TeplFileContent TeplFileContent;
+typedef struct _TeplFileContentClass TeplFileContentClass;
+typedef struct _TeplFileContentPrivate TeplFileContentPrivate;
+
+struct _TeplFileContent
+{
+ GObject parent;
+
+ TeplFileContentPrivate *priv;
+};
+
+struct _TeplFileContentClass
+{
+ GObjectClass parent_class;
+};
+
+G_GNUC_INTERNAL
+GType _tepl_file_content_get_type (void);
+
+G_GNUC_INTERNAL
+TeplFileContent * _tepl_file_content_new (void);
+
+G_GNUC_INTERNAL
+void _tepl_file_content_add_chunk (TeplFileContent *content,
+ GBytes *chunk);
+
+G_GNUC_INTERNAL
+GQueue * _tepl_file_content_get_chunks (TeplFileContent *content);
+
+G_END_DECLS
+
+#endif /* TEPL_FILE_CONTENT_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]