[Rprotobuf-commits] r893 - pkg/src

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Apr 2 19:45:23 CEST 2014


Author: murray
Date: 2014-04-02 19:45:23 +0200 (Wed, 02 Apr 2014)
New Revision: 893

Modified:
   pkg/src/S4_classes.h
   pkg/src/wrapper_EnumDescriptor.cpp
Log:
Two patches from Karl Millar <kmillar at google.com>:
* src/S4_classes.h (rprotobuf): Change handling of
  S4_EnumDescriptor when passed a NULL pointer to just create empty
  object with empty name and full_name rather than setting to
  R_NilValue.
* src/wrapper_EnumDescriptor.cpp (rprotobuf): Change return value
  of getValue* functions on EnumDescriptor and return an
  EnumValueDescriptor or R_NilValue on failure.



Modified: pkg/src/S4_classes.h
===================================================================
--- pkg/src/S4_classes.h	2014-04-02 05:34:40 UTC (rev 892)
+++ pkg/src/S4_classes.h	2014-04-02 17:45:23 UTC (rev 893)
@@ -43,14 +43,14 @@
 class S4_EnumValueDescriptor : public Rcpp::S4 {
    public:
     S4_EnumValueDescriptor(const GPB::EnumValueDescriptor* d) : S4("EnumValueDescriptor") {
-
+        slot("pointer") = Rcpp::XPtr<GPB::EnumValueDescriptor>(
+            const_cast<GPB::EnumValueDescriptor*>(d), false);
         if (d) {
-            slot("pointer") = Rcpp::XPtr<GPB::EnumValueDescriptor>(
-                const_cast<GPB::EnumValueDescriptor*>(d), false);
             slot("name") = d->name();
             slot("full_name") = d->full_name();
         } else {
-            SetSexp(R_NilValue);
+            slot("name") = Rcpp::StringVector(0);
+            slot("full_name") = Rcpp::StringVector(0);
         }
     }
 

Modified: pkg/src/wrapper_EnumDescriptor.cpp
===================================================================
--- pkg/src/wrapper_EnumDescriptor.cpp	2014-04-02 05:34:40 UTC (rev 892)
+++ pkg/src/wrapper_EnumDescriptor.cpp	2014-04-02 17:45:23 UTC (rev 893)
@@ -34,22 +34,29 @@
     return S4_Descriptor(d->containing_type());
 }
 
-RPB_FUNCTION_2(S4_EnumValueDescriptor, METHOD(getValueByIndex), Rcpp::XPtr<GPB::EnumDescriptor> d,
+RPB_FUNCTION_2(SEXP, METHOD(getValueByIndex), Rcpp::XPtr<GPB::EnumDescriptor> d,
                int index) {
     if ((index >= 0) && (index < d->value_count())) {
         return S4_EnumValueDescriptor(d->value(index));
     } else {
-        return S4_EnumValueDescriptor(NULL);
+        return R_NilValue;
     }
 }
 
-RPB_FUNCTION_2(S4_EnumValueDescriptor, METHOD(getValueByNumber), Rcpp::XPtr<GPB::EnumDescriptor> d,
+RPB_FUNCTION_2(SEXP, METHOD(getValueByNumber), Rcpp::XPtr<GPB::EnumDescriptor> d,
                int i) {
-    return S4_EnumValueDescriptor(d->FindValueByNumber(i));
+    const GPB::EnumValueDescriptor* descriptor = d->FindValueByNumber(i);
+    if (descriptor)
+        return S4_EnumValueDescriptor(descriptor);
+    return R_NilValue;
 }
-RPB_FUNCTION_2(S4_EnumValueDescriptor, METHOD(getValueByName), Rcpp::XPtr<GPB::EnumDescriptor> d,
+
+RPB_FUNCTION_2(SEXP, METHOD(getValueByName), Rcpp::XPtr<GPB::EnumDescriptor> d,
                std::string name) {
-    return S4_EnumValueDescriptor(d->FindValueByName(name));
+    const GPB::EnumValueDescriptor* descriptor = d->FindValueByName(name);
+    if (descriptor)
+        return S4_EnumValueDescriptor(descriptor);
+    return R_NilValue;
 }
 
 RPB_FUNCTION_1(S4_Message, METHOD(as_Message), Rcpp::XPtr<GPB::EnumDescriptor> d) {



More information about the Rprotobuf-commits mailing list