romainfrancois commented on pull request #8256:
URL: https://github.com/apache/arrow/pull/8256#issuecomment-724712441
I've added back an `as_sexp()` for `std::shared_ptr<...>` so that we can
return the actual type instead of the catch-all R6, so for example:
```cpp
// [[arrow::export]]
std::shared_ptr<arrow::Field> Field__initialize(
const std::string& name, const std::shared_ptr<arrow::DataType>& field,
bool nullable = true) {
return arrow::field(name, field, nullable);
}
```
`as_sexp()` uses `cpp11::to_r6<>()` which in turns uses `r6_class_name<>()`
to decide the R6 class name.
```cpp
template <typename T>
SEXP as_sexp(const std::shared_ptr<T>& ptr) {
return cpp11::to_r6<T>(ptr);
}
```
I have not been able to replace this template function with a template
struct so far:
```cpp
template <typename T>
const char* r6_class_name(const std::shared_ptr<T>&);
```
this was giving errors about the type not being fully defined or something.
I'm using a macro to help generating the many functions:
```cpp
#define DEFAULT_R6_CLASS_NAME(CLASS, NAME) \
namespace cpp11 { \
template <> \
const char* r6_class_name<CLASS>(const std::shared_ptr<CLASS>&) { \
return NAME; \
} \
}
```
so that for example:
```cpp
DEFAULT_R6_CLASS_NAME(parquet::ArrowReaderProperties,
"ParquetArrowReaderProperties")
DEFAULT_R6_CLASS_NAME(parquet::ArrowWriterProperties,
"ParquetArrowWriterProperties")
DEFAULT_R6_CLASS_NAME(parquet::WriterProperties, "ParquetWriterProperties")
DEFAULT_R6_CLASS_NAME(parquet::arrow::FileReader, "ParquetFileReader")
DEFAULT_R6_CLASS_NAME(parquet::WriterPropertiesBuilder,
"ParquetWriterPropertiesBuilder")
DEFAULT_R6_CLASS_NAME(parquet::arrow::FileWriter, "ParquetFileWriter")
```
So that's still a little bit of housekeeping, and it's a bit brute force,
but neither the R code (no more `shared_ptr()` or `..dispatch()`) nor the C++
side have to deal with conversion from a `std::shared_ptr<arrow::*>` to the
right R6 class.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]