Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

gdcm::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::Dict:

Inheritance graph
[legend]
Collaboration diagram for gdcm::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 ReplaceEntry (DictEntry *newEntry)
 replaces an already existing Dicom Element by a new one
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 it's "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::Dict::Dict  )  [protected]
 

Constructor.

Definition at line 39 of file gdcmDict.cxx.

References Filename.

00040 {
00041    Filename="";
00042 }

gdcm::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::FillDefaultDataDict(), and gdcmWarningMacro.

00049 {
00050 
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       DoTheLoadingJob(from);
00061       Filename = filename;
00062    }
00063 }

gdcm::Dict::~Dict  )  [protected]
 

Destructor.

Definition at line 68 of file gdcmDict.cxx.

References ClearEntry().

00069 {
00070    ClearEntry();
00071 }


Member Function Documentation

bool gdcm::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 81 of file gdcmDict.cxx.

References DoTheLoadingJob(), and gdcmWarningMacro.

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

bool gdcm::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 141 of file gdcmDict.cxx.

References gdcmErrorMacro, gdcm::DictEntry::GetKey(), KeyHt, and gdcm::RefCounter::Register().

Referenced by DoTheLoadingJob().

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

void gdcm::Dict::ClearEntry  ) 
 

Remove all Dicom Dictionary Entries.

Definition at line 213 of file gdcmDict.cxx.

References KeyHt.

Referenced by ~Dict().

00214 {
00215    // we assume all the pointed DictEntries are already cleaned-up
00216    // when we clean KeyHt.
00217    TagKeyHT::const_iterator it;
00218    for(it = KeyHt.begin();it!=KeyHt.end();++it)
00219       it->second->Unregister();
00220    KeyHt.clear();
00221 }

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

Delete the object.

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

Definition at line 39 of file gdcmRefCounter.h.

Referenced by gdcm::SerieHelper::AddFileName(), gdcm::Document::Backtrack(), gdcm::FileHelper::CheckMandatoryElements(), gdcm::FileHelper::CheckMandatoryEntry(), gdcm::FileHelper::CopyMandatoryEntry(), gdcm::DicomDir::CreateDicomDirChainedList(), gdcm::File::DoTheLoadingJob(), DoTheLoadingJob(), gdcm::DicomDirObject::FillObject(), gdcm::DocEntrySet::InsertEntryBinArea(), gdcm::DocEntrySet::InsertEntryString(), gdcm::DocEntrySet::InsertSeqEntry(), vtkGdcmReader::LoadFileInformation(), vtkGdcmReader::LoadImageInMemory(), main(), gdcm::DicomDir::NewMeta(), gdcm::DicomDirStudy::NewVisit(), gdcm::Document::ParseDES(), gdcm::Document::ParseSQ(), gdcm::Document::ReadNextDocEntry(), gdcm::DicomDir::SetElement(), gdcm::FileHelper::SetMandatoryEntry(), gdcm::FileHelper::SetWriteFileTypeToExplicitVR(), gdcm::FileHelper::SetWriteFileTypeToImplicitVR(), gdcm::FileHelper::SetWriteFileTypeToJPEG(), gdcm::FileHelper::SetWriteToLibido(), gdcm::FileHelper::SetWriteToNoLibido(), gdcm::FileHelper::SetWriteToRaw(), gdcm::FileHelper::SetWriteToRGB(), vtkGdcmWriter::WriteDcmFile(), gdcm::DicomDir::~DicomDir(), and gdcm::Global::~Global().

00039 { Unregister(); }

void gdcm::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 290 of file gdcmDict.cxx.

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

Referenced by AddDict(), and Dict().

00291 {
00292    uint16_t group;
00293    uint16_t elem;
00294    VRKey vr;
00295    TagName vm;
00296    TagName name;
00297 
00298    DictEntry *newEntry;
00299    while (!from.eof() && from)
00300    {
00301       from >> std::hex;
00302       from >> group;
00303       from >> elem;
00304       from >> vr;
00305       from >> vm;
00306       from >> std::ws;  //remove white space
00307       std::getline(from, name);
00308 
00309       newEntry = DictEntry::New(group, elem, vr, vm, name);
00310       AddEntry(newEntry);
00311       newEntry->Delete();
00312    }
00313    from.close();
00314 }

