[Rprotobuf-commits] r314 - pkg/src

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sat May 8 12:03:23 CEST 2010


Author: romain
Date: 2010-05-08 12:03:20 +0200 (Sat, 08 May 2010)
New Revision: 314

Added:
   pkg/src/wrapper_Descriptor.cpp
   pkg/src/wrapper_EnumValueDescriptor.cpp
   pkg/src/wrapper_FileDescriptor.cpp
   pkg/src/wrapper_MethodDescriptor.cpp
Removed:
   pkg/src/as.cpp
   pkg/src/size.cpp
Modified:
   pkg/src/ConnectionCopyingInputStream.cpp
   pkg/src/ascharacter.cpp
   pkg/src/aslist.cpp
   pkg/src/constructors.cpp
   pkg/src/rprotobuf.h
   pkg/src/wrapper_EnumDescriptor.cpp
   pkg/src/wrapper_FieldDescriptor.cpp
   pkg/src/wrapper_Message.cpp
   pkg/src/wrapper_ServiceDescriptor.cpp
Log:
keep moving

Modified: pkg/src/ConnectionCopyingInputStream.cpp
===================================================================
--- pkg/src/ConnectionCopyingInputStream.cpp	2010-04-28 13:58:36 UTC (rev 313)
+++ pkg/src/ConnectionCopyingInputStream.cpp	2010-05-08 10:03:20 UTC (rev 314)
@@ -17,7 +17,7 @@
 	int	ConnectionCopyingInputStream::Read(void * buffer, int size){
 		
 		/* TODO: error handling */
-		Rcpp::RawVector res = readBin( con, Rcpp::RawVector( (size_t)0 ), size ) ;
+		Rcpp::RawVector res = readBin( con, Rcpp::RawVector( 0 ), size ) ;
 		memcpy( buffer, res.begin() , res.size() ) ;
 		return res.size() ;
 	}

Deleted: pkg/src/as.cpp
===================================================================
--- pkg/src/as.cpp	2010-04-28 13:58:36 UTC (rev 313)
+++ pkg/src/as.cpp	2010-05-08 10:03:20 UTC (rev 314)
@@ -1,47 +0,0 @@
-#include "rprotobuf.h"
-
-namespace rprotobuf{
-
-	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 ) ) ;
-	}
-	
-	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 ) ) ;
-	}
-	
-	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 ) ) ;
-	}
-	
-	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 ) ) ;
-	}
-	
-	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 ) ) ;
-	}
-	
-	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 ) ) ;
-	}
-	
-	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 ) ) ;
-	}
-	
-} // namespace rprotobuf

Modified: pkg/src/ascharacter.cpp
===================================================================
--- pkg/src/ascharacter.cpp	2010-04-28 13:58:36 UTC (rev 313)
+++ pkg/src/ascharacter.cpp	2010-05-08 10:03:20 UTC (rev 314)
@@ -6,7 +6,6 @@
 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) ;

Modified: pkg/src/aslist.cpp
===================================================================
--- pkg/src/aslist.cpp	2010-04-28 13:58:36 UTC (rev 313)
+++ pkg/src/aslist.cpp	2010-05-08 10:03:20 UTC (rev 314)
@@ -6,36 +6,6 @@
  * @param xp external pointer to a Descriptor
  * @return the descriptor as an R list
  */
-RCPP_FUNCTION_1( Rcpp::List, as_list_descriptor, Rcpp::XPtr<GPB::Descriptor> desc ){
-	
- 	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() ;
-	
-	Rcpp::List res(n); 
-	int i=0;
-	int j=0; 
-	for( i=0; i<nfields; j++, i++){
-		res[j] = S4_FieldDescriptor( desc->field(i) ); 
-	}
-	for( i=0; i<ntypes; j++, i++){
-		res[j] = S4_Descriptor( desc->nested_type(i) ); 
-	}
-	for( i=0; i<nenums; j++, i++){
-		res[j] = S4_EnumDescriptor( desc->enum_type(i) ); 
-	}
-	res.names() = names ;
-	
-	return res; 
-}
-
-
-/**
- * @param xp external pointer to a Descriptor
- * @return the descriptor as an R list
- */
 RCPP_FUNCTION_1( Rcpp::IntegerVector, as_list_enum_descriptor, Rcpp::XPtr<GPB::EnumDescriptor> d ){
 	
 	int n = d->value_count() ;
@@ -88,32 +58,6 @@
 	return res; 
 }
 
-/**
- * @param xp (GPB::ServiceDescriptor*) external pointer
- * @return the descriptor as an R list
- */
-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() ;
-	
-	Rcpp::List res(n); 
-	for( int i=0; i<n; i++){
-		res[i] = S4_MethodDescriptor( desc->method(i) ); 
-	}
-	res.names() = names ;
-	
-#ifdef RPB_DEBUG
-Rprintf( "</as_list_service_descriptor>\n" ) ;
-#endif
-	return res; 
-}
-
-
-
 } // namespace rprotobuf
 

