[Rprotobuf-commits] r494 - in pkg: . R man src
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Tue Jul 9 05:07:02 CEST 2013
Author: murray
Date: 2013-07-09 05:07:02 +0200 (Tue, 09 Jul 2013)
New Revision: 494
Modified:
pkg/ChangeLog
pkg/R/00classes.R
pkg/R/has.R
pkg/R/wrapper_EnumValueDescriptor.R
pkg/R/wrapper_FieldDescriptor.R
pkg/man/EnumDescriptor-class.Rd
pkg/man/EnumValueDescriptor-class.Rd
pkg/man/has.Rd
pkg/man/number.Rd
pkg/src/wrapper_EnumDescriptor.cpp
pkg/src/wrapper_EnumValueDescriptor.cpp
Log:
Add a 'has' method to the EnumDescriptor class to make it easy to
check whether a named constant exists in the enumeration without
having to catch the error on the get methods.
Also, fix the length method for EnumDescriptor which was broken due to
a typo in the C++ method name that the R tried to invoke.
Update the show method for EnumDescriptors to display how many named
constants are in the enumeration.
Add a number method to EnumValueDescriptors to return the numeric
value of this enum constant.
Modified: pkg/ChangeLog
===================================================================
--- pkg/ChangeLog 2013-07-09 03:01:51 UTC (rev 493)
+++ pkg/ChangeLog 2013-07-09 03:07:02 UTC (rev 494)
@@ -1,3 +1,18 @@
+2013-07-08 Murray Stokely <murray at FreeBSD.org>
+
+ * R/has.R: add a has method for EnumDescriptor objects to return a
+ logical indicating if the named constant exists or not.
+ * R/00classes.R: fix a typo that prevented the length method from
+ working properly for EnumDescriptor objects. Use this
+ functionality to add the number of constants in the show method
+ for EnumDescriptors.
+ * R/wrapper_EnumValueDescriptor.R: add a number method to return
+ the numeric value of this enum constant.
+ * man/has.Rd: Add example of the above.
+ * man/number.Rd: Add example of the above.
+ * man/EnumDescriptor-class.Rd: Add example of the above.
+ * man/EnumValueDescriptor-class.Rd: Add example of the above.
+
2013-02-21 Murray Stokely <murray at FreeBSD.org>
* R/00classes.R: add filename and package slots to FileDescriptor
Modified: pkg/R/00classes.R
===================================================================
--- pkg/R/00classes.R 2013-07-09 03:01:51 UTC (rev 493)
+++ pkg/R/00classes.R 2013-07-09 03:07:02 UTC (rev 494)
@@ -70,8 +70,8 @@
# rpc
-setClass( "RpcHTTP", representation(
- host = "character", port = "integer", root = "character"
+setClass( "RpcHTTP", representation(
+ host = "character", port = "integer", root = "character"
), prototype = list( host = "127.0.0.1", port = 4444L, root = "" ) )
# streams
@@ -137,7 +137,7 @@
show( sprintf( "descriptor for field '%s' of type '%s' ", object at name, object at type ) )
} )
setMethod( "show", c( "EnumDescriptor" ), function(object){
- show( sprintf( "descriptor for enum '%s' of type '%s' ", object at name, object at type ) )
+ show( sprintf( "descriptor for enum '%s' of type '%s' with %d values", object at name, object at type, value_count(object) ) )
} )
setMethod( "show", c( "ServiceDescriptor" ), function(object){
show( sprintf( "service descriptor <%s>", object at name ) )
@@ -222,11 +222,10 @@
"name" = function(...) name(x, ...),
"fileDescriptor" = function() fileDescriptor(x ),
"containing_type" = function() containing_type(x),
-
"length" = function() length(x),
"value_count" = function() value_count(x),
"value" = function(...) value(x, ...) ,
-
+ "has" = function(name) .Call( "has_enum_name", x at pointer, name, package = "RProtoBuf"),
# default
.Call( "get_value_of_enum", x at pointer, name, PACKAGE = "RProtoBuf" )
)
@@ -278,11 +277,10 @@
"toString" = function(...) toString(x, ...) ,
"asMessage" = function() asMessage(x),
"as.list" = function() as.list(x),
- "name" = function() x at filename,
- "package" = function() x at package,
+ "name" = function() x at filename,
+ "package" = function() x at package,
invisible(NULL)
)
-
})
setMethod( "$", "EnumValueDescriptor", function(x, name ){
@@ -292,7 +290,7 @@
"toString" = function(...) toString(x, ...) ,
"asMessage" = function() asMessage(x),
"name" = function(...) name(x, ... ),
-
+ "number" = function() number(x),
invisible(NULL)
)
@@ -454,7 +452,7 @@
.Call( "Message__length", x at pointer, PACKAGE = "RProtoBuf" )
} )
setMethod( "length", "EnumDescriptor", function( x ){
- .Call( "EnumDescriptor_length", x at pointer, PACKAGE = "RProtoBuf" )
+ .Call( "EnumDescriptor__length", x at pointer, PACKAGE = "RProtoBuf" )
} )
setMethod( "length", "ServiceDescriptor", function( x ){
.Call( "ServiceDescriptor_method_count", x at pointer, PACKAGE = "RProtoBuf" )
Modified: pkg/R/has.R
===================================================================
--- pkg/R/has.R 2013-07-09 03:01:51 UTC (rev 493)
+++ pkg/R/has.R 2013-07-09 03:07:02 UTC (rev 494)
@@ -9,4 +9,9 @@
return(.Call( "Message__has_field", object at pointer, name, PACKAGE = "RProtoBuf" ))
}
}
+._has_enum_name <- function( object, name, ...){
+ return(.Call( "has_enum_name", object at pointer, name, package = "RProtoBuf"))
+}
+
setMethod( "has", "Message", ._has_message )
+setMethod( "has", "EnumDescriptor", ._has_enum_name)
Modified: pkg/R/wrapper_EnumValueDescriptor.R
===================================================================
--- pkg/R/wrapper_EnumValueDescriptor.R 2013-07-09 03:01:51 UTC (rev 493)
+++ pkg/R/wrapper_EnumValueDescriptor.R 2013-07-09 03:07:02 UTC (rev 494)
@@ -3,3 +3,9 @@
.Call( "EnumValueDescriptor__enum_type", object at pointer, PACKAGE = "RProtoBuf" )
} )
+setGeneric( "number", function(object){
+ standardGeneric( "number" )
+} )
+setMethod( "number", "EnumValueDescriptor", function(object){
+ .Call( "EnumValueDescriptor__number", object at pointer, PACKAGE = "RProtoBuf" )
+} )
Modified: pkg/R/wrapper_FieldDescriptor.R
===================================================================
--- pkg/R/wrapper_FieldDescriptor.R 2013-07-09 03:01:51 UTC (rev 493)
+++ pkg/R/wrapper_FieldDescriptor.R 2013-07-09 03:07:02 UTC (rev 494)
@@ -6,9 +6,6 @@
.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" )
} )
Modified: pkg/man/EnumDescriptor-class.Rd
===================================================================
--- pkg/man/EnumDescriptor-class.Rd 2013-07-09 03:01:51 UTC (rev 493)
+++ pkg/man/EnumDescriptor-class.Rd 2013-07-09 03:07:02 UTC (rev 494)
@@ -3,6 +3,7 @@
\docType{class}
\alias{EnumDescriptor-class}
\alias{show,EnumDescriptor-method}
+\alias{has,EnumDescriptor-method}
\alias{as.character,EnumDescriptor-method}
\alias{toString,EnumDescriptor-method}
\alias{$,EnumDescriptor-method}
@@ -42,12 +43,14 @@
\item{toString}{\code{signature(x = "EnumDescriptor")}: same as \code{as.character} }
\item{$}{\code{signature(x = "EnumDescriptor")}: get the
number associated with the name}
+ \item{has}{\code{signature(object = "EnumDescriptor")}: indicate if
+ the given name is a constant present in this enum.}
\item{containing_type}{\code{signature(object = "EnumDescriptor")} : returns a \linkS4class{Descriptor} of the message type that contains this enum descriptor, or NULL if this is a top level enum descriptor.}
\item{length}{\code{signature(x = "EnumDescriptor")} : number of constants in this enum.}
\item{value_count}{\code{signature(object = "EnumDescriptor")} : number of constants in this enum.}
\item{value}{\code{signature(object = "EnumDescriptor")} : extracts an \linkS4class{EnumValueDescriptor}.
Exactly one argument of \code{index}, \code{number} or \code{name} has to be
- used.
+ used.
If \code{index} is used, the enum value descriptor is retrieved
by position, using the \code{value} method of the C++ class.
If \code{number} is used, the enum value descripror is retrieved
@@ -73,6 +76,14 @@
# enum type
Person$PhoneType
+
+has(Person$PhoneType, "MOBILE")
+has(Person$PhoneType, "HOME")
+has(Person$PhoneType, "WORK")
+
+has(Person$PhoneType, "FOOBAR")
+
+length(protobuf_unittest.TestAllTypes$NestedEnum)
}
}
\keyword{classes}
Modified: pkg/man/EnumValueDescriptor-class.Rd
===================================================================
--- pkg/man/EnumValueDescriptor-class.Rd 2013-07-09 03:01:51 UTC (rev 493)
+++ pkg/man/EnumValueDescriptor-class.Rd 2013-07-09 03:07:02 UTC (rev 494)
@@ -7,6 +7,7 @@
\alias{toString,EnumValueDescriptor-method}
\alias{$,EnumValueDescriptor-method}
\alias{name,EnumValueDescriptor-method}
+\alias{number,EnumValueDescriptor-method}
\alias{enum_type,EnumValueDescriptor,missing,missing-method}
\title{Class "EnumValueDescriptor" }
@@ -26,15 +27,19 @@
\section{Methods}{
\describe{
\item{show}{\code{signature(object = "EnumValueDescriptor")}: small information }
- \item{as.character}{\code{signature(x = "EnumValueDescriptor")}:
- returns the debug string of the enum descriptor.
+ \item{as.character}{\code{signature(x = "EnumValueDescriptor")}:
+ returns the debug string of the enum descriptor.
This is retrieved by a call to the \code{DebugString}
method of the EnumDescriptor object. }
\item{toString}{\code{signature(x = "EnumValueDescriptor")}: same as \code{as.character} }
- \item{$}{\code{signature(x = "EnumValueDescriptor")}: invoke pseudo methods }
+ \item{$}{\code{signature(x = "EnumValueDescriptor")}: invoke pseudo
+ methods }
+ \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.}
}
-
+
}
\references{ The \code{EnumValueDescriptor} C++ class.
\url{http://code.google.com/apis/protocolbuffers/docs/reference/cpp/google.protobuf.descriptor.html#EnumValueDescriptor} }
Modified: pkg/man/has.Rd
===================================================================
--- pkg/man/has.Rd 2013-07-09 03:01:51 UTC (rev 493)
+++ pkg/man/has.Rd 2013-07-09 03:07:02 UTC (rev 494)
@@ -4,25 +4,31 @@
\alias{has-methods}
\alias{has,Message-method}
-\title{Indicates if a message has the given field set}
+\title{Indicates if an object has the given field set}
\description{
-This generic method, currently only implemented
-for \linkS4class{Message} indicates if the message
-has the given field set.
+This generic method, currently implemented
+for \linkS4class{Message} and \linkS4class{EnumDescriptor} indicates if the
+message or enum descriptor has the given field set.
-For non repeated fields, a call to the \code{HasField}
+For messages and non-repeated fields, a call to the \code{HasField}
method of the corresponding \code{Message} is issued.
-For repeated fields, a call to the \code{FieldSize}
+For messages and repeated fields, a call to the \code{FieldSize}
method is issued, and the message is declared to have
the field if the size is greater than 0.
\code{NULL} is returned if the descriptor for the message does not
contain the given field at all.
+
+For EnumDescriptors, a boolean value indicates if the given name is
+present in the enum definition.
}
\section{Methods}{
\describe{
- \item{has}{\code{signature(object = "Message")}: Indicates if the message has a given field.}
+ \item{has}{\code{signature(object = "Message")}:
+ Indicates if the message has a given field.}
+ \item{has}{\code{signature(object = "EnumDescriptor")}:
+ Indicates if the EnumDescriptor has a given named element.}
}
}
\examples{
@@ -38,5 +44,9 @@
# TRUE
test$has("nonexistant")
# NULL
+
+has(protobuf_unittest.TestAllTypes$NestedEnum, "FOO")
+has(protobuf_unittest.TestAllTypes$NestedEnum, "BAR")
+has(protobuf_unittest.TestAllTypes$NestedEnum, "XXX")
}
\keyword{methods}
Modified: pkg/man/number.Rd
===================================================================
--- pkg/man/number.Rd 2013-07-09 03:01:51 UTC (rev 493)
+++ pkg/man/number.Rd 2013-07-09 03:07:02 UTC (rev 494)
@@ -6,7 +6,8 @@
Gets the declared tag number of a field
}
\seealso{
-The method is implemented for the \linkS4class{FieldDescriptor} class
+The method is implemented for \linkS4class{FieldDescriptor} and
+\linkS4class{EnumValueDescriptor} classes.
}
\keyword{methods}
\examples{
@@ -16,5 +17,7 @@
number(Person$id)
number(Person$email)
as.character(Person)
+
+number(value(tutorial.Person$PhoneType, name="HOME"))
}
}
\ No newline at end of file
Modified: pkg/src/wrapper_EnumDescriptor.cpp
===================================================================
--- pkg/src/wrapper_EnumDescriptor.cpp 2013-07-09 03:01:51 UTC (rev 493)
+++ pkg/src/wrapper_EnumDescriptor.cpp 2013-07-09 03:07:02 UTC (rev 494)
@@ -75,6 +75,19 @@
}
/**
+ * Does enum have value named 'name'?
+ *
+ * @param xp external pointer to an EnumDescriptor
+ * @param name the name of the enum
+ * @return logical
+ */
+RCPP_FUNCTION_2(bool,has_enum_name,
+ Rcpp::XPtr<GPB::EnumDescriptor> d, std::string name){
+ const GPB::EnumValueDescriptor* evd = d->FindValueByName(name) ;
+ return ( ! (evd == NULL));
+}
+
+/**
* @param xp external pointer to a Descriptor
* @return the descriptor as an R list
*/
Modified: pkg/src/wrapper_EnumValueDescriptor.cpp
===================================================================
--- pkg/src/wrapper_EnumValueDescriptor.cpp 2013-07-09 03:01:51 UTC (rev 493)
+++ pkg/src/wrapper_EnumValueDescriptor.cpp 2013-07-09 03:07:02 UTC (rev 494)
@@ -38,6 +38,10 @@
return full ? d->full_name() : d->name() ;
}
+RCPP_FUNCTION_1( int, METHOD(number), Rcpp::XPtr<GPB::EnumValueDescriptor> d) {
+ return d->number() ;
+}
+
#undef METHOD
} // namespace rprotobuf
More information about the Rprotobuf-commits
mailing list