[Rprotobuf-commits] r665 - pkg/src

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Dec 31 05:24:26 CET 2013


Author: murray
Date: 2013-12-31 05:24:24 +0100 (Tue, 31 Dec 2013)
New Revision: 665

Modified:
   pkg/src/mutators.cpp
   pkg/src/wrapper_Message.cpp
Log:
Manual clean up pass.

1. Concatenate some strings so that error messages are created on one
  line that fits in less than 100 chars rather than using 3 separate
  lines.
2. Standardize on default:\n<indent>Rcpp::stop(...) instead of default: { Rcpp::stop(...) }
3. Capitalize and add punctuation to many comments.
4. Remove a few more extra blank lines.
5. Adjust spacing of emacs '{{{' '}}}' fold-block  comments.
6. Remove an extraneous BEGIN_RCPP / END_RCPP From one function
  because the throw in that function should unwind up one level to the
  calling function which includes that block.



Modified: pkg/src/mutators.cpp
===================================================================
--- pkg/src/mutators.cpp	2013-12-31 04:05:37 UTC (rev 664)
+++ pkg/src/mutators.cpp	2013-12-31 04:24:24 UTC (rev 665)
@@ -1,6 +1,3 @@
-// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 4 -*-
-/* :tabSize=4:indentSize=4:noTabs=false:folding=explicit:collapseFolds=1: */
-//
 // Copyright (C) 2010 - 2011  Dirk Eddelbuettel and Romain Francois
 //
 // This file is part of RProtoBuf.
@@ -183,23 +180,17 @@
     switch (TYPEOF(x)) {
         case INTSXP:
             if (INTEGER(x)[index] == R_NaInt) {
-                Rcpp::stop(
-                    "NA boolean values can not be stored in "
-                    "bool protocol buffer fields");
+                Rcpp::stop("NA boolean values can not be stored in bool protocol buffer fields");
             }
             return ((bool)INTEGER(x)[index]);
         case REALSXP:
             if (REAL(x)[index] == R_NaReal) {
-                Rcpp::stop(
-                    "NA boolean values can not be stored in "
-                    "bool protocol buffer fields");
+                Rcpp::stop("NA boolean values can not be stored in bool protocol buffer fields");
             }
             return ((bool)REAL(x)[index]);
         case LGLSXP:
             if (LOGICAL(x)[index] == NA_LOGICAL) {
-                Rcpp::stop(
-                    "NA boolean values can not be stored in "
-                    "bool protocol buffer fields");
+                Rcpp::stop("NA boolean values can not be stored in bool protocol buffer fields");
             }
             return ((bool)LOGICAL(x)[index]);
         case RAWSXP:
@@ -414,7 +405,8 @@
                     }
                     break;
                 }
-                default: { Rcpp::stop("impossible to convert to a message"); }
+                default:
+                    Rcpp::stop("impossible to convert to a message");
             }
             break;
         }
@@ -541,17 +533,11 @@
         case CPPTYPE_BOOL: {
             // TODO(mstokely): Rcpp should handle this!
             if ((TYPEOF(value) == LGLSXP) && (LOGICAL(value)[0] == NA_LOGICAL)) {
-                Rcpp::stop(
-                    "NA boolean values can not be stored in "
-                    "bool protocol buffer fields");
+                Rcpp::stop("NA boolean values can not be stored in bool protocol buffer fields");
             } else if ((TYPEOF(value) == INTSXP) && (INTEGER(value)[0] == R_NaInt)) {
-                Rcpp::stop(
-                    "NA boolean values can not be stored in "
-                    "bool protocol buffer fields");
+                Rcpp::stop("NA boolean values can not be stored in bool protocol buffer fields");
             } else if ((TYPEOF(value) == REALSXP) && (REAL(value)[0] == R_NaReal)) {
-                Rcpp::stop(
-                    "NA boolean values can not be stored in "
-                    "bool protocol buffer fields");
+                Rcpp::stop("NA boolean values can not be stored in bool protocol buffer fields");
             }
             ref->SetBool(message, field_desc, Rcpp::as<bool>(value));
             break;
@@ -630,7 +616,8 @@
                     ref->SetString(message, field_desc, __mess->SerializeAsString());
                     break;
                 }
