Statistics
| Revision:

root / tmp / org.txm.statsengine.r.core.win32 / res / win32 / include / R_ext / Callbacks.h @ 2486

History | View | Annotate | Download (3.9 kB)

1
/*
2
 *  R : A Computer Language for Statistical Data Analysis
3
 *  Copyright (C) 2001-2 The R Core Team.
4
 *
5
 *  This program is free software; you can redistribute it and/or modify
6
 *  it under the terms of the GNU Lesser General Public License as published by
7
 *  the Free Software Foundation; either version 2.1 of the License, or
8
 *  (at your option) any later version.
9
 *
10
 *  This program is distributed in the hope that it will be useful,
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 *  GNU Lesser General Public License for more details.
14
 *
15
 *  You should have received a copy of the GNU Lesser General Public License
16
 *  along with this program; if not, a copy is available at
17
 *  http://www.r-project.org/Licenses/
18
 */
19

    
20
/* 
21
   Not part of the API, subject to change at any time.
22
*/
23

    
24
#ifndef R_CALLBACKS_H
25
#define R_CALLBACKS_H
26

    
27
/**
28
  These structures are for C (and R function) top-level task handlers.
29
  Such routines are called at the end of every (successful) top-level task
30
  in the regular REPL. 
31
 */
32

    
33
#include <Rinternals.h>
34
/**
35
  The signature of the C routine that a callback must implement.
36
  expr - the expression for the top-level task that was evaluated.
37
  value - the result of the top-level task, i.e. evaluating expr.
38
  succeeded - a logical value indicating whether the task completed propertly.
39
  visible - a logical value indicating whether the result was printed to the R ``console''/stdout.
40
  data - user-level data passed to the registration routine.
41
 */
42
typedef Rboolean (*R_ToplevelCallback)(SEXP expr, SEXP value, Rboolean succeeded, Rboolean visible, void *);
43

    
44
typedef struct _ToplevelCallback  R_ToplevelCallbackEl;
45
/** 
46
 Linked list element for storing the top-level task callbacks.
47
 */
48
struct _ToplevelCallback {
49
    R_ToplevelCallback cb; /* the C routine to call. */
50
    void *data;            /* the user-level data to pass to the call to cb() */
51
    void (*finalizer)(void *data); /* Called when the callback is removed. */
52

    
53
    char *name;  /* a name by which to identify this element. */ 
54

    
55
    R_ToplevelCallbackEl *next; /* the next element in the linked list. */
56
};
57

    
58
#ifdef __cplusplus
59
extern "C" {
60
#endif
61

    
62
Rboolean Rf_removeTaskCallbackByIndex(int id);
63
Rboolean Rf_removeTaskCallbackByName(const char *name);
64
SEXP R_removeTaskCallback(SEXP which);
65
R_ToplevelCallbackEl* Rf_addTaskCallback(R_ToplevelCallback cb, void *data, void (*finalizer)(void *), const char *name, int *pos);
66

    
67

    
68

    
69
/*
70
  The following definitions are for callbacks to R functions and
71
  methods related to user-level tables.  This was implemented in a
72
  separate package on Omegahat and these declarations allow the package
73
  to interface to the internal R code.
74
  
75
  See http://developer.r-project.org/RObjectTables.pdf,
76
  http://www.omegahat.org/RObjectTables/
77
*/
78

    
79
typedef struct  _R_ObjectTable R_ObjectTable;
80

    
81
/* Do we actually need the exists() since it is never called but R
82
   uses get to see if the symbol is bound to anything? */
83
typedef Rboolean (*Rdb_exists)(const char * const name, Rboolean *canCache, R_ObjectTable *);
84
typedef SEXP     (*Rdb_get)(const char * const name, Rboolean *canCache, R_ObjectTable *);
85
typedef int      (*Rdb_remove)(const char * const name, R_ObjectTable *);
86
typedef SEXP     (*Rdb_assign)(const char * const name, SEXP value, R_ObjectTable *);
87
typedef SEXP     (*Rdb_objects)(R_ObjectTable *);
88
typedef Rboolean (*Rdb_canCache)(const char * const name, R_ObjectTable *);
89

    
90
typedef void     (*Rdb_onDetach)(R_ObjectTable *);
91
typedef void     (*Rdb_onAttach)(R_ObjectTable *);
92

    
93
struct  _R_ObjectTable{
94
  int       type;
95
  char    **cachedNames;
96
  Rboolean  active;
97

    
98
  Rdb_exists   exists;
99
  Rdb_get      get;
100
  Rdb_remove   remove;
101
  Rdb_assign   assign;
102
  Rdb_objects  objects;
103
  Rdb_canCache canCache;
104

    
105
  Rdb_onDetach onDetach;
106
  Rdb_onAttach onAttach;
107
  
108
  void     *privateData;
109
};
110

    
111

    
112
#ifdef __cplusplus
113
}
114
#endif
115

    
116
#endif /* R_CALLBACKS_H */