[Rprotobuf-commits] r538 - in pkg: . R inst/unitTests man src

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Sep 17 08:56:56 CEST 2013


Author: murray
Date: 2013-09-17 08:56:56 +0200 (Tue, 17 Sep 2013)
New Revision: 538

Modified:
   pkg/ChangeLog
   pkg/DESCRIPTION
   pkg/R/00classes.R
   pkg/inst/unitTests/runit.enums.R
   pkg/man/EnumValueDescriptor-class.Rd
   pkg/src/wrapper_EnumValueDescriptor.cpp
Log:
Improve EnumValueDescriptor support:
* Add missing enum_type method and add it to '$' dispatch.
* Add examples and document missing methods.
* Add more unit tests.
* Increment dev version to 0.3.1.1.



Modified: pkg/ChangeLog
===================================================================
--- pkg/ChangeLog	2013-09-13 23:37:12 UTC (rev 537)
+++ pkg/ChangeLog	2013-09-17 06:56:56 UTC (rev 538)
@@ -1,3 +1,14 @@
+2013-09-16  Murray Stokely  <murray at FreeBSD.org>
+
+	* DESCRIPTION (Version): Increment to 0.3.1.1.
+	* R/00classes.R: Improve show method for EnumValueDescriptor and
+	  add enum_type to '$' dispatch.
+	* man/EnumValueDescriptor-class.Rd: Add examples and document
+	  missing methods.
+	* src/wrapper_EnumValueDescriptor.cpp (rprotobuf): Add missing
+	  enum_type method.
+	* inst/unitTests/runit.enums.R (test.enums): Add more tests.
+
 2013-09-13  Dirk Eddelbuettel  <edd at debian.org>
 
 	* DESCRIPTION (Version): Release 0.3.1

Modified: pkg/DESCRIPTION
===================================================================
--- pkg/DESCRIPTION	2013-09-13 23:37:12 UTC (rev 537)
+++ pkg/DESCRIPTION	2013-09-17 06:56:56 UTC (rev 538)
@@ -1,5 +1,5 @@
 Package: RProtoBuf
-Version: 0.3.1
+Version: 0.3.1.1
 Date: $Date$
 Author: Romain Francois, Dirk Eddelbuettel and Murray Stokely
 Maintainer: Dirk Eddelbuettel <edd at debian.org>

Modified: pkg/R/00classes.R
===================================================================
--- pkg/R/00classes.R	2013-09-13 23:37:12 UTC (rev 537)
+++ pkg/R/00classes.R	2013-09-17 06:56:56 UTC (rev 538)
@@ -156,7 +156,7 @@
                       object at filename) )
 } )
 setMethod( "show", c( "EnumValueDescriptor" ), function(object){
-	show( sprintf( "enum value descriptor" ) )
+	show( sprintf( "enum value descriptor %s", object at full_name) )
 } )
 
 # }}}
@@ -302,7 +302,8 @@
 		"asMessage" = function() asMessage(x),
 		"name" = function(...) name(x, ... ),
 		"number" = function() number(x),
-		invisible(NULL)
+		"enum_type" = function(...) enum_type( x, ...),
+               invisible(NULL)
 		)
 
 })

