From 5d76891627a8a68786e55c9068e3b8d0c9b6c0bf Mon Sep 17 00:00:00 2001
From: Jan Schlamelcher <dicom@offis.de>
Date: Mon, 19 Nov 2012 17:30:19 +0100
Subject: [PATCH] trial patch to fix Bug #408

---
 dcmsr/include/dcmtk/dcmsr/dsrtlist.h |   14 +++++++++-----
 dcmsr/libsrc/dsrimgfr.cc             |   10 ----------
 dcmsr/libsrc/dsrsc3gr.cc             |    9 ---------
 dcmsr/libsrc/dsrscogr.cc             |    9 ---------
 dcmsr/libsrc/dsrtcodt.cc             |    9 ---------
 dcmsr/libsrc/dsrtcosp.cc             |    9 ---------
 dcmsr/libsrc/dsrtcoto.cc             |    9 ---------
 dcmsr/libsrc/dsrwavch.cc             |    9 ---------
 8 files changed, 9 insertions(+), 69 deletions(-)

diff --git a/dcmsr/include/dcmtk/dcmsr/dsrtlist.h b/dcmsr/include/dcmtk/dcmsr/dsrtlist.h
index a8c5b46..ac8bea7 100644
--- a/dcmsr/include/dcmtk/dcmsr/dsrtlist.h
+++ b/dcmsr/include/dcmtk/dcmsr/dsrtlist.h
@@ -126,7 +126,7 @@ template<class T> class DSRListOfItems
         if (gotoItemPos(idx, iterator))
             return *iterator;
         else
