TUM-Logo

libRASCH

 

Home
 

General

About libRASCH/News
Design
Screen shots
Sample programs (with source code)
License
 

Download

libRASCH
Tools
 

Documentation

User
Developer
 

Resources

Mailing list
Supported Formats
Plugins
Status
Links
 
Contact
About this site
 
Last updated
Tue Mar 27 23:03:52 2007
libRASCH: eval_auto.c Source File

eval_auto.c

Go to the documentation of this file.
00001 /* ------------------------------ evaluation helper functions ------------------------------ */
00002 #include <string.h>
00003 #include <stdlib.h>
00004 #include <stdio.h>
00005 
00006 #define _LIBRASCH_BUILD
00007 #include <ra_eval.h>
00008 #include <ra_linked_list.h>
00009 
00010 
00011 LIBRAAPI int
00012 ra_eval_save_result(eval_handle eh, class_handle clh, prop_handle ph, proc_handle proc, long res_set)
00013 {
00014         int ret = 0;
00015         int i;
00016         eval_handle eh_use;
00017         value_handle *res;
00018         struct proc_info *pi = proc;
00019         struct plugin_struct *pl;
00020         struct plugin_infos *pli;
00021         long res_offset;
00022 
00023         pl = pi->plugin;
00024         pli = &(pl->info);
00025         res = pi->results;
00026         
00027         res_offset = res_set * pi->num_results;
00028 
00029         if (res_set >= pi->num_result_sets)
00030         {
00031                 _ra_set_error(pi->mh, RA_ERR_ERROR, "libRASCH");
00032                 return -1;
00033         }
00034 
00035         if (eh == NULL)
00036         {
00037                 eh_use = ra_eval_add(pi->mh, "auto-eval", "evaluation created within libRASCH-function ra_eval_save_result()", 0);
00038                 if (!eh_use)
00039                         return -1;
00040         }
00041         else
00042                 eh_use = eh;
00043 
00044         if (clh == NULL)
00045         {
00046                 for (i = 0; i < pli->num_create_class; i++)
00047                 {
00048                         long n = ra_value_get_num_elem(res[pli->create_class[i].start_pos_idx+res_offset]);
00049                         pli->create_class[i].event_ids = malloc(sizeof(long) * n);
00050                         ret = create_auto_class(eh, pli->create_class+i, res, res_offset);
00051                         if (ret != 0)
00052                                 goto clean;
00053                 }
00054         }
00055 
00056         if (ph == NULL)
00057         {
00058                 for (i = 0; i < pli->num_create_prop; i++)
00059                 {
00060                         ret = create_auto_prop(eh, clh, pi, pli->create_class, pli->create_prop+i, res, res_offset);
00061                         if (ret != 0)
00062                                 goto clean;
00063                 }
00064         }
00065         else
00066         {
00067                 /* TODO: add code to set the values for one event-prop (think how to give the values to the function) */
00068                 _ra_set_error(eh, RA_ERR_ERROR_INTERNAL, "libRASCH");
00069                 return -1;
00070         }
00071 
00072  clean:
00073         /* clean up */
00074         if (clh == NULL)
00075         {
00076                 for (i = 0; i < pli->num_create_class; i++)
00077                 {
00078                         if (pli->create_class[i].event_ids)
00079                                 free(pli->create_class[i].event_ids);
00080                 }
00081         }
00082 
00083         return ret;
00084 } /* ra_eval_save_result() */
00085 
00086 
00087 int
00088 create_auto_class(eval_handle eh, struct ra_auto_create_class *acc, value_handle *res, long res_offset)
00089 {
00090         int ret = 0;
00091         long l, num;
00092         const long *startp, *endp;
00093         value_handle vh = NULL;
00094 
00095         ra_eval_edit_start(eh);
00096 
00097         if ((acc->clh = ra_class_add_predef(eh, acc->ascii_id)) == NULL)
00098                 goto error;
00099 
00100         vh = ra_value_malloc();
00101 
00102         ra_value_set_string(vh, acc->info_short);
00103         if (ra_eval_attribute_set(acc->clh, "info-short", vh) != 0)
00104                 goto error;
00105         ra_value_set_string(vh, acc->info_long);
00106         if (ra_eval_attribute_set(acc->clh, "info-long", vh) != 0)
00107                 goto error;
00108         ra_value_set_string(vh, acc->info_ext);
00109         if (ra_eval_attribute_set(acc->clh, "info-ext", vh) != 0)
00110                 goto error;
00111 
00112         /* add events */
00113         num = ra_value_get_num_elem(res[acc->start_pos_idx+res_offset]);
00114         startp = ra_value_get_long_array(res[acc->start_pos_idx+res_offset]);
00115         endp = ra_value_get_long_array(res[acc->end_pos_idx+res_offset]);
00116         if ((num > 0) && ((startp == NULL) || (endp == NULL)))
00117         {
00118                 _ra_set_error(eh, RA_ERR_ERROR_INTERNAL, "libRASCH");
00119                 goto error;
00120         }
00121 
00122         acc->num_events = 0;
00123         for (l = 0; l < num; l++)
00124         {
00125                 acc->event_ids[l] = ra_class_add_event(acc->clh, startp[l], endp[l]);
00126                 if (acc->event_ids[l] < 0)
00127                 {
00128                         ret = -1;
00129                         goto error;
00130                 }               
00131         }
00132         acc->num_events = num;
00133 
00134         ra_eval_edit_complete(eh);
00135 
00136  error:
00137         if (vh)
00138                 ra_value_free(vh);
00139 
00140         if (ret != 0)
00141                 ra_eval_edit_cancel(eh);
00142 
00143         return ret;
00144 } /* create_auto_class */
00145 
00146 
00147 int
00148 create_auto_prop(eval_handle eh, class_handle clh, struct proc_info *pi, struct ra_auto_create_class *acc,
00149                  struct ra_auto_create_prop *acp, value_handle *res, long res_offset)
00150 {
00151         int ret = 0;
00152         long l, num;
00153         class_handle clh_use;
00154         value_handle vh;
00155         const long *ch_nums, *ev_ids;
00156 
00157         /* get class-handle */
00158         if (acp->class_index >= 0)
00159                 clh_use = acc[acp->class_index].clh;
00160         else
00161                 clh_use = clh;
00162         if (clh_use == NULL)
00163                 return -1;
00164 
00165         /* get event-id's */
00166         ev_ids = NULL;
00167         /* are the event-id's available in the results? */
00168         if (acp->event_id_idx >= 0)
00169                 ev_ids = ra_value_get_long_array(res[acp->event_id_idx+res_offset]);
00170         else
00171         {
00172                 /* no; are the events added in create_auto_class()? */
00173                 if (acc && acc->event_ids)
00174                         ev_ids = acc->event_ids;
00175 /*              else if (acc) */
00176 /*              { */
00177 /*                      /\* no, so add them now (and delete  *\/ */
00178 /*                      ev_ids = add_events(); */
00179 /*              } */
00180         }
00181         if (ev_ids == NULL)
00182                 return -1;
00183 
00184         /* add the property (if necessary) */
00185         if ((acp->ph = ra_prop_get(clh_use, acp->ascii_id)) == NULL)
00186                 if ((acp->ph = ra_prop_add_predef(clh_use, acp->ascii_id)) == NULL)
00187                         return -1;
00188 
00189         if (acp->ch_id >= 0)
00190                 ch_nums = ra_value_get_long_array(res[acp->ch_id+res_offset]);
00191         else
00192                 ch_nums = NULL;
00193 
00194         /* set the values */
00195         vh = ra_value_malloc();
00196         num = ra_value_get_num_elem(res[acp->value_id+res_offset]);
00197         for (l = 0; l < num; l++)
00198         {
00199                 long ch;
00200 
00201                 if (ch_nums)
00202                         ch = ch_nums[l];
00203                 else
00204                         ch = -1;
00205 
00206                 ra_value_get_single_elem(vh, res[acp->value_id+res_offset], l);
00207                 if ((ret = ra_prop_set_value(acp->ph, ev_ids[l], ch, vh)) != 0)
00208                         break;
00209         }
00210         ra_value_free(vh);
00211 
00212         return ret;
00213 } /* create_auto_prop */
00214 

Generated on Fri May 27 11:32:38 2005 for libRASCH by  doxygen 1.4.2