GDCM_NAME_SPACE::Dict Class Reference

Dict acts a memory representation of a dicom dictionary i.e. it is a container for a collection of dictionary entries. The dictionary is loaded from in an ascii file. There should be a single public dictionary (THE dictionary of the actual DICOM v3) but as many shadow dictionaries as imagers combined with all software versions... More...

#include <gdcmDict.h>

Inheritance diagram for GDCM_NAME_SPACE::Dict:

Inheritance graph
[legend]
Collaboration diagram for GDCM_NAME_SPACE::Dict:

Collaboration graph
[legend]
List of all members.

Public Member Functions

bool AddDict (std::string const &filename)
 Add all the entries held in a source dictionary.
bool RemoveDict (std::string const &filename)
 Removes from the current Dicom Dict all the entries held in a source dictionary.
void Print (std::ostream &os=std::cout, std::string const &indent="")
 Print all the dictionary entries contained in this dictionary. Entries will be sorted by tag i.e. the couple (group, element).
bool AddEntry (DictEntry *newEntry)
 adds a new Dicom Dictionary Entry
bool RemoveEntry (TagKey const &key)
 removes an already existing Dicom Dictionary Entry, identified by its Tag
bool RemoveEntry (uint16_t group, uint16_t elem)
 removes an already existing Dicom Dictionary Entry, identified by its group,element number
void ClearEntry ()
 Remove all Dicom Dictionary Entries.
DictEntryGetEntry (uint16_t group, uint16_t elem)
 Get the dictionary entry identified by its "group" and "element").
DictEntryGetEntry (TagKey const &key)
 Get the dictionary entry identified by a given tag ("group|element").
DictEntryGetFirstEntry ()
 Get the first entry while visiting the Dict entries.
DictEntryGetNextEntry ()
 Get the next entry while visiting the Hash table (KeyHt).
void Delete ()
 Delete the object.
void Register ()
 Register the object.
void Unregister ()
 Unregister the object.
const unsigned long & GetRefCount () const
 Get the reference counting.
void SetPrintLevel (int level)
 Sets the print level for the Dicom Header Elements.
int GetPrintLevel ()
 Gets the print level for the Dicom Entries.

Static Public Member Functions

static DictNew ()
 Contructs an empty Dict with a RefCounter.
static DictNew (std::string const &filename)
 Contructs a Dict with a RefCounter.

Protected Member Functions

 Dict ()
 Constructor.
 Dict (std::string const &filename)
 Constructor.
 ~Dict ()
 Destructor.

Protected Attributes

int PrintLevel
 Amount of printed details for each Dicom Entries : 0 : stands for the least detail level.

Private Member Functions

 gdcmTypeMacro (Dict)
void DoTheLoadingJob (std::ifstream &ifs)
 Add all the dictionary entries from an already open source file.

Private Attributes

std::string Filename
 ASCII file holding the Dictionnary.
TagKeyHT KeyHt
 Access through TagKey.
TagKeyHT::iterator ItKeyHt
 Iterator for the entries.

Detailed Description

Dict acts a memory representation of a dicom dictionary i.e. it is a container for a collection of dictionary entries. The dictionary is loaded from in an ascii file. There should be a single public dictionary (THE dictionary of the actual DICOM v3) but as many shadow dictionaries as imagers combined with all software versions...

See also:
DictSet

Definition at line 47 of file gdcmDict.h.


Constructor & Destructor Documentation

GDCM_NAME_SPACE::Dict::Dict  )  [protected]
 

Constructor.

Definition at line 39 of file gdcmDict.cxx.

References Filename.

00040 {
00041    Filename="";
00042 }

GDCM_NAME_SPACE::Dict::Dict std::string const &  filename  )  [protected]
 

Constructor.

Parameters:
filename from which to build the dictionary.

Definition at line 48 of file gdcmDict.cxx.

References DoTheLoadingJob(), Filename, GDCM_NAME_SPACE::FillDefaultDataDict(), gdcmDebugMacro, and gdcmWarningMacro.

00049 {
00050    gdcmDebugMacro( "in Dict::Dict, filename =[" << filename << "]" );
00051    std::ifstream from( filename.c_str() );
00052    if ( !from )
00053    {
00054       gdcmWarningMacro( "Can't open dictionary" << filename.c_str());
00055       // Using default embeded one:
00056       FillDefaultDataDict( this );
00057    }
00058    else
00059    { 
00060       gdcmDebugMacro( "in Dict::Dict, DoTheLoadingJob filename =[" 
00061                     << filename << "]" );
00062       DoTheLoadingJob(from);
00063       Filename = filename;
00064    }
00065 }

