From 333e8c702f1cc9b8e704e251e69199497bc08aad Mon Sep 17 00:00:00 2001 From: Thomas Fussell Date: Wed, 28 Jun 2017 10:08:39 -0400 Subject: [PATCH] set up directory structure --- contrib/xlnt-arrow/xlnt-arrow.cpp | 25 ++++++++ contrib/xlnt-arrow/xlnt-arrow.hpp | 5 ++ contrib/xlntpyarrow/setup.py | 5 ++ contrib/xlntpyarrow/xlntpyarrow.cpp | 93 +++++++++++++++++++++++++++++ 4 files changed, 128 insertions(+) create mode 100644 contrib/xlnt-arrow/xlnt-arrow.cpp create mode 100644 contrib/xlnt-arrow/xlnt-arrow.hpp create mode 100644 contrib/xlntpyarrow/setup.py create mode 100644 contrib/xlntpyarrow/xlntpyarrow.cpp diff --git a/contrib/xlnt-arrow/xlnt-arrow.cpp b/contrib/xlnt-arrow/xlnt-arrow.cpp new file mode 100644 index 00000000..8b3c7797 --- /dev/null +++ b/contrib/xlnt-arrow/xlnt-arrow.cpp @@ -0,0 +1,25 @@ +#include "xlnt-arrow.h" + +void xlsx2arrow(std::istream &s, arrow::Table &table) +{ + xlnt::streaming_workbook_reader reader; + reader.open(s); + + reader.begin_worksheet(); + int first_row = 0; + while (reader.has_cell()) + { + auto cell = reader.read_cell(); + + if (first_row < 1) + { + first_row = cell.row(); + } + } + reader.end_worksheet(); +} + +void arrow2xlsx(const arrow::Table &table, std::istream &s) +{ + +} diff --git a/contrib/xlnt-arrow/xlnt-arrow.hpp b/contrib/xlnt-arrow/xlnt-arrow.hpp new file mode 100644 index 00000000..70e80116 --- /dev/null +++ b/contrib/xlnt-arrow/xlnt-arrow.hpp @@ -0,0 +1,5 @@ +#include +#include + +void xlsx2arrow(std::istream &s, arrow::Table &table); +void arrow2xlsx(const arrow::Table &table, std::istream &s); diff --git a/contrib/xlntpyarrow/setup.py b/contrib/xlntpyarrow/setup.py new file mode 100644 index 00000000..886f33bd --- /dev/null +++ b/contrib/xlntpyarrow/setup.py @@ -0,0 +1,5 @@ +from distutils.core import setup, Extension + +setup( + ext_modules=[Extension("xlntpyarrow", ["xlntpyarrow.cpp"])] +) diff --git a/contrib/xlntpyarrow/xlntpyarrow.cpp b/contrib/xlntpyarrow/xlntpyarrow.cpp new file mode 100644 index 00000000..ee76014c --- /dev/null +++ b/contrib/xlntpyarrow/xlntpyarrow.cpp @@ -0,0 +1,93 @@ +#include +#include + +class abc { +public: + static void def() + { + std::cout << "abc" << std::endl; + } +}; + +extern "C" { + +/* + * Implements an example function. + */ +PyDoc_STRVAR(xlntpyarrow_example_doc, "example(obj, number)\ +\ +Example function"); + +PyObject *xlntpyarrow_example(PyObject *self, PyObject *args, PyObject *kwargs) { + /* Shared references that do not need Py_DECREF before returning. */ + PyObject *obj = NULL; + int number = 0; + + abc::def(); + + /* Parse positional and keyword arguments */ + static char* keywords[] = { "obj", "number", NULL }; + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "Oi", keywords, &obj, &number)) { + return NULL; + } + + /* Function implementation starts here */ + + if (number < 0) { + PyErr_SetObject(PyExc_ValueError, obj); + return NULL; /* return NULL indicates error */ + } + + Py_RETURN_NONE; +} + +/* + * List of functions to add to xlntpyarrow in exec_xlntpyarrow(). + */ +static PyMethodDef xlntpyarrow_functions[] = { + { "example", (PyCFunction)xlntpyarrow_example, METH_VARARGS | METH_KEYWORDS, xlntpyarrow_example_doc }, + { NULL, NULL, 0, NULL } /* marks end of array */ +}; + +/* + * Initialize xlntpyarrow. May be called multiple times, so avoid + * using static state. + */ +int exec_xlntpyarrow(PyObject *module) { + PyModule_AddFunctions(module, xlntpyarrow_functions); + + PyModule_AddStringConstant(module, "__author__", "Thomas"); + PyModule_AddStringConstant(module, "__version__", "1.0.0"); + PyModule_AddIntConstant(module, "year", 2017); + + return 0; /* success */ +} + +/* + * Documentation for xlntpyarrow. + */ +PyDoc_STRVAR(xlntpyarrow_doc, "The xlntpyarrow module"); + + +static PyModuleDef_Slot xlntpyarrow_slots[] = { + { Py_mod_exec, exec_xlntpyarrow }, + { 0, NULL } +}; + +static PyModuleDef xlntpyarrow_def = { + PyModuleDef_HEAD_INIT, + "xlntpyarrow", + xlntpyarrow_doc, + 0, /* m_size */ + NULL, /* m_methods */ + xlntpyarrow_slots, + NULL, /* m_traverse */ + NULL, /* m_clear */ + NULL, /* m_free */ +}; + +PyMODINIT_FUNC PyInit_xlntpyarrow() { + return PyModuleDef_Init(&xlntpyarrow_def); +} + +} \ No newline at end of file