diff --git a/internal/binding/sources/gml_includes.h b/internal/binding/sources/gml_includes.h index 969694a..290f777 100644 --- a/internal/binding/sources/gml_includes.h +++ b/internal/binding/sources/gml_includes.h @@ -45,6 +45,7 @@ #include #include #include +#include using std::string; using std::cout; diff --git a/internal/binding/sources/gml_list_model.cpp b/internal/binding/sources/gml_list_model.cpp index bca4cc4..42c4194 100644 --- a/internal/binding/sources/gml_list_model.cpp +++ b/internal/binding/sources/gml_list_model.cpp @@ -32,12 +32,34 @@ //#############// gml_list_model gml_list_model_new(void* go_ptr) { - + try { + GmlListModel* glm = new GmlListModel(go_ptr); + return (gml_list_model)glm; + } + catch (std::exception& e) { + gml_error_log_exception(e.what()); + return NULL; + } + catch (...) { + gml_error_log_exception(); + return NULL; + } } void gml_list_model_free(gml_list_model lm) { if (lm == NULL) { return; } + GmlListModel* glm = (GmlListModel*)lm; + delete glm; + lm = NULL; +} -} \ No newline at end of file +//##########################// +//### GmlListModel Class ###// +//##########################// + +GmlListModel::GmlListModel( + void* goPtr +) : + goPtr(goPtr) {} diff --git a/internal/binding/sources/gml_list_model.h b/internal/binding/sources/gml_list_model.h index 7e845a8..ec95a0c 100644 --- a/internal/binding/sources/gml_list_model.h +++ b/internal/binding/sources/gml_list_model.h @@ -30,4 +30,14 @@ #include "gml_includes.h" +class GmlListModel : public QAbstractListModel { +public: + GmlListModel( + void* goPtr + ); + +private: + void* goPtr; +}; + #endif \ No newline at end of file diff --git a/listmodel.go b/listmodel.go index a8431fc..e077cdd 100644 --- a/listmodel.go +++ b/listmodel.go @@ -40,6 +40,10 @@ import ( type ListModelHandler interface { } +// Ensure the ListModel type implements the ListModelHandler interface. + +var _ ListModelHandler = &ListModel{} + type ListModel struct { freed bool lm C.gml_list_model diff --git a/pointer/pointer.go b/pointer/pointer.go index 705e484..d03b23a 100644 --- a/pointer/pointer.go +++ b/pointer/pointer.go @@ -46,9 +46,9 @@ func Save(v interface{}) unsafe.Pointer { } // Generate real fake C pointer. - // This pointer will not store any data, but will bi used for indexing purposes. - // Since Go doest allow to cast dangling pointer to unsafe.Pointer, we do rally allocate one byte. - // Why we need indexing, because Go doest allow C code to store pointers to Go data. + // This pointer will not store any data, but will be used for indexing purposes. + // Since Go does not allow to cast dangling pointer to unsafe.Pointer, we do really allocate one byte. + // Why we need indexing, because Go does not allow C code to store pointers to Go data. ptr := C.malloc(C.size_t(1)) if ptr == nil { panic("can't allocate 'cgo-pointer hack index pointer': ptr == nil")