[Rcpp-commits] r2710 - in pkg/Rcpp: . inst/include inst/include/Rcpp

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sat Dec 4 14:54:19 CET 2010


Author: romain
Date: 2010-12-04 14:54:19 +0100 (Sat, 04 Dec 2010)
New Revision: 2710

Added:
   pkg/Rcpp/inst/include/Rcpp/sprintf.h
Modified:
   pkg/Rcpp/ChangeLog
   pkg/Rcpp/inst/include/RcppCommon.h
Log:
new sprintf template

Modified: pkg/Rcpp/ChangeLog
===================================================================
--- pkg/Rcpp/ChangeLog	2010-12-04 13:05:39 UTC (rev 2709)
+++ pkg/Rcpp/ChangeLog	2010-12-04 13:54:19 UTC (rev 2710)
@@ -7,6 +7,8 @@
     Christian Gunnning <xian at unm.edu> on Rcpp-devel
     
     * inst/include/Rcpp/vector/SubMatrix.h: factored out of matrix.h
+    
+    * inst/include/Rcpp/sprintf.h: new sprintf template to format strings
 
 2010-12-03  Dirk Eddelbuettel  <edd at debian.org>
 

Added: pkg/Rcpp/inst/include/Rcpp/sprintf.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/sprintf.h	                        (rev 0)
+++ pkg/Rcpp/inst/include/Rcpp/sprintf.h	2010-12-04 13:54:19 UTC (rev 2710)
@@ -0,0 +1,38 @@
+// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
+//
+// sprintf.h: Rcpp R/C++ interface class library -- string formatting
+//
+// Copyright (C) 2009 - 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/>.
+
+#include <cstdio>
+
+namespace Rcpp{
+
+template <int MAX_SIZE>
+const char* sprintf( const char *format, ...) {
+    static char buffer[MAX_SIZE]; 
+    va_list(ap);
+    va_start(ap, format);
+    vsprintf( buffer, format, ap);
+    va_end(ap);
+    buffer[MAX_SIZE] = '\0';
+    return strdup( buffer ) ;
+}
+
+}
+

Modified: pkg/Rcpp/inst/include/RcppCommon.h
===================================================================
--- pkg/Rcpp/inst/include/RcppCommon.h	2010-12-04 13:05:39 UTC (rev 2709)
+++ pkg/Rcpp/inst/include/RcppCommon.h	2010-12-04 13:54:19 UTC (rev 2710)
@@ -101,6 +101,7 @@
 #include <complex>
 #include <limits.h>
 #include <typeinfo>
+#include <Rcpp/sprintf.h>
 
 #ifdef HAS_INIT_LISTS
 #include <initializer_list>



More information about the Rcpp-commits mailing list