[Rprotobuf-commits] r601 - in pkg: . src
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Fri Dec 27 03:48:25 CET 2013
Author: murray
Date: 2013-12-27 03:48:24 +0100 (Fri, 27 Dec 2013)
New Revision: 601
Modified:
pkg/ChangeLog
pkg/src/mutators.cpp
Log:
Refuse to set non-repeated bools to NA, just as we do for repeated
bool fields by raising a stop() error since protocol buffer bools are
2-valued and NA is the third-value of R bools.
Modified: pkg/ChangeLog
===================================================================
--- pkg/ChangeLog 2013-12-27 02:19:33 UTC (rev 600)
+++ pkg/ChangeLog 2013-12-27 02:48:24 UTC (rev 601)
@@ -2,6 +2,9 @@
* src/mutators.cpp: Support setting int32 values with character
vectors of a decimal number, as we do by necessity for int64s.
+ Also, refuse to set non-repeated bools to NA, just as we do for
+ repeated bool fields by raising a stop() error since protocol
+ buffer bools are 2-valued and NA is the third-value of R bools.
* inst/unitTests/runit.int32.R (test.int32): Add tests for above.
* NAMESPACE: Add missing export for .DollarNames
EnumValueDescriptor to allow completion on that class.
Modified: pkg/src/mutators.cpp
===================================================================
--- pkg/src/mutators.cpp 2013-12-27 02:19:33 UTC (rev 600)
+++ pkg/src/mutators.cpp 2013-12-27 02:48:24 UTC (rev 601)
@@ -183,19 +183,22 @@
switch( TYPEOF(x) ){
case INTSXP:
if (INTEGER(x)[index] == R_NaInt) {
- throwException( "NA boolean values not supported by RProtoBuf",
+ throwException( "NA boolean values can not be stored in "
+ "bool protocol buffer fields",
"CastException" ) ;
}
return( (bool)INTEGER(x)[index] );
case REALSXP:
if (REAL(x)[index] == R_NaReal) {
- throwException( "NA boolean values not supported by RProtoBuf",
+ throwException( "NA boolean values can not be stored in "
+ "bool protocol buffer fields",
"CastException" ) ;
}
return( (bool)REAL(x)[index] );
case LGLSXP:
if (LOGICAL(x)[index] == NA_LOGICAL) {
- throwException( "NA boolean values not supported by RProtoBuf",
+ throwException( "NA boolean values can not be stored in "
+ "bool protocol buffer fields",
"CastException" ) ;
}
return( (bool)LOGICAL(x)[index] );
@@ -1046,7 +1049,28 @@
HANDLE_SINGLE_FIELD( CPPTYPE_DOUBLE, Double, double) ;
HANDLE_SINGLE_FIELD( CPPTYPE_FLOAT, Float, float) ;
- HANDLE_SINGLE_FIELD( CPPTYPE_BOOL, Bool, bool) ;
+ case CPPTYPE_BOOL :
+ {
+ // TODO(mstokely): Rcpp should handle this!
+ if ((TYPEOF(value) == LGLSXP) &&
+ (LOGICAL(value)[0] == NA_LOGICAL)) {
+ throwException("NA boolean values can not be stored in "
+ "bool protocol buffer fields",
+ "CastException");
+ } else if ((TYPEOF(value) == INTSXP) &&
+ (INTEGER(value)[0] == R_NaInt)) {
+ throwException( "NA boolean values can not be stored in "
+ "bool protocol buffer fields",
+ "CastException");
+ } else if ((TYPEOF(value) == REALSXP) &&
+ (REAL(value)[0] == R_NaReal)) {
+ throwException( "NA boolean values can not be stored in "
+ "bool protocol buffer fields",
+ "CastException");
+ }
+ ref->SetBool(message, field_desc, Rcpp::as<bool>(value));
+ break ;
+ }
case CPPTYPE_INT32 :
{
if (TYPEOF(value) == STRSXP) {
More information about the Rprotobuf-commits
mailing list