gdcm::Dict::gdcmTypeMacro Dict   )  [private]
 

DictEntry * gdcm::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 228 of file gdcmDict.cxx.

References KeyHt.

00229 {
00230    TagKeyHT::iterator it = KeyHt.find(key);
00231    if ( it == KeyHt.end() )
00232    {
00233       return 0;
00234    }
00235    return it->second;
00236 }

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

Get the dictionary entry identified by it's "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 243 of file gdcmDict.cxx.

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

Referenced by gdcm::DicomDirObject::FillObject(), gdcm::DocEntrySet::GetDictEntry(), and gdcm::DicomDir::SetElement().

00244 {
00245    TagKey key = DictEntry::TranslateToKey(group, elem);
00246    TagKeyHT::iterator it = KeyHt.find(key);
00247    if ( it == KeyHt.end() )
00248    {
00249       return 0;
00250    }
00251    return it->second;
00252 }

DictEntry * gdcm::Dict::GetFirstEntry  ) 
 

Get the first entry while visiting the Dict entries.

Returns:
The first DicEntry if found, otherwhise NULL

Definition at line 258 of file gdcmDict.cxx.

References ItKeyHt, and KeyHt.

00259 {
00260    ItKeyHt = KeyHt.begin();
00261    if ( ItKeyHt != KeyHt.end() )
00262       return ItKeyHt->second;
00263    return NULL;
00264 }

DictEntry * gdcm::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 271 of file gdcmDict.cxx.

References gdcmAssertMacro, ItKeyHt, and KeyHt.

00272 {
00273    gdcmAssertMacro (ItKeyHt != KeyHt.end());
00274 
00275    ++ItKeyHt;
00276    if (ItKeyHt != KeyHt.end())
00277       return ItKeyHt->second;
00278    return NULL;
00279 }

int gdcm::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::RefCounter::GetRefCount  )  const [inline, inherited]
 

Get the reference counting.

Returns:
Reference count

Definition at line 56 of file gdcmRefCounter.h.

00057    {
00058       return RefCount;
00059    }

static Dict* gdcm::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::Dict::New  )  [inline, static]
 

Contructs an empty Dict with a RefCounter.

Definition at line 53 of file gdcmDict.h.

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

00053 {return new Dict();}

void gdcm::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::Base.

Definition at line 323 of file gdcmDict.cxx.

References Filename, and KeyHt.

00324 {
00325    os << "Dict file name : " << Filename << std::endl;
00326    std::ostringstream s;
00327 
00328    for (TagKeyHT::iterator tag = KeyHt.begin(); tag != KeyHt.end(); ++tag)
00329    {
00330       s << "Entry : ";
00331       s << "(" << tag->second->GetKey() << ") = "
00332         << std::dec;
00333       s << tag->second->GetVR() << ", ";
00334       s << tag->second->GetVM() << ", ";
00335       s << tag->second->GetName() << "."  << std::endl;
00336    }
00337    os << s.str();
00338 }

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

Register the object.

Remarks:
It increments the reference counting

Definition at line 44 of file gdcmRefCounter.h.

Referenced by gdcm::SQItem::AddEntry(), gdcm::ElementSet::AddEntry(), AddEntry(), gdcm::SeqEntry::AddSQItem(), gdcm::SeqEntry::Copy(), gdcm::DicomDir::Copy(), gdcm::DocEntry::DocEntry(), gdcm::FileHelper::FileHelper(), gdcm::DocEntrySet::GetDictEntry(), gdcm::CommandManager::InSetCommand(), gdcm::DocEntryArchive::Push(), ReplaceEntry(), and gdcm::SeqEntry::SetDelimitationItem().

00044 { RefCount++; }

