[Rprotobuf-commits] r323 - in pkg: R src
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Sat May 8 13:57:25 CEST 2010
Author: romain
Date: 2010-05-08 13:57:24 +0200 (Sat, 08 May 2010)
New Revision: 323
Modified:
pkg/R/completion.R
pkg/src/completion.cpp
pkg/src/rprotobuf.h
pkg/src/wrapper_EnumDescriptor.cpp
pkg/src/wrapper_FileDescriptor.cpp
pkg/src/wrapper_ServiceDescriptor.cpp
Log:
start moving completion.cpp to wrapper_*
Modified: pkg/R/completion.R
===================================================================
--- pkg/R/completion.R 2010-05-08 11:18:52 UTC (rev 322)
+++ pkg/R/completion.R 2010-05-08 11:57:24 UTC (rev 323)
@@ -40,7 +40,7 @@
.DollarNames.EnumDescriptor <- function(x, pattern = "" ){
names <- c(
- .Call( "getEnumDescriptorConstantNames", x at pointer, PACKAGE = "RProtoBuf" ),
+ .Call( "EnumDescriptor__getConstantNames", x at pointer, PACKAGE = "RProtoBuf" ),
"name(", "fileDescriptor()", "as.character()", "toString()",
"containing_type()", "length()", "value_count()", "value(" )
grep( pattern, names, value = TRUE )
@@ -62,7 +62,7 @@
# {{{ ServiceDescriptor
.DollarNames.ServiceDescriptor <- function(x, pattern = "" ){
names <- c(
- .Call( "getServiceDescriptorMethodNames", x at pointer, PACKAGE = "RProtoBuf" ),
+ .Call( "ServiceDescriptor__getMethodNames", x at pointer, PACKAGE = "RProtoBuf" ),
"as.character()", "toString()", "name(", "fileDescriptor()",
"method_count()", "method(name=", "method(index=" )
grep( pattern, names, value = TRUE )
@@ -80,7 +80,7 @@
# {{{ FileDescriptor
.DollarNames.FileDescriptor <- function(x, pattern = "" ){
names <- c(
- .Call( "getFileDescriptorMemberNames", x at pointer, PACKAGE = "RProtoBuf" ),
+ .Call( "FileDescriptor__getMemberNames", x at pointer, PACKAGE = "RProtoBuf" ),
"as.character()", "toString()", "name(" )
grep( pattern, names, value = TRUE )
}
Modified: pkg/src/completion.cpp
===================================================================
--- pkg/src/completion.cpp 2010-05-08 11:18:52 UTC (rev 322)
+++ pkg/src/completion.cpp 2010-05-08 11:57:24 UTC (rev 323)
@@ -70,102 +70,5 @@
}
-
-/**
- * returns the names of the "members" contained in the
- * file descriptor (message types, enum types, fields)
- *
- * @param xp (GPB::FileDescriptor*) external pointer
- *
- * @return member names, as an R character vector (STRSXP)
- */
-SEXP getFileDescriptorMemberNames( SEXP xp ){
-
- /* the message descriptor */
- GPB::FileDescriptor* desc = (GPB::FileDescriptor*)EXTPTR_PTR(xp) ;
-
- int ntypes = desc->message_type_count() ;
- int nenums = desc->enum_type_count() ;
- int nserv = desc->service_count() ;
-
- SEXP res = PROTECT( Rf_allocVector(STRSXP, ntypes + nenums + nserv ) ) ;
- int i=0;
- int j=0;
- while( i<ntypes){
- SET_STRING_ELT( res, j, Rf_mkChar( desc->message_type(i)->name().c_str() ) ) ;
- i++;
- j++;
- }
- i=0;
- while( i<nenums){
- SET_STRING_ELT( res, j, Rf_mkChar( desc->enum_type(i)->name().c_str() ) ) ;
- i++;
- j++;
- }
- i = 0;
- while( i<nserv){
- SET_STRING_ELT( res, j, Rf_mkChar( desc->service(i)->name().c_str() ) ) ;
- i++;
- j++;
- }
-
- UNPROTECT(1); /* res */
- return( res );
-}
-
-
-
-/**
- * returns the names of the members contained in the descriptor
- * (nested types, enums, fields)
- *
- * @param xp external pointer to a Descriptor
- *
- * @return member names, as an R character vector (STRSXP)
- */
-SEXP getEnumDescriptorConstantNames( SEXP xp){
-
- GPB::EnumDescriptor* d = (GPB::EnumDescriptor*)EXTPTR_PTR(xp) ;
-
- int n = d->value_count() ;
- SEXP names = PROTECT( Rf_allocVector( STRSXP, n ) );
- for( int i=0; i<n; i++){
- SET_STRING_ELT( names, i, Rf_mkChar(d->value(i)->name().c_str() ) ) ;
- }
- UNPROTECT(1) ; /* names */
- return names ;
-
-}
-
-
-/**
- * returns the names of the methods contained in the
- * service descriptor
- *
- * @param xp (GPB::ServiceDescriptor*) external pointer
- *
- * @return method names, as an R character vector (STRSXP)
- */
-SEXP getServiceDescriptorMethodNames( SEXP xp ){
-
- /* the message descriptor */
- GPB::ServiceDescriptor* desc = (GPB::ServiceDescriptor*)EXTPTR_PTR(xp) ;
-
- int nmeths = desc->method_count() ;
-
- SEXP res = PROTECT( Rf_allocVector(STRSXP, nmeths ) ) ;
- int i=0;
- int j=0;
- while( i<nmeths){
- SET_STRING_ELT( res, j, Rf_mkChar( desc->method(i)->name().c_str() ) ) ;
- i++;
- j++;
- }
-
- UNPROTECT(1); /* res */
- return( res );
-}
-
-
} // namespace rprotobuf
Modified: pkg/src/rprotobuf.h
===================================================================
--- pkg/src/rprotobuf.h 2010-05-08 11:18:52 UTC (rev 322)
+++ pkg/src/rprotobuf.h 2010-05-08 11:57:24 UTC (rev 323)
@@ -267,9 +267,6 @@
RcppExport SEXP getMessageFieldNames( SEXP) ;
RcppExport SEXP getMessageFieldNames_(const Rcpp::XPtr<GPB::Message>& message) ;
RcppExport SEXP getDescriptorMemberNames( SEXP) ;
-RcppExport SEXP getFileDescriptorMemberNames( SEXP) ;
-RcppExport SEXP getEnumDescriptorConstantNames( SEXP ) ;
-RcppExport SEXP getServiceDescriptorMethodNames( SEXP ) ;
/* in exceptions.cpp */
RcppExport SEXP throwException( const char*, const char*) ;
Modified: pkg/src/wrapper_EnumDescriptor.cpp
===================================================================
--- pkg/src/wrapper_EnumDescriptor.cpp 2010-05-08 11:18:52 UTC (rev 322)
+++ pkg/src/wrapper_EnumDescriptor.cpp 2010-05-08 11:57:24 UTC (rev 323)
@@ -59,6 +59,14 @@
return values;
}
+RCPP_FUNCTION_1( Rcpp::CharacterVector, METHOD(getConstantNames), Rcpp::XPtr<GPB::EnumDescriptor> d){
+ int n = d->value_count() ;
+ Rcpp::CharacterVector res( n) ;
+ for( int i=0; i<n; i++){
+ res[i] = d->value(i)->name() ;
+ }
+ return names ;
+}
#undef METHOD
Modified: pkg/src/wrapper_FileDescriptor.cpp
===================================================================
--- pkg/src/wrapper_FileDescriptor.cpp 2010-05-08 11:18:52 UTC (rev 322)
+++ pkg/src/wrapper_FileDescriptor.cpp 2010-05-08 11:57:24 UTC (rev 323)
@@ -13,42 +13,67 @@
return message ;
}
+
+RCPP_FUNCTION_1( Rcpp::CharacterVector, METHOD(getMemberNames), Rcpp::XPtr<GPB::FileDescriptor> desc ){
+ int ntypes = desc->message_type_count() ;
+ int nenums = desc->enum_type_count() ;
+ int nserv = desc->service_count() ;
+
+ Rcpp::CharacterVector res( ntypes + nenums + nserv ) ;
+ int i=0;
+ int j=0;
+ while( i<ntypes){
+ res[j] = desc->message_type(i)->name() ;
+ i++;
+ j++;
+ }
+ i=0;
+ while( i<nenums){
+ res[j] = desc->enum_type(i)->name() ;
+ i++;
+ j++;
+ }
+ i = 0;
+ while( i<nserv){
+ res[j] = desc->service(i)->name() ;
+ i++;
+ j++;
+ }
+ return res ;
+
+}
+
/**
* @param xp (GPB::FileDescriptor*) external pointer
* @return the descriptor as an R list
*/
RCPP_FUNCTION_1( Rcpp::List, METHOD(as_list), Rcpp::XPtr<GPB::FileDescriptor> desc ){
-
-#ifdef RPB_DEBUG
-Rprintf( "<as_list_file_descriptor>\n" ) ;
-#endif
-
- Rcpp::CharacterVector names = getFileDescriptorMemberNames(desc) ;
- int n = names.size() ;
int ntypes = desc->message_type_count() ;
int nenums = desc->enum_type_count() ;
int nserv = desc->service_count() ;
+ int n = ntypes + nenums + nserv ;
+ Rcpp::CharacterVector names(n) ;
Rcpp::List res( n );
int i=0;
int j=0;
for( i=0; i<ntypes; j++, i++){
- res[j] = S4_Descriptor( desc->message_type(i) ) ;
+ res[j] = S4_Descriptor( desc->message_type(i) ) ;
+ names[j] = desc->message_type(i)->name() ;
}
for( i=0; i<nenums; j++, i++){
res[j] = S4_EnumDescriptor( desc->enum_type(i) );
+ names[j] = desc->enum_type(i)->name() ;
}
for( i=0; i<nserv; j++, i++){
- res[j] = S4_ServiceDescriptor( desc->service(i) );
+ res[j] = S4_ServiceDescriptor( desc->service(i) );
+ names[j] = desc->service(i)->name() ;
}
res.names() = names ;
-
-#ifdef RPB_DEBUG
-Rprintf( "</as_list_file_descriptor>\n" ) ;
-#endif
return res;
}
+
#undef METHOD
} // namespace rprotobuf
Modified: pkg/src/wrapper_ServiceDescriptor.cpp
===================================================================
--- pkg/src/wrapper_ServiceDescriptor.cpp 2010-05-08 11:18:52 UTC (rev 322)
+++ pkg/src/wrapper_ServiceDescriptor.cpp 2010-05-08 11:57:24 UTC (rev 323)
@@ -12,17 +12,29 @@
RCPP_XP_METHOD_CAST_1( METHOD(getMethodByIndex) , GPB::ServiceDescriptor , method , S4_MethodDescriptor )
RCPP_XP_METHOD_CAST_1( METHOD(getMethodByName) , GPB::ServiceDescriptor , FindMethodByName, S4_MethodDescriptor )
+ RCPP_FUNCTION_1( Rcpp::CharacterVector, METHOD(getMethodNames), Rcpp::XPtr<GPB::ServiceDescriptor> desc){
+ int nmeths = desc->method_count() ;
+ Rcpp::CharacterVector res( nmeths );
+
+ for( int i=0; i<nmeths; i++){
+ res[i] = desc->method(i)->name() ;
+ }
+ return res ;
+ }
+
/**
* @param xp (GPB::ServiceDescriptor*) external pointer
* @return the descriptor as an R list
*/
RCPP_FUNCTION_1( Rcpp::List, METHOD(as_list), Rcpp::XPtr<GPB::ServiceDescriptor> desc ){
- Rcpp::CharacterVector names = getServiceDescriptorMethodNames(desc) ;
- int n = names.size() ;
+ int n = desc->method_count() ;
+ Rcpp::CharacterVector names(n) ;
Rcpp::List res(n);
for( int i=0; i<n; i++){
- res[i] = S4_MethodDescriptor( desc->method(i) );
+ const GPB::MethodDescriptor* met = desc->method(i) ;
+ res[i] = S4_MethodDescriptor( met );
+ names[i] = met->name() ;
}
res.names() = names ;
return res;
More information about the Rprotobuf-commits
mailing list