From f29c54f3791113ec76146912ac6776c9ca1957be Mon Sep 17 00:00:00 2001 From: Abdo Eid Date: Fri, 24 Mar 2023 01:04:27 +0200 Subject: [PATCH] Add basic support for std::deque (#121) * Add basic support for std::deque * removed the constructor that takes an std::allocator and some includes that I have added randomly before * removed the settings of vscode and added it to .gitignore --- .gitignore | 3 ++- include/jlcxx/stl.hpp | 24 ++++++++++++++++++++++++ src/stl.cpp | 4 +++- test/test_type_init.cpp | 1 + 4 files changed, 30 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 9901a12..e56d344 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ /.vs /out/build/x64-Debug /CMakeSettings.json -/build \ No newline at end of file +/build +/.vscode \ No newline at end of file diff --git a/include/jlcxx/stl.hpp b/include/jlcxx/stl.hpp index 7043904..b845c47 100644 --- a/include/jlcxx/stl.hpp +++ b/include/jlcxx/stl.hpp @@ -3,6 +3,7 @@ #include #include +#include #include "module.hpp" #include "smart_pointers.hpp" @@ -45,6 +46,7 @@ class JLCXX_API StlWrappers public: TypeWrapper1 vector; TypeWrapper1 valarray; + TypeWrapper1 deque; static void instantiate(Module& mod); static StlWrappers& instance(); @@ -156,11 +158,33 @@ struct WrapValArray } }; +struct WrapDeque +{ + template + void operator()(TypeWrapperT&& wrapped) + { + using WrappedT = typename TypeWrapperT::type; + using T = typename WrappedT::value_type; + wrapped.template constructor(); + wrapped.module().set_override_module(StlWrappers::instance().module()); + wrapped.method("cppsize", &WrappedT::size); + wrapped.method("resize", [](WrappedT &v, const cxxint_t s) { v.resize(s); }); + wrapped.method("cxxgetindex", [](const WrappedT& v, cxxint_t i) -> const T& { return v[i - 1]; }); + wrapped.method("cxxsetindex!", [](WrappedT& v, const T& val, cxxint_t i) { v[i - 1] = val; }); + wrapped.method("push_back!", [] (WrappedT& v, const T& val) { v.push_back(val); }); + wrapped.method("push_front!", [] (WrappedT& v, const T& val) { v.push_front(val); }); + wrapped.method("pop_back!", [] (WrappedT& v) { v.pop_back(); }); + wrapped.method("pop_front!", [] (WrappedT& v) { v.pop_front(); }); + wrapped.module().unset_override_module(); + } +}; + template inline void apply_stl(jlcxx::Module& mod) { TypeWrapper1(mod, StlWrappers::instance().vector).apply>(WrapVector()); TypeWrapper1(mod, StlWrappers::instance().valarray).apply>(WrapValArray()); + TypeWrapper1(mod, StlWrappers::instance().deque).apply>(WrapDeque()); } } diff --git a/src/stl.cpp b/src/stl.cpp index 040794b..c1fdcaa 100644 --- a/src/stl.cpp +++ b/src/stl.cpp @@ -19,6 +19,7 @@ JLCXX_API void StlWrappers::instantiate(Module& mod) m_instance.reset(new StlWrappers(mod)); m_instance->vector.apply_combination(stl::WrapVector()); m_instance->valarray.apply_combination(stl::WrapValArray()); + m_instance->deque.apply_combination(stl::WrapDeque()); smartptr::apply_smart_combination(mod); smartptr::apply_smart_combination(mod); smartptr::apply_smart_combination(mod); @@ -41,7 +42,8 @@ JLCXX_API StlWrappers& wrappers() JLCXX_API StlWrappers::StlWrappers(Module& stl) : m_stl_mod(stl), vector(stl.add_type>>("StdVector", julia_type("AbstractVector"))), - valarray(stl.add_type>>("StdValArray", julia_type("AbstractVector"))) + valarray(stl.add_type>>("StdValArray", julia_type("AbstractVector"))), + deque(stl.add_type>>("StdDeque", julia_type("AbstractVector"))) { } diff --git a/test/test_type_init.cpp b/test/test_type_init.cpp index 4d6014f..b473410 100644 --- a/test/test_type_init.cpp +++ b/test/test_type_init.cpp @@ -18,6 +18,7 @@ int main() test_type("CxxChar16"); test_type("CxxChar32"); test_type("CxxBool"); + test_type("CxxWchar"); jl_atexit_hook(0); return 0;