Modified: pkg/src/constructors.cpp
===================================================================
--- pkg/src/constructors.cpp	2010-04-28 13:58:36 UTC (rev 313)
+++ pkg/src/constructors.cpp	2010-05-08 10:03:20 UTC (rev 314)
@@ -2,14 +2,6 @@
 
 namespace rprotobuf{
 
-void Message_finalizer( SEXP xp){
-	if (TYPEOF(xp)==EXTPTRSXP) {
-		GPB::Message* message = (GPB::Message*)XPP(xp) ;
-		FIN_DBG( message, "Message" ) ;
-		delete message;
-	}
-}
-
 /**
  * Creates an R object of S4 class Descriptor
  * from a google::protobuf::Descriptor pointer
@@ -117,28 +109,6 @@
 	return oo; 
 }
 
-/* same as above, but get the type from the message */
-SEXP new_RS4_Message_( const GPB::Message* message ){
-	
-	NEW_S4_OBJECT( "Message" ) ;
-  	
-	/* external pointer to the Message */
-	SEXP ptr   = PROTECT( R_MakeExternalPtr( (void*)message , 
-		R_NilValue, R_NilValue));
-	R_RegisterCFinalizerEx( ptr, Message_finalizer , _FALSE_ ) ;
-	
-	/* the message type */
-	SEXP type = PROTECT( Rf_mkString( message->GetDescriptor()->full_name().c_str() )) ;
-	
-	SET_SLOT( oo, Rf_install("type"), type ) ;
-	SET_SLOT( oo, Rf_install("pointer"), ptr ) ;
-	
-	UNPROTECT( 3) ; /* ptr, oo, type */
-	return( oo ); 
-	
-}
-
-
 /**
  * Creates a new "ServiceDescriptor" R S4 object
  *

Modified: pkg/src/rprotobuf.h
===================================================================
--- pkg/src/rprotobuf.h	2010-04-28 13:58:36 UTC (rev 313)
+++ pkg/src/rprotobuf.h	2010-05-08 10:03:20 UTC (rev 314)
@@ -213,7 +213,7 @@
 			if( type_desc ){
 				slot( "type" ) = type_desc->full_name()  ;
 			} else{
-				slot( "type" ) = Rcpp::StringVector( (size_t)0) ;
+				slot( "type" ) = Rcpp::StringVector(0) ;
 			}
 			
 		}
@@ -257,11 +257,9 @@
 RcppExport SEXP get_protobuf_library_version() ;
                                                                                     
 /* in constructors.cpp */
-void Message_finalizer( SEXP ) ;
 RcppExport SEXP new_RS4_Descriptor( const GPB::Descriptor*  ); 
 RcppExport SEXP new_RS4_FieldDescriptor( const GPB::FieldDescriptor* ); 
 RcppExport SEXP new_RS4_EnumDescriptor( const GPB::EnumDescriptor*); 
-RcppExport SEXP new_RS4_Message_( const GPB::Message* );
 RcppExport SEXP new_RS4_ServiceDescriptor( const GPB::ServiceDescriptor* ) ;
 RcppExport SEXP new_RS4_MethodDescriptor( const GPB::MethodDescriptor* ) ;
 RcppExport SEXP new_RS4_FileDescriptor( const GPB::FileDescriptor* ) ;
@@ -306,7 +304,6 @@
 RcppExport SEXP as_list_descriptor( SEXP ); 
 RcppExport SEXP as_list_enum_descriptor( SEXP );
 RcppExport SEXP as_list_file_descriptor( SEXP ) ;
-RcppExport SEXP as_list_service_descriptor( SEXP ); 
 
 /* in merge.cpp */
 RcppExport SEXP merge_message( SEXP, SEXP ); 
@@ -317,8 +314,6 @@
 RcppExport SEXP readMessageFromRawVector( SEXP, SEXP );
 
 /* in size.cpp */
-RcppExport SEXP get_message_bytesize( SEXP ) ;
-RcppExport SEXP get_field_size(SEXP, SEXP);
 RcppExport SEXP set_field_size(SEXP, SEXP, SEXP);
 
 /* in swap.cpp */

Deleted: pkg/src/size.cpp
===================================================================
--- pkg/src/size.cpp	2010-04-28 13:58:36 UTC (rev 313)
+++ pkg/src/size.cpp	2010-05-08 10:03:20 UTC (rev 314)
@@ -1,207 +0,0 @@
-#include "rprotobuf.h"
-#include "fieldtypes.h" 
-
-namespace rprotobuf{
-
-/** 
- * get the number of bytes the message will take on the wire
- * 
- * @param xp external pointer to a GPB::Message*
- * @return the number of bytes 
- */
-SEXP get_message_bytesize( SEXP xp ){
-	
-	GPB::Message* message = GET_MESSAGE_POINTER_FROM_XP( xp ); 
-	
-	SEXP size = PROTECT( Rf_ScalarInteger( message->ByteSize() ) );
-	UNPROTECT( 1 ) ; /* size */
-	return size ; 
-}
-
-SEXP get_field_size(SEXP xp, SEXP field){
-	
-	GPB::Message* message = GET_MESSAGE_POINTER_FROM_XP( xp ); 
-	
-	GPB::FieldDescriptor* field_desc = getFieldDescriptor( message, field ) ;
-	
-	SEXP res = PROTECT( Rf_allocVector( INTSXP, 1 ) ) ;
-	if( field_desc->is_repeated() ){
-		INTEGER(res)[0] = message->GetReflection()->FieldSize(*message, field_desc ) ;
-	} else{
-		INTEGER(res)[0] = message->GetReflection()->HasField(*message, field_desc) ? 1: 0 ;
-	}
-	UNPROTECT(1) ;
-	return res ;
-}
-
-SEXP set_field_size(SEXP xp, SEXP field, SEXP newsize){
-	
-	GPB::Message* message = GET_MESSAGE_POINTER_FROM_XP( xp ); 
-	
-	GPB::FieldDescriptor* field_desc = getFieldDescriptor( message, field ) ;
-	const GPB::Reflection* ref = message->GetReflection() ;
-	
-	int target = INTEGER(newsize)[0] ;
-	if( field_desc->is_repeated() ){
-		int current = ref->FieldSize(*message, field_desc ) ;
-		
-		if( target == 0){
-			ref->ClearField( message, field_desc );
-		} else if( current > target ){
-			while( current != target ){
-				ref->RemoveLast( message, field_desc ) ;
-				current-- ;
-			}
-		} else if( current == target ) {
-			/* nothing to do */
-		} else { /* current < target */
-			
-			while( current != target ){
-			
-				switch( field_desc->type() ){
-						case TYPE_INT32:
-    					case TYPE_SINT32:
-    					case TYPE_SFIXED32:
-    				        {
-    				        	ref->AddInt32(message, field_desc, (int32)0 ) ;
-    				        	break ;
-    				        }
-    					case TYPE_INT64:
-						case TYPE_SINT64:
-						case TYPE_SFIXED64:
-    				        {
-    				        	ref->AddInt64(message, field_desc, (int64)0 ) ;
-    				        	break ;
-    				        }
-		    			case TYPE_UINT32:
-    					case TYPE_FIXED32:
-    						{
-    							ref->AddUInt32(message, field_desc, (uint32)0 ) ;
-    				        	break ;
-    				        }
-    					case TYPE_UINT64:
-    					case TYPE_FIXED64:
-    						{
-    							ref->AddUInt32(message, field_desc, (uint64)0 ) ;
-    				        	break ;
-    						}
-    				    case TYPE_DOUBLE:
-    				    	{
-    				    		ref->AddDouble(message, field_desc, (double)0.0 ) ;
-    				    		break ;
-    				    	}
-    				    case TYPE_FLOAT:
-    				    	{
-    				    		ref->AddFloat(message, field_desc, (float)0.0 ) ;
-    				    		break ;
-    				    	}
-    				    case TYPE_BOOL:
-    				    	{
-    				    		ref->AddBool(message, field_desc, (bool)0 ) ;
-    				    		break ;
-    				    	}
-    				    case TYPE_STRING:
-    				    case TYPE_BYTES:
-    				    	{
-    				    		ref->AddString(message, field_desc, "" ) ;
-    							break ;
-    				    	}
-    				    case TYPE_MESSAGE:
-    				    case TYPE_GROUP:
-    				    	{
-    				    		/* fill with the prototype for that message type */
-    				    		Rf_error( "growing repeated messages not implemented yet, patches welcome" ) ;
-    				    		break ;
-    				    	}
-    				    case TYPE_ENUM:
-    				    	{ 
-    				    		/* fill with the prototype for that message type */
-    				    		Rf_error( "growing repeated enum not implemented yet, patches welcome" ) ;
-    				    		break ;
-    				    	}
-    				} /* switch */
-    			
-    			current++ ;
-    		} /* while */
-			
-			
-		}
-		
-	} else{
-		if( target == 0 ){
-			if( ref->HasField( *message, field_desc ) ){
-				ref->ClearField( message, field_desc );
-			}
-		} else {
-			if( !ref->HasField( *message, field_desc ) ){
-				switch( field_desc->type() ){
-					case TYPE_INT32:
-    				case TYPE_SINT32:
-    				case TYPE_SFIXED32:
-    			        {
-    			        	ref->SetInt32(message, field_desc, (int32)0 ) ;
-    			        	break ;
-    			        }
-    				case TYPE_INT64:
-					case TYPE_SINT64:
-					case TYPE_SFIXED64:
-    			        {
-    			        	ref->SetInt64(message, field_desc, (int64)0 ) ;
-    			        	break ;
-    			        }
-		    		case TYPE_UINT32:
-    				case TYPE_FIXED32:
-    					{
-    						ref->SetUInt32(message, field_desc, (uint32)0 ) ;
-    			        	break ;
-    			        }
-    				case TYPE_UINT64:
-    				case TYPE_FIXED64:
-    					{
-    						ref->SetUInt32(message, field_desc, (uint64)0 ) ;
-    			        	break ;
-    					}
-    			    case TYPE_DOUBLE:
-    			    	{
-    			    		ref->SetDouble(message, field_desc, (double)0.0 ) ;
-    			    		break ;
-    			    	}
-    			    case TYPE_FLOAT:
-    			    	{
-    			    		ref->SetFloat(message, field_desc, (float)0.0 ) ;
-    			    		break ;
-    			    	}
-    			    case TYPE_BOOL:
-    			    	{
-    			    		ref->SetBool(message, field_desc, (bool)0 ) ;
-    			    		break ;
-    			    	}
-    			    case TYPE_STRING:
-    			    case TYPE_BYTES:
-    			    	{
-    			    		ref->SetString(message, field_desc, "" ) ;
-    						break ;
-    			    	}
-    			    case TYPE_MESSAGE:
-    			    case TYPE_GROUP:
-    			    	{
-    			    		/* fill with the prototype for that message type */
-    			    		Rf_error( "not implemented yet, patches welcome" ) ;
-    			    		break ;
-    			    	}
-    			    case TYPE_ENUM:
-    			    	{ 
-    			    		/* fill with the prototype for that message type */
-    			    		Rf_error( "not implemented yet, patches welcome" ) ;
-    			    		break ;
-    			    	}
-    				}
-    			}
-		}
-	}
-	return R_NilValue ;
-}
-
-
-
-} // namespace rprotobuf

Added: pkg/src/wrapper_Descriptor.cpp
===================================================================
--- pkg/src/wrapper_Descriptor.cpp	                        (rev 0)
+++ pkg/src/wrapper_Descriptor.cpp	2010-05-08 10:03:20 UTC (rev 314)
@@ -0,0 +1,46 @@
+#include "rprotobuf.h"
+
+namespace rprotobuf{
+
+#undef METHOD
+#define METHOD(__NAME__) RCPP_PP_CAT(Descriptor__,__NAME__)	
+	
+/**
+ * @param xp external pointer to a Descriptor
+ * @return the descriptor as an R list
+ */
+RCPP_FUNCTION_1( Rcpp::List, METHOD(as_lis), Rcpp::XPtr<GPB::Descriptor> desc ){
+	
+ 	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() ;
+	
+	Rcpp::List res(n); 
+	int i=0;
+	int j=0; 
+	for( i=0; i<nfields; j++, i++){
+		res[j] = S4_FieldDescriptor( desc->field(i) ); 
+	}
+	for( i=0; i<ntypes; j++, i++){
+		res[j] = S4_Descriptor( desc->nested_type(i) ); 
+	}
+	for( i=0; i<nenums; j++, i++){
+		res[j] = S4_EnumDescriptor( desc->enum_type(i) ); 
+	}
+	res.names() = names ;
+	
+	return res; 
+}
+
+RCPP_FUNCTION_1(S4_Message, METHOD(as_Message) , Rcpp::XPtr<GPB::Descriptor> d ){
+	GPB::DescriptorProto* message = new GPB::DescriptorProto() ; 
+	d->CopyTo( message ); 
+	return message  ;
+}
+
+
+#undef METHOD
+
+} // namespace rprotobuf

Modified: pkg/src/wrapper_EnumDescriptor.cpp
===================================================================
--- pkg/src/wrapper_EnumDescriptor.cpp	2010-04-28 13:58:36 UTC (rev 313)
+++ pkg/src/wrapper_EnumDescriptor.cpp	2010-05-08 10:03:20 UTC (rev 314)
@@ -2,11 +2,23 @@
 
 namespace rprotobuf{
 
-	RCPP_XP_METHOD_0(EnumDescriptor_length      ,GPB::EnumDescriptor,value_count)
-	RCPP_XP_METHOD_0(EnumDescriptor__value_count,GPB::EnumDescriptor,value_count)
+#undef METHOD
+#define METHOD(__NAME__) RCPP_PP_CAT(Descriptor__,__NAME__)	
+
+	RCPP_XP_METHOD_0(METHOD(length)      ,GPB::EnumDescriptor,value_count)
+	RCPP_XP_METHOD_0(METHOD(value_count) ,GPB::EnumDescriptor,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 )
+	RCPP_XP_METHOD_CAST_1(METHOD(getValueByIndex) , GPB::EnumDescriptor , value            , S4_EnumValueDescriptor ) 
+	RCPP_XP_METHOD_CAST_1(METHOD(getValueByNumber), GPB::EnumDescriptor , FindValueByNumber, S4_EnumValueDescriptor )
+	RCPP_XP_METHOD_CAST_1(METHOD(getValueByName)  , GPB::EnumDescriptor , FindValueByName  , S4_EnumValueDescriptor )
+
+	RCPP_FUNCTION_1(S4_EnumDescriptor, METHOD(as_Message), Rcpp::XPtr<GPB::EnumDescriptor> d ){
+		GPB::EnumDescriptorProto* message = new GPB::EnumDescriptorProto() ; 
+		d->CopyTo( message ); 
+		return message ;
+	}
 	
+ 
+#undef METHOD
+
 } // namespace rprotobuf

Added: pkg/src/wrapper_EnumValueDescriptor.cpp
===================================================================
--- pkg/src/wrapper_EnumValueDescriptor.cpp	                        (rev 0)
+++ pkg/src/wrapper_EnumValueDescriptor.cpp	2010-05-08 10:03:20 UTC (rev 314)
@@ -0,0 +1,16 @@
+#include "rprotobuf.h"
+
+namespace rprotobuf{
+
+#undef METHOD
+#define METHOD(__NAME__) RCPP_PP_CAT(EnumValueDescriptor__,__NAME__)
+	
+RCPP_FUNCTION_1(S4_EnumValueDescriptor, asMessage_EnumValueDescriptor, Rcpp::XPtr<GPB::EnumValueDescriptor> d ){
+	GPB::EnumValueDescriptorProto* message = new GPB::EnumValueDescriptorProto() ; 
+	d->CopyTo( message ); 
+	return message ;
+}
+		
+#undef METHOD
+
+} // namespace rprotobuf

Modified: pkg/src/wrapper_FieldDescriptor.cpp
===================================================================
--- pkg/src/wrapper_FieldDescriptor.cpp	2010-04-28 13:58:36 UTC (rev 313)
+++ pkg/src/wrapper_FieldDescriptor.cpp	2010-05-08 10:03:20 UTC (rev 314)
@@ -3,15 +3,18 @@
 
 namespace rprotobuf {
 
-	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 )  
+#undef METHOD
+#define METHOD(__NAME__) RCPP_PP_CAT(FieldDescriptor__,__NAME__)	
+
+	RCPP_XP_METHOD_0( METHOD(is_extension)      , GPB::FieldDescriptor, is_extension)  
+	RCPP_XP_METHOD_0( METHOD(number)            , GPB::FieldDescriptor, number)  
+	RCPP_XP_METHOD_0( METHOD(type)              , GPB::FieldDescriptor, type )  
+	RCPP_XP_METHOD_0( METHOD(cpp_type)          , GPB::FieldDescriptor, cpp_type )  
+	RCPP_XP_METHOD_0( METHOD(label)             , GPB::FieldDescriptor, label )  
+	RCPP_XP_METHOD_0( METHOD(is_repeated)       , GPB::FieldDescriptor, is_repeated )  
+	RCPP_XP_METHOD_0( METHOD(is_optional)       , GPB::FieldDescriptor, is_optional )  
+	RCPP_XP_METHOD_0( METHOD(is_required)       , GPB::FieldDescriptor, is_required )  
+	RCPP_XP_METHOD_0( METHOD(has_default_value) , GPB::FieldDescriptor, has_default_value )  
 	
 
 #define RPB_HANDLE_CASE(__CPP__,__LC__)                           \
@@ -21,7 +24,7 @@
 		break ;                                                   \
 	}
 
