[Rprotobuf-commits] r309 - in pkg: R src
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Wed Apr 28 15:35:58 CEST 2010
Author: romain
Date: 2010-04-28 15:35:58 +0200 (Wed, 28 Apr 2010)
New Revision: 309
Removed:
pkg/src/length.cpp
Modified:
pkg/R/00classes.R
pkg/R/aslist.R
pkg/R/clear.R
pkg/src/aslist.cpp
pkg/src/clear.cpp
pkg/src/rprotobuf.h
pkg/src/wrapper_Message.cpp
Log:
move some Message methods to wrapp_Message.cpp
Modified: pkg/R/00classes.R
===================================================================
--- pkg/R/00classes.R 2010-04-28 13:21:39 UTC (rev 308)
+++ pkg/R/00classes.R 2010-04-28 13:35:58 UTC (rev 309)
@@ -153,8 +153,6 @@
"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, ... ),
"bytesize" = function() bytesize(x),
"swap" = function(...) swap(x,...),
@@ -168,6 +166,9 @@
"toString" = function(...) toString( x, ... ),
"add" = function(...) add( x, ...),
+ "serialize" = function(...) serialize( x, ... ),
+ "clear" = function(...) clear( x, ... ),
+
"descriptor" = function() descriptor(x),
"fileDescriptor" = function() fileDescriptor(x ),
@@ -440,7 +441,7 @@
# {{{ length
setGeneric( "length" )
setMethod( "length", "Message", function( x ){
- .Call( "get_message_length", x at pointer, PACKAGE = "RProtoBuf" )
+ .Call( "Message__length", x at pointer, PACKAGE = "RProtoBuf" )
} )
setMethod( "length", "EnumDescriptor", function( x ){
.Call( "EnumDescriptor_length", x at pointer, PACKAGE = "RProtoBuf" )
Modified: pkg/R/aslist.R
===================================================================
--- pkg/R/aslist.R 2010-04-28 13:21:39 UTC (rev 308)
+++ pkg/R/aslist.R 2010-04-28 13:35:58 UTC (rev 309)
@@ -1,5 +1,5 @@
as.list.Message <- function( x, ...){
- .Call( "as_list_message", x at pointer, PACKAGE = "RProtoBuf" )
+ .Call( "Message__as_list", x at pointer, PACKAGE = "RProtoBuf" )
}
as.list.Descriptor <- function(x, ...){
.Call( "as_list_descriptor", x at pointer, PACKAGE = "RProtoBuf" )
Modified: pkg/R/clear.R
===================================================================
--- pkg/R/clear.R 2010-04-28 13:21:39 UTC (rev 308)
+++ pkg/R/clear.R 2010-04-28 13:35:58 UTC (rev 309)
@@ -2,7 +2,7 @@
standardGeneric( "clear" )
} )
setMethod( "clear", signature( "Message", "missing" ), function(object, field, ...){
- .Call( "clear_message", object at pointer, PACKAGE = "RProtoBuf" )
+ .Call( "Message__clear", object at pointer, PACKAGE = "RProtoBuf" )
invisible( object )
} )
Modified: pkg/src/aslist.cpp
===================================================================
--- pkg/src/aslist.cpp 2010-04-28 13:21:39 UTC (rev 308)
+++ pkg/src/aslist.cpp 2010-04-28 13:35:58 UTC (rev 309)
@@ -3,22 +3,6 @@
namespace rprotobuf{
/**
- * @param xp external pointer to a Message
- * @return the message as an R list
- */
-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( message, Rcpp::CharacterVector::create( fieldNames[i] ) ) ;
- }
- val.names() = fieldNames ;
- return val ;
-}
-
-/**
* @param xp external pointer to a Descriptor
* @return the descriptor as an R list
*/
Modified: pkg/src/clear.cpp
===================================================================
--- pkg/src/clear.cpp 2010-04-28 13:21:39 UTC (rev 308)
+++ pkg/src/clear.cpp 2010-04-28 13:35:58 UTC (rev 309)
@@ -2,20 +2,5 @@
namespace rprotobuf{
- RCPP_XP_METHOD_VOID_0(clear_message, GPB::Message, Clear )
- /**
- * Clear a field of a message
- *
- * @param xp (GPB::Message*) external pointer
- * @param field name or tag of the field
- */
- SEXP clear_message_field( SEXP xp, SEXP field ){
- GPB::Message* m = GET_MESSAGE_POINTER_FROM_XP( xp ) ;
- GPB::FieldDescriptor* field_desc = getFieldDescriptor( m, field ) ;
- const GPB::Reflection* ref = m->GetReflection();
- ref->ClearField( m, field_desc ) ;
- return( R_NilValue );
- }
-
} // namespace rprotobuf
Deleted: pkg/src/length.cpp
===================================================================
--- pkg/src/length.cpp 2010-04-28 13:21:39 UTC (rev 308)
+++ pkg/src/length.cpp 2010-04-28 13:35:58 UTC (rev 309)
@@ -1,43 +0,0 @@
-#include "rprotobuf.h"
-
-namespace rprotobuf{
-
-/**
- * The number of fields the message has. A field counts in these two situations :
- * - it is repeated and the array size is greater than 0
- * - it is not repeated and the message has it
- *
- * @param xp external pointer to the Message
- */
-RCPP_FUNCTION_1(int, get_message_length, Rcpp::XPtr<GPB::Message> message){
-
-RPB_DEBUG_BEGIN(get_message_length)
-
- const GPB::Descriptor* desc = message->GetDescriptor();
- const GPB::Reflection * ref = message->GetReflection() ;
-
- int nfields = desc->field_count() ;
-
- int res = 0;
-
- for( int i=0; i<nfields; i++){
- const GPB::FieldDescriptor* field_desc = desc->field( i ) ;
- if( field_desc->is_repeated() ){
- if( ref->FieldSize( *message, field_desc ) > 0 ){
- res++ ;
- }
- } else{
- if( ref->HasField( *message, field_desc ) ){
- res++ ;
- }
- }
- }
-
-RPB_DEBUG_END(get_message_length)
-
- return res ;
-
-}
-
-} // namespace rprotobuf
-
Modified: pkg/src/rprotobuf.h
===================================================================
--- pkg/src/rprotobuf.h 2010-04-28 13:21:39 UTC (rev 308)
+++ pkg/src/rprotobuf.h 2010-04-28 13:35:58 UTC (rev 309)
@@ -304,7 +304,6 @@
RcppExport void CHECK_messages( GPB::FieldDescriptor*, SEXP) ;
/* in aslist.cpp */
-RcppExport SEXP as_list_message( SEXP ) ;
RcppExport SEXP as_list_descriptor( SEXP );
RcppExport SEXP as_list_enum_descriptor( SEXP );
RcppExport SEXP as_list_file_descriptor( SEXP ) ;
@@ -323,12 +322,6 @@
RcppExport SEXP get_field_size(SEXP, SEXP);
RcppExport SEXP set_field_size(SEXP, SEXP, SEXP);
-/* in length.cpp */
-RcppExport SEXP get_message_length( SEXP ) ;
-
-/* in clear.cpp */
-RcppExport SEXP clear_message_field( SEXP, SEXP ) ;
-
/* in swap.cpp */
RcppExport SEXP message_swap_fields(SEXP, SEXP, SEXP, SEXP) ;
Modified: pkg/src/wrapper_Message.cpp
===================================================================
--- pkg/src/wrapper_Message.cpp 2010-04-28 13:21:39 UTC (rev 308)
+++ pkg/src/wrapper_Message.cpp 2010-04-28 13:35:58 UTC (rev 309)
@@ -87,6 +87,67 @@
return( payload ) ;
}
+RCPP_XP_METHOD_VOID_0(Message__clear, GPB::Message, Clear )
+/**
+ * Clear a field of a message
+ *
+ * @param xp (GPB::Message*) external pointer
+ * @param field name or tag of the field
+ */
+RCPP_FUNCTION_VOID_1(Message__clear_field, Rcpp::XPtr<GPB::Message> m, SEXP field ){
+ GPB::FieldDescriptor* field_desc = getFieldDescriptor( m, field ) ;
+ const GPB::Reflection* ref = m->GetReflection();
+ ref->ClearField( m, field_desc ) ;
}
+
+/**
+ * @param xp external pointer to a Message
+ * @return the message as an R list
+ */
+RCPP_FUNCTION_1( Rcpp::List, Message__as_list, 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( message, Rcpp::CharacterVector::create( fieldNames[i] ) ) ;
+ }
+ val.names() = fieldNames ;
+ return val ;
+}
+
+/**
+ * The number of fields the message has. A field counts in these two situations :
+ * - it is repeated and the array size is greater than 0
+ * - it is not repeated and the message has it
+ *
+ * @param xp external pointer to the Message
+ */
+RCPP_FUNCTION_1(int, Message__length, Rcpp::XPtr<GPB::Message> message){
+ const GPB::Descriptor* desc = message->GetDescriptor();
+ const GPB::Reflection * ref = message->GetReflection() ;
+
+ int nfields = desc->field_count() ;
+
+ int res = 0;
+
+ for( int i=0; i<nfields; i++){
+ const GPB::FieldDescriptor* field_desc = desc->field( i ) ;
+ if( field_desc->is_repeated() ){
+ if( ref->FieldSize( *message, field_desc ) > 0 ){
+ res++ ;
+ }
+ } else{
+ if( ref->HasField( *message, field_desc ) ){
+ res++ ;
+ }
+ }
+ }
+ return res ;
+}
+
+
+}
+
More information about the Rprotobuf-commits
mailing list