GDCM_NAME_SPACE::Dict::~Dict  )  [protected]
 

Destructor.

Definition at line 70 of file gdcmDict.cxx.

References ClearEntry().

00071 {
00072    ClearEntry();
00073 }


Member Function Documentation

bool GDCM_NAME_SPACE::Dict::AddDict std::string const &  filename  ) 
 

Add all the entries held in a source dictionary.

Note:
it concerns only Private Dictionnary
Parameters:
filename from which to build the dictionary.

Definition at line 83 of file gdcmDict.cxx.

References DoTheLoadingJob(), and gdcmWarningMacro.

00084 {
00085    std::ifstream from( filename.c_str() );
00086    if ( !from )
00087    {
00088       gdcmWarningMacro( "Can't open dictionary" << filename.c_str());
00089       return false;
00090    }
00091    else
00092    {
00093       DoTheLoadingJob(from);
00094       return true;
00095    }
00096 }

bool GDCM_NAME_SPACE::Dict::AddEntry DictEntry newEntry  ) 
 

adds a new Dicom Dictionary Entry

Parameters:
newEntry entry to add
Returns:
false if Dicom Element already exists

Definition at line 145 of file gdcmDict.cxx.

References gdcmErrorMacro, GDCM_NAME_SPACE::DictEntry::GetKey(), and KeyHt.

Referenced by DoTheLoadingJob(), and GDCM_NAME_SPACE::FillDefaultDataDict().

00146 {
00147    const TagKey &key = newEntry->GetKey();
00148 
00149    if ( KeyHt.count(key) == 1 )
00150    {
00151       gdcmErrorMacro( "Already present:" << key );
00152       return false;
00153    } 
00154    else 
00155    {
00156       newEntry->Register();
00157       KeyHt.insert( TagKeyHT::value_type(key, newEntry));
00158       return true;
00159    }
00160 }

void GDCM_NAME_SPACE::Dict::ClearEntry  ) 
 

Remove all Dicom Dictionary Entries.

Definition at line 221 of file gdcmDict.cxx.

References KeyHt.

Referenced by ~Dict().

00222 {
00223    // we assume all the pointed DictEntries are already cleaned-up
00224    // when we clean KeyHt.
00225    TagKeyHT::const_iterator it;
00226 
00227    for(it = KeyHt.begin();it!=KeyHt.end();++it)
00228       it->second->Unregister(); // delete the entry
00229    KeyHt.clear();               // remove all the entries from HTable
00230 
00231 }

void GDCM_NAME_SPACE::RefCounter::Delete  )  [inline, inherited]
 

Delete the object.

Remarks:
The object is deleted only if its reference counting is to zero

Definition at line 41 of file gdcmRefCounter.h.

Referenced by GDCM_NAME_SPACE::SerieHelper::AddFileName(), GDCM_NAME_SPACE::Document::Backtrack(), GDCM_NAME_SPACE::FileHelper::CheckMandatoryElements(), GDCM_NAME_SPACE::FileHelper::CheckMandatoryEntry(), GDCM_NAME_SPACE::FileHelper::CopyMandatoryEntry(), DoTheLoadingJob(), GDCM_NAME_SPACE::FillDefaultDataDict(), GDCM_NAME_SPACE::DicomDirObject::FillObject(), vtkGdcmReader::GetFileInformation(), GDCM_NAME_SPACE::DocEntrySet::InsertEntryBinArea(), GDCM_NAME_SPACE::DocEntrySet::InsertEntryString(), GDCM_NAME_SPACE::DocEntrySet::InsertSeqEntry(), vtkGdcmReader::LoadFileInformation(), GDCM_NAME_SPACE::DicomDir::NewMeta(), GDCM_NAME_SPACE::DicomDirStudy::NewVisit(), GDCM_NAME_SPACE::Document::ReadNextDocEntry(), GDCM_NAME_SPACE::DicomDir::SetElement(), GDCM_NAME_SPACE::FileHelper::SetMandatoryEntry(), GDCM_NAME_SPACE::FileHelper::SetWriteFileTypeToExplicitVR(), GDCM_NAME_SPACE::FileHelper::SetWriteFileTypeToImplicitVR(), GDCM_NAME_SPACE::FileHelper::SetWriteFileTypeToJPEG(), GDCM_NAME_SPACE::FileHelper::SetWriteFileTypeToJPEG2000(), GDCM_NAME_SPACE::FileHelper::SetWriteToLibido(), GDCM_NAME_SPACE::DicomDir::~DicomDir(), GDCM_NAME_SPACE::DictSet::~DictSet(), and GDCM_NAME_SPACE::Global::~Global().