-	RCPP_FUNCTION_1( SEXP, FieldDescriptor_default_value , Rcpp::XPtr<GPB::FieldDescriptor> d ){
+	RCPP_FUNCTION_1( SEXP, METHOD(default_value) , Rcpp::XPtr<GPB::FieldDescriptor> d ){
 		switch( d->cpp_type() ){
 			
 			RPB_HANDLE_CASE(INT32,int32)
@@ -44,21 +47,30 @@
 		return R_NilValue ;
 	}
 	
-	RCPP_FUNCTION_1(S4_Descriptor, FieldDescriptor_message_type, Rcpp::XPtr<GPB::FieldDescriptor> d){
+	RCPP_FUNCTION_1(S4_Descriptor, METHOD(message_type), Rcpp::XPtr<GPB::FieldDescriptor> d){
 		if( d->cpp_type() != CPPTYPE_MESSAGE ){
 			throw Rcpp::not_compatible( "not a message type field" )  ;
 		}
 		return S4_Descriptor( d->message_type() ) ;
 	}
 	
-	RCPP_FUNCTION_1(S4_EnumDescriptor, FieldDescriptor_enum_type, Rcpp::XPtr<GPB::FieldDescriptor> d){
+	RCPP_FUNCTION_1(S4_EnumDescriptor, METHOD(enum_type), Rcpp::XPtr<GPB::FieldDescriptor> d){
 		if( d->cpp_type() != CPPTYPE_ENUM ){
 			throwException( "not an enum type field", "NotEnumType" ); 
 		}
 		return S4_EnumDescriptor( d->enum_type() ) ;
 	}
+
+	RCPP_FUNCTION_1(S4_FieldDescriptor, METHOD(as_Message), Rcpp::XPtr<GPB::FieldDescriptor> d ){
+		GPB::FieldDescriptorProto* message = new GPB::FieldDescriptorProto() ; 
+		d->CopyTo( message ); 
+		return message ;
+	}
 	
+	
 #undef RPB_HANDLE_CASE
-	
+#undef METHOD
+
+
 } // namespace rprotobuf
 

Added: pkg/src/wrapper_FileDescriptor.cpp
===================================================================
--- pkg/src/wrapper_FileDescriptor.cpp	                        (rev 0)
+++ pkg/src/wrapper_FileDescriptor.cpp	2010-05-08 10:03:20 UTC (rev 314)
@@ -0,0 +1,16 @@
+#include "rprotobuf.h"
+
+namespace rprotobuf{
+
+#undef METHOD
+#define METHOD(__NAME__) RCPP_PP_CAT(FileDescriptor__,__NAME__)
+	
+RCPP_FUNCTION_1(S4_FileDescriptor, METHOD(as_Message), Rcpp::XPtr<GPB::FileDescriptor> d ){
+	GPB::FileDescriptorProto* message = new GPB::FileDescriptorProto() ; 
+	d->CopyTo( message ); 
+	return message ;
+}
+	
+#undef METHOD
+
+} // namespace rprotobuf

Modified: pkg/src/wrapper_Message.cpp
===================================================================
--- pkg/src/wrapper_Message.cpp	2010-04-28 13:58:36 UTC (rev 313)
+++ pkg/src/wrapper_Message.cpp	2010-05-08 10:03:20 UTC (rev 314)
@@ -1,14 +1,28 @@
 #include "rprotobuf.h"
+#include "fieldtypes.h"
 
 namespace rprotobuf{
 	
+#undef METHOD
+#define METHOD(__NAME__) RCPP_PP_CAT(Message__,__NAME__)
+
+/* same as above, but get the type from the message */
+SEXP new_RS4_Message_( const GPB::Message* message ){
+	
+	Rcpp::S4 oo( "Message" ) ;
+	Rcpp::XPtr<GPB::Message> xp(message, true ) ;
+	oo.slot("pointer") = xp ;
+	oo.slot("type"   ) = message->GetDescriptor()->full_name() ;
+	return oo ;
+}
+
 /**
  * clone a message
  *
  * @param xp external pointer to a message
  * @return a new message, clone of the input message
  */
-RCPP_FUNCTION_1( S4_Message, Message__clone, Rcpp::XPtr<GPB::Message> message ){
+RCPP_FUNCTION_1( S4_Message, METHOD(clone) , Rcpp::XPtr<GPB::Message> message ){
 	/* cloning message as sheep */
 	GPB::Message* sheep = message->New() ;
 	sheep->CopyFrom( *message );
@@ -22,7 +36,7 @@
  * @param xp external pointer to the Message
  * @param name name of the field
  */
-RCPP_FUNCTION_2(bool, Message__has_field, Rcpp::XPtr<GPB::Message> message, std::string name ){
+RCPP_FUNCTION_2(bool, METHOD(has_field), Rcpp::XPtr<GPB::Message> message, std::string name ){
 
 	const GPB::Descriptor* desc = message->GetDescriptor(); 
 	const GPB::FieldDescriptor* field_desc = desc->FindFieldByName( name ) ;
@@ -45,7 +59,7 @@
  *
  * @param xp external pointer to the Message
  */
-RCPP_FUNCTION_1( bool, Message__is_initialized, Rcpp::XPtr<GPB::Message> message){
+RCPP_FUNCTION_1( bool, METHOD(is_initialized), Rcpp::XPtr<GPB::Message> message){
 	return message->IsInitialized() ;
 }
 
@@ -56,7 +70,7 @@
  * @param xp external pointer to a GPB::Message*
  * @param filename file name where to serialize
  */
-RCPP_FUNCTION_VOID_2( Message__serialize_to_file, Rcpp::XPtr<GPB::Message> message, const char* filename){
+RCPP_FUNCTION_VOID_2( METHOD(serialize_to_file) , Rcpp::XPtr<GPB::Message> message, const char* filename){
 	
 	/* open the file in binary mode to write */
 	/* we make sure in the R side that filename is the full path of the file */
@@ -75,7 +89,7 @@
  *
  * @param xp xternal pointer to the message
  */
-RCPP_FUNCTION_1( Rcpp::RawVector, Message__get_payload, Rcpp::XPtr<GPB::Message> message ){
+RCPP_FUNCTION_1( Rcpp::RawVector, METHOD(get_payload), Rcpp::XPtr<GPB::Message> message ){
 
 	/* create a raw vector of the appropriate size */
 	int size = message->ByteSize() ;
@@ -87,7 +101,7 @@
 	return( payload ) ;
 }
 
-RCPP_XP_METHOD_VOID_0(Message__clear, GPB::Message, Clear )
+RCPP_XP_METHOD_VOID_0(METHOD(clear), GPB::Message, Clear )
 
 /**
  * Clear a field of a message
@@ -95,7 +109,7 @@
  * @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 ){
+RCPP_FUNCTION_VOID_2(METHOD(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 ) ;
@@ -106,7 +120,7 @@
  * @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_FUNCTION_1( Rcpp::List, METHOD(as_list), Rcpp::XPtr<GPB::Message> message ){
     
 	Rcpp::CharacterVector fieldNames = getMessageFieldNames_(message) ;
 	int nf = fieldNames.size() ;
@@ -125,7 +139,7 @@
  *
  * @param xp external pointer to the Message
  */
-RCPP_FUNCTION_1(int, Message__length, Rcpp::XPtr<GPB::Message> message){
+RCPP_FUNCTION_1(int, METHOD(length), Rcpp::XPtr<GPB::Message> message){
 	const GPB::Descriptor* desc = message->GetDescriptor(); 
 	const GPB::Reflection * ref = message->GetReflection() ;
 	
@@ -155,11 +169,193 @@
  * @param xp (GPB::Message*) external pointer
  * @return the descriptor, as a Descriptor R S4 object
  */
-RCPP_FUNCTION_1(S4_Descriptor, Message__descriptor, Rcpp::XPtr<GPB::Message> message ){
+RCPP_FUNCTION_1(S4_Descriptor, METHOD(descriptor), Rcpp::XPtr<GPB::Message> message ){
 	return( message->GetDescriptor() ) ;
 }
 
+RCPP_XP_METHOD_0( METHOD(as_character) , GPB::Message, DebugString) ;
+RCPP_XP_METHOD_0( METHOD(bytesize), GPB::Message, ByteSize )
 
+RCPP_FUNCTION_2( int, METHOD(field_size), Rcpp::XPtr<GPB::Message> message, SEXP field  ){
+	
+	GPB::FieldDescriptor* field_desc = getFieldDescriptor( message, field ) ;
+	
+	int res = 0 ;
+	if( field_desc->is_repeated() ){
+		res = message->GetReflection()->FieldSize(*message, field_desc ) ;
+	} else{
+		res = message->GetReflection()->HasField(*message, field_desc) ? 1: 0 ;
+	}
+	return res ;
+}
 
+
+RCPP_FUNCTION_VOID_3( METHOD(set_field_size), Rcpp::XPtr<GPB::Message> message, SEXP field, int target){
+	
+	GPB::FieldDescriptor* field_desc = getFieldDescriptor( message, field ) ;
+	const GPB::Reflection* ref = message->GetReflection() ;
+	
+	if( field_desc->is_repeated() ){
+		int current = ref->FieldSize(*message, field_desc ) ;
+		
+		if( target == 0){
+			ref->ClearField( message, field_desc );
+		} else if( current > target ){
+			while( current != target ){
+				ref->RemoveLast( message, field_desc ) ;
+				current-- ;
+			}
+		} else if( current == target ) {
+			/* nothing to do */
+		} else { /* current < target */
+			
+			while( current != target ){
+			
+				switch( field_desc->type() ){
+						case TYPE_INT32:
+    					case TYPE_SINT32:
+    					case TYPE_SFIXED32:
+    				        {
+    				        	ref->AddInt32(message, field_desc, (int32)0 ) ;
+    				        	break ;
+    				        }
+    					case TYPE_INT64:
+						case TYPE_SINT64:
+						case TYPE_SFIXED64:
+    				        {
+    				        	ref->AddInt64(message, field_desc, (int64)0 ) ;
+    				        	break ;
+    				        }
+		    			case TYPE_UINT32:
+    					case TYPE_FIXED32:
+    						{
+    							ref->AddUInt32(message, field_desc, (uint32)0 ) ;
+    				        	break ;
+    				        }
+    					case TYPE_UINT64:
+    					case TYPE_FIXED64:
+    						{
+    							ref->AddUInt32(message, field_desc, (uint64)0 ) ;
+    				        	break ;
+    						}
+    				    case TYPE_DOUBLE:
+    				    	{
+    				    		ref->AddDouble(message, field_desc, (double)0.0 ) ;
+    				    		break ;
+    				    	}
+    				    case TYPE_FLOAT:
+    				    	{
+    				    		ref->AddFloat(message, field_desc, (float)0.0 ) ;
+    				    		break ;
+    				    	}
+    				    case TYPE_BOOL:
+    				    	{
+    				    		ref->AddBool(message, field_desc, (bool)0 ) ;
+    				    		break ;
+    				    	}
+    				    case TYPE_STRING:
+    				    case TYPE_BYTES:
+    				    	{
+    				    		ref->AddString(message, field_desc, "" ) ;
+    							break ;
+    				    	}
+    				    case TYPE_MESSAGE:
+    				    case TYPE_GROUP:
+    				    	{
+    				    		/* fill with the prototype for that message type */
+    				    		Rf_error( "growing repeated messages not implemented yet, patches welcome" ) ;
+    				    		break ;
+    				    	}
+    				    case TYPE_ENUM:
+    				    	{ 
+    				    		/* fill with the prototype for that message type */
+    				    		Rf_error( "growing repeated enum not implemented yet, patches welcome" ) ;
+    				    		break ;
+    				    	}
+    				} /* switch */
+    			
+    			current++ ;
+    		} /* while */
+			
+			
+		}
+		
+	} else{
+		if( target == 0 ){
+			if( ref->HasField( *message, field_desc ) ){
+				ref->ClearField( message, field_desc );
+			}
+		} else {
+			if( !ref->HasField( *message, field_desc ) ){
+				switch( field_desc->type() ){
+					case TYPE_INT32:
+    				case TYPE_SINT32:
+    				case TYPE_SFIXED32:
+    			        {
+    			        	ref->SetInt32(message, field_desc, (int32)0 ) ;
+    			        	break ;
+    			        }
+    				case TYPE_INT64:
+					case TYPE_SINT64:
+					case TYPE_SFIXED64:
+    			        {
+    			        	ref->SetInt64(message, field_desc, (int64)0 ) ;
+    			        	break ;
+    			        }
+		    		case TYPE_UINT32:
+    				case TYPE_FIXED32:
+    					{
+    						ref->SetUInt32(message, field_desc, (uint32)0 ) ;
+    			        	break ;
+    			        }
+    				case TYPE_UINT64:
+    				case TYPE_FIXED64:
+    					{
+    						ref->SetUInt32(message, field_desc, (uint64)0 ) ;
+    			        	break ;
+    					}
+    			    case TYPE_DOUBLE:
+    			    	{
+    			    		ref->SetDouble(message, field_desc, (double)0.0 ) ;
+    			    		break ;
+    			    	}
+    			    case TYPE_FLOAT:
+    			    	{
+    			    		ref->SetFloat(message, field_desc, (float)0.0 ) ;
+    			    		break ;
+    			    	}
+    			    case TYPE_BOOL:
+    			    	{
+    			    		ref->SetBool(message, field_desc, (bool)0 ) ;
+    			    		break ;
+    			    	}
+    			    case TYPE_STRING:
+    			    case TYPE_BYTES:
+    			    	{
+    			    		ref->SetString(message, field_desc, "" ) ;
+    						break ;
+    			    	}
+    			    case TYPE_MESSAGE:
+    			    case TYPE_GROUP:
+    			    	{
+    			    		/* fill with the prototype for that message type */
+    			    		Rf_error( "not implemented yet, patches welcome" ) ;
+    			    		break ;
+    			    	}
+    			    case TYPE_ENUM:
+    			    	{ 
+    			    		/* fill with the prototype for that message type */
+    			    		Rf_error( "not implemented yet, patches welcome" ) ;
+    			    		break ;
+    			    	}
+    				}
+    			}
+		}
+	}
+	return R_NilValue ;
 }
 
+
+
+}
+

Added: pkg/src/wrapper_MethodDescriptor.cpp
===================================================================
--- pkg/src/wrapper_MethodDescriptor.cpp	                        (rev 0)
+++ pkg/src/wrapper_MethodDescriptor.cpp	2010-05-08 10:03:20 UTC (rev 314)
@@ -0,0 +1,17 @@
+#include "rprotobuf.h"
+
+namespace rprotobuf{
+
+#undef METHOD
+#define METHOD(__NAME__) RCPP_PP_CAT(MethodDescriptor__,__NAME__)
+
+RCPP_FUNCTION_1(S4_MethodDescriptor, METHOD(as_Message), Rcpp::XPtr<GPB::MethodDescriptor> d ){
+	GPB::MethodDescriptorProto* message = new GPB::MethodDescriptorProto() ; 
+	d->CopyTo( message ); 
+	return message ;
+}
+	
+	
+#undef METHOD
+
+} // namespace rprotobuf

Modified: pkg/src/wrapper_ServiceDescriptor.cpp
===================================================================
--- pkg/src/wrapper_ServiceDescriptor.cpp	2010-04-28 13:58:36 UTC (rev 313)
+++ pkg/src/wrapper_ServiceDescriptor.cpp	2010-05-08 10:03:20 UTC (rev 314)
@@ -2,10 +2,39 @@
 
 namespace rprotobuf{
 
-	RCPP_XP_METHOD_0(ServiceDescriptor_length,GPB::ServiceDescriptor, method_count )
-	RCPP_XP_METHOD_0(ServiceDescriptor_method_count,GPB::ServiceDescriptor, method_count )
+#undef METHOD
+#define METHOD(__NAME__) RCPP_PP_CAT(ServiceDescriptor__,__NAME__)	
 	
-	RCPP_XP_METHOD_CAST_1(ServiceDescriptor_getMethodByIndex , GPB::ServiceDescriptor , method          , S4_MethodDescriptor ) 
-	RCPP_XP_METHOD_CAST_1(ServiceDescriptor_getMethodByName  , GPB::ServiceDescriptor , FindMethodByName, S4_MethodDescriptor ) 
+	RCPP_XP_METHOD_0( METHOD(length),GPB::ServiceDescriptor, method_count )
[TRUNCATED]

To get the complete diff run:
    svnlook diff /svnroot/rprotobuf -r 314


More information about the Rprotobuf-commits mailing list