Verified Commit df63b608 authored by Artem Klevtsov's avatar Artem Klevtsov 😹

Split C++ code

parent 8f2cedf8
# Generated by using Rcpp::compileAttributes() -> do not edit by hand
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393
#' @rdname uuid
#' @title Generate UUIDs Version 5
#'
#' @description
#' Function generates uuids using operating system provided entropy.
#'
#' @param x Character vector.
#' @return Character vector with UUIDs.
#'
#' @note
#' This function generates valid uuids for the `NA`.
#'
#' @export
uuid_generate_random <- function(n = 1L) {
.Call(`_RcppUUID_uuid_generate_random`, n)
#'
#' @references
#' <https://www.boost.org/doc/libs/1_72_0/libs/uuid/doc/uuid.html#Name%20Generator>
#'
#' @export
#'
#' @examples
#' # generate name UUIDs
#' uuid_generate_name(c("one", "two"))
#'
uuid_generate_name <- function(x) {
.Call(`_RcppUUID_uuid_generate_name`, x)
}
#' @rdname uuid
#' @title Generrates Nil UUIDs
#'
#' @description
#' Function generates nil uuids.
#'
#' @param n Number of generated UUIDs.
#' @return Character vector with UUIDs.
#'
#' @references
#' <https://www.boost.org/doc/libs/1_72_0/libs/uuid/doc/uuid.html#Nil%20Generator>
#'
#' @export
#'
#' @examples
#' # generate nil UUIDs
#' uuid_generate_nil(2)
#'
uuid_generate_nil <- function(n = 1L) {
.Call(`_RcppUUID_uuid_generate_nil`, n)
}
#' @rdname uuid
#' @title Generate UUIDs Version 4
#'
#' @description
#' Function generates uuids using operating system provided entropy.
#'
#' @param n Number of generated UUIDs.
#' @return Character vector with UUIDs.
#'
#' @export
uuid_generate_name <- function(x) {
.Call(`_RcppUUID_uuid_generate_name`, x)
#'
#' @references
#' <https://www.boost.org/doc/libs/1_72_0/libs/uuid/doc/uuid.html#Random%20Generator>
#'
#' @examples
#' # generate random UUIDs
#' uuid_generate_random(2)
#'
uuid_generate_random <- function(n = 1L) {
.Call(`_RcppUUID_uuid_generate_random`, n)
}
#' @rdname uuid
#' @title Validate UUIDs
#'
#' @description
#' Function validates uuids.
#'
#' @param x Character vector.
#' @return Logical vector.
#'
#' @export
#'
#' @examples
#' # validate UUIDs
#' uuid_validate(uuid_generate_random(2))
#' uuid_validate(uuid_generate_nil(2))
#' uuid_validate(uuid_generate_name(c("one", "two")))
#' uuid_validate(c("a", ""))
#'
uuid_validate <- function(x) {
.Call(`_RcppUUID_uuid_validate`, x)
}
......
#' @title
#' Generate UUIDs
#'
#' @description
#' Function generates a set of Universally Unique Identifiers.
#' Supported version 4 and 5 UUIDs.
#'
#' @param n Number of generated UUIDs.
#' @param x Character vector.
#'
#' @return Character vector with UUIDs.
#'
#' @name uuid
#'
#' @examples
#' # generate random UUIDs
#' uuid_generate_random(2)
#' # generate nil UUIDs
#' uuid_generate_nil(2)
#' # generate name UUIDs
#' uuid_generate_name(c("one", "two"))
#' # validate UUIDs
#' uuid_validate(uuid_generate_random(2))
#' uuid_validate(uuid_generate_nil(2))
#' uuid_validate(uuid_generate_name(c("one", "two")))
#' uuid_validate(c("a", ""))
#'
NULL
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/RcppExports.R
\name{uuid_generate_name}
\alias{uuid_generate_name}
\title{Generate UUIDs Version 5}
\usage{
uuid_generate_name(x)
}
\arguments{
\item{x}{Character vector.}
}
\value{
Character vector with UUIDs.
}
\description{
Function generates uuids using operating system provided entropy.
}
\note{
This function generates valid uuids for the \code{NA}.
}
\examples{
# generate name UUIDs
uuid_generate_name(c("one", "two"))
}
\references{
\url{https://www.boost.org/doc/libs/1_72_0/libs/uuid/doc/uuid.html#Name\%20Generator}
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/RcppExports.R
\name{uuid_generate_nil}
\alias{uuid_generate_nil}
\title{Generrates Nil UUIDs}
\usage{
uuid_generate_nil(n = 1L)
}
\arguments{
\item{n}{Number of generated UUIDs.}
}
\value{
Character vector with UUIDs.
}
\description{
Function generates nil uuids.
}
\examples{
# generate nil UUIDs
uuid_generate_nil(2)
}
\references{
\url{https://www.boost.org/doc/libs/1_72_0/libs/uuid/doc/uuid.html#Nil\%20Generator}
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/RcppExports.R
\name{uuid_generate_random}
\alias{uuid_generate_random}
\title{Generate UUIDs Version 4}
\usage{
uuid_generate_random(n = 1L)
}
\arguments{
\item{n}{Number of generated UUIDs.}
}
\value{
Character vector with UUIDs.
}
\description{
Function generates uuids using operating system provided entropy.
}
\examples{
# generate random UUIDs
uuid_generate_random(2)
}
\references{
\url{https://www.boost.org/doc/libs/1_72_0/libs/uuid/doc/uuid.html#Random\%20Generator}
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/RcppExports.R, R/uuid.R
\name{uuid_generate_random}
\alias{uuid_generate_random}
\alias{uuid_generate_nil}
\alias{uuid_generate_name}
% Please edit documentation in R/RcppExports.R
\name{uuid_validate}
\alias{uuid_validate}
\alias{uuid}
\title{Generate UUIDs}
\title{Validate UUIDs}
\usage{
uuid_generate_random(n = 1L)
uuid_generate_nil(n = 1L)
uuid_generate_name(x)
uuid_validate(x)
}
\arguments{
\item{n}{Number of generated UUIDs.}
\item{x}{Character vector.}
}
\value{
Character vector with UUIDs.
Logical vector.
}
\description{
Function generates a set of Universally Unique Identifiers.
Supported version 4 and 5 UUIDs.
Function validates uuids.
}
\examples{
# generate random UUIDs
uuid_generate_random(2)
# generate nil UUIDs
uuid_generate_nil(2)
# generate name UUIDs
uuid_generate_name(c("one", "two"))
# validate UUIDs
uuid_validate(uuid_generate_random(2))
uuid_validate(uuid_generate_nil(2))
......
CXX_STD = CXX11
PKG_CXXFLAGS = -DRCPP_NO_MODULES
......@@ -5,18 +5,18 @@
using namespace Rcpp;
// uuid_generate_random
std::vector<std::string> uuid_generate_random(size_t n);
RcppExport SEXP _RcppUUID_uuid_generate_random(SEXP nSEXP) {
// uuid_generate_name
StringVector uuid_generate_name(StringVector x);
RcppExport SEXP _RcppUUID_uuid_generate_name(SEXP xSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::traits::input_parameter< size_t >::type n(nSEXP);
rcpp_result_gen = Rcpp::wrap(uuid_generate_random(n));
Rcpp::traits::input_parameter< StringVector >::type x(xSEXP);
rcpp_result_gen = Rcpp::wrap(uuid_generate_name(x));
return rcpp_result_gen;
END_RCPP
}
// uuid_generate_nil
std::vector<std::string> uuid_generate_nil(size_t n);
StringVector uuid_generate_nil(size_t n);
RcppExport SEXP _RcppUUID_uuid_generate_nil(SEXP nSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
......@@ -25,31 +25,31 @@ BEGIN_RCPP
return rcpp_result_gen;
END_RCPP
}
// uuid_generate_name
std::vector<std::string> uuid_generate_name(const std::vector<std::string>& x);
RcppExport SEXP _RcppUUID_uuid_generate_name(SEXP xSEXP) {
// uuid_generate_random
StringVector uuid_generate_random(size_t n);
RcppExport SEXP _RcppUUID_uuid_generate_random(SEXP nSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::traits::input_parameter< const std::vector<std::string>& >::type x(xSEXP);
rcpp_result_gen = Rcpp::wrap(uuid_generate_name(x));
Rcpp::traits::input_parameter< size_t >::type n(nSEXP);
rcpp_result_gen = Rcpp::wrap(uuid_generate_random(n));
return rcpp_result_gen;
END_RCPP
}
// uuid_validate
std::vector<bool> uuid_validate(const std::vector<std::string>& x);
LogicalVector uuid_validate(StringVector x);
RcppExport SEXP _RcppUUID_uuid_validate(SEXP xSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::traits::input_parameter< const std::vector<std::string>& >::type x(xSEXP);
Rcpp::traits::input_parameter< StringVector >::type x(xSEXP);
rcpp_result_gen = Rcpp::wrap(uuid_validate(x));
return rcpp_result_gen;
END_RCPP
}
static const R_CallMethodDef CallEntries[] = {
{"_RcppUUID_uuid_generate_random", (DL_FUNC) &_RcppUUID_uuid_generate_random, 1},
{"_RcppUUID_uuid_generate_nil", (DL_FUNC) &_RcppUUID_uuid_generate_nil, 1},
{"_RcppUUID_uuid_generate_name", (DL_FUNC) &_RcppUUID_uuid_generate_name, 1},
{"_RcppUUID_uuid_generate_nil", (DL_FUNC) &_RcppUUID_uuid_generate_nil, 1},
{"_RcppUUID_uuid_generate_random", (DL_FUNC) &_RcppUUID_uuid_generate_random, 1},
{"_RcppUUID_uuid_validate", (DL_FUNC) &_RcppUUID_uuid_validate, 1},
{NULL, NULL, 0}
};
......
#include <Rcpp.h>
#include <boost/uuid/uuid.hpp>
#include <boost/uuid/uuid_generators.hpp>
#include <boost/uuid/uuid_io.hpp>
using namespace Rcpp;
//' @rdname uuid
//' @export
// [[Rcpp::export(rng=false)]]
std::vector<std::string> uuid_generate_random(size_t n = 1) {
std::vector<std::string> res(n);
boost::uuids::random_generator gen;
#pragma omp parallel for
for (size_t i = 0; i < n; ++i) {
boost::uuids::uuid id = gen();
res[i] = to_string(id);
}
return res;
}
//' @rdname uuid
//' @export
// [[Rcpp::export(rng=false)]]
std::vector<std::string> uuid_generate_nil(size_t n = 1) {
boost::uuids::nil_generator gen;
boost::uuids::uuid id = gen();
std::string val = to_string(id);
std::vector<std::string> res(n);
#pragma omp parallel for
for (size_t i = 0; i < n; ++i) {
res[i] = val;
}
return res;
}
//' @rdname uuid
//' @export
// [[Rcpp::export(rng=false)]]
std::vector<std::string> uuid_generate_name(const std::vector<std::string>& x) {
size_t n = x.size();
std::vector<std::string> res(n);
boost::uuids::name_generator_sha1 gen(boost::uuids::ns::x500dn());
auto nil_uuid = boost::uuids::nil_generator()();
#pragma omp parallel for
for (size_t i = 0; i < n; ++i) {
boost::uuids::uuid id = x[i].empty() ? nil_uuid : gen(x[i]);
res[i] = to_string(id);
}
return res;
}
//' @rdname uuid
//' @export
// [[Rcpp::export(rng=false)]]
std::vector<bool> uuid_validate(const std::vector<std::string>& x) {
size_t n = x.size();
std::vector<bool> res(n);
boost::uuids::string_generator gen;
for (size_t i = 0; i < n; ++i) {
if (x[i].empty()) {
res[i] = false;
} else {
try {
boost::uuids::uuid id = gen(x[i]);
res[i] = id.is_nil() || id.version() != boost::uuids::uuid::version_unknown;
} catch(...) {
res[i] = false;
}
}
}
return res;
}
#include "wrap.h"
#include <boost/uuid/uuid.hpp>
#include <boost/uuid/name_generator.hpp>
#include <Rcpp.h>
using namespace Rcpp;
using namespace boost;
using boost::uuids::uuid;
//' @title Generate UUIDs Version 5
//'
//' @description
//' Function generates uuids using operating system provided entropy.
//'
//' @param x Character vector.
//' @return Character vector with UUIDs.
//'
//' @note
//' This function generates valid uuids for the `NA`.
//'
//' @export
//'
//' @references
//' <https://www.boost.org/doc/libs/1_72_0/libs/uuid/doc/uuid.html#Name%20Generator>
//'
//' @export
//'
//' @examples
//' # generate name UUIDs
//' uuid_generate_name(c("one", "two"))
//'
// [[Rcpp::export(rng=false)]]
StringVector uuid_generate_name(StringVector x) {
std::vector<uuid> res(x.size());
uuids::name_generator_sha1 gen(uuids::ns::x500dn());
std::transform(x.begin(), x.end(), res.begin(), gen);
return wrap(res);
}
#include "wrap.h"
#include <boost/uuid/uuid.hpp>
#include <boost/uuid/nil_generator.hpp>
#include <Rcpp.h>
using namespace Rcpp;
using namespace boost;
using boost::uuids::uuid;
//' @title Generrates Nil UUIDs
//'
//' @description
//' Function generates nil uuids.
//'
//' @param n Number of generated UUIDs.
//' @return Character vector with UUIDs.
//'
//' @references
//' <https://www.boost.org/doc/libs/1_72_0/libs/uuid/doc/uuid.html#Nil%20Generator>
//'
//' @export
//'
//' @examples
//' # generate nil UUIDs
//' uuid_generate_nil(2)
//'
// [[Rcpp::export(rng=false)]]
StringVector uuid_generate_nil(size_t n = 1) {
std::vector<uuid> res(n);
std::generate(res.begin(), res.end(), uuids::nil_generator());
return wrap(res);
}
#include "wrap.h"
#include <boost/uuid/uuid.hpp>
#include <boost/uuid/random_generator.hpp>
#include <Rcpp.h>
using namespace Rcpp;
using namespace boost;
using boost::uuids::uuid;
//' @title Generate UUIDs Version 4
//'
//' @description
//' Function generates uuids using operating system provided entropy.
//'
//' @param n Number of generated UUIDs.
//' @return Character vector with UUIDs.
//'
//' @export
//'
//' @references
//' <https://www.boost.org/doc/libs/1_72_0/libs/uuid/doc/uuid.html#Random%20Generator>
//'
//' @examples
//' # generate random UUIDs
//' uuid_generate_random(2)
//'
// [[Rcpp::export(rng=false)]]
StringVector uuid_generate_random(size_t n = 1) {
std::vector<uuid> res(n);
std::generate(res.begin(), res.end(), uuids::random_generator());
return wrap(res);
}
#include "wrap.h"
#include <boost/uuid/uuid.hpp>
#include <boost/uuid/uuid_generators.hpp>
#include <Rcpp.h>
using namespace Rcpp;
using namespace boost;
using boost::uuids::uuid;
inline bool try_uuid(const char* s) {
try {
uuids::string_generator gen;
uuids::uuid id = gen(s);
return id.is_nil() || id.version() != uuids::uuid::version_unknown;
} catch(...) {
return false;
}
}
//' @title Validate UUIDs
//'
//' @description
//' Function validates uuids.
//'
//' @param x Character vector.
//' @return Logical vector.
//'
//' @export
//'
//' @examples
//' # validate UUIDs
//' uuid_validate(uuid_generate_random(2))
//' uuid_validate(uuid_generate_nil(2))
//' uuid_validate(uuid_generate_name(c("one", "two")))
//' uuid_validate(c("a", ""))
//'
// [[Rcpp::export(rng=false)]]
LogicalVector uuid_validate(StringVector x) {
LogicalVector res = no_init(x.size());
std::transform(x.begin(), x.end(), res.begin(), try_uuid);
return res;
}
#include "wrap.h"
#include <Rcpp.h>
#include <boost/uuid/uuid.hpp>
#include <boost/uuid/uuid_io.hpp>
namespace Rcpp {
using boost::uuids::uuid;
template<>
SEXP wrap(const uuid& u) {
return wrap(to_string(u));
}
template<>
SEXP wrap(const std::vector<uuid>& x) {
StringVector res = no_init(x.size());
std::transform(x.begin(), x.end(), res.begin(), [](const uuid& u) { return to_string(u); });
return wrap(res);
}
} // Rcpp
#pragma once
#include <RcppCommon.h>
#include <boost/uuid/uuid.hpp>
namespace Rcpp {
using boost::uuids::uuid;
template<> SEXP wrap(const uuid&);
template<> SEXP wrap(const std::vector<uuid>&);
} // Rcpp
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment