]> Creatis software - gdcm.git/blob - src/gdcmDicomDirObject.cxx
* Remove memory leaks on the DicomDir
[gdcm.git] / src / gdcmDicomDirObject.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmDicomDirObject.cxx,v $
5   Language:  C++
6   Date:      $Date: 2004/12/03 17:13:18 $
7   Version:   $Revision: 1.8 $
8                                                                                 
9   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10   l'Image). All rights reserved. See Doc/License.txt or
11   http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
12                                                                                 
13      This software is distributed WITHOUT ANY WARRANTY; without even
14      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15      PURPOSE.  See the above copyright notices for more information.
16                                                                                 
17 =========================================================================*/
18
19 #include "gdcmDicomDirObject.h"
20 #include "gdcmGlobal.h"
21 #include "gdcmDebug.h"
22 #include "gdcmValEntry.h"
23 namespace gdcm 
24 {
25
26 //-----------------------------------------------------------------------------
27 /**
28  * \ingroup DicomDirObject
29  * \brief  Constructor 
30  *          
31  * @param ptagHT pointer to the HTable (DicomDirObject needs it 
32  *               to build the DocEntries)
33  * @param depth Sequence depth level
34  */
35   
36 DicomDirObject::DicomDirObject(int depth) 
37           : SQItem (depth)
38 {
39 }
40
41
42 /**
43  * \ingroup DicomDirObject
44  * \brief   Canonical destructor.
45  */
46 DicomDirObject::~DicomDirObject()
47 {
48 }
49
50
51
52 //-----------------------------------------------------------------------------
53 // Public
54
55
56 /**
57  * \ingroup DicomDirObject
58  * \brief   Builds a hash table (multimap) containing 
59  *          pointers to all Header Entries (i.e Dicom Element)
60  *          related to this 'object'
61  * @return
62  */ 
63 TagDocEntryHT DicomDirObject::GetEntry()
64 {
65    TagDocEntryHT HT;
66    DocEntries = GetDocEntries();   
67    for(ListDocEntry::iterator i = DocEntries.begin(); 
68                               i != DocEntries.end(); ++i)
69    {
70       HT[(*i)->GetKey()] = *i;
71    }
72    return HT;
73 }
74
75 //-----------------------------------------------------------------------------
76 // Protected
77 /**
78  * \brief   add the 'Object' related Dicom Elements to the listEntries
79  *          of a partially created DICOMDIR
80  */
81 void DicomDirObject::FillObject(ListDicomDirMetaElem const & elemList)
82 {
83   // FillObject rempli le SQItem qui sera accroche au bon endroit
84
85    ListDicomDirMetaElem::const_iterator it;
86    uint16_t tmpGr,tmpEl;
87    DictEntry *dictEntry;
88    ValEntry *entry;
89       
90    // for all the Elements found in they own part of the DicomDir dict.     
91    for(it = elemList.begin(); it != elemList.end(); ++it)
92    {
93       tmpGr = it->Group;
94       tmpEl = it->Elem;
95       dictEntry = Global::GetDicts()->GetDefaultPubDict()->GetDictEntryByNumber(tmpGr,tmpEl);
96       entry = new ValEntry(dictEntry);
97       entry->SetOffset(0); // just to avoid further missprinting
98       entry->SetValue(it->Value);
99
100       // dealing with value length ...
101   
102       if(dictEntry->GetGroup()==0xfffe) 
103       {
104          entry->SetLength(entry->GetValue().length());
105       }
106       else if( dictEntry->GetVR() == "UL" || dictEntry->GetVR() == "SL" ) 
107       {
108          entry->SetLength(4);
109       } 
110       else if( dictEntry->GetVR() == "US" || dictEntry->GetVR() == "SS" ) 
111       {
112          entry->SetLength(2); 
113       } 
114       else if( dictEntry->GetVR() == "SQ" )
115       {
116          entry->SetLength(0xffffffff);
117       }
118       else
119       {
120          entry->SetLength(entry->GetValue().length()); 
121       }                                
122       AddDocEntry(entry);
123    }   
124 }   
125 } // end namespace gdcm
126