ROOT  6.06/09
Reference Guide
rrcommon.h
Go to the documentation of this file.
1 // @(#)root/ruby:$Id$
2 // Author: Elias Athanasopoulos, May 2004
3 
4 /* ruby-root
5  *
6  * Elias Athanasopoulos <elathan@phys.uoa.gr>
7  * George Tzanakos (Supervisor) <tzanakos@cc.uoa.gr>
8  *
9  * University of Athens
10  * Department of Physics
11  * HEPA Lab
12  * (http://daedalus.phys.uoa.gr)
13  * (c) 2003, 2004
14  */
15 
16 #ifndef rr_common_h
17 #define rr_common_h
18 
19 #include "ruby.h"
20 
21 #include "TObject.h"
22 #include "TList.h"
23 #include "TArrayC.h"
24 #include "TArrayS.h"
25 #include "TArrayI.h"
26 #include "TArrayL.h"
27 #include "TArrayF.h"
28 #include "TArrayD.h"
29 #include "TSeqCollection.h"
30 
31 #include "CallFunc.h"
32 
33 /* FIXME: This is from SWIG. */
34 #ifdef __cplusplus
35 # ifndef RUBY_METHOD_FUNC /* These definitions should work for Ruby 1.4.6 */
36 # define VALUEFUNC(f) ((VALUE (*)()) f)
37 # define VOIDFUNC(f) ((void (*)()) f)
38 # else
39 # ifndef ANYARGS /* These definitions should work for Ruby 1.6 */
40 # define VALUEFUNC(f) ((VALUE (*)()) f)
41 # define VOIDFUNC(f) ((RUBY_DATA_FUNC) f)
42 # else /* These definitions should work for Ruby 1.7 */
43 # define VALUEFUNC(f) ((VALUE (*)(ANYARGS)) f)
44 # define VOIDFUNC(f) ((RUBY_DATA_FUNC) f)
45 # endif
46 # endif
47 #else
48 # define VALUEFUNC(f) (f)
49 # define VOIDFUNC(f) (f)
50 #endif
51 
52 /* some usefull macros */
53 
54 #define RRNEW(obj, type) obj = rb_class_new_instance (0, NULL, type)
55 
56 #define RRGRAB(fromobj, type, toobj) \
57  type *toobj; \
58  Data_Get_Struct (rb_iv_get (fromobj, "__rr__"), type, toobj)
59 
60 #define RRCALL(obj, type) \
61  type *v; \
62  Data_Get_Struct(rb_iv_get (obj, "__rr__"), type, v); ((type *)(v))
63 
64 #define RRCALL2(obj, type, ptr) \
65  type *v; \
66  Data_Get_Struct(rb_iv_get (obj, "__rr__"), type, v); ptr = v
67 
68 #define RRMODCALL(obj, modtype, convfunc) \
69  modtype *v; \
70  Data_Get_Struct (rb_iv_get (obj, "__rr__"), modtype, v); \
71  convfunc ((void**)&v, obj); v
72 
73 #define RRMODCALL2(obj, modtype, convfunc, ptr) \
74  modtype *v; \
75  Data_Get_Struct (rb_iv_get (obj, "__rr__"), modtype, v); \
76  convfunc ((void**)&v, obj); ptr = v
77 
78 
79 #define RRSTRING(v) (TYPE(v) == T_STRING)
80 #define RRINT(v) (TYPE(v) == T_FIXNUM)
81 #define RRFLOAT(v) ((TYPE(v) == T_FLOAT) || (TYPE(v) == T_FIXNUM))
82 #define RRARRAY(v, kind) (TYPE(v) == T_ARRAY && kind(rb_ary_entry(v, 0)))
83 #define RRDATA(v) (TYPE(v) == T_OBJECT)
84 #define RRFUNC(v) (TYPE(v) == T_SYMBOL)
85 #define RRVOID(v) (v)
86 
87 extern VALUE cTObject;
88 
89 VALUE rr_bool (Bool_t q);
90 
91 VALUE rr_ary_new (TList *l);
92 VALUE rr_arrayc_new (const TArrayC *a);
93 VALUE rr_arrays_new (const TArrayS *a);
94 VALUE rr_arrayi_new (const TArrayI *a);
95 VALUE rr_arrayl_new (const TArrayL *a);
96 VALUE rr_arrayf_new (const TArrayF *a);
97 VALUE rr_arrayd_new (const TArrayD *a);
99 
100 /* mod convertions */
101 void rr_tattfill_conv(void **ptr, VALUE klass);
102 void rr_tattline_conv(void **ptr, VALUE klass);
103 void rr_tattmarker_conv(void **ptr, VALUE klass);
104 void rr_tattpad_conv(void **ptr, VALUE klass);
105 void rr_tatttext_conv(void **ptr, VALUE klass);
106 void rr_tattaxis_conv(void **ptr, VALUE klass);
107 
108 
109 /* Map user defined C functions to Ruby methods. */
110 struct rr_fcn_info {
111  ID id;
112  char *name;
113 };
114 
115 /* TF1 user defined methods */
116 
117 double rr_ctf1_fcn (double *, double *);
118 void rr_register_ctf1_fcn (char *name, ID id);
119 
120 /* TF2 user defined methods */
121 
122 double rr_ctf2_fcn (double *, double *);
123 void rr_register_ctf2_fcn (char *name, ID id);
124 
125 /* Dynamic ruby-root specific. */
126 
128  G__CallFunc *func;
129  G__ClassInfo *klass;
130  char *name;
131  char *cproto;
132  int rtype;
133 };
134 
139 };
140 
141 /* Function cache. */
143 void drr_func_cache_push (struct drr_func_cache *cache, struct drr_func_entry *entry);
144 struct drr_func_entry * drr_func_cache_find (struct drr_func_cache *cache, char *name);
146 
147 static VALUE drr_generic_method(int argc, VALUE argv[], VALUE self);
148 static VALUE drr_method_missing(int argc, VALUE argv[], VALUE self);
149 
150 #endif
VALUE rr_arrayf_new(const TArrayF *a)
Definition: drr.cxx:128
int rtype
Definition: rrcommon.h:132
Definition: rrcommon.h:127
void rr_tattaxis_conv(void **ptr, VALUE klass)
void rr_tattpad_conv(void **ptr, VALUE klass)
struct drr_func_entry * drr_func_cache_find(struct drr_func_cache *cache, char *name)
Definition: drr.cxx:594
void drr_func_cache_push(struct drr_func_cache *cache, struct drr_func_entry *entry)
Definition: drr.cxx:577
struct drr_func_entry * entry
Definition: rrcommon.h:136
void rr_register_ctf1_fcn(char *name, ID id)
Definition: drr.cxx:214
void rr_register_ctf2_fcn(char *name, ID id)
Definition: drr.cxx:262
VALUE rr_bool(Bool_t q)
Definition: drr.cxx:166
Array of floats (32 bits per element).
Definition: TArrayF.h:29
bool Bool_t
Definition: RtypesCore.h:59
TArc * a
Definition: textangle.C:12
VALUE rr_arrayi_new(const TArrayI *a)
Definition: drr.cxx:106
void rr_tattmarker_conv(void **ptr, VALUE klass)
Array of integers (32 bits per element).
Definition: TArrayI.h:29
VALUE rr_arrayl_new(const TArrayL *a)
Definition: drr.cxx:117
VALUE rr_arrayd_new(const TArrayD *a)
Definition: drr.cxx:139
Sequenceable collection abstract base class.
VALUE rr_arrays_new(const TArrayS *a)
Definition: drr.cxx:95
VALUE rr_arrayc_new(const TArrayC *a)
Definition: drr.cxx:84
void rr_tattfill_conv(void **ptr, VALUE klass)
A doubly linked list.
Definition: TList.h:47
char * name
Definition: rrcommon.h:130
Array of shorts (16 bits per element).
Definition: TArrayS.h:29
char * cproto
Definition: rrcommon.h:131
VALUE cTObject
Definition: drr.cxx:54
double rr_ctf1_fcn(double *, double *)
Definition: drr.cxx:181
struct drr_func_cache * drr_func_cache_init(struct drr_func_entry *entry)
Definition: drr.cxx:568
Array of longs (32 or 64 bits per element).
Definition: TArrayL.h:29
TLine * l
Definition: textangle.C:4
double rr_ctf2_fcn(double *, double *)
Definition: drr.cxx:229
Long64_t entry
struct drr_func_cache * last
Definition: rrcommon.h:138
struct drr_func_cache * next
Definition: rrcommon.h:137
char * name
Definition: rrcommon.h:112
static VALUE drr_method_missing(int argc, VALUE argv[], VALUE self)
static VALUE drr_generic_method(int argc, VALUE argv[], VALUE self)
VALUE rr_ary_new(TList *l)
Definition: drr.cxx:56
void rr_tatttext_conv(void **ptr, VALUE klass)
void drr_func_entry_free(struct drr_func_entry *entry)
Definition: drr.cxx:607
Array of doubles (64 bits per element).
Definition: TArrayD.h:29
#define name(a, b)
Definition: linkTestLib0.cpp:5
VALUE rr_seqcollection_new(TSeqCollection *sc)
Definition: drr.cxx:150
float * q
Definition: THbookFile.cxx:87
G__ClassInfo * klass
Definition: rrcommon.h:129
G__CallFunc * func
Definition: rrcommon.h:128
void rr_tattline_conv(void **ptr, VALUE klass)
Array of chars or bytes (8 bits per element).
Definition: TArrayC.h:29