00041 { Unregister(); }

void GDCM_NAME_SPACE::Dict::DoTheLoadingJob std::ifstream &  from  )  [private]
 

Add all the dictionary entries from an already open source file.

Parameters:
from input stream to read from.

Definition at line 300 of file gdcmDict.cxx.

References AddEntry(), GDCM_NAME_SPACE::RefCounter::Delete(), and GDCM_NAME_SPACE::DictEntry::New().

Referenced by AddDict(), and Dict().

00301 {
00302    if (!from)
00303       return;
00304       
00305    uint16_t group;
00306    uint16_t elem;
00307    VRKey vr;
00308    TagName vm;
00309    TagName name;
00310 
00311    DictEntry *newEntry;
00312    while ( true )
00313    {
00314       from >> std::hex;
00315       from >> group;      
00316       from >> elem;
00317       from >> vr;
00318       from >> vm;
00319       from >> std::ws;  //remove white space
00320       std::getline(from, name);
00321       
00322       if(from.eof()) {
00323          break;
00324       }
00325       
00326       newEntry = DictEntry::New(group, elem, vr, vm, name);
00327       AddEntry(newEntry);
00328       newEntry->Delete();
00329    }
00330    from.close();
00331 }

GDCM_NAME_SPACE::Dict::gdcmTypeMacro Dict   )  [private]
 

DictEntry * GDCM_NAME_SPACE::Dict::GetEntry TagKey const &  key  ) 
 

Get the dictionary entry identified by a given tag ("group|element").

Parameters:
key tag of the searched entry
Returns:
the corresponding dictionary entry when existing, NULL otherwise

Definition at line 238 of file gdcmDict.cxx.

References KeyHt.

00239 {
00240    TagKeyHT::iterator it = KeyHt.find(key);
00241    if ( it == KeyHt.end() )
00242    {
00243       return 0;
00244    }
00245    return it->second;
00246 }

DictEntry * GDCM_NAME_SPACE::Dict::GetEntry uint16_t  group,
uint16_t  elem
 

Get the dictionary entry identified by its "group" and "element").

Parameters:
group Group number of the searched entry.
elem Element number of the searched entry.
Returns:
the corresponding dictionary entry when existing, NULL otherwise

Definition at line 253 of file gdcmDict.cxx.

References KeyHt, and GDCM_NAME_SPACE::DictEntry::TranslateToKey().

Referenced by GDCM_NAME_SPACE::DocEntrySet::GetDictEntry(), GDCM_NAME_SPACE::DocEntry::GetName(), GDCM_NAME_SPACE::DocEntry::GetVM(), and GDCM_NAME_SPACE::DocEntrySet::InsertEntryString().

00254 {
00255    TagKey key = DictEntry::TranslateToKey(group, elem);
00256    TagKeyHT::iterator it = KeyHt.find(key);
00257    if ( it == KeyHt.end() )
00258    {
00259       return 0;
00260    }
00261    return it->second;
00262 }

DictEntry * GDCM_NAME_SPACE::Dict::GetFirstEntry  ) 
 

Get the first entry while visiting the Dict entries.

Returns:
The first DicEntry if found, otherwhise NULL

Definition at line 268 of file gdcmDict.cxx.

References ItKeyHt, and KeyHt.

00269 {
00270    ItKeyHt = KeyHt.begin();
00271    if ( ItKeyHt != KeyHt.end() )
00272       return ItKeyHt->second;
00273    return NULL;
00274 }

DictEntry * GDCM_NAME_SPACE::Dict::GetNextEntry  ) 
 

Get the next entry while visiting the Hash table (KeyHt).

Note:
: meaningfull only if GetFirstEntry already called
Returns:
The next DictEntry if found, otherwhise NULL

Definition at line 281 of file gdcmDict.cxx.

References gdcmAssertMacro, ItKeyHt, and KeyHt.

00282 {
00283    gdcmAssertMacro (ItKeyHt != KeyHt.end());
00284 
00285    ++ItKeyHt;
00286    if (ItKeyHt != KeyHt.end())
00287       return ItKeyHt->second;
00288    return NULL;
00289 }

int GDCM_NAME_SPACE::Base::GetPrintLevel  )  [inline, inherited]
 

