From a7907abfaeaf71e7f33b8da5ed22ca719d653749 Mon Sep 17 00:00:00 2001
From: Marcin Nowak <Marcin.Nowak@cern.ch>
Date: Tue, 20 Jun 2017 16:41:08 +0200
Subject: [PATCH] Add helper class CreateTransient to TPConverterBase

Factorize creation of the transient object into a helper templated
class, to make it easier to specialize it (before it was based on
specilizing of a single templated converter method, but that
was apparently not always compiling)


Former-commit-id: 0b511c7d56b462f3fa2a00aadb785dfd608cc0b3
---
 Database/TPTools/TPTools/TPConverter.h   | 19 +++++++++++++++++++
 Database/TPTools/TPTools/TPConverter.icc |  9 ++++++---
 2 files changed, 25 insertions(+), 3 deletions(-)

diff --git a/Database/TPTools/TPTools/TPConverter.h b/Database/TPTools/TPTools/TPConverter.h
index 6eda8c220b5..0c973e8ed98 100644
--- a/Database/TPTools/TPTools/TPConverter.h
+++ b/Database/TPTools/TPTools/TPConverter.h
@@ -470,6 +470,25 @@ protected:
 
 // --------------------------------------------------------------
 
+namespace TPCnv {
+
+/** @class  TPCnv::CreateTransient
+    Helper class to make specializing the creation of transient objects
+    in the TPConverterBase::createTransient() easier.
+
+    Provide specialization before definition of your T/P converter for transient typeTRANS
+    The final T/P converter can still overwrite its whole createTransient() method 
+*/
+   template<class TRANS>
+   class CreateTransient  {
+      public:
+      static std::unique_ptr<TRANS>  create() { return std::make_unique<TRANS>(); }
+   };
+
+} // namespace TPCnv
+
+
+
 // Base converter template for polymorphic types
 
 // Converters for objects in the same inheritance tree must share the same
diff --git a/Database/TPTools/TPTools/TPConverter.icc b/Database/TPTools/TPTools/TPConverter.icc
index 4864c828e9c..01634dfea72 100644
--- a/Database/TPTools/TPTools/TPConverter.icc
+++ b/Database/TPTools/TPTools/TPConverter.icc
@@ -62,10 +62,13 @@ toPersistent_impl( const TRANS *trans, MsgStream &log )
 
 template< class TRANS_BASE, class TRANS, class PERS >
 TRANS* TPPolyCnvBase<TRANS_BASE, TRANS, PERS>::
-createTransient(const PERS* persObj, MsgStream &log) {
-   std::unique_ptr<TRANS>	trans(new TRANS());
+createTransient(const PERS* persObj, MsgStream &log)
+{
+   // this is by default equivalent to 'new TRANS()'
+   std::unique_ptr<TRANS> trans = TPCnv::CreateTransient<TRANS>::create();
+   
    this->persToTrans(persObj, trans.get(), log);
-   return(trans.release());
+   return( trans.release() );
 }
 
    
-- 
GitLab