Statistics
| Revision:

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

History | View | Annotate | Download (5.8 kB)

1
/*
2
 *  R : A Computer Language for Statistical Data Analysis
3
 *  Copyright (C) 1999-2013 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
#ifndef R_DEFINES_H
21
#define R_DEFINES_H
22

    
23
#if !defined(R_R_H) && !defined(R_S_H)
24
/* user forgot to include R.h or S.h */
25
# include <R_ext/Memory.h>
26
# include <R_ext/RS.h>
27
#endif
28

    
29
#include <Rinternals.h>
30

    
31
/*
32
 *  Much is from John Chambers' "Programming With Data".
33
 *  Some of this is from Doug Bates.
34
 *
35
 *  It is presented here to support a joint programming style which
36
 *  will work in both R and S.  In particular it helps with:
37
 *
38
 *    1. S/R <-> CORBA code.
39
 *    2. S/R <-> Java Code.
40
 *
41
 *  And to hide some internal nastiness.
42
 */
43

    
44

    
45
/*
46
 *  Added some macros defined in S.h from Splus 5.1
47
 */
48

    
49
#define NULL_USER_OBJECT        R_NilValue
50

    
51
#define AS_LOGICAL(x)                coerceVector(x,LGLSXP)
52
#define AS_INTEGER(x)                coerceVector(x,INTSXP)
53
#define AS_NUMERIC(x)                coerceVector(x,REALSXP)
54
#define AS_CHARACTER(x)                coerceVector(x,STRSXP)
55
#define AS_COMPLEX(x)                coerceVector(x,CPLXSXP)
56
#define AS_VECTOR(x)                coerceVector(x,VECSXP)
57
#define AS_LIST(x)                coerceVector(x,VECSXP)
58
#define AS_RAW(x)                coerceVector(x,RAWSXP)
59

    
60
#define IS_LOGICAL(x)                isLogical(x)
61
#define IS_INTEGER(x)                isInteger(x)
62
#define IS_NUMERIC(x)                isReal(x)
63
#define IS_CHARACTER(x)                isString(x)
64
#define IS_COMPLEX(x)                isComplex(x)
65
/* NB: is this right? It means atomic or VECSXP or EXPRSXP */
66
#define IS_VECTOR(x)                isVector(x)
67
/* And this cannot be right: isVectorList(x)? */
68
#define IS_LIST(x)                IS_VECTOR(x)
69
#define IS_RAW(x)                (TYPEOF(x) == RAWSXP)
70

    
71
#define NEW_LOGICAL(n)                allocVector(LGLSXP,n)
72
#define NEW_INTEGER(n)                allocVector(INTSXP,n)
73
#define NEW_NUMERIC(n)                allocVector(REALSXP,n)
74
#define NEW_CHARACTER(n)        allocVector(STRSXP,n)
75
#define NEW_COMPLEX(n)                allocVector(CPLXSXP,n)
76
#define NEW_LIST(n)                allocVector(VECSXP,n)
77
#define NEW_STRING(n)                NEW_CHARACTER(n)
78
#define NEW_RAW(n)                allocVector(RAWSXP,n)
79

    
80
#define LOGICAL_POINTER(x)        LOGICAL(x)
81
#define INTEGER_POINTER(x)        INTEGER(x)
82
#define NUMERIC_POINTER(x)        REAL(x)
83
#define CHARACTER_POINTER(x)        STRING_PTR(x)
84
#define COMPLEX_POINTER(x)        COMPLEX(x)
85
/* Use of VECTOR_PTR will fail unless USE_RINTERNALS is in use
86
   This is probably unused.
87
*/
88
#define LIST_POINTER(x)                VECTOR_PTR(x)
89
#define RAW_POINTER(x)                RAW(x)
90

    
91
/* The following are not defined in `Programming with Data' but are
92
   defined in S.h in Svr4 */
93

    
94
/*
95
 * Note that LIST_DATA and RAW_DATA are missing.
96
 * This is consistent with Svr4.
97
 */