Gets the print level for the Dicom Entries.

Definition at line 50 of file gdcmBase.h.

00050 { return PrintLevel; }

const unsigned long& GDCM_NAME_SPACE::RefCounter::GetRefCount  )  const [inline, inherited]
 

Get the reference counting.

Returns:
Reference count

Definition at line 59 of file gdcmRefCounter.h.

00060    {
00061       return RefCount;
00062    }

static Dict* GDCM_NAME_SPACE::Dict::New std::string const &  filename  )  [inline, static]
 

Contructs a Dict with a RefCounter.

Definition at line 55 of file gdcmDict.h.

00055 {return new Dict(filename);}

static Dict* GDCM_NAME_SPACE::Dict::New  )  [inline, static]
 

Contructs an empty Dict with a RefCounter.

Definition at line 53 of file gdcmDict.h.

Referenced by GDCM_NAME_SPACE::DictSet::DictSet(), and GDCM_NAME_SPACE::DictSet::LoadDictFromFile().

00053 {return new Dict();}

void GDCM_NAME_SPACE::Dict::Print std::ostream &  os = std::cout,
std::string const &  indent = ""
[virtual]
 

Print all the dictionary entries contained in this dictionary. Entries will be sorted by tag i.e. the couple (group, element).

Parameters:
os The output stream to be written to.
indent Indentation string to be prepended during printing

Reimplemented from GDCM_NAME_SPACE::Base.

Definition at line 340 of file gdcmDict.cxx.

References Filename, and KeyHt.

00341 {
00342    os << "Dict file name : [" << Filename << "]" << std::endl;
00343    std::ostringstream s;
00344 
00345    for (TagKeyHT::iterator tag = KeyHt.begin(); tag != KeyHt.end(); ++tag)
00346    {  
00347 std::cout << tag->second->GetKey() << " " << tag->second->GetName() 
00348           << std::endl;
00349       s << "Entry : ";
00350       s << "(" << tag->second->GetKey() << ") = "
00351         << std::dec;
00352       s << tag->second->GetVR() << ", ";
00353       s << tag->second->GetVM() << ", ";
00354       s << tag->second->GetName() << "."  << std::endl;
00355      
00356    }
00357    os << s.str();
00358 
00359 }

void GDCM_NAME_SPACE::RefCounter::Register  )  [inline, inherited]
 

Register the object.

Remarks:
It increments the reference counting

Definition at line 46 of file gdcmRefCounter.h.

Referenced by GDCM_NAME_SPACE::SQItem::AddEntry(), GDCM_NAME_SPACE::SeqEntry::AddSQItem(), GDCM_NAME_SPACE::SeqEntry::Copy(), GDCM_NAME_SPACE::DicomDir::Copy(), GDCM_NAME_SPACE::FileHelper::FileHelper(), GDCM_NAME_SPACE::DocEntrySet::GetDictEntry(), GDCM_NAME_SPACE::DocEntry::GetName(), GDCM_NAME_SPACE::DocEntry::GetVM(), GDCM_NAME_SPACE::DocEntrySet::InsertEntryString(), GDCM_NAME_SPACE::CommandManager::InSetCommand(), GDCM_NAME_SPACE::DocEntryArchive::Push(), and GDCM_NAME_SPACE::SeqEntry::SetDelimitationItem().

00046 { RefCount++; }

bool GDCM_NAME_SPACE::Dict::RemoveDict std::string const &  filename  ) 
 

Removes from the current Dicom Dict all the entries held in a source dictionary.

Note:
it concerns only Private Dictionnary
Parameters:
filename from which we read the entries to remove.

Definition at line 103 of file gdcmDict.cxx.

References gdcmWarningMacro, and RemoveEntry().

00104 {
00105    std::ifstream from( filename.c_str() );
00106    if ( !from )
00107    {
00108       gdcmWarningMacro( "Can't open dictionary" << filename.c_str());
00109       return false;
00110    }
00111    else
00112    {
00113       uint16_t group;
00114       uint16_t elem;
00115       TagName vr;
00116       TagName vm;
00117       TagName name;
00118 
00119       while ( true )
00120       {
00121          from >> std::hex;
00122          from >> group;
00123 
00124          if (from.eof())
00125             break;
00126 
00127          from >> elem;
00128          from >> vr;
00129          from >> vm;
00130         // from >> std::ws;  //remove white space
00131          std::getline(from, name);
00132  
00133          RemoveEntry(group,elem);
00134       }
00135       from.close();
00136       return true;
00137    }
00138 }

