[template-glib] scope: Add helpers for setting symbols
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [template-glib] scope: Add helpers for setting symbols
- Date: Wed, 19 Oct 2016 21:37:19 +0000 (UTC)
commit 8ac08e8f1b18862bfb15297fea5c60c6fb17d098
Author: Guillaume Poirier-Morency <guillaumepoiriermorency gmail com>
Date: Tue Sep 13 10:01:36 2016 -0400
scope: Add helpers for setting symbols
src/tmpl-scope.c | 90 ++++++++++++++++++++++++++++++++++++++++++++++-------
src/tmpl-scope.h | 15 +++++++++
2 files changed, 93 insertions(+), 12 deletions(-)
---
diff --git a/src/tmpl-scope.c b/src/tmpl-scope.c
index a4a0792..f62e6c8 100644
--- a/src/tmpl-scope.c
+++ b/src/tmpl-scope.c
@@ -133,7 +133,8 @@ tmpl_scope_get_full (TmplScope *self,
if (parent->resolver)
{
if (parent->resolver (parent, name, &symbol, parent->resolver_data) && symbol)
- goto save_symbol;
+ tmpl_scope_set (self, name, symbol);
+ return symbol;
}
}
@@ -141,20 +142,10 @@ tmpl_scope_get_full (TmplScope *self,
{
/* Define the symbol in this scope */
symbol = tmpl_symbol_new ();
- goto save_symbol;
+ tmpl_scope_set (self, name, symbol);
}
return symbol;
-
-save_symbol:
- if (self->symbols == NULL)
- self->symbols = g_hash_table_new_full (g_str_hash,
- g_str_equal,
- g_free,
- (GDestroyNotify)tmpl_symbol_unref);
- g_hash_table_insert (self->symbols, g_strdup (name), symbol);
-
- return symbol;
}
/**
@@ -172,6 +163,81 @@ tmpl_scope_get (TmplScope *self,
}
/**
+ * tmpl_scope_set:
+ *
+ * If the symbol already exists, it will be overwritten.
+ *
+ * Parameter: (transfer none): #t
+ */
+void
+tmpl_scope_set (TmplScope *self,
+ const gchar *name,
+ TmplSymbol *symbol)
+{
+ if (self->symbols == NULL)
+ self->symbols = g_hash_table_new_full (g_str_hash,
+ g_str_equal,
+ g_free,
+ (GDestroyNotify) tmpl_symbol_unref);
+ g_hash_table_insert (self->symbols, g_strdup (name), symbol);
+}
+
+/**
+ * tmpl_scope_set_value:
+ */
+void
+tmpl_scope_set_value (TmplScope *self,
+ const gchar *name,
+ const GValue *symbol)
+{
+ tmpl_symbol_assign_value (tmpl_scope_get_full (self, name, TRUE), symbol);
+}
+
+/**
+ * tmpl_scope_set_boolean:
+ */
+void
+tmpl_scope_set_boolean (TmplScope *self,
+ const gchar *name,
+ gboolean symbol)
+{
+ tmpl_symbol_assign_boolean (tmpl_scope_get_full (self, name, TRUE), symbol);
+}
+
+/**
+ * tmpl_scope_set_double:
+ */
+void
+tmpl_scope_set_double (TmplScope *self,
+ const gchar *name,
+ gdouble symbol)
+{
+ tmpl_symbol_assign_double (tmpl_scope_get_full (self, name, TRUE), symbol);
+}
+
+/**
+ * tmpl_scope_set_object:
+ */
+void
+tmpl_scope_set_object (TmplScope *self,
+ const gchar *name,
+ gpointer symbol)
+{
+ tmpl_symbol_assign_object (tmpl_scope_get_full (self, name, TRUE), symbol);
+}
+
+/**
+ * tmpl_scope_set_string:
+ */
+void
+tmpl_scope_set_string (TmplScope *self,
+ const gchar *name,
+ const gchar *symbol)
+{
+ tmpl_symbol_assign_string (tmpl_scope_get_full (self, name, TRUE), symbol);
+}
+
+/**
* tmpl_scope_peek:
*
* If the symbol could not be found, %NULL is returned.
diff --git a/src/tmpl-scope.h b/src/tmpl-scope.h
index 12e1871..838fcf5 100644
--- a/src/tmpl-scope.h
+++ b/src/tmpl-scope.h
@@ -43,6 +43,21 @@ TmplSymbol *tmpl_scope_get (TmplScope *self,
void tmpl_scope_set (TmplScope *self,
const gchar *name,
TmplSymbol *symbol);
+void tmpl_scope_set_value (TmplScope *self,
+ const gchar *name,
+ const GValue *symbol);
+void tmpl_scope_set_boolean (TmplScope *self,
+ const gchar *name,
+ gboolean symbol);
+void tmpl_scope_set_double (TmplScope *self,
+ const gchar *name,
+ gdouble symbol);
+void tmpl_scope_set_string (TmplScope *self,
+ const gchar *name,
+ const gchar *symbol);
+void tmpl_scope_set_object (TmplScope *self,
+ const gchar *name,
+ gpointer symbol);
void tmpl_scope_set_resolver (TmplScope *self,
TmplScopeResolver resolver,
gpointer user_data,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]