00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include <RcppStringVectorView.h>
00024
00025 RcppStringVectorView::RcppStringVectorView(SEXP vec) {
00026 if (Rf_isMatrix(vec) || Rf_isLogical(vec))
00027 throw std::range_error("RcppStringVectorView: invalid numeric vector in constructor");
00028 if (!Rf_isString(vec))
00029 throw std::range_error("RcppStringVectorView: invalid string");
00030 int len = Rf_length(vec);
00031 if (len == 0)
00032 throw std::range_error("RcppStringVectorView: null vector in constructor");
00033 length = len;
00034 v = vec;
00035 }
00036
00037 const char* RcppStringVectorView::operator()(int i) const {
00038 if (i < 0 || i >= length) {
00039 std::ostringstream oss;
00040 oss << "RcppStringVector: subscript out of range: " << i;
00041 throw std::range_error(oss.str());
00042 }
00043 return CHAR(STRING_ELT(v,i));
00044 }
00045
00046 int RcppStringVectorView::size() const {
00047 return length;
00048 }