initial implementation
This commit is contained in:
commit
c96029fa1b
8 changed files with 204 additions and 0 deletions
8
src/pyprintjson/CMakeLists.txt
Normal file
8
src/pyprintjson/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
# xo_pyprintjson/src/pyprintjson/CMakeLists.txt
|
||||
|
||||
set(SELF_LIB pyprintjson)
|
||||
set(SELF_SRCS pyprintjson.cpp)
|
||||
|
||||
xo_pybind11_library(${SELF_LIB} ${PROJECT_NAME}Targets ${SELF_SRCS})
|
||||
|
||||
xo_pybind11_dependency(${SELF_LIB} printjson)
|
||||
2
src/pyprintjson/EXAMPLES
Normal file
2
src/pyprintjson/EXAMPLES
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
import pyprintjson
|
||||
pj=pyprintjson.PrintJson()
|
||||
50
src/pyprintjson/pyprintjson.cpp
Normal file
50
src/pyprintjson/pyprintjson.cpp
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
/* @file pyprintjson.cpp */
|
||||
|
||||
// note: need pyreflect/ here bc pyreflect.hpp is generated, located in build directory
|
||||
#include "pyprintjson.hpp"
|
||||
#include "xo/pyreflect/pyreflect.hpp"
|
||||
|
||||
#include "xo/printjson/PrintJson.hpp"
|
||||
#include "xo/reflect/TaggedRcptr.hpp"
|
||||
//#include "reflect/SelfTagging.hpp"
|
||||
//#include "refcnt/Refcounted.hpp"
|
||||
//#include "refcnt/Unowned.hpp"
|
||||
#include "xo/pyutil/pyutil.hpp"
|
||||
//#include <pybind11/pybind11.h>
|
||||
//#include <pybind11/stl.h>
|
||||
//#include <pybind11/chrono.h>
|
||||
//#include <pybind11/operators.h>
|
||||
|
||||
namespace xo {
|
||||
namespace py = pybind11;
|
||||
|
||||
namespace json {
|
||||
using xo::reflect::SelfTagging;
|
||||
using xo::reflect::TaggedRcptr;
|
||||
using xo::ref::rp;
|
||||
using xo::ref::unowned_ptr;
|
||||
|
||||
PYBIND11_MODULE(PYPRINTJSON_MODULE_NAME(), m) {
|
||||
PYREFLECT_IMPORT_MODULE();
|
||||
|
||||
py::class_<PrintJson, rp<PrintJson>>(m, "PrintJson")
|
||||
.def_static("instance", &PrintJsonSingleton::instance)
|
||||
.def("print",
|
||||
[](PrintJson & pj, TaggedRcptr p)
|
||||
{
|
||||
pj.print_tp(p, &std::cout); std::cout << "\n";
|
||||
},
|
||||
py::arg("value"))
|
||||
.def("print",
|
||||
[](PrintJson & pj, rp<SelfTagging> const & p)
|
||||
{
|
||||
pj.print_obj(p, &std::cout); std::cout << "\n";
|
||||
},
|
||||
py::arg("value"));
|
||||
|
||||
//m.def("print_json", [](){ return PrintJsonSingleton::instance_ptr(); });
|
||||
} /*pyprintjson*/
|
||||
} /*namespace json*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end pyprintjson.cpp */
|
||||
25
src/pyprintjson/pyprintjson.hpp.in
Normal file
25
src/pyprintjson/pyprintjson.hpp.in
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
/* @file pyprintjson.hpp
|
||||
*
|
||||
* automatically generated from src/pyprintjson/pyprintjson.hpp.in
|
||||
* see src/pyprintjson/CMakeLists.txt
|
||||
*/
|
||||
|
||||
/* python requires module name = library name
|
||||
* example:
|
||||
* PYBIND11_MODULE(PYPRINTJSON_MODULE_NAME(), m) { ... }
|
||||
*/
|
||||
#define PYPRINTJSON_MODULE_NAME() @SELF_LIB@
|
||||
|
||||
/* example:
|
||||
* py::module_::import(PYPRINTJSON_MODULE_NAME_STR)
|
||||
*/
|
||||
#define PYPRINTJSON_MODULE_NAME_STR "@SELF_LIB@"
|
||||
|
||||
/* example:
|
||||
* PYPRINTJSON_IMPORT_MODULE()
|
||||
* replaces
|
||||
* py::module_::import("pyprintjson")
|
||||
*/
|
||||
#define PYPRINTJSON_IMPORT_MODULE() py::module_::import("@SELF_LIB@")
|
||||
|
||||
/* end pyprintjson.hpp */
|
||||
Loading…
Add table
Add a link
Reference in a new issue