[Rprotobuf-commits] r607 - in pkg: . src

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Dec 27 10:11:22 CET 2013


Author: murray
Date: 2013-12-27 10:11:21 +0100 (Fri, 27 Dec 2013)
New Revision: 607

Modified:
   pkg/ChangeLog
   pkg/src/mutators.cpp
   pkg/src/rprotobuf.h
   pkg/src/wrapper_Message.cpp
Log:
More const correctness for field_desc type throughout, which then lets
us remove a small amount of duplicate code and reuse a function.



Modified: pkg/ChangeLog
===================================================================
--- pkg/ChangeLog	2013-12-27 08:52:31 UTC (rev 606)
+++ pkg/ChangeLog	2013-12-27 09:11:21 UTC (rev 607)
@@ -7,6 +7,8 @@
 	  error instead of terminating our R instance.
 	* inst/unitTests/runit.messages.R (test.message): Add unit tests
 	  for our handling of setting repeated message fields.
+	* src/wrapper_Message.cpp: Add const qualifier to
+	  field_desc throughout file.
 
 2013-12-26  Murray Stokely  <mstokely at google.com>
 

Modified: pkg/src/mutators.cpp
===================================================================
--- pkg/src/mutators.cpp	2013-12-27 08:52:31 UTC (rev 606)
+++ pkg/src/mutators.cpp	2013-12-27 09:11:21 UTC (rev 607)
@@ -288,7 +288,7 @@
  * @param value value to potentially fill the enum
  *
  */
-void CHECK_values_for_enum( GPB::FieldDescriptor* field_desc, SEXP value ){
+void CHECK_values_for_enum( const GPB::FieldDescriptor* field_desc, SEXP value ){
 	
 	const GPB::EnumDescriptor* enum_desc = field_desc->enum_type() ;
 	// N.B. n undefined if TYPEOF(value) not a vector, but we catch that below.
@@ -365,7 +365,7 @@
 /**
  * check that the values are suitable for the field descriptor
  */
-void CHECK_messages( GPB::FieldDescriptor* field_desc, SEXP values ){
+void CHECK_messages( const GPB::FieldDescriptor* field_desc, SEXP values ){
 	
 	if( TYPEOF( values ) != VECSXP ){
 		throwException( "expecting a list of messages", "ConversionException" ) ;
@@ -396,26 +396,25 @@
 			switch( TYPEOF( value ) ){
 			case VECSXP :
 				{
-					/* check that it is a list of Messages of the appropriate type */
-					for( int i=0; i<value_size; i++){
-						if( !isMessage( VECTOR_ELT(value, i), field_desc->message_type()->full_name().c_str() ) ){
-							/* TODO: include i, target type and actual type in the message */
-							throwException( "incorrect type", "IncorrectMessageTypeException" ) ;
-						}
-					}
+
+					/* check that it is a list of Messages of the
+					   appropriate type */
+					CHECK_messages(field_desc, value);
 					break ;
 				}
 			case S4SXP: 
 				{
 					/* check that this is a message of the appropriate type */
-					if( !isMessage( value, field_desc->message_type()->full_name().c_str() ) ){
+					if( !isMessage( value,
+									field_desc->message_type()->full_name().c_str() ) ){
 						throwException( "incorrect type", "IncorrectMessageTypeException" ) ;
 					}
 					break ;
 				}
 			default:
 				{
-					throwException( "impossible to convert to a message" , "ConversionException" ) ; 
+					throwException( "impossible to convert to a message" ,
+									"ConversionException" ) ; 
 				}
 			}
 			break ;

Modified: pkg/src/rprotobuf.h
===================================================================
--- pkg/src/rprotobuf.h	2013-12-27 08:52:31 UTC (rev 606)
+++ pkg/src/rprotobuf.h	2013-12-27 09:11:21 UTC (rev 607)
@@ -148,8 +148,8 @@
 bool GET_bool( SEXP, int) ;
 std::string GET_stdstring( SEXP, int ) ;
 std::string GET_bytes( SEXP, int ) ;
-void CHECK_values_for_enum( GPB::FieldDescriptor*, SEXP) ;
-void CHECK_messages( GPB::FieldDescriptor*, SEXP) ;
+void CHECK_values_for_enum( const GPB::FieldDescriptor*, SEXP) ;
+void CHECK_messages( const GPB::FieldDescriptor*, SEXP) ;
 
 /* in wrapper_ServiceDescriptor.cpp */
 RcppExport SEXP ServiceDescriptor_length(SEXP);

Modified: pkg/src/wrapper_Message.cpp
===================================================================
--- pkg/src/wrapper_Message.cpp	2013-12-27 08:52:31 UTC (rev 606)
+++ pkg/src/wrapper_Message.cpp	2013-12-27 09:11:21 UTC (rev 607)
@@ -167,7 +167,7 @@
  * @param field name or tag of the field
  */
 RPB_FUNCTION_VOID_2(METHOD(clear_field), Rcpp::XPtr<GPB::Message> m, SEXP field ){
-	GPB::FieldDescriptor* field_desc = getFieldDescriptor( m, field ) ;
+	const GPB::FieldDescriptor* field_desc = getFieldDescriptor( m, field ) ;
 	const GPB::Reflection* ref = m->GetReflection(); 
 	ref->ClearField( m, field_desc ) ;
 }
@@ -258,7 +258,7 @@
 
 RPB_FUNCTION_2( int, METHOD(field_size), Rcpp::XPtr<GPB::Message> message, SEXP field  ){
 	
-	GPB::FieldDescriptor* field_desc = getFieldDescriptor( message, field ) ;
+	const GPB::FieldDescriptor* field_desc = getFieldDescriptor( message, field ) ;
 	
 	int res = 0 ;
 	if( field_desc->is_repeated() ){
@@ -276,7 +276,7 @@
 
 RPB_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::FieldDescriptor* field_desc = getFieldDescriptor( message, field ) ;
 	const GPB::Reflection* ref = message->GetReflection() ;
 	
 	if( field_desc->is_repeated() ){
@@ -688,7 +688,7 @@
  */ 
 RPB_FUNCTION_VOID_3( METHOD(add_values), Rcpp::XPtr<GPB::Message> message, SEXP field, SEXP values){
 		const Reflection * ref = message->GetReflection() ;
-		GPB::FieldDescriptor* field_desc = getFieldDescriptor( message, field );
+		const GPB::FieldDescriptor* field_desc = getFieldDescriptor( message, field );
 		
 		if( values == R_NilValue || LENGTH(values) == 0 ){
 			return ; 
@@ -1076,7 +1076,7 @@
 	 */
 	RPB_FUNCTION_VOID_4( METHOD(set_field_values), Rcpp::XPtr<GPB::Message> message, SEXP field, Rcpp::IntegerVector index, SEXP values ){
 		
-		GPB::FieldDescriptor* field_desc = getFieldDescriptor( message, field ) ;
+		const GPB::FieldDescriptor* field_desc = getFieldDescriptor( message, field ) ;
 		if( !field_desc->is_repeated() ){
 			throw std::range_error( "set can only be used on repeated fields" ) ;
 		}



More information about the Rprotobuf-commits mailing list