rrcommon.h

Go to the documentation of this file.
00001 // @(#)root/ruby:$Id: rrcommon.h 20882 2007-11-19 11:31:26Z rdm $
00002 // Author:  Elias Athanasopoulos, May 2004
00003 
00004 /*  ruby-root
00005  *  
00006  *  Elias Athanasopoulos            <elathan@phys.uoa.gr>
00007  *  George Tzanakos (Supervisor)    <tzanakos@cc.uoa.gr>
00008  *    
00009  *  University of Athens 
00010  *  Department of Physics  
00011  *  HEPA Lab
00012  *  (http://daedalus.phys.uoa.gr)
00013  *  (c) 2003, 2004
00014  */
00015 
00016 #ifndef rr_common_h
00017 #define rr_common_h
00018 
00019 #include "ruby.h"
00020 
00021 #include "TObject.h"
00022 #include "TList.h"
00023 #include "TArrayC.h"
00024 #include "TArrayS.h"
00025 #include "TArrayI.h"
00026 #include "TArrayL.h"
00027 #include "TArrayF.h"
00028 #include "TArrayD.h"
00029 #include "TSeqCollection.h"
00030 
00031 #include "CallFunc.h"
00032 
00033 /* FIXME: This is from SWIG. */
00034 #ifdef __cplusplus
00035 #  ifndef RUBY_METHOD_FUNC      /* These definitions should work for Ruby 1.4.6 */
00036 #    define VALUEFUNC(f) ((VALUE (*)()) f)
00037 #    define VOIDFUNC(f)  ((void (*)()) f)
00038 #  else
00039 #    ifndef ANYARGS             /* These definitions should work for Ruby 1.6 */
00040 #      define VALUEFUNC(f) ((VALUE (*)()) f)
00041 #      define VOIDFUNC(f)  ((RUBY_DATA_FUNC) f)
00042 #    else /* These definitions should work for Ruby 1.7 */
00043 #      define VALUEFUNC(f) ((VALUE (*)(ANYARGS)) f)
00044 #      define VOIDFUNC(f)  ((RUBY_DATA_FUNC) f)
00045 #    endif
00046 #  endif
00047 #else
00048 #  define VALUEFUNC(f) (f)
00049 #  define VOIDFUNC(f) (f)
00050 #endif
00051 
00052 /* some usefull macros */
00053 
00054 #define RRNEW(obj, type) obj = rb_class_new_instance (0, NULL, type)
00055 
00056 #define RRGRAB(fromobj, type, toobj)                            \
00057     type *toobj;                                                \
00058     Data_Get_Struct (rb_iv_get (fromobj, "__rr__"), type, toobj)
00059  
00060 #define RRCALL(obj, type)                                       \
00061     type *v;                                                    \
00062     Data_Get_Struct(rb_iv_get (obj, "__rr__"), type, v); ((type *)(v)) 
00063 
00064 #define RRCALL2(obj, type, ptr)                                 \
00065     type *v;                                                    \
00066     Data_Get_Struct(rb_iv_get (obj, "__rr__"), type, v); ptr = v 
00067 
00068 #define RRMODCALL(obj, modtype, convfunc)                       \
00069     modtype *v;                                                 \
00070     Data_Get_Struct (rb_iv_get (obj, "__rr__"), modtype, v);    \
00071     convfunc ((void**)&v, obj); v
00072     
00073 #define RRMODCALL2(obj, modtype, convfunc, ptr)                 \
00074     modtype *v;                                                 \
00075     Data_Get_Struct (rb_iv_get (obj, "__rr__"), modtype, v);    \
00076     convfunc ((void**)&v, obj); ptr = v
00077 
00078 
00079 #define RRSTRING(v) (TYPE(v) == T_STRING)
00080 #define RRINT(v) (TYPE(v) == T_FIXNUM)
00081 #define RRFLOAT(v) ((TYPE(v) == T_FLOAT) || (TYPE(v) == T_FIXNUM)) 
00082 #define RRARRAY(v, kind) (TYPE(v) == T_ARRAY && kind(rb_ary_entry(v, 0)))
00083 #define RRDATA(v) (TYPE(v) == T_OBJECT)
00084 #define RRFUNC(v) (TYPE(v) == T_SYMBOL)
00085 #define RRVOID(v) (v)
00086 
00087 extern VALUE cTObject;
00088 
00089 VALUE rr_bool (bool q);
00090 
00091 VALUE rr_ary_new (TList *l);
00092 VALUE rr_arrayc_new (const TArrayC *a);
00093 VALUE rr_arrays_new (const TArrayS *a);
00094 VALUE rr_arrayi_new (const TArrayI *a);
00095 VALUE rr_arrayl_new (const TArrayL *a);
00096 VALUE rr_arrayf_new (const TArrayF *a);
00097 VALUE rr_arrayd_new (const TArrayD *a);
00098 VALUE rr_seqcollection_new (TSeqCollection *sc);
00099 
00100 void * rr_parse_void (VALUE o);
00101 
00102 /* mod convertions */
00103 void rr_tattfill_conv(void **ptr, VALUE klass);
00104 void rr_tattline_conv(void **ptr, VALUE klass);
00105 void rr_tattmarker_conv(void **ptr, VALUE klass);
00106 void rr_tattpad_conv(void **ptr, VALUE klass);
00107 void rr_tatttext_conv(void **ptr, VALUE klass);
00108 void rr_tattaxis_conv(void **ptr, VALUE klass);
00109 
00110 
00111 /* Map user defined C functions to Ruby methods.  */
00112 struct rr_fcn_info {
00113     ID id;
00114     char *name;
00115 };
00116 
00117 /* TF1 user defined methods  */
00118 
00119 double rr_ctf1_fcn (double *, double *);
00120 void rr_register_ctf1_fcn (char *name, ID id);
00121 
00122 /* TF2 user defined methods  */
00123 
00124 double rr_ctf2_fcn (double *, double *);
00125 void rr_register_ctf2_fcn (char *name, ID id);
00126 
00127 /* Dynamic ruby-root specific.  */
00128 
00129 struct drr_func_entry {
00130   G__CallFunc *func;
00131   G__ClassInfo *klass;
00132   char *name;
00133   char *cproto;
00134   int rtype;
00135 };
00136 
00137 struct drr_func_cache {
00138   struct drr_func_entry *entry;
00139   struct drr_func_cache *next;
00140   struct drr_func_cache *last;
00141 };
00142 
00143 /* Function cache.  */
00144 struct drr_func_cache * drr_func_cache_init(struct drr_func_entry *entry);
00145 void drr_func_cache_push (struct drr_func_cache *cache, struct drr_func_entry *entry);
00146 struct drr_func_entry * drr_func_cache_find (struct drr_func_cache *cache, char *name);
00147 void drr_func_entry_free (struct drr_func_entry *entry);
00148 
00149 static VALUE drr_generic_method(int argc, VALUE argv[], VALUE self);
00150 static VALUE drr_method_missing(int argc, VALUE argv[], VALUE self);
00151         
00152 #endif

Generated on Tue Jul 5 14:10:17 2011 for ROOT_528-00b_version by  doxygen 1.5.1