src/midgard_object.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 "midgard/midgard_object.h"
00020 #include "midgard/types.h"
00021 #include "schema.h"
00022 
00023 /* Returns table name used for object. */
00024 const gchar *midgard_object_class_get_table(MidgardObjectClass *klass)
00025 {
00026         g_assert(klass != NULL);
00027         return klass->data->table;
00028 }
00029 
00030 /* Returns table names used for object. */  
00031 const gchar *midgard_object_class_get_tables(MidgardObjectClass *klass)
00032 {
00033         g_assert(klass != NULL);
00034         g_assert(klass->data->query->tables != NULL);
00035         return klass->data->query->tables;
00036 }
00037 
00038 /* Returns primary field name used for object's class. */
00039 const gchar *midgard_object_class_get_primary_field(MidgardObjectClass *klass)
00040 {       
00041         g_assert(klass);
00042         return klass->data->query->primary;
00043 }
00044 
00045 /* Returns table name used for property. */ 
00046 const gchar *midgard_object_class_get_property_table(MidgardObjectClass *klass, 
00047                 const gchar *property_name)
00048 {
00049         g_assert(klass);
00050         /* FIXME */
00051         return NULL; 
00052 }
00053 
00054 /* Returns field name used for property name. */
00055 const gchar *midgard_object_class_get_property_field(
00056         MidgardObjectClass *klass, const gchar *property_name)
00057 {
00058         g_assert(klass);
00059         /* FIXME */
00060         return NULL;
00061 }
00062 
00063 /* Returns MidgardObjectClass for linked object. */
00064 MidgardObjectClass *midgard_object_class_get_link_target(
00065         MidgardObjectClass *klass, const gchar *property_name)
00066 {       
00067         g_assert(klass);
00068         /* FIXME */
00069         return NULL;
00070 }
00071 
00072 /* Returns the name of object's primary property. */
00073 const gchar *midgard_object_class_get_primary_property(
00074                 MidgardObjectClass *klass)
00075 {       
00076         g_assert(klass);
00077         return klass->data->primary;
00078 } 
00079 
00080 /* Returns the name of object's parent property. */  
00081 const gchar *midgard_object_class_get_parent_property(
00082                 MidgardObjectClass *klass)
00083 {
00084         g_assert(klass);
00085         return klass->data->property_parent;    
00086 }
00087 
00088 /* Returns the name of object's up property. */
00089 const gchar *midgard_object_class_get_up_property(
00090                 MidgardObjectClass *klass)
00091 {       
00092         g_assert(klass);
00093         return klass->data->property_up;
00094 }
00095 
00096 /* Returns class' lang usage information. */
00097 gboolean midgard_object_class_is_multilang(
00098                 MidgardObjectClass *klass)
00099 {
00100     g_assert(klass);
00101 
00102     if(klass->data->use_lang == 0)
00103         return FALSE;
00104 
00105     return TRUE;
00106 }
00107 
00108 /* Returns children ( in tree ) classes' pointers */
00109 MidgardObjectClass **midgard_object_class_list_children(
00110                         MidgardObjectClass *klass)
00111 {
00112         g_assert(klass);
00113 
00114         if(!klass->data->childs)
00115                 return NULL;
00116         
00117         GSList *slist = klass->data->childs;
00118         guint i = 0;
00119         MidgardObjectClass **children = 
00120                 g_new(MidgardObjectClass *, g_slist_length(slist)+1);
00121 
00122         for(; slist; slist = slist->next){
00123                 children[i] = 
00124                         MIDGARD_OBJECT_GET_CLASS_BY_NAME(
00125                                         g_type_name((GType)slist->data));
00126                 i++;
00127 
00128         }
00129         children[i] = NULL;
00130 
00131         return children;
00132 }
00133 

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