00001 // -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*- 00002 // 00003 // RcppList.h: Rcpp.h: R/C++ interface class library -- 'list' type support 00004 // 00005 // Copyright (C) 2009 Dirk Eddelbuettel 00006 // 00007 // This library is free software; you can redistribute it and/or modify it 00008 // under the terms of the GNU Lesser General Public License as published by 00009 // the Free Software Foundation; either version 2.1 of the License, or (at 00010 // your option) any later version. 00011 // 00012 // This library is distributed in the hope that it will be useful, but 00013 // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 00014 // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 00015 // License for more details. 00016 // 00017 // You should have received a copy of the GNU Lesser General Public License 00018 // along with this library; if not, write to the Free Software Foundation, 00019 // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00020 00021 #ifndef RcppList_h 00022 #define RcppList_h 00023 00024 #include <iostream> 00025 #include <sstream> 00026 #include <string> 00027 #include <list> 00028 #include <map> 00029 #include <stdexcept> 00030 #include <vector> 00031 00032 // include R headers, but set R_NO_REMAP and access everything via Rf_ prefixes 00033 #define R_NO_REMAP 00034 00035 #include <R.h> 00036 #include <Rinternals.h> 00037 00038 // This class was first used in the RProtoBuf project (currently on r-forge only) 00039 // but is more generally useful and hence moved over here 00040 class RcppList { 00041 public: 00042 RcppList(void): 00043 listArg(R_NilValue), listSize(0), currListPosn(0), numProtected(0) { }; 00044 ~RcppList() { 00045 UNPROTECT(numProtected); 00046 } 00047 void setSize(int size); 00048 void append(std::string name, double value); 00049 void append(std::string name, int value); 00050 void append(std::string name, std::string value); 00051 //void append(std::string name, RcppDate& date); 00052 //void append(std::string name, RcppDatetime& datetime); 00053 void append(std::string name, SEXP sexp); 00054 void clearProtectionStack(); 00055 SEXP getList(void) const; 00056 00057 protected: 00058 friend class RcppResultSet; 00059 00060 private: 00061 SEXP listArg; 00062 int listSize, currListPosn, numProtected; 00063 std::vector<std::string> names; 00064 }; 00065 00066 #endif