1use ::rdll::*;
9use rtype::{Rtype, RTYPEOF};
10use error::RResult;
11use macros::rbool;
12
13
14pub mod intor;
15pub mod attr;
16pub mod slot;
17pub mod name;
18pub mod rfield;
19pub mod dim;
20pub mod dimname;
21#[cfg(feature = "extra")]
22pub mod rlist;
23
24pub use self::attr::*;
25pub use self::slot::*;
26pub use self::name::*;
27pub use self::rfield::*;
28pub use self::dim::*;
29#[cfg(feature = "extra")]
30pub use self::rlist::*;
31
32use util::c_str;
33pub trait Args: Named {}
34
35pub struct Rtemp {
38 data: SEXP,
39}
40pub trait RSize {
41 fn rsize(&self) -> R_xlen_t;
42}
43
44#[allow(non_snake_case)]
45pub trait SetSEXP {
46 fn set_s(&mut self, X: SEXP);
47}
48
49pub trait SetSelf {
50 fn set(&mut self, x: Self);
51}
52
53pub trait ToExpr {
54 unsafe fn expr(&self) -> SEXP;
55}
56
57pub trait ToSEXP {
58 unsafe fn s(&self) -> SEXP;
59
60 fn rtype(&self) -> Rtype {
61 unsafe { RTYPEOF(self.s()) }
62 }
63 unsafe fn t(&self) -> Rtemp {
64 Rtemp { data: self.s() }
65 }
66 fn print(&self) {
67 unsafe {
68 Rf_PrintValue(self.s());
69 }
70 }
71 fn is_null(&self) -> bool {
72 unsafe { rbool(Rf_isNull(self.s())) }
73 }
74 fn is_object(&self) -> bool {
75 unsafe { rbool(Rf_isObject(self.s())) }
76 }
77 fn is_s4(&self) -> bool {
78 unsafe { rbool(Rf_isS4(self.s())) }
79 }
80 fn is_array(&self) -> bool {
81 unsafe { rbool(Rf_isArray(self.s())) }
82 }
83 fn is_factor(&self) -> bool {
84 unsafe { rbool(Rf_isFactor(self.s())) }
85 }
86 fn is_frame(&self) -> bool {
87 unsafe { rbool(Rf_isFrame(self.s())) }
88 }
89 fn is_function(&self) -> bool {
90 unsafe { rbool(Rf_isFunction(self.s())) }
91 }
92 fn is_integer(&self) -> bool {
93 unsafe { rbool(Rf_isInteger(self.s())) }
94 }
95 fn is_language(&self) -> bool {
96 unsafe { rbool(Rf_isLanguage(self.s())) }
97 }
98 fn is_list(&self) -> bool {
99 unsafe { rbool(Rf_isList(self.s())) }
100 }
101 fn is_matrix(&self) -> bool {
102 unsafe { rbool(Rf_isMatrix(self.s())) }
103 }
104 fn is_newlist(&self) -> bool {
105 unsafe { rbool(Rf_isNewList(self.s())) }
106 }
107 fn is_number(&self) -> bool {
108 unsafe { rbool(Rf_isNumber(self.s())) }
109 }
110 fn is_numeric(&self) -> bool {
111 unsafe { rbool(Rf_isNumeric(self.s())) }
112 }
113 fn is_pairlist(&self) -> bool {
114 unsafe { rbool(Rf_isPairList(self.s())) }
115 }
116 fn is_primitive(&self) -> bool {
117 unsafe { rbool(Rf_isPrimitive(self.s())) }
118 }
119 fn is_ts(&self) -> bool {
120 unsafe { rbool(Rf_isTs(self.s())) }
121 }
122 fn is_userbinop(&self) -> bool {
123 unsafe { rbool(Rf_isUserBinop(self.s())) }
124 }
125 fn is_validstring(&self) -> bool {
126 unsafe { rbool(Rf_isValidString(self.s())) }
127 }
128 fn is_validstringf(&self) -> bool {
129 unsafe { rbool(Rf_isValidStringF(self.s())) }
130 }
131 fn is_vector(&self) -> bool {
132 unsafe { rbool(Rf_isVector(self.s())) }
133 }
134 fn is_vectoratomic(&self) -> bool {
135 unsafe { rbool(Rf_isVectorAtomic(self.s())) }
136 }
137 fn is_vectorlist(&self) -> bool {
138 unsafe { rbool(Rf_isVectorList(self.s())) }
139 }
140 fn is_vectorizable(&self) -> bool {
141 unsafe { rbool(Rf_isVectorizable(self.s())) }
142 }
143 fn is_ordered(&self) -> bool {
144 unsafe { rbool(Rf_isOrdered(self.s())) }
145 }
146 fn is_unordered(&self) -> bool {
147 unsafe { rbool(Rf_isUnordered(self.s())) }
148 }
149 fn is_data_frame(&self)->bool{
150 unsafe {rbool(Rf_inherits( self.s(), c_str("data.frame").as_ptr() ))}
151 }
152}
153
154
155impl ToSEXP for Rtemp {
156 unsafe fn s(&self) -> SEXP {
157 self.data
158 }
159}
160
161impl ToSEXP for SEXP {
162 unsafe fn s(&self) -> SEXP {
163 *self
164 }
165}
166
167pub trait NoneSEXP {}
168
169pub trait FromR<T> {
170 fn fromr(&self) -> RResult<T>;
171}
172
173pub trait RNew
174 where Self: Sized
175{
176 fn rnew(x: SEXP) -> RResult<Self>;
177}
178
179pub trait URNew
180 where Self: Sized
181{
182 unsafe fn urnew(x: SEXP) -> Self;
183}
184
185pub trait IntoR {
186 fn intor(&self) -> RResult<SEXP>;
187}
188
189pub trait UIntoR {
190 unsafe fn uintor(&self) -> SEXP;
191}
192
193impl FromR<SEXP> for SEXP {
198 fn fromr(&self) -> RResult<SEXP> {
199 Ok(*self)
200 }
201}
202
203impl RNew for SEXP {
204 fn rnew(x: SEXP) -> RResult<SEXP> {
205 Ok(x)
206 }
207}
208
209impl IntoR for SEXP {
210 fn intor(&self) -> RResult<SEXP> {
211 Ok(*self)
212 }
213}
214
215pub trait Moves {
216 fn moves(x: Self) -> Self;
217}
218
219pub trait Others {
220 fn others(x: &Self) -> Self;
221}
222
223pub trait Empty {
224 fn empty() -> Self;
225}
226
227pub trait Gettable {
228 type Res;
229 fn get(self) -> Self::Res;
230}
231
232pub trait ErrGettable {
233 type Res;
234 fn get_err(self) -> Self::Res;
235}
236
237pub trait RObjClass: ToSEXP {
238 type Origin;
239}
240
241use storage::*;
242use robject::*;
243
244pub trait FromRObj<T:SEXPbucket, E:ToSEXP> : Sized+NewRObj{
245 fn r(x: RObjM<T>) -> RResult<Self> {
246 Self::new(x)
247 }
248}
249
250pub trait NewRObj : Sized{
251 fn new<E: ToSEXP>(x: E) -> RResult<Self>;
252 unsafe fn unew<E: ToSEXP>(x: E) -> Self;
253}
254
255pub trait Shallow: Sized + ToSEXP {
256 fn sc(&self) -> Self;
257 fn sclone_from(&mut self, source: &Self) {
258 *self = source.sc()
259 }
260}
261
262
263pub trait Named: ToSEXP {
264 fn named(&self) -> bool {
265 false
266 }
267 fn name(&self) -> SEXP {
268 unsafe { R_NilValue }
269 }
270}
271
272impl Named for SEXP {}
273
274impl<T: Named> Args for T {}
275
276pub trait FromCastSEXP: Sized {
277 fn casts(x: SEXP) -> RResult<Self>;
278}