diff --git a/test/test_nr1.cc b/test/test_nr1.cc index 5b2c4a5..639c18f 100644 --- a/test/test_nr1.cc +++ b/test/test_nr1.cc @@ -476,6 +476,19 @@ namespace pEp { } } + T** data() + { + return _c_struct_pp; + } + + const T* c_data() const + { + if (_c_struct_pp == nullptr) { + throw Exception{ EXSTR("invalid state") }; + } + return *_c_struct_pp; + } + operator T*() { return _c_struct_p; @@ -557,26 +570,14 @@ namespace pEp { class TestStruct1 : public PODStruct<::Test_struct1> { public: TestStruct1(bool is_owner, ::Test_struct1** test_struct1_p = nullptr) : - PODStruct<::Test_struct1>(is_owner, _alloc, _free, test_struct1_p) + PODStruct<::Test_struct1>(is_owner, test_struct1_p) { } // fields of the struct as 'properties' ;) - pEp::POD c_int{ &_c_struct_p->c_int }; - pEp::POD<::Test_enum> c_enum{ &_c_struct_p->c_enum }; - pEp::String c_str{ false, &_c_struct_p->c_str,"fd" }; - - private: - static Test_struct1* _alloc() - { - return (Test_struct1*)calloc(1, sizeof(Test_struct1)); - } - - static void _free(Test_struct1* ptr) - { - pEpLog("called"); - ::free_test_struct(ptr); - } + pEp::POD c_int{ &(*data())->c_int }; + pEp::POD<::Test_enum> c_enum{ &(*data())->c_enum }; + pEp::String c_str{ true, &(*data())->c_str }; }; template<>