bool GDCM_NAME_SPACE::Dict::RemoveEntry uint16_t  group,
uint16_t  elem
 

removes an already existing Dicom Dictionary Entry, identified by its group,element number

Parameters:
group Dicom group number of the Dicom Element
elem Dicom element number of the Dicom Element
Returns:
false if Dicom Dictionary Entry doesn't exist

Definition at line 213 of file gdcmDict.cxx.

References RemoveEntry(), and GDCM_NAME_SPACE::DictEntry::TranslateToKey().

00214 {
00215    return RemoveEntry(DictEntry::TranslateToKey(group, elem));
00216 }

bool GDCM_NAME_SPACE::Dict::RemoveEntry TagKey const &  key  ) 
 

removes an already existing Dicom Dictionary Entry, identified by its Tag

Parameters:
key (group|element)
Returns:
false if Dicom Dictionary Entry doesn't exist

Definition at line 189 of file gdcmDict.cxx.

References KeyHt.

Referenced by RemoveDict(), and RemoveEntry().

00190 {
00191    TagKeyHT::const_iterator it = KeyHt.find(key);
00192    if ( it != KeyHt.end() ) 
00193    {
00194       it->second->Unregister(); // delete the entry
00195       KeyHt.erase(key);         // remove pointer from HTable
00196 
00197       return true;
00198    } 
00199    else 
00200    {
00201       gdcmWarningMacro( "Unfound entry" << key );
00202       return false;
00203   }
00204 }

void GDCM_NAME_SPACE::Base::SetPrintLevel int  level  )  [inline, inherited]
 

Sets the print level for the Dicom Header Elements.

Note:
0 for Light Print; 1 for 'medium' Print, 2 for Heavy Print

Definition at line 47 of file gdcmBase.h.

Referenced by GDCM_NAME_SPACE::FileHelper::Print(), and GDCM_NAME_SPACE::DicomDir::Print().

00047 { PrintLevel = level; }

void GDCM_NAME_SPACE::RefCounter::Unregister  )  [inline, inherited]
 

Unregister the object.

Remarks:
It decrements the reference counting

Definition at line 50 of file gdcmRefCounter.h.

Referenced by GDCM_NAME_SPACE::Document::ReadNextDocEntry(), GDCM_NAME_SPACE::SQItem::RemoveEntry(), GDCM_NAME_SPACE::ElementSet::RemoveEntry(), and GDCM_NAME_SPACE::FileHelper::~FileHelper().

00051    {
00052 //std::cout <<"================Unreg " << typeid(*this).name() << std::endl;
00053       RefCount--;
00054       if(RefCount<=0)
00055         delete this;
00056    }


Member Data Documentation

std::string GDCM_NAME_SPACE::Dict::Filename [private]
 

ASCII file holding the Dictionnary.

Definition at line 85 of file gdcmDict.h.

Referenced by Dict(), and Print().

TagKeyHT::iterator GDCM_NAME_SPACE::Dict::ItKeyHt [private]
 

Iterator for the entries.

Definition at line 90 of file gdcmDict.h.

Referenced by GetFirstEntry(), and GetNextEntry().

TagKeyHT GDCM_NAME_SPACE::Dict::KeyHt [private]
 

Access through TagKey.

Definition at line 88 of file gdcmDict.h.

Referenced by AddEntry(), ClearEntry(), GetEntry(), GetFirstEntry(), GetNextEntry(), Print(), and RemoveEntry().

int GDCM_NAME_SPACE::Base::PrintLevel [protected, inherited]
 

Amount of printed details for each Dicom Entries : 0 : stands for the least detail level.

Definition at line 55 of file gdcmBase.h.

Referenced by GDCM_NAME_SPACE::SeqEntry::Print(), GDCM_NAME_SPACE::FileHelper::Print(), GDCM_NAME_SPACE::ElementSet::Print(), GDCM_NAME_SPACE::DocEntry::Print(), GDCM_NAME_SPACE::DictEntry::Print(), GDCM_NAME_SPACE::DicomDirStudy::Print(), GDCM_NAME_SPACE::DicomDirSerie::Print(), GDCM_NAME_SPACE::DicomDirPatient::Print(), GDCM_NAME_SPACE::DicomDirMeta::Print(), GDCM_NAME_SPACE::DicomDir::Print(), and GDCM_NAME_SPACE::DataEntry::Print().


The documentation for this class was generated from the following files:
Generated on Fri Aug 24 13:01:37 2007 for gdcm by  doxygen 1.4.6