本文整理汇总了C++中SourcePtr类的典型用法代码示例。如果您正苦于以下问题:C++ SourcePtr类的具体用法?C++ SourcePtr怎么用?C++ SourcePtr使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SourcePtr类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: read_lines_
// [[Rcpp::export]]
CharacterVector read_lines_(List sourceSpec, int n_max = -1) {
SourcePtr source = Source::create(sourceSpec);
TokenizerLine tokenizer;
tokenizer.tokenize(source->begin(), source->end());
int n = (n_max < 0) ? 1000 : n_max;
CharacterVector out(n);
int i = 0;
for (Token t = tokenizer.nextToken(); t.type() != TOKEN_EOF; t = tokenizer.nextToken()) {
if (i >= n) {
if (n_max < 0) {
n = (n * 3)/2 + 1;
out = Rf_lengthgets(out, n);
} else {
break;
}
}
if (t.type() == TOKEN_STRING)
out[i] = t.asString();
++i;
}
if (i < n) {
out = Rf_lengthgets(out, i);
}
return out;
}
示例2: tokenize_
// [[Rcpp::export]]
RObject tokenize_(List sourceSpec, List tokenizerSpec, int n_max) {
Warnings warnings;
SourcePtr source = Source::create(sourceSpec);
TokenizerPtr tokenizer = Tokenizer::create(tokenizerSpec);
tokenizer->tokenize(source->begin(), source->end());
tokenizer->setWarnings(&warnings);
std::vector<std::vector<std::string> > rows;
for (Token t = tokenizer->nextToken(); t.type() != TOKEN_EOF; t = tokenizer->nextToken()) {
if (n_max > 0 && t.row() >= (size_t) n_max)
break;
if (t.row() >= rows.size()) {
rows.resize(t.row() + 1);
}
std::vector<std::string>& row = rows[t.row()];
if (t.col() >= row.size())
row.resize(t.col() + 1);
row[t.col()] = t.asString();
}
RObject out = wrap(rows);
return warnings.addAsAttribute(out);
}
示例3: read_file_
// [[Rcpp::export]]
CharacterVector read_file_(List sourceSpec) {
SourcePtr source = Source::create(sourceSpec);
CharacterVector out(1);
out[0] = Rf_mkCharLen(source->begin(), source->end() - source->begin());
return out;
}
示例4: tokenize_
// [[Rcpp::export]]
std::vector<std::vector<std::string> > tokenize_(List sourceSpec, List tokenizerSpec, int n) {
SourcePtr source = Source::create(sourceSpec);
TokenizerPtr tokenizer = Tokenizer::create(tokenizerSpec);
tokenizer->tokenize(source->begin(), source->end());
std::vector<std::vector<std::string> > rows;
int i = 0;
for (Token t = tokenizer->nextToken(); t.type() != TOKEN_EOF; t = tokenizer->nextToken()) {
if (n > 0 && i > n)
break;
if (t.row() >= rows.size()) {
rows.resize(t.row() + 1);
}
std::vector<std::string>& row = rows[t.row()];
if (t.col() >= row.size())
row.resize(t.col() + 1);
row[t.col()] = t.asString();
++i;
}
return rows;
}
示例5: guess_header_
// [[Rcpp::export]]
RObject guess_header_(List sourceSpec, List tokenizerSpec, List locale_) {
Warnings warnings;
LocaleInfo locale(locale_);
SourcePtr source = Source::create(sourceSpec);
TokenizerPtr tokenizer = Tokenizer::create(tokenizerSpec);
tokenizer->tokenize(source->begin(), source->end());
tokenizer->setWarnings(&warnings);
CollectorCharacter out(&locale.encoder_);
out.setWarnings(&warnings);
for (Token t = tokenizer->nextToken(); t.type() != TOKEN_EOF; t = tokenizer->nextToken()) {
if (t.row() > (size_t) 0) // only read one row
break;
if (t.col() >= (size_t) out.size()) {
out.resize(t.col() + 1);
}
if (t.type() == TOKEN_STRING) {
out.setValue(t.col(), t);
}
}
return out.vector();
}
示例6: collectorsGuess
// [[Rcpp::export]]
std::vector<std::string> collectorsGuess(List sourceSpec, List tokenizerSpec, int n = 100) {
Warnings warnings;
SourcePtr source = Source::create(sourceSpec);
TokenizerPtr tokenizer = Tokenizer::create(tokenizerSpec);
tokenizer->tokenize(source->begin(), source->end());
tokenizer->setWarnings(&warnings); // silence warnings
std::vector<CollectorCharacter> collectors;
for (Token t = tokenizer->nextToken(); t.type() != TOKEN_EOF; t = tokenizer->nextToken()) {
if (t.row() >= (size_t) n)
break;
// Add new collectors, if needed
if (t.col() >= collectors.size()) {
int old_p = collectors.size();
collectors.resize(t.col() + 1);
for (size_t j = old_p; j < collectors.size(); ++j) {
collectors[j].resize(n);
}
}
collectors[t.col()].setValue(t.row(), t);
}
std::vector<std::string> out;
for (size_t j = 0; j < collectors.size(); ++j) {
CharacterVector col = as<CharacterVector>(collectors[j].vector());
out.push_back(collectorGuess(col));
}
return out;
}
示例7: read_file_
// [[Rcpp::export]]
CharacterVector read_file_(List sourceSpec, List locale_) {
SourcePtr source = Source::create(sourceSpec);
LocaleInfo locale(locale_);
return CharacterVector::create(
locale.encoder_.makeSEXP(source->begin(), source->end())
);
}
示例8: initLexer
static void initLexer(SourcePtr source, size_t offset, size_t length) {
lexerSource = source.ptr();
begin = source->data() + offset;
end = begin + length;
ptr = begin;
maxPtr = begin;
beginOffset = offset;
}
示例9: desugarEvalStatement
llvm::ArrayRef<StatementPtr> desugarEvalStatement(EvalStatementPtr eval, EnvPtr env)
{
if (eval->evaled)
return eval->value;
else {
SourcePtr source = evalToSource(eval->location, eval->args, env);
parseStatements(source, 0, unsigned(source->size()), eval->value);
eval->evaled = true;
return eval->value;
}
}
示例10: desugarEvalExpr
ExprListPtr desugarEvalExpr(EvalExprPtr eval, EnvPtr env, CompilerState* cst)
{
if (eval->evaled)
return eval->value;
else {
SourcePtr source = evalToSource(eval->location, new ExprList(eval->args), env, cst);
eval->value = parseExprList(source, 0, unsigned(source->size()), cst);
eval->evaled = true;
return eval->value;
}
}
示例11: desugarEvalTopLevel
llvm::ArrayRef<TopLevelItemPtr> desugarEvalTopLevel(EvalTopLevelPtr eval, EnvPtr env)
{
if (eval->evaled)
return eval->value;
else {
SourcePtr source = evalToSource(eval->location, eval->args, env);
parseTopLevelItems(source, 0, unsigned(source->size()), eval->value, eval->module);
eval->evaled = true;
return eval->value;
}
}
示例12: dim_tokens_
// [[Rcpp::export]]
IntegerVector dim_tokens_(List sourceSpec, List tokenizerSpec) {
SourcePtr source = Source::create(sourceSpec);
TokenizerPtr tokenizer = Tokenizer::create(tokenizerSpec);
tokenizer->tokenize(source->begin(), source->end());
size_t rows = -1, cols = -1;
for (Token t = tokenizer->nextToken(); t.type() != TOKEN_EOF; t = tokenizer->nextToken()) {
rows = t.row();
if (t.col() > cols)
cols = t.col();
}
return IntegerVector::create(rows + 1, cols + 1);
}
示例13: eval
static void eval(llvm::StringRef line) {
SourcePtr source = new Source(line, 0);
try {
ReplItem x = parseInteractive(source, 0, source->size());
if (x.isExprSet) {
jitAndPrintExpr(x.expr);
} else {
loadImports(x.imports);
jitTopLevel(x.toplevels);
jitStatements(x.stmts);
}
}
catch (CompilerError) {
return;
}
}
示例14: count_fields_
// [[Rcpp::export]]
std::vector<int> count_fields_(List sourceSpec, List tokenizerSpec) {
SourcePtr source = Source::create(sourceSpec);
TokenizerPtr tokenizer = Tokenizer::create(tokenizerSpec);
tokenizer->tokenize(source->begin(), source->end());
std::vector<int> fields;
for (Token t = tokenizer->nextToken(); t.type() != TOKEN_EOF; t = tokenizer->nextToken()) {
if (t.row() >= fields.size()) {
fields.resize(t.row() + 1);
}
fields[t.row()] = t.col();
}
return fields;
}
示例15: read_lines_
// [[Rcpp::export]]
CharacterVector read_lines_(List sourceSpec, List locale_, int n_max = -1,
bool progress = true) {
SourcePtr source = Source::create(sourceSpec);
TokenizerLine tokenizer;
tokenizer.tokenize(source->begin(), source->end());
LocaleInfo locale(locale_);
Progress progressBar;
int n = (n_max < 0) ? 10000 : n_max;
CharacterVector out(n);
int i = 0;
for (Token t = tokenizer.nextToken(); t.type() != TOKEN_EOF; t = tokenizer.nextToken()) {
if (progress && (i + 1) % 25000 == 0)
progressBar.show(tokenizer.progress());
if (i >= n) {
if (n_max < 0) {
// Estimate rows in full dataset
n = (i / tokenizer.progress().first) * 1.2;
out = Rf_lengthgets(out, n);
} else {
break;
}
}
if (t.type() == TOKEN_STRING)
out[i] = t.asSEXP(&locale.encoder_);
++i;
}
if (i < n) {
out = Rf_lengthgets(out, i);
}
if (progress)
progressBar.show(tokenizer.progress());
progressBar.stop();
return out;
}