-                default: { Rcpp::stop("Cannot convert to string"); }
+                default:
+                    Rcpp::stop("Cannot convert to string");
             }
             break;
         }
@@ -682,10 +669,12 @@
                     }
                     break;
                 }
-                default: { Rcpp::stop("cannot set enum value"); }
+                default:
+                    Rcpp::stop("cannot set enum value");
             }
+            break;
         }
-            // }}}
+        // }}}
     }
 }
 
@@ -748,7 +737,8 @@
                     break;
                 }
 
-                default: { Rcpp::stop("Cannot convert to int32"); }
+                default:
+                    Rcpp::stop("Cannot convert to int32");
             }
             break;
         }
@@ -1119,12 +1109,11 @@
                 }
                 // }}}
 
-                // {{{ default
-                default: { Rcpp::stop("cannot set enum value"); }
-                    // }}}
+                default:
+                    Rcpp::stop("cannot set enum value");
             }
         }
-            // }}}
+        // }}}
     }
 }
 
@@ -1139,7 +1128,7 @@
  */
 SEXP setMessageField(SEXP pointer, SEXP name, SEXP value) {
     BEGIN_RCPP
-// {{{ grab data
+    // {{{ grab data
 #ifdef RPB_DEBUG
     Rprintf("<setMessageField>\n");
 

Modified: pkg/src/wrapper_Message.cpp
===================================================================
--- pkg/src/wrapper_Message.cpp	2013-12-31 04:05:37 UTC (rev 664)
+++ pkg/src/wrapper_Message.cpp	2013-12-31 04:24:24 UTC (rev 665)
@@ -59,7 +59,7 @@
 #define METHOD(__NAME__) RCPP_PP_CAT(Message__, __NAME__)
 
 /**
- * clone a message
+ * Clone a message
  *
  * @param xp external pointer to a message
  * @return a new message, clone of the input message
@@ -120,7 +120,7 @@
 }
 
 /**
- * serialize a message to a file
+ * Serialize a message to a file
  *
  * @param xp external pointer to a GPB::Message*
  * @param filename file name where to serialize
@@ -139,8 +139,7 @@
 }
 
 /**
- * create a raw vector that contains the content of the serialized
- * message
+ * Create a raw vector that contains the content of the serialized message
  *
  * @param xp xternal pointer to the message
  */
@@ -171,6 +170,8 @@
 }
 
 /**
+ * Return a named list representation of the fields set in a message.
+ *
  * @param xp external pointer to a Message
  * @return the message as an R list
  */
@@ -192,8 +193,7 @@
 }
 
 /**
- * The number of fields the message has. A field counts in these two situations
- *:
+ * 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
  *
@@ -204,7 +204,6 @@
     const GPB::Reflection* ref = message->GetReflection();
 
     int nfields = desc->field_count();
-
     int res = 0;
 
     for (int i = 0; i < nfields; i++) {
@@ -241,7 +240,7 @@
 }
 
 /**
- * Get the message descriptor of a Message
+ * Get the message descriptor of a Message.
  *
  * @param xp (GPB::Message*) external pointer
  * @return the descriptor, as a Descriptor R S4 object
@@ -254,7 +253,6 @@
 RPB_XP_METHOD_0(METHOD(bytesize), GPB::Message, ByteSize)
 
 RPB_FUNCTION_2(int, METHOD(field_size), Rcpp::XPtr<GPB::Message> message, SEXP field) {
-
     const GPB::FieldDescriptor* field_desc = getFieldDescriptor(message, field);
 
     int res = 0;
@@ -272,7 +270,6 @@
 
 RPB_FUNCTION_VOID_3(METHOD(set_field_size), Rcpp::XPtr<GPB::Message> message, SEXP field,
                     int target) {
-
     const GPB::FieldDescriptor* field_desc = getFieldDescriptor(message, field);
     const GPB::Reflection* ref = message->GetReflection();
 
@@ -291,7 +288,6 @@
         } else {/* current < target */
 
             while (current != target) {
-
                 switch (field_desc->type()) {
                     case TYPE_INT32:
                     case TYPE_SINT32:
@@ -414,7 +410,7 @@
 }
 
 /**
- * returns the field names of the message
+ * Returns the field names of the message.
  *
  * @param xp external pointer to a Message
  *
@@ -432,7 +428,6 @@
 }
 
 bool identical_messages_(GPB::Message* m1, GPB::Message* m2, double tol) {
-    BEGIN_RCPP
     const GPB::Descriptor* d1 = m1->GetDescriptor();
     const GPB::Descriptor* d2 = m2->GetDescriptor();
 
@@ -619,7 +614,6 @@
             }
         }
     }
-    VOID_END_RCPP
     /* finally */
     return true;
 }
