File: util.h

package info (click to toggle)
r-cran-bigmemory 4.6.4-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 648 kB
  • sloc: cpp: 4,930; ansic: 131; sh: 13; makefile: 2
file content (81 lines) | stat: -rw-r--r-- 1,747 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#ifndef BIGMEMORY_UTIL_HPP
#define BIGMEMORY_UTIL_HPP

#include "bigmemoryDefines.h"

using namespace std;

vector<string> RChar2StringVec( SEXP charVec );

vector<string> RChar2StringVec( SEXP charVec, 
  const vector<index_type> &indices );

SEXP String2RChar(const std::string &str);

std::string RChar2String(SEXP str);

SEXP StringVec2RChar( const vector<string> &strVec );

// Removed because no longer required with Rcpp
/*
template<typename T>
SEXP StringVec2RChar( const vector<string> &strVec,
  T indices, const index_type indicesLength )
{
  if (strVec.empty())
    return NULL_USER_OBJECT;
  SEXP ret = PROTECT(allocVector(STRSXP, indicesLength));
  index_type i;
  for (i=0; i < indicesLength; ++i)
  {
    SET_STRING_ELT(ret, i, 
      mkChar(strVec[static_cast<index_type>(indices[i])-1].c_str()));
  }
  UNPROTECT(1);
  return ret;
}
*/

template<typename T>
struct NewVec;

template<>
struct NewVec<int>
{SEXP operator()(index_type n) const {return Rcpp::IntegerVector(n);};};


inline
SEXP NEW_FLOAT(index_type n)
{
    std::vector<float> out (n, 0);
    return Rcpp::wrap(out);
}

template<>
struct NewVec<float>
{SEXP operator()(index_type n) const {return NEW_FLOAT(n);};};

template<>
struct NewVec<double>
{SEXP operator()(index_type n) const {return Rcpp::NumericVector(n);};};

template<typename T>
struct VecPtr;

template<>
struct VecPtr<unsigned char>
{Rbyte* operator()(SEXP vec) const {return RAW(vec);};};

template<>
struct VecPtr<int>
{int* operator()(SEXP vec) const {return INTEGER(vec);};};

template<>
struct VecPtr<float>
{float* operator()(SEXP vec) const {return (float *)(vec);};};

template<>
struct VecPtr<double>
{double* operator()(SEXP vec) const {return REAL(vec);};};

#endif // BIGMEMORY_UTIL_HPP