CXXR (C++ R) API
Callbacks.h
1 /*CXXR $Id: Callbacks.h 1348 2013-02-25 17:49:03Z arr $
2  *CXXR
3  *CXXR This file is part of CXXR, a project to refactor the R interpreter
4  *CXXR into C++. It may consist in whole or in part of program code and
5  *CXXR documentation taken from the R project itself, incorporated into
6  *CXXR CXXR (and possibly MODIFIED) under the terms of the GNU General Public
7  *CXXR Licence.
8  *CXXR
9  *CXXR CXXR is Copyright (C) 2008-13 Andrew R. Runnalls, subject to such other
10  *CXXR copyrights and copyright restrictions as may be stated below.
11  *CXXR
12  *CXXR CXXR is not part of the R project, and bugs and other issues should
13  *CXXR not be reported via r-bugs or other R project channels; instead refer
14  *CXXR to the CXXR website.
15  *CXXR */
16 
17 /*
18  * R : A Computer Language for Statistical Data Analysis
19  * Copyright (C) 2001-2 The R Core Team.
20  *
21  * This program is free software; you can redistribute it and/or modify
22  * it under the terms of the GNU Lesser General Public License as published by
23  * the Free Software Foundation; either version 2.1 of the License, or
24  * (at your option) any later version.
25  *
26  * This program is distributed in the hope that it will be useful,
27  * but WITHOUT ANY WARRANTY; without even the implied warranty of
28  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29  * GNU Lesser General Public License for more details.
30  *
31  * You should have received a copy of the GNU Lesser General Public License
32  * along with this program; if not, a copy is available at
33  * http://www.r-project.org/Licenses/
34  */
35 
36 #ifndef R_CALLBACKS_H
37 #define R_CALLBACKS_H
38 
39 /*
40  These structures are for C (and R function) top-level task handlers.
41  Such routines are called at the end of every (successful) top-level task
42  in the regular REPL.
43  */
44 
45 #include <Rinternals.h>
46 /*
47  The signature of the C routine that a callback must implement.
48  expr - the expression for the top-level task that was evaluated.
49  value - the result of the top-level task, i.e. evaluating expr.
50  succeeded - a logical value indicating whether the task completed propertly.
51  visible - a logical value indicating whether the result was printed to the R ``console''/stdout.
52  data - user-level data passed to the registration routine.
53  */
54 typedef Rboolean (*R_ToplevelCallback)(SEXP expr, SEXP value, Rboolean succeeded, Rboolean visible, void *);
55 
56 typedef struct _ToplevelCallback R_ToplevelCallbackEl;
57 /*
58  Linked list element for storing the top-level task callbacks.
59  */
60 struct _ToplevelCallback {
61  R_ToplevelCallback cb; /* the C routine to call. */
62  void *data; /* the user-level data to pass to the call to cb() */
63  void (*finalizer)(void *data); /* Called when the callback is removed. */
64 
65  char *name; /* a name by which to identify this element. */
66 
67  R_ToplevelCallbackEl *next; /* the next element in the linked list. */
68 };
69 
70 #ifdef __cplusplus
71 extern "C" {
72 #endif
73 
74 Rboolean Rf_removeTaskCallbackByIndex(int id);
75 Rboolean Rf_removeTaskCallbackByName(const char *name);
76 SEXP R_removeTaskCallback(SEXP which);
77 R_ToplevelCallbackEl* Rf_addTaskCallback(R_ToplevelCallback cb, void *data, void (*finalizer)(void *), const char *name, int *pos);
78 
79 
80 
81 /*
82  The following definitions are for callbacks to R functions and methods
83  related to user-level tables. This is currently implemented in a
84  separate package and these declarations allow the package to
85  interface to the internal R code.
86 
87  See http://developer.r-project.org/RObjectTables.pdf.
88  */
89 
90 typedef struct _R_ObjectTable R_ObjectTable;
91 
92 /* Do we actually need the exists() since it is never called but R uses get to see if
93  the symbol is bound to anything? */
94 typedef Rboolean (*Rdb_exists)(const char * const name, Rboolean *canCache, R_ObjectTable *);
95 typedef SEXP (*Rdb_get)(const char * const name, Rboolean *canCache, R_ObjectTable *);
96 typedef int (*Rdb_remove)(const char * const name, R_ObjectTable *);
97 typedef SEXP (*Rdb_assign)(const char * const name, SEXP value, R_ObjectTable *);
98 typedef SEXP (*Rdb_objects)(R_ObjectTable *);
99 typedef Rboolean (*Rdb_canCache)(const char * const name, R_ObjectTable *);
100 
101 typedef void (*Rdb_onDetach)(R_ObjectTable *);
102 typedef void (*Rdb_onAttach)(R_ObjectTable *);
103 
104 struct _R_ObjectTable{
105  int type;
106  char **cachedNames;
107  Rboolean active;
108 
109  Rdb_exists exists;
110  Rdb_get get;
111  Rdb_remove remove;
112  Rdb_assign assign;
113  Rdb_objects objects;
114  Rdb_canCache canCache;
115 
116  Rdb_onDetach onDetach;
117  Rdb_onAttach onAttach;
118 
119  void *privateData;
120 };
121 
122 
123 #ifdef __cplusplus
124 }
125 #endif
126 
127 #endif /* R_CALLBACKS_H */