-            return EmptyItem;
+            return emptyItem();
     }
 
     /** get copy of the specified item
@@ -207,10 +207,14 @@ template<class T> class DSRListOfItems
     }
 
     /// default item which is returned in getItem() if the index is invalid.
-    /// This static member variable needs to be defined (not only declared)
-    /// in each derived class.
-    static const T EmptyItem;
-
+    /// Implemented using Meyers Singleton so no explicit instatiation is
+    /// necessary.
+    static const T& emptyItem() 
+    {
+        //initialize EmptyItem to zero, no matter what kind of thing it is.    
+        static const T EmptyItem( 0 );
+        return EmptyItem;
+    }
 
   protected:
 
diff --git a/dcmsr/libsrc/dsrimgfr.cc b/dcmsr/libsrc/dsrimgfr.cc
index 379db1a..50f393f 100644
--- a/dcmsr/libsrc/dsrimgfr.cc
+++ b/dcmsr/libsrc/dsrimgfr.cc
@@ -28,16 +28,6 @@
 #define INCLUDE_CSTDIO
 #include "dcmtk/ofstd/ofstdinc.h"
 
-#ifdef HAVE_EXPLICIT_TEMPLATE_SPECIALIZATION
-#define EXPLICIT_SPECIALIZATION template<>
-#else
-#define EXPLICIT_SPECIALIZATION
-#endif
-
-/* declared in class DSRListOfItems<T> */
-EXPLICIT_SPECIALIZATION const Sint32 DSRListOfItems<Sint32>::EmptyItem = 0;
-
-
 DSRImageFrameList::DSRImageFrameList()
   : DSRListOfItems<Sint32>()
 {
diff --git a/dcmsr/libsrc/dsrsc3gr.cc b/dcmsr/libsrc/dsrsc3gr.cc
index 056aca0..4c6b2c2 100644
--- a/dcmsr/libsrc/dsrsc3gr.cc
+++ b/dcmsr/libsrc/dsrsc3gr.cc
@@ -26,15 +26,6 @@
 #include "dcmtk/dcmsr/dsrsc3gr.h"
 #include "dcmtk/ofstd/ofstd.h"
 
-#ifdef HAVE_EXPLICIT_TEMPLATE_SPECIALIZATION
-#define EXPLICIT_SPECIALIZATION template<>
-#else
-#define EXPLICIT_SPECIALIZATION
-#endif
-
-/* declared in class DSRListOfItems<T> */
-EXPLICIT_SPECIALIZATION const DSRGraphicData3DItem DSRListOfItems<DSRGraphicData3DItem>::EmptyItem(0, 0, 0);
-
 
 DSRGraphicData3DList::DSRGraphicData3DList()
   : DSRListOfItems<DSRGraphicData3DItem>()
diff --git a/dcmsr/libsrc/dsrscogr.cc b/dcmsr/libsrc/dsrscogr.cc
index 55559d0..4826e0a 100644
--- a/dcmsr/libsrc/dsrscogr.cc
+++ b/dcmsr/libsrc/dsrscogr.cc
@@ -26,15 +26,6 @@
 #include "dcmtk/dcmsr/dsrscogr.h"
 #include "dcmtk/ofstd/ofstd.h"
 
-#ifdef HAVE_EXPLICIT_TEMPLATE_SPECIALIZATION
-#define EXPLICIT_SPECIALIZATION template<>
-#else
-#define EXPLICIT_SPECIALIZATION
-#endif
-
-/* declared in class DSRListOfItems<T> */
-EXPLICIT_SPECIALIZATION const DSRGraphicDataItem DSRListOfItems<DSRGraphicDataItem>::EmptyItem(0, 0);
-
 
 DSRGraphicDataList::DSRGraphicDataList()
   : DSRListOfItems<DSRGraphicDataItem>()
diff --git a/dcmsr/libsrc/dsrtcodt.cc b/dcmsr/libsrc/dsrtcodt.cc
index c6ab484..65ea2e0 100644
--- a/dcmsr/libsrc/dsrtcodt.cc
+++ b/dcmsr/libsrc/dsrtcodt.cc
@@ -25,15 +25,6 @@
 
 #include "dcmtk/dcmsr/dsrtcodt.h"
 
-#ifdef HAVE_EXPLICIT_TEMPLATE_SPECIALIZATION
-#define EXPLICIT_SPECIALIZATION template<>
-#else
-#define EXPLICIT_SPECIALIZATION
-#endif
-
-/* declared in class DSRListOfItems<T> */
-EXPLICIT_SPECIALIZATION const OFString DSRListOfItems<OFString>::EmptyItem;
-
 
 DSRReferencedDateTimeList::DSRReferencedDateTimeList()
   : DSRListOfItems<OFString>()
diff --git a/dcmsr/libsrc/dsrtcosp.cc b/dcmsr/libsrc/dsrtcosp.cc
index 41810ab..be4c06e 100644
--- a/dcmsr/libsrc/dsrtcosp.cc
+++ b/dcmsr/libsrc/dsrtcosp.cc
@@ -28,15 +28,6 @@
 #define INCLUDE_CSTDIO
 #include "dcmtk/ofstd/ofstdinc.h"
 
-#ifdef HAVE_EXPLICIT_TEMPLATE_SPECIALIZATION
-#define EXPLICIT_SPECIALIZATION template<>
-#else
-#define EXPLICIT_SPECIALIZATION
-#endif
-
-/* declared in class DSRListOfItems<T> */
-EXPLICIT_SPECIALIZATION const Uint32 DSRListOfItems<Uint32>::EmptyItem = 0;
-
 
 DSRReferencedSamplePositionList::DSRReferencedSamplePositionList()
   : DSRListOfItems<Uint32>()
diff --git a/dcmsr/libsrc/dsrtcoto.cc b/dcmsr/libsrc/dsrtcoto.cc
index e96e590..6d3d511 100644
--- a/dcmsr/libsrc/dsrtcoto.cc
+++ b/dcmsr/libsrc/dsrtcoto.cc
@@ -29,15 +29,6 @@
 #define INCLUDE_CSTDIO
 #include "dcmtk/ofstd/ofstdinc.h"
 
-#ifdef HAVE_EXPLICIT_TEMPLATE_SPECIALIZATION
-#define EXPLICIT_SPECIALIZATION template<>
-#else
-#define EXPLICIT_SPECIALIZATION
-#endif
-
-/* declared in class DSRListOfItems<T> */
-EXPLICIT_SPECIALIZATION const Float64 DSRListOfItems<Float64>::EmptyItem = 0;
-
 
 DSRReferencedTimeOffsetList::DSRReferencedTimeOffsetList()
   : DSRListOfItems<Float64>()
diff --git a/dcmsr/libsrc/dsrwavch.cc b/dcmsr/libsrc/dsrwavch.cc
index 05008c2..9133f47 100644
--- a/dcmsr/libsrc/dsrwavch.cc
+++ b/dcmsr/libsrc/dsrwavch.cc
@@ -29,15 +29,6 @@
 #define INCLUDE_CSTDIO
 #include "dcmtk/ofstd/ofstdinc.h"
 
-#ifdef HAVE_EXPLICIT_TEMPLATE_SPECIALIZATION
-#define EXPLICIT_SPECIALIZATION template<>
-#else
-#define EXPLICIT_SPECIALIZATION
-#endif
-
-/* declared in class DSRListOfItems<T> */
-EXPLICIT_SPECIALIZATION const DSRWaveformChannelItem DSRListOfItems<DSRWaveformChannelItem>::EmptyItem(0, 0);
-
 
 DSRWaveformChannelList::DSRWaveformChannelList()
   : DSRListOfItems<DSRWaveformChannelItem>()
-- 
1.7.2.5

