[Rprotobuf-commits] r473 - in pkg: R inst/unitTests man src
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Thu Aug 9 14:10:11 CEST 2012
Author: edd
Date: 2012-08-09 14:10:11 +0200 (Thu, 09 Aug 2012)
New Revision: 473
Modified:
pkg/R/wrapper_FieldDescriptor.R
pkg/inst/unitTests/runit.golden.message.R
pkg/man/FieldDescriptor-class.Rd
pkg/man/has.Rd
pkg/man/size.Rd
pkg/man/type.Rd
pkg/src/mutators.cpp
Log:
two more patches by Murray, NEWS and ChangeLog entries to follow
Modified: pkg/R/wrapper_FieldDescriptor.R
===================================================================
--- pkg/R/wrapper_FieldDescriptor.R 2012-08-09 12:09:38 UTC (rev 472)
+++ pkg/R/wrapper_FieldDescriptor.R 2012-08-09 12:10:11 UTC (rev 473)
@@ -3,14 +3,14 @@
standardGeneric("is_extension")
} )
setMethod( "is_extension", "FieldDescriptor", function(object){
- .Call( "FieldDescriptor_is_extension", object at pointer, PACKAGE = "RProtoBuf" )
+ .Call( "FieldDescriptor__is_extension", object at pointer, PACKAGE = "RProtoBuf" )
})
setGeneric( "number", function(object){
standardGeneric( "number" )
} )
setMethod( "number", "FieldDescriptor", function(object){
- .Call( "FieldDescriptor_number", object at pointer, PACKAGE = "RProtoBuf" )
+ .Call( "FieldDescriptor__number", object at pointer, PACKAGE = "RProtoBuf" )
} )
TYPE_DOUBLE <- 1L
@@ -38,7 +38,7 @@
standardGeneric( "type" )
} )
setMethod( "type", "FieldDescriptor", function(object, as.string = FALSE){
- type <- .Call( "FieldDescriptor_type", object at pointer, PACKAGE = "RProtoBuf" )
+ type <- .Call( "FieldDescriptor__type", object at pointer, PACKAGE = "RProtoBuf" )
if( as.string ) .TYPES[type] else type
} )
@@ -59,7 +59,7 @@
standardGeneric( "cpp_type" )
} )
setMethod( "cpp_type", "FieldDescriptor", function(object, as.string = FALSE){
- cpptype <- .Call( "FieldDescriptor_cpp_type", object at pointer, PACKAGE = "RProtoBuf" )
+ cpptype <- .Call( "FieldDescriptor__cpp_type", object at pointer, PACKAGE = "RProtoBuf" )
if( as.string ) .CPPTYPES[cpptype] else cpptype
} )
@@ -72,7 +72,7 @@
standardGeneric( "label" )
} )
setMethod( "label", "FieldDescriptor", function(object, as.string = FALSE){
- lab <- .Call( "FieldDescriptor_label", object at pointer, PACKAGE = "RProtoBuf" )
+ lab <- .Call( "FieldDescriptor__label", object at pointer, PACKAGE = "RProtoBuf" )
if( as.string ) .LABELS[lab] else lab
} )
@@ -80,35 +80,35 @@
standardGeneric( "is_repeated" )
} )
setMethod( "is_repeated", "FieldDescriptor", function(object){
- .Call( "FieldDescriptor_is_repeated", object at pointer, PACKAGE = "RProtoBuf" )
+ .Call( "FieldDescriptor__is_repeated", object at pointer, PACKAGE = "RProtoBuf" )
} )
setGeneric( "is_optional", function(object){
standardGeneric( "is_optional" )
} )
setMethod( "is_optional", "FieldDescriptor", function(object){
- .Call( "FieldDescriptor_is_optional", object at pointer, PACKAGE = "RProtoBuf" )
+ .Call( "FieldDescriptor__is_optional", object at pointer, PACKAGE = "RProtoBuf" )
} )
setGeneric( "is_required", function(object ){
standardGeneric( "is_required" )
} )
setMethod( "is_required", "FieldDescriptor", function(object){
- .Call( "FieldDescriptor_is_required", object at pointer, PACKAGE = "RProtoBuf" )
+ .Call( "FieldDescriptor__is_required", object at pointer, PACKAGE = "RProtoBuf" )
} )
setGeneric( "has_default_value", function(object ){
standardGeneric( "has_default_value" )
} )
setMethod( "has_default_value", "FieldDescriptor", function(object){
- .Call( "FieldDescriptor_has_default_value", object at pointer, PACKAGE = "RProtoBuf" )
+ .Call( "FieldDescriptor__has_default_value", object at pointer, PACKAGE = "RProtoBuf" )
} )
setGeneric( "default_value", function(object ){
standardGeneric( "default_value" )
} )
setMethod( "default_value", "FieldDescriptor", function(object){
- .Call( "FieldDescriptor_default_value", object at pointer, PACKAGE = "RProtoBuf" )
+ .Call( "FieldDescriptor__default_value", object at pointer, PACKAGE = "RProtoBuf" )
} )
@@ -116,10 +116,9 @@
standardGeneric( "message_type" )
} )
setMethod( "message_type", "FieldDescriptor", function(object){
- .Call( "FieldDescriptor_message_type", object at pointer, PACKAGE = "RProtoBuf" )
+ .Call( "FieldDescriptor__message_type", object at pointer, PACKAGE = "RProtoBuf" )
} )
setMethod( "enum_type", c( object = "FieldDescriptor", index = "missing", name = "missing"), function(object){
- .Call( "FieldDescriptor_enum_type", object at pointer, PACKAGE = "RProtoBuf" )
+ .Call( "FieldDescriptor__enum_type", object at pointer, PACKAGE = "RProtoBuf" )
} )
-
Modified: pkg/inst/unitTests/runit.golden.message.R
===================================================================
--- pkg/inst/unitTests/runit.golden.message.R 2012-08-09 12:09:38 UTC (rev 472)
+++ pkg/inst/unitTests/runit.golden.message.R 2012-08-09 12:10:11 UTC (rev 473)
@@ -60,9 +60,18 @@
test <- new(protobuf_unittest.TestAllTypes)
test$add("repeated_int32", c(1:5))
checkEquals(test$repeated_int32, c(1:5))
+}
- # Prior to RProtoBuf v0.2.5, this was not handled properly.
- test.2 <- new(protobuf_unittest.TestAllTypes,
- repeated_string=c("foo", "bar"))
- checkEquals(test.2$repeated_string, c("foo", "bar"))
+test.repeated.bools <- function() {
+ test <- new(protobuf_unittest.TestAllTypes)
+ test$add("repeated_bool", c(TRUE, FALSE))
+ checkEquals(test$repeated_bool, c(TRUE, FALSE))
+
+ test$add("repeated_bool", as.integer(c(TRUE, FALSE)))
+ test$add("repeated_bool", as.numeric(c(TRUE, FALSE)))
+
+ checkEquals(test$repeated_bool, rep(c(TRUE, FALSE), 3))
+
+ # Verify that we don't silently cast NA into TRUE or FALSE.
+ checkException(test$add("repeated_bool"), c(TRUE, FALSE, NA))
}
Modified: pkg/man/FieldDescriptor-class.Rd
===================================================================
--- pkg/man/FieldDescriptor-class.Rd 2012-08-09 12:09:38 UTC (rev 472)
+++ pkg/man/FieldDescriptor-class.Rd 2012-08-09 12:10:11 UTC (rev 473)
@@ -97,6 +97,15 @@
# or as a pseudo method
Person$email$as.character()
+
+Person$email$is_required()
+Person$email$is_optional()
+Person$email$is_repeated()
+
+Person$email$has_default_value()
+Person$email$default_value()
+
+Person$email$is_extension()
}
}
\keyword{classes}
Modified: pkg/man/has.Rd
===================================================================
--- pkg/man/has.Rd 2012-08-09 12:09:38 UTC (rev 472)
+++ pkg/man/has.Rd 2012-08-09 12:10:11 UTC (rev 473)
@@ -22,5 +22,15 @@
\item{has}{\code{signature(object = "Message")}: Indicates if the message has a given field.}
}
}
+\examples{
+unitest.proto.file <- system.file("unitTests", "data", "unittest.proto",
+ package = "RProtoBuf" )
+readProtoFiles(file = unitest.proto.file)
+
+test <- new(protobuf_unittest.TestAllTypes)
+test$has("optional_int32")
+
+test$add("repeated_int32", 1:10)
+test$has("repeated_int32")
+}
\keyword{methods}
-
Modified: pkg/man/size.Rd
===================================================================
--- pkg/man/size.Rd 2012-08-09 12:09:38 UTC (rev 472)
+++ pkg/man/size.Rd 2012-08-09 12:10:11 UTC (rev 473)
@@ -16,5 +16,15 @@
\describe{
\item{\code{signature(object = "Message")}}{Number of objects in a message field}
}}
+\examples{
+unitest.proto.file <- system.file("unitTests", "data", "unittest.proto",
+ package = "RProtoBuf" )
+readProtoFiles(file = unitest.proto.file)
+
+test <- new(protobuf_unittest.TestAllTypes)
+test$size("optional_int32")
+
+test$add("repeated_int32", 1:10)
+test$size("test$repeated_int32")
+}
\keyword{methods}
-
Modified: pkg/man/type.Rd
===================================================================
--- pkg/man/type.Rd 2012-08-09 12:09:38 UTC (rev 472)
+++ pkg/man/type.Rd 2012-08-09 12:10:11 UTC (rev 473)
@@ -36,12 +36,11 @@
\alias{CPPTYPE_STRING}
\alias{CPPTYPE_MESSAGE}
-\title{Gets the type or the c++ type of a field}
+\title{Gets the type or the C++ type of a field}
\description{
-Gets the type or the c++ type of a field
+Gets the type or the C++ type of a field
}
\seealso{
The method is implemented for the \linkS4class{FieldDescriptor} class
}
\keyword{methods}
-
Modified: pkg/src/mutators.cpp
===================================================================
--- pkg/src/mutators.cpp 2012-08-09 12:09:38 UTC (rev 472)
+++ pkg/src/mutators.cpp 2012-08-09 12:10:11 UTC (rev 473)
@@ -151,10 +151,22 @@
bool GET_bool( SEXP x, int index ){
switch( TYPEOF(x) ){
case INTSXP:
+ if (INTEGER(x)[index] == R_NaInt) {
+ throwException( "NA boolean values not supported by RProtoBuf",
+ "CastException" ) ;
+ }
return( (bool)INTEGER(x)[index] );
case REALSXP:
+ if (REAL(x)[index] == R_NaReal) {
+ throwException( "NA boolean values not supported by RProtoBuf",
+ "CastException" ) ;
+ }
return( (bool)REAL(x)[index] );
case LGLSXP:
+ if (LOGICAL(x)[index] == NA_LOGICAL) {
+ throwException( "NA boolean values not supported by RProtoBuf",
+ "CastException" ) ;
+ }
return( (bool)LOGICAL(x)[index] );
case RAWSXP:
return( (bool)RAW(x)[index] ) ;
More information about the Rprotobuf-commits
mailing list