chainlink_base.h

00001 /****************************************************************************
00002  This file is part of ChainLink
00003  Copyright (C) 2007 Jeremy Magland (Jeremy.Magland@gmail.com)
00004 
00005  ChainLink is free software; you can redistribute it and/or modify
00006  it under the terms of the GNU General Public License as published by
00007  the Free Software Foundation; either version 2 of the License, or
00008  (at your option) any later version.
00009 
00010  ChainLink is distributed in the hope that it will be useful,
00011  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  GNU General Public License for more details.
00014 
00015  You should have received a copy of the GNU General Public License
00016  along with ChainLink; if not, write to the Free Software
00017  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 
00019 *****************************************************************************/
00020 
00021 
00022 
00023 #ifndef CHAINLINK_BASE_H
00024 #define CHAINLINK_BASE_H
00025 
00026 #include "chainlink_complex.h"
00027 #include "chainlink_string.h"
00028 #include "mda.h"
00029 
00048 //the vector and matrix types are nothing more than mdas
00049 //the ChainLink framework will do some checking to ensure that a vector is 1D and matrix is 2D
00050 typedef mda vector; 
00051 typedef mda matrix;
00052 
00053 typedef int32 integer;
00054 
00055 class mdac_object_base  {
00056 public:
00057         void *data;
00058         char data_type[100];
00059 
00060         mdac_object_base() {
00061                 strcpy(data_type,"NULL");
00062                 data=0;
00063         };
00064         virtual ~mdac_object_base() {
00065         };
00066 };
00067 
00068 bool convert_object(mdac_object_base *dest,mdac_object_base *src);
00069 bool can_convert(char *dest_str,mdac_object_base *src);
00070 
00071 class workspace_shell {
00072 public:
00073         virtual ~workspace_shell() {};
00074         virtual void display(const char *str,bool is_error=false) {
00075         }
00076 
00077         virtual void clear_command_window() {
00078         }
00079 
00080         virtual void display_prompt() {
00081         }
00082         virtual void on_exit() {
00083         }
00084 };
00085 
00086 class workspace {
00087 public:
00088         workspace_shell *the_shell;
00089         char current_directory[500];
00090 
00091         workspace() {
00092                 strcpy(current_directory,"");
00093                 the_shell=0;
00094         };
00095         virtual ~workspace() {
00096         };      
00097 
00099         virtual void display_object(mdac_object_base *obj) {
00100         }
00101         virtual void delete_object(mdac_object_base *obj) {
00102         }
00103         virtual bool copy_object(mdac_object_base *obj_dest,mdac_object_base *obj_src) {
00104                 return true;
00105         }
00106         virtual mdac_object_base *allocate_mdac_object() {
00107                 return new mdac_object_base;
00108         }
00110 
00111         
00112         void display(const char *str,bool is_error=false);
00113         void execute_command(char *str);
00114         virtual bool execute_code(char *str) {
00115                 return true;
00116         }
00117 
00118         virtual void change_working_directory(char *str) {}
00119         virtual void list_directory(char *pattern) {}
00120         virtual void create_directory(char *dirname) {}
00121         virtual void remove_directory(char *dirname) {}
00122         
00123         void display_prompt() {
00124                 if (the_shell) the_shell->display_prompt();
00125         }
00126 
00127         
00128 };
00129 
00130 #define MAX_PARAMETERS 100
00131 #define MAX_LIBRARY_FUNCTIONS 500
00132 #define MAX_LIBRARY_DATATYPES 100
00133 #define MAX_ADDITIONAL_OBJECTS 10
00134 
00135 typedef mdac_object_base *mdac_object_base_ptr;
00136 
00137 class additional_object_list {
00138 public:
00139         int num_objects;
00140         mdac_object_base_ptr objects[MAX_ADDITIONAL_OBJECTS];
00141 
00142         additional_object_list() {
00143                 num_objects=0;
00144         }
00145         void add_object(mdac_object_base *obj);
00146 };
00147 
00148 struct mdac_function_parameter {
00149         char data_type[20];
00150         char name[40];
00151 };
00152 
00153 typedef mdac_function_parameter *mdac_function_parameter_ptr;
00154 
00155 class mdac_library;
00156 
00157 class mdac_function {
00158 public:
00159         char name[100];
00160         int num_input_params,num_optional_input_params;
00161         mdac_function_parameter_ptr input_params[MAX_PARAMETERS];
00162         mdac_function_parameter_ptr optional_input_params[MAX_PARAMETERS];
00163         mdac_function_parameter output_param;
00164         long begin_line_number,end_line_number;
00165         mdac_library *library;
00166 
00167         mdac_object_base_ptr converted_parameters[MAX_PARAMETERS];
00168         mdac_object_base_ptr optional_converted_parameters[MAX_PARAMETERS];
00169         bool converted_parameters_allocated;
00170 
00171         mdac_function(mdac_library *library_in);
00172         virtual ~mdac_function() {
00173                 delete_parameters();
00174         }
00175         virtual bool matches(char *function_name,int num_input_params_in,mdac_object_base_ptr *input_params_in);
00176         virtual bool execute(int num_input_params,mdac_object_base_ptr *input_params,mdac_object_base_ptr output_param,additional_object_list &additional_outputs,bool do_alloc=true) {
00177                 return false;
00178         }
00179         mdac_object_base *allocate_mdac_object();
00180 
00181         void delete_parameters();
00182         void allocate_parameters();
00183         void allocate_converted_parameters();
00184         
00185         bool matches_exact(char *function_name,int num_input_params_in,mdac_object_base_ptr *input_params_in);
00186         void convert_parameters(int num_input_params_in,mdac_object_base_ptr *input_params_in);
00187         void clear_converted_parameters(int num_input_params_in,mdac_object_base_ptr *input_params_in);
00188 };
00189 
00190 typedef mdac_function *mdac_function_ptr;
00191 
00192 class mdac_datatype {
00193 public:
00194         char name[100];
00195         mdac_library *library;
00196         mdac_datatype(mdac_library *library_in);
00197         virtual bool delete_object(mdac_object_base *ptr);
00198         virtual bool copy_object(mdac_object_base *dest,mdac_object_base *src);
00199 };
00200 
00201 typedef mdac_datatype *mdac_datatype_ptr;
00202 
00203 class mdac_library {
00204 public:
00205         mdac_function_ptr functions[MAX_LIBRARY_FUNCTIONS];
00206         mdac_datatype_ptr datatypes[MAX_LIBRARY_DATATYPES];
00207         int num_functions,num_datatypes;
00208         char library_name[100];
00209         workspace *WS;
00210 
00211         mdac_library();
00212         virtual ~mdac_library();
00213 
00214         void add_function(mdac_function *ptr);
00215         mdac_function *find_function(char *function_name,int num_input_params,mdac_object_base_ptr *input_params);
00216         mdac_function *find_function_exact(char *function_name,int num_input_params,mdac_object_base_ptr *input_params);
00217         void add_datatype(mdac_datatype *ptr);
00218         mdac_datatype *find_datatype(char *datatype_name);
00219         mdac_function *execute_function(char *function_name,int num_input_params,mdac_object_base_ptr *input_params,mdac_object_base_ptr output_param,
00220                                                                   additional_object_list &additional_outputs,bool &did_find);
00221         mdac_function *execute_function_exact(char *function_name,int num_input_params,mdac_object_base_ptr *input_params,mdac_object_base_ptr output_param,
00222                                                                   additional_object_list &additional_outputs,bool &did_find);
00223 
00224 };
00225 
00226 typedef mdac_library *mdac_library_ptr;
00227 
00228 bool get_real_value(mdac_object_base *obj,real &ret);
00229 bool get_complex_value(mdac_object_base *obj,complex &ret);
00230 
00231 integer to_integer(real val);
00232 bool is_integer(real val);
00233 
00234 
00235 
00236 
00237 #endif
00238 

Generated on Mon Feb 5 12:16:36 2007 for ChainLinkBase by  doxygen 1.5.1-p1