[gnome-builder/wip/slaf/xml-pack: 24/56] xml-pack: IdeXmlSchema object



commit e90b26939037a98009a305ae32ac1261c2a17f45
Author: Sebastien Lafargue <slafargue gnome org>
Date:   Sun May 14 23:10:16 2017 +0200

    xml-pack: IdeXmlSchema object
    
    Used to store rng parser result

 plugins/xml-pack/ide-xml-schema.c |   78 +++++++++++++++++++++++++++++++++++++
 plugins/xml-pack/ide-xml-schema.h |   49 +++++++++++++++++++++++
 plugins/xml-pack/meson.build      |    2 +
 3 files changed, 129 insertions(+), 0 deletions(-)
---
diff --git a/plugins/xml-pack/ide-xml-schema.c b/plugins/xml-pack/ide-xml-schema.c
new file mode 100644
index 0000000..cf42bd3
--- /dev/null
+++ b/plugins/xml-pack/ide-xml-schema.c
@@ -0,0 +1,78 @@
+/* ide-xml-schema.c
+ *
+ * Copyright (C) 2017 Sebastien Lafargue <slafargue gnome org>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "ide-xml-schema.h"
+
+G_DEFINE_BOXED_TYPE (IdeXmlSchema, ide_xml_schema, ide_xml_schema_ref, ide_xml_schema_unref)
+
+IdeXmlSchema *
+ide_xml_schema_new (void)
+{
+  IdeXmlSchema *self;
+
+  self = g_slice_new0 (IdeXmlSchema);
+  self->ref_count = 1;
+
+  return self;
+}
+
+IdeXmlSchema *
+ide_xml_schema_copy (IdeXmlSchema *self)
+{
+  IdeXmlSchema *copy;
+
+  g_return_val_if_fail (self, NULL);
+  g_return_val_if_fail (self->ref_count, NULL);
+
+  copy = ide_xml_schema_new ();
+
+  return copy;
+}
+
+static void
+ide_xml_schema_free (IdeXmlSchema *self)
+{
+  g_assert (self);
+  g_assert_cmpint (self->ref_count, ==, 0);
+
+  if (self->top_grammar != NULL)
+    ide_xml_rng_grammar_unref (self->top_grammar);
+
+  g_slice_free (IdeXmlSchema, self);
+}
+
+IdeXmlSchema *
+ide_xml_schema_ref (IdeXmlSchema *self)
+{
+  g_return_val_if_fail (self, NULL);
+  g_return_val_if_fail (self->ref_count, NULL);
+
+  g_atomic_int_inc (&self->ref_count);
+
+  return self;
+}
+
+void
+ide_xml_schema_unref (IdeXmlSchema *self)
+{
+  g_return_if_fail (self);
+  g_return_if_fail (self->ref_count);
+
+  if (g_atomic_int_dec_and_test (&self->ref_count))
+    ide_xml_schema_free (self);
+}
diff --git a/plugins/xml-pack/ide-xml-schema.h b/plugins/xml-pack/ide-xml-schema.h
new file mode 100644
index 0000000..afc3f83
--- /dev/null
+++ b/plugins/xml-pack/ide-xml-schema.h
@@ -0,0 +1,49 @@
+/* ide-xml-schema.h
+ *
+ * Copyright (C) 2017 Sebastien Lafargue <slafargue gnome org>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef IDE_XML_SCHEMA_H
+#define IDE_XML_SCHEMA_H
+
+#include <glib.h>
+#include <glib-object.h>
+
+#include "ide-xml-rng-grammar.h"
+
+G_BEGIN_DECLS
+
+#define IDE_TYPE_XML_SCHEMA (ide_xml_schema_get_type())
+
+typedef struct _IdeXmlSchema IdeXmlSchema;
+
+struct _IdeXmlSchema
+{
+  guint             ref_count;
+
+  IdeXmlRngGrammar *top_grammar;
+};
+
+IdeXmlSchema     *ide_xml_schema_new   (void);
+IdeXmlSchema     *ide_xml_schema_copy  (IdeXmlSchema *self);
+IdeXmlSchema     *ide_xml_schema_ref   (IdeXmlSchema *self);
+void              ide_xml_schema_unref (IdeXmlSchema *self);
+
+G_DEFINE_AUTOPTR_CLEANUP_FUNC (IdeXmlSchema, ide_xml_schema_unref)
+
+G_END_DECLS
+
+#endif /* IDE_XML_SCHEMA_H */
diff --git a/plugins/xml-pack/meson.build b/plugins/xml-pack/meson.build
index 9d32387..48d583c 100644
--- a/plugins/xml-pack/meson.build
+++ b/plugins/xml-pack/meson.build
@@ -25,6 +25,8 @@ xml_pack_sources = [
   'ide-xml-rng-grammar.h',
   'ide-xml-sax.c',
   'ide-xml-sax.h',
+  'ide-xml-schema.c',
+  'ide-xml-schema.h',
   'ide-xml-schema-cache-entry.c',
   'ide-xml-schema-cache-entry.h',
   'ide-xml-service.c',


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]