From ecf040a59253d548c293ff8c998d02f64c1ce9b5 Mon Sep 17 00:00:00 2001 From: Jan Orend <56254096+3dJan@users.noreply.github.com> Date: Wed, 4 Dec 2024 16:39:18 +0100 Subject: [PATCH 1/3] [cppbinding] classParam now keeps ownership of the shared_ptr for its own lifetime --- Source/buildbindingccpp.go | 55 +++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 27 deletions(-) diff --git a/Source/buildbindingccpp.go b/Source/buildbindingccpp.go index 5995eae2..b67319f9 100644 --- a/Source/buildbindingccpp.go +++ b/Source/buildbindingccpp.go @@ -1200,33 +1200,34 @@ func getCPPInheritanceSpecifier(component ComponentDefinition, class ComponentDe } func writeClassParamDefinition(w LanguageWriter, NameSpace string) { - w.Writeln("") - w.Writeln("/*************************************************************************************************************************") - w.Writeln(" classParam Definition") - w.Writeln("**************************************************************************************************************************/") - w.Writeln("") - w.Writeln("template class classParam {") - w.Writeln("private:") - w.Writeln(" const T* m_ptr;") - w.Writeln("") - w.Writeln("public:") - w.Writeln(" classParam(const T* ptr)") - w.Writeln(" : m_ptr (ptr)") - w.Writeln(" {") - w.Writeln(" }") - w.Writeln("") - w.Writeln(" classParam(std::shared_ptr sharedPtr)") - w.Writeln(" : m_ptr (sharedPtr.get())") - w.Writeln(" {") - w.Writeln(" }") - w.Writeln("") - w.Writeln(" %sHandle GetHandle()", NameSpace) - w.Writeln(" {") - w.Writeln(" if (m_ptr != nullptr)") - w.Writeln(" return m_ptr->handle();") - w.Writeln(" return (%sHandle)nullptr;", NameSpace) - w.Writeln(" }") - w.Writeln("};") + w.Writeln("") + w.Writeln("/*************************************************************************************************************************") + w.Writeln(" classParam Definition") + w.Writeln("**************************************************************************************************************************/") + w.Writeln("") + w.Writeln("template class classParam {") + w.Writeln("private:") + w.Writeln(" std::shared_ptr m_sharedPtr;") + w.Writeln(" const T* m_ptr;") + w.Writeln("") + w.Writeln("public:") + w.Writeln(" classParam(const T* ptr)") + w.Writeln(" : m_ptr(ptr)") + w.Writeln(" {") + w.Writeln(" }") + w.Writeln("") + w.Writeln(" classParam(std::shared_ptr sharedPtr)") + w.Writeln(" : m_sharedPtr(sharedPtr), m_ptr(sharedPtr.get())") + w.Writeln(" {") + w.Writeln(" }") + w.Writeln("") + w.Writeln(" %sHandle GetHandle()", NameSpace) + w.Writeln(" {") + w.Writeln(" if (m_ptr != nullptr)") + w.Writeln(" return m_ptr->handle();") + w.Writeln(" return (%sHandle)nullptr;", NameSpace) + w.Writeln(" }") + w.Writeln("};") } func writeExceptionClass(w LanguageWriter, NameSpace string, errors ComponentDefinitionErrors) { From 71a2ea01619b467179da3e921588e43a2f9fd403 Mon Sep 17 00:00:00 2001 From: Jan Orend <56254096+3dJan@users.noreply.github.com> Date: Thu, 5 Dec 2024 08:15:07 +0100 Subject: [PATCH 2/3] restore previous formatting of writeClassParamDefinition --- Source/buildbindingccpp.go | 56 +++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/Source/buildbindingccpp.go b/Source/buildbindingccpp.go index b67319f9..daac4857 100644 --- a/Source/buildbindingccpp.go +++ b/Source/buildbindingccpp.go @@ -1200,34 +1200,34 @@ func getCPPInheritanceSpecifier(component ComponentDefinition, class ComponentDe } func writeClassParamDefinition(w LanguageWriter, NameSpace string) { - w.Writeln("") - w.Writeln("/*************************************************************************************************************************") - w.Writeln(" classParam Definition") - w.Writeln("**************************************************************************************************************************/") - w.Writeln("") - w.Writeln("template class classParam {") - w.Writeln("private:") - w.Writeln(" std::shared_ptr m_sharedPtr;") - w.Writeln(" const T* m_ptr;") - w.Writeln("") - w.Writeln("public:") - w.Writeln(" classParam(const T* ptr)") - w.Writeln(" : m_ptr(ptr)") - w.Writeln(" {") - w.Writeln(" }") - w.Writeln("") - w.Writeln(" classParam(std::shared_ptr sharedPtr)") - w.Writeln(" : m_sharedPtr(sharedPtr), m_ptr(sharedPtr.get())") - w.Writeln(" {") - w.Writeln(" }") - w.Writeln("") - w.Writeln(" %sHandle GetHandle()", NameSpace) - w.Writeln(" {") - w.Writeln(" if (m_ptr != nullptr)") - w.Writeln(" return m_ptr->handle();") - w.Writeln(" return (%sHandle)nullptr;", NameSpace) - w.Writeln(" }") - w.Writeln("};") + w.Writeln("") + w.Writeln("/*************************************************************************************************************************") + w.Writeln(" classParam Definition") + w.Writeln("**************************************************************************************************************************/") + w.Writeln("") + w.Writeln("template class classParam {") + w.Writeln("private:") + w.Writeln(" std::shared_ptr m_sharedPtr;") + w.Writeln(" const T* m_ptr;") + w.Writeln("") + w.Writeln("public:") + w.Writeln(" classParam(const T* ptr)") + w.Writeln(" : m_ptr(ptr)") + w.Writeln(" {") + w.Writeln(" }") + w.Writeln("") + w.Writeln(" classParam(std::shared_ptr sharedPtr)") + w.Writeln(" : m_sharedPtr(sharedPtr), m_ptr(sharedPtr.get())") + w.Writeln(" {") + w.Writeln(" }") + w.Writeln("") + w.Writeln(" %sHandle GetHandle()", NameSpace) + w.Writeln(" {") + w.Writeln(" if (m_ptr != nullptr)") + w.Writeln(" return m_ptr->handle();") + w.Writeln(" return (%sHandle)nullptr;", NameSpace) + w.Writeln(" }") + w.Writeln("};") } func writeExceptionClass(w LanguageWriter, NameSpace string, errors ComponentDefinitionErrors) { From 7f29e70528994e8fe38b87aee3faf7b2c59769e7 Mon Sep 17 00:00:00 2001 From: Jan Orend <56254096+3dJan@users.noreply.github.com> Date: Thu, 5 Dec 2024 08:20:31 +0100 Subject: [PATCH 3/3] reducing white space changes to make the diff more comprehensive --- Source/buildbindingccpp.go | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/Source/buildbindingccpp.go b/Source/buildbindingccpp.go index daac4857..c54855f8 100644 --- a/Source/buildbindingccpp.go +++ b/Source/buildbindingccpp.go @@ -1207,26 +1207,26 @@ func writeClassParamDefinition(w LanguageWriter, NameSpace string) { w.Writeln("") w.Writeln("template class classParam {") w.Writeln("private:") - w.Writeln(" std::shared_ptr m_sharedPtr;") - w.Writeln(" const T* m_ptr;") - w.Writeln("") + w.Writeln(" std::shared_ptr m_sharedPtr;") + w.Writeln(" const T* m_ptr;") + w.Writeln("") w.Writeln("public:") - w.Writeln(" classParam(const T* ptr)") - w.Writeln(" : m_ptr(ptr)") - w.Writeln(" {") - w.Writeln(" }") + w.Writeln(" classParam(const T* ptr)") + w.Writeln(" : m_ptr(ptr)") + w.Writeln(" {") + w.Writeln(" }") w.Writeln("") - w.Writeln(" classParam(std::shared_ptr sharedPtr)") - w.Writeln(" : m_sharedPtr(sharedPtr), m_ptr(sharedPtr.get())") - w.Writeln(" {") - w.Writeln(" }") + w.Writeln(" classParam(std::shared_ptr sharedPtr)") + w.Writeln(" : m_sharedPtr(sharedPtr), m_ptr(sharedPtr.get())") + w.Writeln(" {") + w.Writeln(" }") w.Writeln("") - w.Writeln(" %sHandle GetHandle()", NameSpace) - w.Writeln(" {") - w.Writeln(" if (m_ptr != nullptr)") - w.Writeln(" return m_ptr->handle();") - w.Writeln(" return (%sHandle)nullptr;", NameSpace) - w.Writeln(" }") + w.Writeln(" %sHandle GetHandle()", NameSpace) + w.Writeln(" {") + w.Writeln(" if (m_ptr != nullptr)") + w.Writeln(" return m_ptr->handle();") + w.Writeln(" return (%sHandle)nullptr;", NameSpace) + w.Writeln(" }") w.Writeln("};") }