bool gdcm::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 (!from.eof() && from)
00120       {
00121          from >> std::hex;
00122          from >> group;
00123          from >> elem;
00124          from >> vr;
00125          from >> vm;
00126         // from >> std::ws;  //remove white space
00127          std::getline(from, name);
00128  
00129          RemoveEntry(group,elem);
00130       }
00131       from.close();
00132       return true;
00133    }
00134 }

bool gdcm::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 205 of file gdcmDict.cxx.

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

00206 {
00207    return RemoveEntry(DictEntry::TranslateToKey(group, elem));
00208 }

bool gdcm::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 181 of file gdcmDict.cxx.

References gdcmWarningMacro, and KeyHt.

Referenced by RemoveDict(), RemoveEntry(), and ReplaceEntry().

00182 {
00183    TagKeyHT::const_iterator it = KeyHt.find(key);
00184    if ( it != KeyHt.end() ) 
00185    {
00186       it->second->Unregister();
00187       KeyHt.erase(key);
00188 
00189       return true;
00190    } 
00191    else 
00192    {
00193       gdcmWarningMacro( "Unfound entry" << key );
00194       return false;
00195   }
00196 }

bool gdcm::Dict::ReplaceEntry DictEntry newEntry  ) 
 

replaces an already existing Dicom Element by a new one

Parameters:
newEntry new entry (overwrites any previous one with same tag)
Returns:
false if Dicom Element doesn't exist

Definition at line 163 of file gdcmDict.cxx.

References gdcm::DictEntry::GetKey(), KeyHt, gdcm::RefCounter::Register(), and RemoveEntry().

00164 {
00165    const TagKey &key = newEntry->GetKey();
00166    if ( RemoveEntry(key) )
00167    {
00168       newEntry->Register();
00169       KeyHt.insert( TagKeyHT::value_type(key, newEntry));
00170       return true;
00171    } 
00172    return false;
00173 }

void gdcm::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::SQItem::Print(), gdcm::SeqEntry::Print(), gdcm::FileHelper::Print(), gdcm::ElementSet::Print(), and gdcm::DicomDir::Print().

00047 { PrintLevel = level; }

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

Unregister the object.

Remarks:
It decrements the reference counting

Definition at line 48 of file gdcmRefCounter.h.

Referenced by gdcm::SeqEntry::ClearSQItem(), gdcm::DicomDir::Copy(), gdcm::DocEntrySet::GetDictEntry(), gdcm::CommandManager::InSetCommand(), gdcm::DocEntrySet::NewDataEntry(), gdcm::DocEntrySet::NewSeqEntry(), gdcm::Document::ReadNextDocEntry(), gdcm::SQItem::RemoveEntry(), gdcm::ElementSet::RemoveEntry(), gdcm::SeqEntry::SetDelimitationItem(), gdcm::DocEntry::~DocEntry(), and gdcm::FileHelper::~FileHelper().

00049    {
00050       RefCount--;
00051       if(RefCount<=0)
00052          delete this;
00053    }


Member Data Documentation

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

ASCII file holding the Dictionnary.

Definition at line 85 of file gdcmDict.h.

Referenced by Dict(), and Print().

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

Iterator for the entries.

Definition at line 90 of file gdcmDict.h.

Referenced by GetFirstEntry(), and GetNextEntry().

TagKeyHT gdcm::Dict::KeyHt [private]
 

Access through TagKey.

Definition at line 88 of file gdcmDict.h.

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

int gdcm::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::SQItem::Print(), gdcm::SeqEntry::Print(), gdcm::FileHelper::Print(), gdcm::ElementSet::Print(), gdcm::DocEntry::Print(), gdcm::DictEntry::Print(), gdcm::DicomDirStudy::Print(), gdcm::DicomDirSerie::Print(), gdcm::DicomDirPatient::Print(), gdcm::DicomDirMeta::Print(), gdcm::DicomDir::Print(), and gdcm::DataEntry::Print().


The documentation for this class was generated from the following files:
Generated on Fri Jan 20 10:14:34 2006 for gdcm by  doxygen 1.4.4