00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include <RcppStringVector.h>
00024
00025 RcppStringVector::RcppStringVector(SEXP vec) {
00026 int i;
00027 if (Rf_isMatrix(vec) || Rf_isLogical(vec))
00028 throw std::range_error("RcppStringVector: invalid numeric vector in constructor");
00029 if (!Rf_isString(vec))
00030 throw std::range_error("RcppStringVector: invalid string");
00031 int len = Rf_length(vec);
00032 if (len == 0)
00033 throw std::range_error("RcppStringVector: null vector in constructor");
00034 v = new std::string[len];
00035 for (i = 0; i < len; i++)
00036 v[i] = std::string(CHAR(STRING_ELT(vec,i)));
00037 length = len;
00038 }
00039
00040 RcppStringVector::~RcppStringVector() {
00041 delete [] v;
00042 }
00043
00044 std::string& RcppStringVector::operator()(int i) const {
00045 if (i < 0 || i >= length) {
00046 std::ostringstream oss;
00047 oss << "RcppStringVector: subscript out of range: " << i;
00048 throw std::range_error(oss.str());
00049 }
00050 return v[i];
00051 }
00052
00053 int RcppStringVector::size() const {
00054 return length;
00055 }
00056
00057 std::vector<std::string> RcppStringVector::stlVector() const {
00058 std::vector<std::string> tmp(length);
00059 for (int i = 0; i < length; i++)
00060 tmp[i] = v[i];
00061 return tmp;
00062 }