Main Page | Modules | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

init_cond.c

00001 /*****************************************************************************
00002  * init_cond.:
00003  *****************************************************************************
00004  * Copyright (C) 2004 the VideoLAN team
00005  * $Id: init_cond.c 11664 2005-07-09 06:17:09Z courmisch $
00006  *
00007  * Authors: Cyril Deguet <[email protected]>
00008  *          code from projectM http://xmms-projectm.sourceforge.net
00009  *
00010  * This program is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2 of the License, or
00013  * (at your option) any later version.
00014  *
00015  * This program is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  * GNU General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU General Public License
00021  * along with this program; if not, write to the Free Software
00022  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
00023  *****************************************************************************/
00024 
00025 
00026 
00027 /* Library functions to manipulate initial condition values */
00028 
00029 #include <stdio.h>
00030 #include <stdlib.h>
00031 #include <string.h>
00032 
00033 #include "common.h"
00034 #include "fatal.h"
00035 
00036 #include "param_types.h"
00037 #include "expr_types.h"
00038 #include "init_cond_types.h"
00039 #include "init_cond.h"
00040 
00041 #include "splaytree_types.h"
00042 #include "splaytree.h"
00043 char init_cond_string_buffer[STRING_BUFFER_SIZE];
00044 int init_cond_string_buffer_index = 0;
00045 
00046 
00047 void init_cond_to_string(init_cond_t * init_cond);
00048 
00049 /* Frees initial condition structure */
00050 void free_init_cond(init_cond_t * init_cond) {
00051   free(init_cond);
00052 }
00053 
00054 /* Evaluate an initial conditon */
00055 void eval_init_cond(init_cond_t * init_cond) {
00056 
00057   if (init_cond == NULL)
00058     return;
00059  
00060   /* Parameter is of boolean type, either a 1 or 0 value integer */
00061 
00062   /* Set matrix flag to zero. This ensures
00063      its constant value will be used rather than a matrix value 
00064   */
00065   init_cond->param->matrix_flag = 0;
00066   if (init_cond->param->type == P_TYPE_BOOL) {
00067          if (INIT_COND_DEBUG) printf("init_cond: %s = %d (TYPE BOOL)\n", init_cond->param->name, init_cond->init_val.bool_val); 
00068          *((int*)init_cond->param->engine_val) = init_cond->init_val.bool_val;
00069      return;
00070   }
00071   
00072   /* Parameter is an integer type, just like C */
00073   
00074   if (init_cond->param->type == P_TYPE_INT) {
00075          if (INIT_COND_DEBUG) printf("init_cond: %s = %d (TYPE INT)\n", init_cond->param->name, init_cond->init_val.int_val);
00076          *((int*)init_cond->param->engine_val) = init_cond->init_val.int_val;
00077      return;
00078   }
00079 
00080   /* Parameter is of a double type, just like C */
00081 
00082   if (init_cond->param->type == P_TYPE_DOUBLE) {
00083         if (INIT_COND_DEBUG) printf("init_cond: %s = %f (TYPE DOUBLE)\n", init_cond->param->name, init_cond->init_val.double_val);
00084         *((double*)init_cond->param->engine_val) = init_cond->init_val.double_val;
00085     return;
00086   }
00087 
00088   /* Unknown type of parameter */
00089   return;
00090 }
00091 
00092 /* Creates a new initial condition */
00093 init_cond_t * new_init_cond(param_t * param, value_t init_val) {
00094 
00095   init_cond_t * init_cond;
00096 
00097   init_cond = (init_cond_t*)malloc(sizeof(init_cond_t));
00098    
00099   if (init_cond == NULL)
00100     return NULL;
00101  
00102   init_cond->param = param;
00103   init_cond->init_val = init_val;
00104   return init_cond;
00105 }
00106 
00107 /* WIP */
00108 void init_cond_to_string(init_cond_t * init_cond) {
00109         
00110         int string_length;
00111         char string[MAX_TOKEN_SIZE];
00112         
00113         if (init_cond == NULL)
00114                 return;
00115 
00116         /* Create a string "param_name=val" */
00117         switch (init_cond->param->type) {
00118                 
00119                 case P_TYPE_BOOL:
00120                         sprintf(string, "%s=%d\n", init_cond->param->name, init_cond->init_val.bool_val);
00121                         break; 
00122                 case P_TYPE_INT:
00123                         sprintf(string, "%s=%d\n", init_cond->param->name, init_cond->init_val.int_val);
00124                         break;
00125                 case P_TYPE_DOUBLE:
00126                         sprintf(string, "%s=%f\n", init_cond->param->name, init_cond->init_val.double_val);
00127                         break;
00128                 default:
00129                         return;
00130         }               
00131                 
00132         /* Compute the length of the string */
00133         string_length = strlen(string);
00134         
00135         /* Buffer overflow check */
00136         if ((init_cond_string_buffer_index + string_length + 1)  > (STRING_BUFFER_SIZE - 1))
00137                 return;
00138         
00139         /* Copy the string into the initial condition string buffer */
00140         
00141         strncpy(init_cond_string_buffer + init_cond_string_buffer_index, string, string_length);
00142         
00143         /* Increment the string buffer, offset by one for the null terminator, which will be
00144            overwritten by the next call to this function */
00145         init_cond_string_buffer_index+= string_length + 1;
00146                 
00147 }
00148 
00149 
00150 char * create_init_cond_string_buffer(splaytree_t * init_cond_tree) {
00151 
00152         if (init_cond_tree == NULL)
00153                 return NULL;
00154         
00155         init_cond_string_buffer_index = 0;
00156         
00157         splay_traverse(init_cond_to_string, init_cond_tree);
00158         
00159         return init_cond_string_buffer;
00160                 
00161 }

Generated on Tue Dec 20 10:14:58 2005 for vlc-0.8.4a by  doxygen 1.4.2