src/types_export.c

00001 /* 
00002  * Copyright (C) 2005 Piotr Pokora <piotr.pokora@infoglob.pl>
00003  *
00004  * This program is free software; you can redistribute it and/or modify it
00005  * under the terms of the GNU Lesser General Public License as published
00006  * by the Free Software Foundation; either version 2 of the License, or
00007  * (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00017  */
00018 
00019 #include <config.h>
00020 #include <glib.h>
00021 #include <glib-object.h>
00022 #include "midgard/types.h"
00023 #include "midgard/midgard_legacy.h"
00024 
00025 gchar * midgard_object_serialize(MgdObject *mobj)
00026 {
00027 
00028   GParamSpec **pspec; 
00029   guint propn, i;
00030   GString *so;
00031   GValue pval = {0,};
00032   gchar *rso;
00033   const gchar *pcchar;
00034     
00035 
00036   if ((pspec = g_object_class_list_properties((GObjectClass *) mobj->klass, &propn)) == NULL )
00037     return NULL;
00038 
00039   so = g_string_new("<type name=");
00040   g_string_append_printf(so, "\"%s\">\n", mobj->cname);
00041 
00042   for (i = 0; i < propn; i++) {
00043 
00044     g_value_init(&pval,pspec[i]->value_type);
00045 
00046     g_string_append(so, "\t<property name=");
00047     g_string_append_printf(so, "\"%s\"", pspec[i]->name);
00048     g_string_append(so, " value=");
00049 
00050     switch (pspec[i]->value_type) {
00051 
00052       case G_TYPE_STRING:
00053         
00054         if ((pcchar = g_strdup(g_value_get_string(&pval))) == NULL ) 
00055           pcchar = "";         
00056         g_string_append_printf(so, "\"%s\"/>\n", pcchar);
00057         break;
00058 
00059       case G_TYPE_UINT:
00060 
00061         g_string_append_printf(so, "\"%d\"/>\n", g_value_get_uint(&pval));
00062         break;
00063 
00064     }
00065 
00066     g_value_unset(&pval);
00067    
00068   }
00069   
00070   g_string_append(so, "</type>\n");
00071   
00072   rso = g_string_free(so, FALSE);
00073 
00074   return rso;
00075 }
00076 

Generated on Thu Feb 22 06:15:19 2007 for midgard-core by  doxygen 1.4.6