[Rcpp-commits] r1682 - in pkg/Rcpp: inst inst/include inst/include/Rcpp src

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Jun 23 20:16:33 CEST 2010


Author: edd
Date: 2010-06-23 20:16:32 +0200 (Wed, 23 Jun 2010)
New Revision: 1682

Added:
   pkg/Rcpp/inst/include/Rcpp/DateVector.h
   pkg/Rcpp/src/DateVector.cpp
Modified:
   pkg/Rcpp/inst/ChangeLog
   pkg/Rcpp/inst/include/Rcpp.h
Log:
new DateVector class


Modified: pkg/Rcpp/inst/ChangeLog
===================================================================
--- pkg/Rcpp/inst/ChangeLog	2010-06-23 18:13:15 UTC (rev 1681)
+++ pkg/Rcpp/inst/ChangeLog	2010-06-23 18:16:32 UTC (rev 1682)
@@ -3,6 +3,9 @@
 	* src/Date.cpp: Import mktime00() from R's src/main/datetime.c
 	* inst/include/Rcpp/Date.h: Add mktime00() declaration
 
+	* inst/include/Rcpp/DateVector.h: New DateVector class
+	* src/Date.cpp: Implementation for new DateVector class
+
 2010-06-23  Romain Francois <romain at r-enthusiasts.com>
 
 	* inst/include/Rcpp/Date_forward.h: forward declaration of Rcpp::Date and

Added: pkg/Rcpp/inst/include/Rcpp/DateVector.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/DateVector.h	                        (rev 0)
+++ pkg/Rcpp/inst/include/Rcpp/DateVector.h	2010-06-23 18:16:32 UTC (rev 1682)
@@ -0,0 +1,44 @@
+// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 4 -*-
+//
+// DateVector.h: Rcpp R/C++ interface class library -- Date vector support
+//
+// Copyright (C) 2005 - 2006 Dominick Samperi
+// 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__DateVector_h
+#define Rcpp__DateVector_h
+
+#include <RcppCommon.h>
+
+namespace Rcpp {
+
+	class DateVector {
+	public:
+		DateVector(SEXP vec);
+		DateVector(int n);
+		~DateVector() {};
+		const Date& operator()(unsigned int i) const;
+		Date& operator()(unsigned int i);
+		int size() const;
+		std::vector<Date> getVector() const;
+	private:
+		std::vector<Date> v;
+	};
+}
+
+#endif

Modified: pkg/Rcpp/inst/include/Rcpp.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp.h	2010-06-23 18:13:15 UTC (rev 1681)
+++ pkg/Rcpp/inst/include/Rcpp.h	2010-06-23 18:16:32 UTC (rev 1682)
@@ -69,6 +69,7 @@
 #include <Rcpp/Formula.h>
 #include <Rcpp/DataFrame.h>
 #include <Rcpp/Date.h>
+#include <Rcpp/DateVector.h>
 
 #ifdef RCPP_ENABLE_MODULES
 #include <Rcpp/Module.h>

Added: pkg/Rcpp/src/DateVector.cpp
===================================================================
--- pkg/Rcpp/src/DateVector.cpp	                        (rev 0)
+++ pkg/Rcpp/src/DateVector.cpp	2010-06-23 18:16:32 UTC (rev 1682)
@@ -0,0 +1,71 @@
+// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 4 -*-
+//
+// DateVector.cpp: Rcpp R/C++ interface class library -- Date vector support
+//
+// Copyright (C) 2005 - 2006 Dominick Samperi
+// 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/>.
+
+#include <Rcpp/DateVector.h>
+#include <Rcpp/Date.h>
+
+namespace Rcpp {
+
+	DateVector::DateVector(SEXP vec) {
+		int i;
+		if (!Rf_isNumeric(vec) || Rf_isMatrix(vec) || Rf_isLogical(vec))
+			throw std::range_error("DateVector: invalid numeric vector in constructor");
+		int len = Rf_length(vec);
+		if (len == 0)
+			throw std::range_error("DateVector: null vector in constructor");
+		v.resize(len);
+		for (i = 0; i < len; i++)
+			v[i] = Date( static_cast<int>(REAL(vec)[i]));
+	}
+
+
+	DateVector::DateVector(int n) {
+		v.resize(n);
+	}
+
+	const Date & DateVector::operator()(unsigned int i) const {
+		if (i >= v.size()) {
+			std::ostringstream oss;
+			oss << "DateVector: subscript out of range: " << i;
+			throw std::range_error(oss.str());
+		}
+		return v[i];
+	}
+
+	Date & DateVector::operator()(unsigned int i) {
+		if (i >= v.size()) {
+			std::ostringstream oss;
+			oss << "DateVector: subscript out of range: " << i;
+			throw std::range_error(oss.str());
+		}
+		return v[i];
+	}
+
+	int DateVector::size() const { 
+		return v.size(); 
+	}
+
+	std::vector<Date> DateVector::getVector() const {
+		return v;
+	}
+
+}



More information about the Rcpp-commits mailing list