[Rcpp-commits] r847 - in pkg/Rcpp/src: . Rcpp

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sun Mar 7 14:02:16 CET 2010


Author: romain
Date: 2010-03-07 14:02:16 +0100 (Sun, 07 Mar 2010)
New Revision: 847

Added:
   pkg/Rcpp/src/Rcpp/StringTransformer.h
Modified:
   pkg/Rcpp/src/Rcpp.h
Log:
added StringTransformer

Added: pkg/Rcpp/src/Rcpp/StringTransformer.h
===================================================================
--- pkg/Rcpp/src/Rcpp/StringTransformer.h	                        (rev 0)
+++ pkg/Rcpp/src/Rcpp/StringTransformer.h	2010-03-07 13:02:16 UTC (rev 847)
@@ -0,0 +1,53 @@
+// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
+//
+// clone.h: Rcpp R/C++ interface class library -- clone RObject's
+//
+// Copyright (C) 2010	Dirk Eddelbuettel and Romain Francois
+//
+// This file is part of Rcpp.
+//
+// Rcpp is free software: you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 2 of the License, or
+// (at your option) any later version.
+//
+// Rcpp is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Rcpp.  If not, see <http://www.gnu.org/licenses/>.
+
+#ifndef Rcpp__StringTransformer_h
+#define Rcpp__StringTransformer_h
+
+#include <RcppCommon.h>
+
+namespace Rcpp{
+
+	template <typename UnaryOperator>
+	class StringTransformer : public std::unary_function<const char*, const char*>{
+		public:
+		StringTransformer( const UnaryOperator& op_ ): op(op_){}
+		~StringTransformer(){}
+		
+		const char* operator()(const char* input ) {
+			buffer = input ;
+			std::transform( buffer.begin(), buffer.end(), buffer.begin(), op ) ;
+			return buffer.c_str() ;
+		}
+		
+	private:	
+		const UnaryOperator& op ;
+		std::string buffer ;
+	} ;
+	
+	template <typename UnaryOperator>
+	StringTransformer<UnaryOperator> make_string_transformer( UnaryOperator fun){
+		return StringTransformer<UnaryOperator>( fun ) ;
+	} ;
+	
+}
+
+#endif

Modified: pkg/Rcpp/src/Rcpp.h
===================================================================
--- pkg/Rcpp/src/Rcpp.h	2010-03-07 12:33:30 UTC (rev 846)
+++ pkg/Rcpp/src/Rcpp.h	2010-03-07 13:02:16 UTC (rev 847)
@@ -64,7 +64,6 @@
 #include <Rcpp/Pairlist.h>
 #include <Rcpp/Function.h>
 #include <Rcpp/WeakReference.h>
+#include <Rcpp/StringTransformer.h>
 
-// #define ARG(name) ::Rcpp::Named name(#name) ;
-
 #endif



More information about the Rcpp-commits mailing list