[Rprotobuf-commits] r307 - in pkg: . R src
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Wed Apr 28 09:33:18 CEST 2010
Author: romain
Date: 2010-04-28 09:33:17 +0200 (Wed, 28 Apr 2010)
New Revision: 307
Removed:
pkg/src/clone.cpp
pkg/src/has.cpp
pkg/src/initialized.cpp
Modified:
pkg/DESCRIPTION
pkg/R/00classes.R
pkg/R/clone.R
pkg/R/has.R
pkg/src/ConnectionCopyingInputStream.cpp
pkg/src/ConnectionCopyingInputStream.h
pkg/src/ConnectionCopyingOutputStream.cpp
pkg/src/ConnectionCopyingOutputStream.h
pkg/src/EnumDescriptor_wrapper.cpp
pkg/src/FieldDescriptor_wrapper.cpp
pkg/src/ServiceDescriptor_wrapper.cpp
pkg/src/as.cpp
pkg/src/ascharacter.cpp
pkg/src/aslist.cpp
pkg/src/clear.cpp
pkg/src/length.cpp
pkg/src/methods.cpp
pkg/src/mutators.cpp
pkg/src/rprotobuf.cpp
pkg/src/rprotobuf.h
pkg/src/serialize.cpp
pkg/src/update.cpp
Log:
using Rcpp 0.8.0 macros
Modified: pkg/DESCRIPTION
===================================================================
--- pkg/DESCRIPTION 2010-04-08 19:49:57 UTC (rev 306)
+++ pkg/DESCRIPTION 2010-04-28 07:33:17 UTC (rev 307)
@@ -7,7 +7,7 @@
Description: Protocol Buffers are a way of encoding structured data in an
efficient yet extensible format. Google uses Protocol Buffers for almost all
of its internal RPC protocols and file formats.
-Depends: R (>= 2.10.0), RCurl, Rcpp (>= 0.7.11.3), methods
+Depends: R (>= 2.11.0), RCurl, Rcpp (>= 0.7.12.9), methods
LinkingTo: Rcpp
Suggests: RUnit, highlight
SystemRequirements: Protocol Buffer compiler (to create C++ header and source files
Modified: pkg/R/00classes.R
===================================================================
--- pkg/R/00classes.R 2010-04-08 19:49:57 UTC (rev 306)
+++ pkg/R/00classes.R 2010-04-28 07:33:17 UTC (rev 307)
@@ -150,9 +150,9 @@
setMethod("$", "Message", function(x, name) {
switch( name,
- "has" = function( what ) .Call( "message_has_field", x at pointer, what, PACKAGE = "RProtoBuf" ),
- "clone" = function( ... ) ._clone.message( x, ... ),
- "isInitialized" = function() isInitialized( x ),
+ "has" = function( ... ) .Call( "Message__has_field" , x at pointer, ..., PACKAGE = "RProtoBuf"),
+ "clone" = function( ... ) .Call( "Message__clone" , x at pointer, ..., PACKAGE = "RProtoBuf"),
+ "isInitialized" = function() .Call( "Message__is_initialized", x at pointer, PACKAGE = "RProtoBuf"),
"serialize" = function(...) serialize( x, ... ),
"clear" = function(...) clear( x, ... ),
"size" = function(field, ...) size(x, field, ... ),
Modified: pkg/R/clone.R
===================================================================
--- pkg/R/clone.R 2010-04-08 19:49:57 UTC (rev 306)
+++ pkg/R/clone.R 2010-04-28 07:33:17 UTC (rev 307)
@@ -3,7 +3,7 @@
standardGeneric( "clone" )
} )
._clone.message <- function( object, ... ){
- message <- .Call( "clone_message", object at pointer )
+ message <- .Call( "Message__clone", object at pointer )
update( message, ... )
message
}
Modified: pkg/R/has.R
===================================================================
--- pkg/R/has.R 2010-04-08 19:49:57 UTC (rev 306)
+++ pkg/R/has.R 2010-04-28 07:33:17 UTC (rev 307)
@@ -3,7 +3,7 @@
standardGeneric( "has" )
} )
._has_message <- function( object, name, ...){
- .Call( "message_has_field", object at pointer, name, PACKAGE = "RProtoBuf" )
+ .Call( "Message__has_field", object at pointer, name, PACKAGE = "RProtoBuf" )
}
setMethod( "has", "Message", ._has_message )
Modified: pkg/src/ConnectionCopyingInputStream.cpp
===================================================================
--- pkg/src/ConnectionCopyingInputStream.cpp 2010-04-08 19:49:57 UTC (rev 306)
+++ pkg/src/ConnectionCopyingInputStream.cpp 2010-04-28 07:33:17 UTC (rev 307)
@@ -3,7 +3,8 @@
namespace rprotobuf{
- ConnectionCopyingInputStream::ConnectionCopyingInputStream(SEXP con) : con(con){}
+ ConnectionCopyingInputStream::ConnectionCopyingInputStream(SEXP con) :
+ con(con), readBin("readBin") {}
/**
* call readBin to read size bytes from R
@@ -15,15 +16,10 @@
*/
int ConnectionCopyingInputStream::Read(void * buffer, int size){
- /* we need to take care of error handling */
- SEXP what = PROTECT( Rf_allocVector(RAWSXP, 0) ) ;
- SEXP n = PROTECT( Rf_ScalarInteger( size ) );
- SEXP call = PROTECT( Rf_lang4( Rf_install( "readBin" ), con, what, n) ) ;
- SEXP res = PROTECT( Rf_eval( call, R_GlobalEnv ) );
- int len = LENGTH( res ) ;
- memcpy( buffer, RAW(res), len ) ;
- UNPROTECT( 4 ) ; /* res, call, n, what */
- return len ;
+ /* TODO: error handling */
+ Rcpp::RawVector res = readBin( con, Rcpp::RawVector( (size_t)0 ), size ) ;
+ memcpy( buffer, res.begin() , res.size() ) ;
+ return res.size() ;
}
Modified: pkg/src/ConnectionCopyingInputStream.h
===================================================================
--- pkg/src/ConnectionCopyingInputStream.h 2010-04-08 19:49:57 UTC (rev 306)
+++ pkg/src/ConnectionCopyingInputStream.h 2010-04-28 07:33:17 UTC (rev 307)
@@ -17,6 +17,8 @@
care of GC here
*/
SEXP con ;
+
+ Rcpp::Function readBin ;
} ;
} // namespace rprotobuf
Modified: pkg/src/ConnectionCopyingOutputStream.cpp
===================================================================
--- pkg/src/ConnectionCopyingOutputStream.cpp 2010-04-08 19:49:57 UTC (rev 306)
+++ pkg/src/ConnectionCopyingOutputStream.cpp 2010-04-28 07:33:17 UTC (rev 307)
@@ -3,19 +3,16 @@
namespace rprotobuf{
- ConnectionCopyingOutputStream::ConnectionCopyingOutputStream(SEXP con) : con(con) {}
+ ConnectionCopyingOutputStream::ConnectionCopyingOutputStream(SEXP con) : con(con), writeBin("writeBin") {}
bool ConnectionCopyingOutputStream::Write(const void * buffer, int size){
/* we need to take care of error handling */
- SEXP payload = PROTECT( Rf_allocVector( RAWSXP, size )) ;
- memcpy( RAW(payload), buffer, size ) ;
- SEXP call = PROTECT( Rf_lang3( Rf_install( "writeBin" ), payload, con) ) ;
- SEXP res = PROTECT( Rf_eval( call, R_GlobalEnv ) );
+ Rcpp::RawVector payload(size) ;
+ memcpy( payload.begin() , buffer, size ) ;
- UNPROTECT(3) ; /* res, call, payload */
+ writeBin( payload, con) ;
return true ;
- res = R_NilValue; // not reached, but shuts g++ -Wall up
}
}
Modified: pkg/src/ConnectionCopyingOutputStream.h
===================================================================
--- pkg/src/ConnectionCopyingOutputStream.h 2010-04-08 19:49:57 UTC (rev 306)
+++ pkg/src/ConnectionCopyingOutputStream.h 2010-04-28 07:33:17 UTC (rev 307)
@@ -17,7 +17,8 @@
care of GC here
*/
SEXP con ;
- /* SEXP getWriteBinCall(int size) ; */
+
+ Rcpp::Function writeBin ;
} ;
} // namespace rprotobuf
Modified: pkg/src/EnumDescriptor_wrapper.cpp
===================================================================
--- pkg/src/EnumDescriptor_wrapper.cpp 2010-04-08 19:49:57 UTC (rev 306)
+++ pkg/src/EnumDescriptor_wrapper.cpp 2010-04-28 07:33:17 UTC (rev 307)
@@ -2,38 +2,11 @@
namespace rprotobuf{
- SEXP EnumDescriptor_length(SEXP xp){
- GPB::EnumDescriptor* d = (GPB::EnumDescriptor*)EXTPTR_PTR(xp) ;
- return Rf_ScalarInteger( d->value_count() ) ;
- }
+ RCPP_XP_METHOD_0(EnumDescriptor_length ,GPB::EnumDescriptor,value_count)
+ RCPP_XP_METHOD_0(EnumDescriptor__value_count,GPB::EnumDescriptor,value_count)
- SEXP EnumDescriptor__value_count(SEXP xp){
- GPB::EnumDescriptor* d = (GPB::EnumDescriptor*)EXTPTR_PTR(xp) ;
- return Rf_ScalarInteger( d->value_count() ) ;
- }
+ RCPP_XP_METHOD_CAST_1(EnumDescriptor_getValueByIndex , GPB::EnumDescriptor , value , S4_EnumValueDescriptor )
+ RCPP_XP_METHOD_CAST_1(EnumDescriptor_getValueByNumber, GPB::EnumDescriptor , FindValueByNumber, S4_EnumValueDescriptor )
+ RCPP_XP_METHOD_CAST_1(EnumDescriptor_getValueByName , GPB::EnumDescriptor , FindValueByName , S4_EnumValueDescriptor )
- SEXP EnumDescriptor_getValueByIndex(SEXP xp, SEXP index){
- GPB::EnumDescriptor* d = (GPB::EnumDescriptor*)EXTPTR_PTR(xp) ;
- int i = INTEGER(index)[0] ;
- const GPB::EnumValueDescriptor* evd = d->value(i);
- if( !evd ) return R_NilValue ;
- return new_RS4_EnumValueDescriptor( evd );
- }
-
- SEXP EnumDescriptor_getValueByNumber(SEXP xp, SEXP number){
- GPB::EnumDescriptor* d = (GPB::EnumDescriptor*)EXTPTR_PTR(xp) ;
- int num = INTEGER(number)[0] ;
- const GPB::EnumValueDescriptor* evd = d->FindValueByNumber(num);
- if( !evd ) return R_NilValue ;
- return new_RS4_EnumValueDescriptor( evd );
- }
-
- SEXP EnumDescriptor_getValueByName(SEXP xp, SEXP name){
- GPB::EnumDescriptor* d = (GPB::EnumDescriptor*)EXTPTR_PTR(xp) ;
- std::string nam = CHAR( STRING_ELT(name, 0) ) ;
- const GPB::EnumValueDescriptor* evd = d->FindValueByName(nam);
- if( !evd ) return R_NilValue ;
- return new_RS4_EnumValueDescriptor( evd );
- }
-
} // namespace rprotobuf
Modified: pkg/src/FieldDescriptor_wrapper.cpp
===================================================================
--- pkg/src/FieldDescriptor_wrapper.cpp 2010-04-08 19:49:57 UTC (rev 306)
+++ pkg/src/FieldDescriptor_wrapper.cpp 2010-04-28 07:33:17 UTC (rev 307)
@@ -3,121 +3,62 @@
namespace rprotobuf {
- SEXP FieldDescriptor_is_extension(SEXP xp){
- GPB::FieldDescriptor* d = (GPB::FieldDescriptor*)EXTPTR_PTR(xp) ;
- return Rf_ScalarLogical( d->is_extension() ) ;
- }
+ RCPP_XP_METHOD_0( FieldDescriptor_is_extension , GPB::FieldDescriptor, is_extension)
+ RCPP_XP_METHOD_0( FieldDescriptor_number , GPB::FieldDescriptor, number)
+ RCPP_XP_METHOD_0( FieldDescriptor_type , GPB::FieldDescriptor, type )
+ RCPP_XP_METHOD_0( FieldDescriptor_cpp_type , GPB::FieldDescriptor, cpp_type )
+ RCPP_XP_METHOD_0( FieldDescriptor_label , GPB::FieldDescriptor, label )
+ RCPP_XP_METHOD_0( FieldDescriptor_is_repeated , GPB::FieldDescriptor, is_repeated )
+ RCPP_XP_METHOD_0( FieldDescriptor_is_optional , GPB::FieldDescriptor, is_optional )
+ RCPP_XP_METHOD_0( FieldDescriptor_is_required , GPB::FieldDescriptor, is_required )
+ RCPP_XP_METHOD_0( FieldDescriptor_has_default_value , GPB::FieldDescriptor, has_default_value )
- SEXP FieldDescriptor_number(SEXP xp){
- GPB::FieldDescriptor* d = (GPB::FieldDescriptor*)EXTPTR_PTR(xp) ;
- return Rf_ScalarInteger( d->number() ) ;
+
+#define RPB_HANDLE_CASE(__CPP__,__LC__) \
+case CPPTYPE_##__CPP__: \
+ { \
+ return Rcpp::wrap( d->default_value_##__LC__() ); \
+ break ; \
}
-
- SEXP FieldDescriptor_type(SEXP xp){
- GPB::FieldDescriptor* d = (GPB::FieldDescriptor*)EXTPTR_PTR(xp) ;
- return Rf_ScalarInteger( d->type() ) ;
- }
-
- SEXP FieldDescriptor_cpp_type(SEXP xp){
- GPB::FieldDescriptor* d = (GPB::FieldDescriptor*)EXTPTR_PTR(xp) ;
- return Rf_ScalarInteger( d->cpp_type() ) ;
- }
-
- SEXP FieldDescriptor_label(SEXP xp){
- GPB::FieldDescriptor* d = (GPB::FieldDescriptor*)EXTPTR_PTR(xp) ;
- return Rf_ScalarInteger( d->label() ) ;
- }
-
- SEXP FieldDescriptor_is_repeated(SEXP xp){
- GPB::FieldDescriptor* d = (GPB::FieldDescriptor*)EXTPTR_PTR(xp) ;
- return Rf_ScalarLogical( d->is_repeated() ) ;
- }
-
- SEXP FieldDescriptor_is_optional(SEXP xp){
- GPB::FieldDescriptor* d = (GPB::FieldDescriptor*)EXTPTR_PTR(xp) ;
- return Rf_ScalarInteger( d->is_optional() ) ;
- }
-
- SEXP FieldDescriptor_is_required(SEXP xp){
- GPB::FieldDescriptor* d = (GPB::FieldDescriptor*)EXTPTR_PTR(xp) ;
- return Rf_ScalarInteger( d->is_required() ) ;
- }
-
- SEXP FieldDescriptor_has_default_value(SEXP xp){
- GPB::FieldDescriptor* d = (GPB::FieldDescriptor*)EXTPTR_PTR(xp) ;
- return Rf_ScalarLogical( d->has_default_value() ) ;
- }
-
- SEXP FieldDescriptor_default_value(SEXP xp){
- GPB::FieldDescriptor* d = (GPB::FieldDescriptor*)EXTPTR_PTR(xp) ;
+
+ RCPP_FUNCTION_1( SEXP, FieldDescriptor_default_value , Rcpp::XPtr<GPB::FieldDescriptor> d ){
switch( d->cpp_type() ){
- case CPPTYPE_INT32:
- {
- return Rf_ScalarInteger( (int)d->default_value_int32() ) ;
- break ;
- }
- case CPPTYPE_INT64:
- {
- return Rf_ScalarInteger( (int)d->default_value_int64() ) ;
- break ;
- }
- case CPPTYPE_UINT32:
- {
- return Rf_ScalarInteger( (int)d->default_value_uint32() ) ;
- break ;
- }
- case CPPTYPE_UINT64:
- {
- return Rf_ScalarInteger( (int)d->default_value_uint64() ) ;
- break ;
- }
- case CPPTYPE_DOUBLE:
- {
- return Rf_ScalarReal( (double)d->default_value_double() ) ;
- break ;
- }
- case CPPTYPE_FLOAT:
- {
- return Rf_ScalarReal( (double)d->default_value_float() ) ;
- break ;
- }
- case CPPTYPE_BOOL:
- {
- return Rf_ScalarLogical(d->default_value_bool() ) ;
- break ;
- }
+
+ RPB_HANDLE_CASE(INT32,int32)
+ RPB_HANDLE_CASE(INT64,int64)
+ RPB_HANDLE_CASE(UINT32,uint32)
+ RPB_HANDLE_CASE(UINT64,uint64)
+ RPB_HANDLE_CASE(DOUBLE,double)
+ RPB_HANDLE_CASE(FLOAT,float)
+ RPB_HANDLE_CASE(BOOL,bool)
+ RPB_HANDLE_CASE(STRING,string)
+
case CPPTYPE_ENUM:
{
return Rf_ScalarInteger( d->default_value_enum()->number() ) ;
break ;
}
- case CPPTYPE_STRING:
- {
- return Rf_mkString( d->default_value_string().c_str() ) ;
- break ;
- }
default:
break ;
}
return R_NilValue ;
}
- SEXP FieldDescriptor_message_type(SEXP xp){
- GPB::FieldDescriptor* d = (GPB::FieldDescriptor*)EXTPTR_PTR(xp) ;
+ RCPP_FUNCTION_1(S4_Descriptor, FieldDescriptor_message_type, Rcpp::XPtr<GPB::FieldDescriptor> d){
if( d->cpp_type() != CPPTYPE_MESSAGE ){
- throwException( "not a message type field", "NotMessageType" );
+ throw Rcpp::not_compatible( "not a message type field" ) ;
}
- return new_RS4_Descriptor( d->message_type() ) ;
+ return S4_Descriptor( d->message_type() ) ;
}
- SEXP FieldDescriptor_enum_type(SEXP xp){
- GPB::FieldDescriptor* d = (GPB::FieldDescriptor*)EXTPTR_PTR(xp) ;
+ RCPP_FUNCTION_1(S4_EnumDescriptor, FieldDescriptor_enum_type, Rcpp::XPtr<GPB::FieldDescriptor> d){
if( d->cpp_type() != CPPTYPE_ENUM ){
throwException( "not an enum type field", "NotEnumType" );
}
- return new_RS4_EnumDescriptor( d->enum_type() ) ;
+ return S4_EnumDescriptor( d->enum_type() ) ;
}
+#undef RPB_HANDLE_CASE
} // namespace rprotobuf
Modified: pkg/src/ServiceDescriptor_wrapper.cpp
===================================================================
--- pkg/src/ServiceDescriptor_wrapper.cpp 2010-04-08 19:49:57 UTC (rev 306)
+++ pkg/src/ServiceDescriptor_wrapper.cpp 2010-04-28 07:33:17 UTC (rev 307)
@@ -2,30 +2,10 @@
namespace rprotobuf{
- SEXP ServiceDescriptor_length(SEXP xp){
- GPB::ServiceDescriptor* d = (GPB::ServiceDescriptor*)EXTPTR_PTR(xp) ;
- return Rf_ScalarInteger( d->method_count() ) ;
- }
+ RCPP_XP_METHOD_0(ServiceDescriptor_length,GPB::ServiceDescriptor, method_count )
+ RCPP_XP_METHOD_0(ServiceDescriptor_method_count,GPB::ServiceDescriptor, method_count )
- SEXP ServiceDescriptor_method_count(SEXP xp){
- GPB::ServiceDescriptor* d = (GPB::ServiceDescriptor*)EXTPTR_PTR(xp) ;
- return Rf_ScalarInteger( d->method_count() ) ;
- }
+ RCPP_XP_METHOD_CAST_1(ServiceDescriptor_getMethodByIndex , GPB::ServiceDescriptor , method , S4_MethodDescriptor )
+ RCPP_XP_METHOD_CAST_1(ServiceDescriptor_getMethodByName , GPB::ServiceDescriptor , FindMethodByName, S4_MethodDescriptor )
- SEXP ServiceDescriptor_getMethodByIndex(SEXP xp, SEXP index){
- GPB::ServiceDescriptor* d = (GPB::ServiceDescriptor*)EXTPTR_PTR(xp) ;
- int i = INTEGER(index)[0] ;
- const GPB::MethodDescriptor* md = d->method(i);
- if( !md ) return R_NilValue ;
- return new_RS4_MethodDescriptor( md );
- }
-
- SEXP ServiceDescriptor_getMethodByName(SEXP xp, SEXP name){
- GPB::ServiceDescriptor* d = (GPB::ServiceDescriptor*)EXTPTR_PTR(xp) ;
- std::string nam = CHAR( STRING_ELT(name, 0) ) ;
- const GPB::MethodDescriptor* md = d->FindMethodByName(nam);
- if( !md ) return R_NilValue ;
- return new_RS4_MethodDescriptor( md );
- }
-
} // namespace rprotobuf
Modified: pkg/src/as.cpp
===================================================================
--- pkg/src/as.cpp 2010-04-08 19:49:57 UTC (rev 306)
+++ pkg/src/as.cpp 2010-04-28 07:33:17 UTC (rev 307)
@@ -1,51 +1,44 @@
#include "rprotobuf.h"
namespace rprotobuf{
-
- SEXP asMessage_Descriptor( SEXP xp){
- GPB::Descriptor* d = (GPB::Descriptor*)EXTPTR_PTR(xp) ;
+
+ RCPP_FUNCTION_1(SEXP, asMessage_Descriptor, Rcpp::XPtr<GPB::Descriptor> d ){
GPB::DescriptorProto* message = new GPB::DescriptorProto() ;
d->CopyTo( message );
return( new_RS4_Message_( (GPB::Message*)message ) ) ;
}
- SEXP asMessage_FieldDescriptor( SEXP xp){
- GPB::FieldDescriptor* d = (GPB::FieldDescriptor*)EXTPTR_PTR(xp) ;
+ RCPP_FUNCTION_1(SEXP, asMessage_FieldDescriptor, Rcpp::XPtr<GPB::FieldDescriptor> d ){
GPB::FieldDescriptorProto* message = new GPB::FieldDescriptorProto() ;
d->CopyTo( message );
return( new_RS4_Message_( (GPB::Message*)message ) ) ;
}
- SEXP asMessage_EnumDescriptor( SEXP xp){
- GPB::EnumDescriptor* d = (GPB::EnumDescriptor*)EXTPTR_PTR(xp) ;
+ RCPP_FUNCTION_1(SEXP, asMessage_EnumDescriptor, Rcpp::XPtr<GPB::EnumDescriptor> d ){
GPB::EnumDescriptorProto* message = new GPB::EnumDescriptorProto() ;
d->CopyTo( message );
return( new_RS4_Message_( (GPB::Message*)message ) ) ;
}
- SEXP asMessage_ServiceDescriptor( SEXP xp){
- GPB::ServiceDescriptor* d = (GPB::ServiceDescriptor*)EXTPTR_PTR(xp) ;
+ RCPP_FUNCTION_1(SEXP, asMessage_ServiceDescriptor, Rcpp::XPtr<GPB::ServiceDescriptor> d ){
GPB::ServiceDescriptorProto* message = new GPB::ServiceDescriptorProto() ;
d->CopyTo( message );
return( new_RS4_Message_( (GPB::Message*)message ) ) ;
}
- SEXP asMessage_MethodDescriptor( SEXP xp){
- GPB::MethodDescriptor* d = (GPB::MethodDescriptor*)EXTPTR_PTR(xp) ;
+ RCPP_FUNCTION_1(SEXP, asMessage_MethodDescriptor, Rcpp::XPtr<GPB::MethodDescriptor> d ){
GPB::MethodDescriptorProto* message = new GPB::MethodDescriptorProto() ;
d->CopyTo( message );
return( new_RS4_Message_( (GPB::Message*)message ) ) ;
}
- SEXP asMessage_FileDescriptor( SEXP xp){
- GPB::FileDescriptor* d = (GPB::FileDescriptor*)EXTPTR_PTR(xp) ;
+ RCPP_FUNCTION_1(SEXP, asMessage_FileDescriptor, Rcpp::XPtr<GPB::FileDescriptor> d ){
GPB::FileDescriptorProto* message = new GPB::FileDescriptorProto() ;
d->CopyTo( message );
return( new_RS4_Message_( (GPB::Message*)message ) ) ;
}
- SEXP asMessage_EnumValueDescriptor( SEXP xp){
- GPB::EnumValueDescriptor* d = (GPB::EnumValueDescriptor*)EXTPTR_PTR(xp) ;
+ RCPP_FUNCTION_1(SEXP, asMessage_EnumValueDescriptor, Rcpp::XPtr<GPB::EnumValueDescriptor> d ){
GPB::EnumValueDescriptorProto* message = new GPB::EnumValueDescriptorProto() ;
d->CopyTo( message );
return( new_RS4_Message_( (GPB::Message*)message ) ) ;
Modified: pkg/src/ascharacter.cpp
===================================================================
--- pkg/src/ascharacter.cpp 2010-04-08 19:49:57 UTC (rev 306)
+++ pkg/src/ascharacter.cpp 2010-04-28 07:33:17 UTC (rev 307)
@@ -2,124 +2,17 @@
namespace rprotobuf{
-SEXP as_character_enum_descriptor( SEXP xp){
-#ifdef RPB_DEBUG
-Rprintf( "<as_character_enum_descriptor>\n" ) ;
-#endif
-
- GPB::EnumDescriptor* d = (GPB::EnumDescriptor*)EXTPTR_PTR(xp) ;
-
- SEXP res = PROTECT( Rf_mkString( d->DebugString().c_str() ) ) ;
- UNPROTECT(1); /* res */
-
-#ifdef RPB_DEBUG
-Rprintf( "</as_character_enum_descriptor>\n" ) ;
-#endif
- return(res);
-}
+RCPP_XP_METHOD_0(as_character_enum_descriptor , GPB::EnumDescriptor , DebugString) ;
+RCPP_XP_METHOD_0(as_character_field_descriptor , GPB::FieldDescriptor , DebugString) ;
+RCPP_XP_METHOD_0(as_character_file_descriptor , GPB::FileDescriptor , DebugString) ;
+RCPP_XP_METHOD_0(as_character_enum_value_descriptor , GPB::EnumValueDescriptor , DebugString) ;
+RCPP_XP_METHOD_0(as_character_message , GPB::Message , DebugString) ;
+RCPP_XP_METHOD_0(as_character_descriptor , GPB::Descriptor , DebugString) ;
+RCPP_XP_METHOD_0(as_character_service_descriptor , GPB::ServiceDescriptor , DebugString) ;
+RCPP_XP_METHOD_0(as_character_method_descriptor , GPB::MethodDescriptor , DebugString) ;
-SEXP as_character_field_descriptor( SEXP xp){
-#ifdef RPB_DEBUG
-Rprintf( "<as_character_field_descriptor>\n" ) ;
-#endif
-
- GPB::FieldDescriptor* d = (GPB::FieldDescriptor*)EXTPTR_PTR(xp) ;
-
- SEXP res = PROTECT( Rf_mkString( d->DebugString().c_str() ) ) ;
- UNPROTECT(1); /* res */
-
-#ifdef RPB_DEBUG
-Rprintf( "</as_character_field_descriptor>\n" ) ;
-#endif
- return(res);
-}
-
-SEXP as_character_file_descriptor( SEXP xp){
-#ifdef RPB_DEBUG
-Rprintf( "<as_character_file_descriptor>\n" ) ;
-#endif
-
- GPB::FileDescriptor* d = (GPB::FileDescriptor*)EXTPTR_PTR(xp) ;
-
- SEXP res = PROTECT( Rf_mkString( d->DebugString().c_str() ) ) ;
- UNPROTECT(1); /* res */
-
-#ifdef RPB_DEBUG
-Rprintf( "</as_character_file_descriptor>\n" ) ;
-#endif
- return(res);
-}
-
-SEXP as_character_enum_value_descriptor( SEXP xp){
- GPB::EnumValueDescriptor* d = (GPB::EnumValueDescriptor*)EXTPTR_PTR(xp) ;
- return Rf_mkString( d->DebugString().c_str() ) ;
-}
-
/**
- * Get the debug string of a message
- *
- * @param xp external pointer to a Message pointer
- */
-SEXP as_character_message( SEXP xp ){
-
- /* grab the Message pointer */
- GPB::Message* message = (GPB::Message*)EXTPTR_PTR(xp) ;
-
- SEXP res = PROTECT( Rf_mkString(message->DebugString().c_str() ) ) ;
- UNPROTECT(1); /* res */
- return res ;
-}
-
-
-/**
- * Get the debug string of a message
- *
- * @param xp external pointer to a Descriptor pointer
- */
-SEXP as_character_descriptor( SEXP xp ){
-
- /* grab the Message pointer */
- GPB::Descriptor* desc = (GPB::Descriptor*)EXTPTR_PTR(xp) ;
-
- SEXP res = PROTECT( Rf_mkString(desc->DebugString().c_str() ) ) ;
- UNPROTECT(1); /* res */
- return res ;
-}
-
-/**
- * Get the debug string of a service descriptor
- *
- * @param xp (GPB::ServiceDescriptor*) external pointer
- */
-SEXP as_character_service_descriptor( SEXP xp ){
-
- /* grab the Message pointer */
- GPB::ServiceDescriptor* desc = (GPB::ServiceDescriptor*)EXTPTR_PTR(xp) ;
-
- SEXP res = PROTECT( Rf_mkString(desc->DebugString().c_str() ) ) ;
- UNPROTECT(1); /* res */
- return res ;
-}
-
-/**
- * Get the debug string of a method descriptor
- *
- * @param xp (GPB::MethodDescriptor*) external pointer
- */
-SEXP as_character_method_descriptor( SEXP xp ){
-
- /* grab the Message pointer */
- GPB::MethodDescriptor* desc = (GPB::MethodDescriptor*)EXTPTR_PTR(xp) ;
-
- SEXP res = PROTECT( Rf_mkString(desc->DebugString().c_str() ) ) ;
- UNPROTECT(1); /* res */
- return res ;
-}
-
-
-
-/**
* Get the value of the enum called name
*
* @param xp external pointer to an EnumDescriptor
@@ -127,30 +20,15 @@
*
* @param the value associated with the name
*/
-SEXP get_value_of_enum( SEXP xp, SEXP name ){
-#ifdef RPB_DEBUG
-Rprintf( "<get_value_of_enum>\n" ) ;
-#endif
+RCPP_FUNCTION_2(int,get_value_of_enum,
+ Rcpp::XPtr<GPB::EnumDescriptor> d, std::string name){
- GPB::EnumDescriptor* d = (GPB::EnumDescriptor*)EXTPTR_PTR(xp) ;
-
- /* only the first one is used */
- std::string val = CHAR( STRING_ELT( name, 0) ) ;
- const GPB::EnumValueDescriptor* evd = d->FindValueByName(val) ;
+ const GPB::EnumValueDescriptor* evd = d->FindValueByName(name) ;
if( !evd ){
/* or maybe it should just be NA */
throwException( "cannot get the value", "UnknownEnumValueException" ) ;
}
-
- SEXP res = PROTECT( Rf_allocVector(INTSXP, 1 ) ) ;
- INTEGER(res)[0] = evd->number() ;
- UNPROTECT(1); /* res */
-
-#ifdef RPB_DEBUG
-Rprintf( "</get_value_of_enum>\n" ) ;
-#endif
-
- return res ;
+ return evd->number();
}
} // namespace rprotobuf
Modified: pkg/src/aslist.cpp
===================================================================
--- pkg/src/aslist.cpp 2010-04-08 19:49:57 UTC (rev 306)
+++ pkg/src/aslist.cpp 2010-04-28 07:33:17 UTC (rev 307)
@@ -6,26 +6,15 @@
* @param xp external pointer to a Message
* @return the message as an R list
*/
-SEXP as_list_message( SEXP xp){
-
-#ifdef RPB_DEBUG
-Rprintf( "<as_list_message>\n" ) ;
-#endif
-
- /* grab the Message pointer */
- Rcpp::XPtr<GPB::Message> message(xp) ;
+RCPP_FUNCTION_1( Rcpp::List, as_list_message, Rcpp::XPtr<GPB::Message> message ){
Rcpp::CharacterVector fieldNames = getMessageFieldNames_(message) ;
int nf = fieldNames.size() ;
Rcpp::List val( nf ) ;
for( int i=0; i<nf; i++){
- val[i] = getMessageField( xp, Rf_mkString(CHAR(STRING_ELT(fieldNames, i)) )) ;
+ val[i] = getMessageField( message, Rcpp::CharacterVector::create( fieldNames[i] ) ) ;
}
val.names() = fieldNames ;
-
-#ifdef RPB_DEBUG
-Rprintf( "</as_list_message>\n" ) ;
-#endif
return val ;
}
@@ -33,38 +22,28 @@
* @param xp external pointer to a Descriptor
* @return the descriptor as an R list
*/
-SEXP as_list_descriptor( SEXP xp){
+RCPP_FUNCTION_1( Rcpp::List, as_list_descriptor, Rcpp::XPtr<GPB::Descriptor> desc ){
-#ifdef RPB_DEBUG
-Rprintf( "<as_list_descriptor>\n" ) ;
-#endif
-
- GPB::Descriptor* desc = (GPB::Descriptor*) EXTPTR_PTR(xp) ;
-
- SEXP names = PROTECT( getDescriptorMemberNames(xp) ) ;
- int n = LENGTH(names) ;
+ Rcpp::CharacterVector names = getDescriptorMemberNames(desc) ;
+ int n = names.size() ;
int nfields = desc->field_count() ;
int ntypes = desc->nested_type_count() ;
int nenums = desc->enum_type_count() ;
- SEXP res = PROTECT( Rf_allocVector( VECSXP, n ) );
+ Rcpp::List res(n);
int i=0;
int j=0;
for( i=0; i<nfields; j++, i++){
- SET_VECTOR_ELT( res, j, new_RS4_FieldDescriptor( desc->field(i) ) );
+ res[j] = S4_FieldDescriptor( desc->field(i) );
}
for( i=0; i<ntypes; j++, i++){
- SET_VECTOR_ELT( res, j, new_RS4_Descriptor( desc->nested_type(i) ) );
+ res[j] = S4_Descriptor( desc->nested_type(i) );
}
for( i=0; i<nenums; j++, i++){
- SET_VECTOR_ELT( res, j, new_RS4_EnumDescriptor( desc->enum_type(i) ) );
+ res[j] = S4_EnumDescriptor( desc->enum_type(i) );
}
- Rf_setAttrib( res, Rf_install("names"), names) ;
- UNPROTECT(2); /* res, names */
+ res.names() = names ;
-#ifdef RPB_DEBUG
-Rprintf( "</as_list_descriptor>\n" ) ;
-#endif
return res;
}
@@ -73,66 +52,51 @@
* @param xp external pointer to a Descriptor
* @return the descriptor as an R list
*/
-SEXP as_list_enum_descriptor( SEXP xp){
-#ifdef RPB_DEBUG
-Rprintf( "<as_list_enum_descriptor>\n" ) ;
-#endif
-
- GPB::EnumDescriptor* d = (GPB::EnumDescriptor*)EXTPTR_PTR(xp) ;
+RCPP_FUNCTION_1( Rcpp::IntegerVector, as_list_enum_descriptor, Rcpp::XPtr<GPB::EnumDescriptor> d ){
int n = d->value_count() ;
- SEXP values = PROTECT( Rf_allocVector( INTSXP, n ) ) ;
- SEXP names = PROTECT( Rf_allocVector( STRSXP, n ) ) ;
+ Rcpp::IntegerVector values(n) ;
+ Rcpp::CharacterVector names(n) ;
for( int i=0; i<n; i++){
const GPB::EnumValueDescriptor* value_d = d->value(i) ;
- INTEGER(values)[i] = value_d->number() ;
- SET_STRING_ELT( names, i, Rf_mkChar(value_d->name().c_str()) ) ;
+ values[i] = value_d->number() ;
+ names[i] = value_d->name() ;
}
-
- Rf_setAttrib( values, Rf_install("names"), names ) ;
- UNPROTECT(2); /* names, values */
-#ifdef RPB_DEBUG
-Rprintf( "</as_list_enum_descriptor>\n" ) ;
-#endif
+ values.names() = names ;
return values;
-
}
-
/**
* @param xp (GPB::FileDescriptor*) external pointer
* @return the descriptor as an R list
*/
-SEXP as_list_file_descriptor( SEXP xp){
-
+RCPP_FUNCTION_1( Rcpp::List, as_list_file_descriptor, Rcpp::XPtr<GPB::FileDescriptor> desc ){
+
#ifdef RPB_DEBUG
Rprintf( "<as_list_file_descriptor>\n" ) ;
#endif
- GPB::FileDescriptor* desc = (GPB::FileDescriptor*) EXTPTR_PTR(xp) ;
-
- SEXP names = PROTECT( getFileDescriptorMemberNames(xp) ) ;
- int n = LENGTH(names) ;
+ 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() ;
- SEXP res = PROTECT( Rf_allocVector( VECSXP, n ) );
+ Rcpp::List res( n );
int i=0;
int j=0;
for( i=0; i<ntypes; j++, i++){
- SET_VECTOR_ELT( res, j, new_RS4_Descriptor( desc->message_type(i) ) );
+ res[j] = S4_Descriptor( desc->message_type(i) ) ;
}
for( i=0; i<nenums; j++, i++){
- SET_VECTOR_ELT( res, j, new_RS4_EnumDescriptor( desc->enum_type(i) ) );
+ res[j] = S4_EnumDescriptor( desc->enum_type(i) );
}
for( i=0; i<nserv; j++, i++){
- SET_VECTOR_ELT( res, j, new_RS4_ServiceDescriptor( desc->service(i) ) );
+ res[j] = S4_ServiceDescriptor( desc->service(i) );
}
- Rf_setAttrib( res, Rf_install("names"), names) ;
- UNPROTECT(2); /* res, names */
+ res.names() = names ;
#ifdef RPB_DEBUG
Rprintf( "</as_list_file_descriptor>\n" ) ;
@@ -144,24 +108,20 @@
* @param xp (GPB::ServiceDescriptor*) external pointer
* @return the descriptor as an R list
*/
-SEXP as_list_service_descriptor( SEXP xp){
+RCPP_FUNCTION_1( Rcpp::List, as_list_service_descriptor, Rcpp::XPtr<GPB::ServiceDescriptor> desc ){
#ifdef RPB_DEBUG
Rprintf( "<as_list_service_descriptor>\n" ) ;
#endif
+
+ Rcpp::CharacterVector names = getServiceDescriptorMethodNames(desc) ;
+ int n = names.size() ;
- GPB::ServiceDescriptor* desc = (GPB::ServiceDescriptor*) EXTPTR_PTR(xp) ;
-
- SEXP names = PROTECT( getServiceDescriptorMethodNames(xp) ) ;
- int n = LENGTH(names) ;
-
- SEXP res = PROTECT( Rf_allocVector( VECSXP, n ) );
- int i=0;
- for( i=0; i<n; i++){
- SET_VECTOR_ELT( res, i, new_RS4_MethodDescriptor( desc->method(i) ) );
+ Rcpp::List res(n);
+ for( int i=0; i<n; i++){
+ res[i] = S4_MethodDescriptor( desc->method(i) );
}
- Rf_setAttrib( res, Rf_install("names"), names) ;
- UNPROTECT(2); /* res, names */
+ res.names() = names ;
#ifdef RPB_DEBUG
Rprintf( "</as_list_service_descriptor>\n" ) ;
Modified: pkg/src/clear.cpp
===================================================================
--- pkg/src/clear.cpp 2010-04-08 19:49:57 UTC (rev 306)
+++ pkg/src/clear.cpp 2010-04-28 07:33:17 UTC (rev 307)
@@ -2,16 +2,7 @@
namespace rprotobuf{
- /**
- * clear a message
- *
- * @param xp external pointer to the message
- */
- SEXP clear_message( SEXP xp ){
- GPB::Message* m = GET_MESSAGE_POINTER_FROM_XP( xp ) ;
- m->Clear() ;
- return( R_NilValue );
- }
+ RCPP_XP_METHOD_VOID_0(clear_message, GPB::Message, Clear )
/**
* Clear a field of a message
Deleted: pkg/src/clone.cpp
===================================================================
--- pkg/src/clone.cpp 2010-04-08 19:49:57 UTC (rev 306)
+++ pkg/src/clone.cpp 2010-04-28 07:33:17 UTC (rev 307)
@@ -1,36 +0,0 @@
-#include "rprotobuf.h"
-
-namespace rprotobuf{
-
-/**
- * clone a message
- *
- * @param xp external pointer to a message
- * @return a new message, clone of the input message
- */
-SEXP clone_message( SEXP xp ){
-
-#ifdef RPB_DEBUG
-Rprintf( "<clone_message>\n" ) ;
-#endif
-
- /* grab the Message pointer */
- GPB::Message* message = (GPB::Message*)EXTPTR_PTR(xp) ;
-
- /* cloning message as sheep */
- GPB::Message* sheep = message->New() ;
- sheep->CopyFrom( *message );
-
- SEXP sheep_xp = PROTECT( new_RS4_Message_( sheep ) ) ;
- UNPROTECT(1);
-
-#ifdef RPB_DEBUG
-Rprintf( "</clone_message>\n" ) ;
-#endif
-
- return sheep_xp;
-
-}
-
-} // namespace rprotobuf
-
Deleted: pkg/src/has.cpp
===================================================================
--- pkg/src/has.cpp 2010-04-08 19:49:57 UTC (rev 306)
+++ pkg/src/has.cpp 2010-04-28 07:33:17 UTC (rev 307)
@@ -1,48 +0,0 @@
-#include "rprotobuf.h"
-
-namespace rprotobuf{
-
-/**
- * TRUE if the message has the field name
- *
- * @param xp external pointer to the Message
- * @param name name of the field
- */
-SEXP message_has_field( SEXP xp, SEXP name ){
-#ifdef RPB_DEBUG
-Rprintf( "<message_has_field>\n" ) ;
-#endif
-
- /* grab the Message pointer */
- GPB::Message* message = (GPB::Message*)EXTPTR_PTR(xp) ;
-
- const GPB::Descriptor* desc = message->GetDescriptor();
-
- const char* what= CHAR(STRING_ELT(name,0));
-
- const GPB::FieldDescriptor* field_desc = desc->FindFieldByName( what ) ;
-
- SEXP res = PROTECT( Rf_allocVector( LGLSXP, 1 ) );
-
- if( !field_desc ){
- LOGICAL(res)[0] = 0 ;
- } else{
- const GPB::Reflection * ref = message->GetReflection() ;
- if( field_desc->is_repeated() ){
- LOGICAL(res)[0] = ref->FieldSize( *message, field_desc ) > 0 ? 1 : 0 ;
- } else{
- LOGICAL(res)[0] = ref->HasField( *message, field_desc ) ? 1 : 0 ;
- }
- }
- UNPROTECT(1);
-
-#ifdef RPB_DEBUG
-Rprintf( "</message_has_field>\n" ) ;
-#endif
-
- return res ;
-
-}
-
-} // namespace rprotobuf
-
Deleted: pkg/src/initialized.cpp
===================================================================
--- pkg/src/initialized.cpp 2010-04-08 19:49:57 UTC (rev 306)
+++ pkg/src/initialized.cpp 2010-04-28 07:33:17 UTC (rev 307)
@@ -1,35 +0,0 @@
-#include "rprotobuf.h"
-
-namespace rprotobuf{
-
-/**
- * Check if all required fields are set
- *
- * @param xp external pointer to the Message
- */
-SEXP is_message_initialized( SEXP xp ){
-#ifdef RPB_DEBUG
-Rprintf( "<is_message_initialized>\n" ) ;
-#endif
-
- /* grab the Message pointer */
- GPB::Message* message = GET_MESSAGE_POINTER_FROM_XP(xp) ;
-
- SEXP ans = PROTECT( Rf_ScalarLogical( (int) message->IsInitialized() ) );
- if( !LOGICAL(ans)[0] ){
- /* then find out why */
- Rf_setAttrib( ans, Rf_install("uninitialized") ,
- Rf_mkString( message->InitializationErrorString().c_str() ) ) ;
- }
- UNPROTECT(1) ; /* ans */
-
-#ifdef RPB_DEBUG
-Rprintf( "</is_message_initialized>\n" ) ;
-#endif
-
- return ans ;
-
-}
-
-} // namespace rprotobuf
-
Modified: pkg/src/length.cpp
===================================================================
--- pkg/src/length.cpp 2010-04-08 19:49:57 UTC (rev 306)
+++ pkg/src/length.cpp 2010-04-28 07:33:17 UTC (rev 307)
@@ -9,14 +9,10 @@
*
* @param xp external pointer to the Message
*/
-SEXP get_message_length( SEXP xp ){
-#ifdef RPB_DEBUG
-Rprintf( "<get_message_length>\n" ) ;
-#endif
+RCPP_FUNCTION_1(int, get_message_length, Rcpp::XPtr<GPB::Message> message){
- /* grab the Message pointer */
- GPB::Message* message = GET_MESSAGE_POINTER_FROM_XP(xp) ;
-
+RPB_DEBUG_BEGIN(get_message_length)
+
const GPB::Descriptor* desc = message->GetDescriptor();
[TRUNCATED]
To get the complete diff run:
svnlook diff /svnroot/rprotobuf -r 307
More information about the Rprotobuf-commits
mailing list