Add cxx{in,out}type typemaps and use them for std::string

This makes using returning strings much simpler to use from C++ code as
the returned pointers don't have to be deleted manually -- although, of
course, this does require an extra allocation and copy and so should be
avoided for the very long strings.

Add a new runtime test showing how simple and convenient it is to use
the functions working with string using the C++ wrappers now.
This commit is contained in:
Vadim Zeitlin 2021-12-06 04:27:23 +01:00
commit fd11a591a3
5 changed files with 135 additions and 30 deletions

View file

@ -5,11 +5,11 @@
int main(int argc, const char *argv[]) {
{
li_boost_shared_ptr::Klass k("me oh my");
assert( strcmp(k.getValue(), "me oh my") == 0 );
assert( k.getValue() == "me oh my" );
}
{
li_boost_shared_ptr::Klass k{li_boost_shared_ptr_factorycreate()};
assert( strcmp(k.getValue(), "factorycreate") == 0 );
assert( k.getValue() == "factorycreate" );
}
}

View file

@ -0,0 +1,26 @@
#include "li_std_string_wrap.h"
#include <assert.h>
using namespace li_std_string;
int main(int argc, const char *argv[]) {
Structure st;
assert( st.MemberString().empty() );
st.MemberString("bloordyblop");
assert( st.MemberString() == "bloordyblop" );
assert( st.MemberString2() == "member string 2" );
assert( st.ConstMemberString() == "const member string" );
st.StaticMemberString(std::string("static bloordyblop"));
assert( st.StaticMemberString() == "static bloordyblop" );
assert( Structure::StaticMemberString2() == "static member string 2" );
assert( Structure::ConstStaticMemberString() == "const static member string" );
Foo f;
assert( f.test("1+") == "1+1" );
}