@@ -647,7 +641,7 @@
 }
 
 /**
- * creates a new message by merging two messages of the same type
+ * Creates a new message by merging two messages of the same type.
  *
  * @param xp1 external pointer to a GPB::Message*
  * @param xp2 external pointer to a GPB::Message*
@@ -663,7 +657,7 @@
 }
 
 /**
- * Add values to a repeated field
+ * Add values to a repeated field.
  *
  * @param xp (GPB::Message*) external pointer
  * @param field field tag number or name
@@ -710,7 +704,8 @@
                         }
                         break;
                     }
-                    default: { Rcpp::stop("Cannot convert to int32"); }
+                    default:
+                        Rcpp::stop("Cannot convert to int32");
                 }
                 break;
             }
@@ -907,9 +902,8 @@
                     }
                     // }}}
 
-                    // {{{ default
-                    default: { Rcpp::stop("cannot set enum value"); }
-                        // }}}
+                    default:
+                        Rcpp::stop("cannot set enum value"); }
                 }
                 break;
             }
@@ -924,7 +918,7 @@
 }
 
 /**
- * fetch a subset of the values of a field
+ * Fetch a subset of the values of a field.
  *
  * @param (GPB::Message*) external pointer
  * @param field name or tag number of the field
@@ -939,7 +933,6 @@
 
     int n = index.size();
     switch (field_desc->type()) {
-
         case TYPE_INT32:
         case TYPE_SINT32:
         case TYPE_SFIXED32:
@@ -1014,7 +1007,6 @@
  */
 RPB_FUNCTION_VOID_4(METHOD(set_field_values), Rcpp::XPtr<GPB::Message> message, SEXP field,
                     Rcpp::IntegerVector index, SEXP values) {
-
     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");
@@ -1025,7 +1017,6 @@
     /* we know here that LENGTH(index) == LENGTH(values) */
     int n = index.size();
     switch (field_desc->type()) {
-
         case TYPE_INT32:
         case TYPE_SINT32:
         case TYPE_SFIXED32: {
@@ -1104,7 +1095,6 @@
                         ref->SetRepeatedEnum(message, field_desc, i,
                                              enum_desc->FindValueByNumber(val));
                     }
-
                     break;
                 }
                 case STRSXP: {
@@ -1115,7 +1105,6 @@
                         const GPB::EnumValueDescriptor* evd = enum_desc->FindValueByName(val);
                         ref->SetRepeatedEnum(message, field_desc, i, evd);
                     }
-
                     break;
                 }
                 default:
@@ -1129,7 +1118,6 @@
             for (int i = 0; i < n; i++) {
                 GPB::Message* mess = GET_MESSAGE_POINTER_FROM_S4(vals[i]);
                 ref->MutableRepeatedMessage(message, field_desc, i)->CopyFrom(*mess);
-                ;
             }
             break;
         }



More information about the Rprotobuf-commits mailing list