98

    
99
#define LOGICAL_DATA(x)                (LOGICAL(x))
100
#define INTEGER_DATA(x)                (INTEGER(x))
101
#define DOUBLE_DATA(x)                (REAL(x))
102
#define NUMERIC_DATA(x)                (REAL(x))
103
#define CHARACTER_DATA(x)        (STRING_PTR(x))
104
#define COMPLEX_DATA(x)                (COMPLEX(x))
105
/* Use of VECTOR_PTR will fail unless USE_RINTERNALS is in use
106
   VECTOR_DATA seems unused, and RECURSIVE_DATA is used only in
107
   the Expat part of XML.
108
*/
109
#define RECURSIVE_DATA(x)        (VECTOR_PTR(x))
110
#define VECTOR_DATA(x)                (VECTOR_PTR(x))
111

    
112
#define LOGICAL_VALUE(x)        asLogical(x)
113
#define INTEGER_VALUE(x)        asInteger(x)
114
#define NUMERIC_VALUE(x)        asReal(x)
115
#define CHARACTER_VALUE(x)        CHAR(asChar(x))
116
#define STRING_VALUE(x)                CHAR(asChar(x))
117
#define LIST_VALUE(x)                error("the 'value' of a list object is not defined")
118
#define RAW_VALUE(x)                error("the 'value' of a raw object is not defined")
119

    
120
#define SET_ELEMENT(x, i, val)        SET_VECTOR_ELT(x, i, val)
121
#define GET_ATTR(x,what)               getAttrib(x, what)
122
#define GET_CLASS(x)               getAttrib(x, R_ClassSymbol)
123
#define GET_DIM(x)               getAttrib(x, R_DimSymbol)
124
#define GET_DIMNAMES(x)               getAttrib(x, R_DimNamesSymbol)
125
#define GET_COLNAMES(x)               GetColNames(x)
126
#define GET_ROWNAMES(x)               GetRowNames(x)
127
#define GET_LEVELS(x)               getAttrib(x, R_LevelsSymbol)
128
#define GET_TSP(x)               getAttrib(x, R_TspSymbol)
129
#define GET_NAMES(x)                getAttrib(x, R_NamesSymbol)
130
#define SET_ATTR(x, what, n)             setAttrib(x, what, n)
131
#define SET_CLASS(x, n)             setAttrib(x, R_ClassSymbol, n)
132
#define SET_DIM(x, n)             setAttrib(x, R_DimSymbol, n)
133
#define SET_DIMNAMES(x, n)             setAttrib(x, R_DimNamesSymbol, n)
134
#define SET_LEVELS(x, l)               setAttrib(x, R_LevelsSymbol, l)
135
#define SET_NAMES(x, n)                setAttrib(x, R_NamesSymbol, n)
136
/* These do not support long vectors */
137
#define GET_LENGTH(x)                length(x)
138
#define SET_LENGTH(x, n)        (x = lengthgets(x, n))
139

    
140
#define GET_SLOT(x, what)       R_do_slot(x, what)
141
#define SET_SLOT(x, what, value)  R_do_slot_assign(x, what, value)
142

    
143
#define MAKE_CLASS(what)        R_do_MAKE_CLASS(what)
144
/* NEW_OBJECT is recommended; NEW is for green book compatibility */
145
#define NEW_OBJECT(class_def)        R_do_new_object(class_def)
146
#define NEW(class_def)                R_do_new_object(class_def)
147

    
148
#define s_object                SEXPREC
149
#define S_EVALUATOR             /**/
150

    
151
/* These conflict with definitions in R_ext/Boolean.h,
152
   but spatstat relies on them in a C file */
153
#ifdef __cplusplus
154
# ifndef R_EXT_BOOLEAN_H_
155
#  ifndef TRUE
156
#   define TRUE 1
157
#  endif
158
#  ifndef FALSE
159
#   define FALSE 0
160
#  endif
161
# endif
162
#else
163
#  ifndef TRUE
164
#   define TRUE 1
165
#  endif
166
#  ifndef FALSE
167
#   define FALSE 0
168
#  endif
169
#endif
170

    
171
#define COPY_TO_USER_STRING(x)        mkChar(x)
172
#define CREATE_STRING_VECTOR(x)        mkChar(x)
173

    
174
#define CREATE_FUNCTION_CALL(name, argList) createFunctionCall(name, argList)
175

    
176
#define EVAL(x)                        eval(x,R_GlobalEnv)
177

    
178

    
179
#endif