[Rcpp-commits] r1065 - pkg/Rcpp/inst/include/Rcpp
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Sun Apr 18 20:58:17 CEST 2010
Author: romain
Date: 2010-04-18 20:58:15 +0200 (Sun, 18 Apr 2010)
New Revision: 1065
Modified:
pkg/Rcpp/inst/include/Rcpp/Vector.h
Log:
adding comparison operators to string_proxy
Modified: pkg/Rcpp/inst/include/Rcpp/Vector.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/Vector.h 2010-04-18 17:22:00 UTC (rev 1064)
+++ pkg/Rcpp/inst/include/Rcpp/Vector.h 2010-04-18 18:58:15 UTC (rev 1065)
@@ -2567,6 +2567,11 @@
return *this ;
}
+ void import( const string_proxy& other){
+ parent = other.parent ;
+ index = other.index ;
+ }
+
/**
* lhs use. Adds the content of the rhs proxy to the
* element this proxy refers to.
@@ -2636,9 +2641,9 @@
set( ::Rf_mkChar(x.c_str()) ) ;
}
- inline iterator begin(){ return CHAR( STRING_ELT( *parent, index ) ) ; }
- inline iterator end(){ return begin() + size() ; }
- inline int size(){ return strlen( begin() ) ; }
+ inline iterator begin() const { return CHAR( STRING_ELT( *parent, index ) ) ; }
+ inline iterator end() const { return begin() + size() ; }
+ inline int size() const { return strlen( begin() ) ; }
inline reference operator[]( int n ){ return *( begin() + n ) ; }
template <typename UnaryOperator>
@@ -2661,12 +2666,45 @@
bool operator==( const char* other){
return strcmp( begin(), other ) == 0 ;
}
-
+
private:
static std::string buffer ;
} ;
+ template <int RT>
+ bool operator<( const string_proxy<RT>& lhs, const string_proxy<RT>& rhs) {
+ return strcmp(
+ const_cast<char *>(lhs.begin() ),
+ const_cast<char *>(rhs.begin())
+ ) < 0 ;
+ }
+
+ template <int RT>
+ bool operator>( const string_proxy<RT>& lhs, const string_proxy<RT>& rhs) {
+ return strcmp(
+ const_cast<char *>(lhs.begin() ),
+ const_cast<char *>(rhs.begin())
+ ) > 0 ;
+ }
+
+ template <int RT>
+ bool operator>=( const string_proxy<RT>& lhs, const string_proxy<RT>& rhs) {
+ return strcmp(
+ const_cast<char *>(lhs.begin() ),
+ const_cast<char *>(rhs.begin())
+ ) >= 0 ;
+ }
+
+ template <int RT>
+ bool operator<=( const string_proxy<RT>& lhs, const string_proxy<RT>& rhs) {
+ return strcmp(
+ const_cast<char *>(lhs.begin() ),
+ const_cast<char *>(rhs.begin())
+ ) <= 0 ;
+ return res ;
+ }
+
template<int RTYPE> std::string string_proxy<RTYPE>::buffer ;
inline std::ostream& operator<<(std::ostream& os, const string_proxy<STRSXP>& proxy) {
More information about the Rcpp-commits
mailing list