Modified: pkg/inst/unitTests/runit.enums.R
===================================================================
--- pkg/inst/unitTests/runit.enums.R	2013-09-13 23:37:12 UTC (rev 537)
+++ pkg/inst/unitTests/runit.enums.R	2013-09-17 06:56:56 UTC (rev 538)
@@ -17,9 +17,26 @@
 test.enums <- function() {
   ProtoFormat <- P("tutorial.Person")
 
+  # value(..) returns an EnumValueDescriptor object
+
   checkEquals(name(value(ProtoFormat$PhoneType, index=1)), "MOBILE")
+  checkEquals(name(value(ProtoFormat$PhoneType, index=1), TRUE),
+              "tutorial.Person.MOBILE")
+  checkEquals(number(value(ProtoFormat$PhoneType, index=1)), 0)
+  checkTrue(inherits(enum_type(value(ProtoFormat$PhoneType, index=1)),
+                     "EnumDescriptor"))
+  checkTrue(inherits(asMessage(value(ProtoFormat$PhoneType, index=1)),
+                     "Message"))
+  
+  # Now check the '$' interfaces
+  checkEquals(name(value(ProtoFormat$PhoneType, index=1)),
+              value(ProtoFormat$PhoneType, index=1)$name())
+  checkEquals(number(value(ProtoFormat$PhoneType, index=1)),
+              value(ProtoFormat$PhoneType, index=1)$number())
+  
   checkEquals(name(value(ProtoFormat$PhoneType, index=2)), "HOME")
 
+
   checkEquals(length(ProtoFormat$PhoneType), 3)
   checkTrue(has(ProtoFormat$PhoneType, "WORK"))
   checkTrue(!has(ProtoFormat$PhoneType, "NONEXISTANT"))

Modified: pkg/man/EnumValueDescriptor-class.Rd
===================================================================
--- pkg/man/EnumValueDescriptor-class.Rd	2013-09-13 23:37:12 UTC (rev 537)
+++ pkg/man/EnumValueDescriptor-class.Rd	2013-09-17 06:56:56 UTC (rev 538)
@@ -34,9 +34,10 @@
     \item{toString}{\code{signature(x = "EnumValueDescriptor")}: same as \code{as.character} }
     \item{$}{\code{signature(x = "EnumValueDescriptor")}: invoke pseudo
       methods }
+    \item{name}{\code{signature(object = "EnumValueDescriptor", full = "logical")}:
+      return the name of this enum constant.}
     \item{number}{\code{signature(object = "EnumValueDescriptor")}:
       return the numeric value of this enum constant.}
-    % TODO(mstokely): This next one is broken.
     \item{enum_type}{\code{signature(object = "EnumDescriptor")} : retrieves the \linkS4class{EnumDescriptor} related to this value descriptor.}
   }
 
@@ -44,4 +45,25 @@
 \references{ The \code{EnumValueDescriptor} C++ class. 
   \url{http://code.google.com/apis/protocolbuffers/docs/reference/cpp/google.protobuf.descriptor.html#EnumValueDescriptor} }
 \author{ Romain Francois <francoisromain at free.fr> }
+\examples{
+\dontrun{
+# example proto file supplied with this package
+proto.file <- system.file( "proto", "addressbook.proto", package = "RProtoBuf" ) 
+# reading a proto file and creating the descriptor
+Person <- P( "tutorial.Person", file = proto.file )
+}
+\dontshow{Person <- P( "tutorial.Person" ) }
+# enum type
+Person$PhoneType
+
+# enum value type
+value(Person$PhoneType, 1)
+
+name(value(Person$PhoneType, 1))
+name(value(Person$PhoneType, 1), TRUE)
+
+number(value(Person$PhoneType, number=1))
+
+enum_type(value(Person$PhoneType, number=1))
+}
 \keyword{classes}

Modified: pkg/src/wrapper_EnumValueDescriptor.cpp
===================================================================
--- pkg/src/wrapper_EnumValueDescriptor.cpp	2013-09-13 23:37:12 UTC (rev 537)
+++ pkg/src/wrapper_EnumValueDescriptor.cpp	2013-09-17 06:56:56 UTC (rev 538)
@@ -43,6 +43,10 @@
         return d->number() ;
 }
 
+RPB_FUNCTION_1(S4_EnumDescriptor, METHOD(enum_type), Rcpp::XPtr<GPB::EnumValueDescriptor> d ){
+	return S4_EnumDescriptor( d->type());
+}
+
 #undef METHOD
 
 } // namespace rprotobuf



More information about the Rprotobuf-commits mailing list