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

gdcmDict Class Reference

#include <gdcmDict.h>

List of all members.

Public Member Functions

 gdcmDict (std::string &FileName)
 Construtor.

 ~gdcmDict ()
 Destructor.

void Print (std::ostream &os=std::cout)
 Print all the dictionary entries contained in this dictionary. Entries will be sorted by tag i.e. the couple (group, element).

void PrintByKey (std::ostream &os=std::cout)
 Print all the dictionary entries contained in this dictionary. Entries will be sorted by tag i.e. the couple (group, element).

void PrintByName (std::ostream &os=std::cout)
 Print all the dictionary entries contained in this dictionary. Entries will be sorted by the name of the dictionary entries.

bool AddNewEntry (gdcmDictEntry *NewEntry)
 adds a new Dicom Dictionary Entry

bool ReplaceEntry (gdcmDictEntry *NewEntry)
 replaces an already existing Dicom Element by a new one

bool RemoveEntry (TagKey key)
 removes an already existing Dicom Dictionary Entry, identified by its Tag

bool RemoveEntry (guint16 group, guint16 element)
 removes an already existing Dicom Dictionary Entry, identified by its group,element number

gdcmDictEntryGetDictEntryByName (TagName name)
 Get the dictionnary entry identified by it's name.

gdcmDictEntryGetDictEntryByNumber (guint16 group, guint16 element)
 Get the dictionnary entry identified by a given tag (group,element).

std::list< std::string > * GetDictEntryNames (void)
 Consider all the entries of the public dicom dictionnary. Build all list of all the tag names of all those entries.

std::map< std::string, std::list<
std::string > > * 
GetDictEntryNamesByCategory (void)
 Consider all the entries of the public dicom dictionnary. Build an hashtable whose keys are the names of the groups (fourth field in each line of dictionary) and whose corresponding values are lists of all the dictionnary entries among that group. Note that apparently the Dicom standard doesn't explicitely define a name (as a string) for each group. A typical usage of this method would be to enable a dynamic configuration of a Dicom file browser: the admin/user can select in the interface which Dicom tags should be displayed.

TagKeyHTGetEntries (void)
 returns a ref to the Dicom Dictionary H table (map) return the Dicom Dictionary H table


Private Attributes

std::string filename
TagKeyHT KeyHt
 Access through TagKey (see alternate access with NameHt).

TagNameHT NameHt
 Access through TagName (see alternate access with KeyHt).


Constructor & Destructor Documentation

gdcmDict::gdcmDict std::string &  FileName  ) 
 

Construtor.

Parameters:
FileName from which to build the dictionary.

Definition at line 24 of file gdcmDict.cxx.

References AddNewEntry(), dbg, eatwhite(), gdcmDebug::Error(), filename, and TagName.

00024                                        {
00025    guint16 group, element;
00026    char buff[1024];
00027    TagName vr;
00028    TagName fourth;
00029    TagName name;
00030 
00031    std::ifstream from(FileName.c_str());
00032    dbg.Error(!from, "gdcmDict::gdcmDict: can't open dictionary",
00033                     FileName.c_str());
00034 
00035    while (!from.eof()) {
00036       from >> std::hex >> group >> element;
00037       eatwhite(from);
00038       from.getline(buff, 256, ' ');
00039       vr = buff;
00040       eatwhite(from);
00041       from.getline(buff, 256, ' ');
00042       fourth = buff;
00043       from.getline(buff, 256, '\n');
00044       name = buff;
00045 
00046       gdcmDictEntry * newEntry = new gdcmDictEntry(group, element,
00047                                                    vr, fourth, name);
00048       AddNewEntry(newEntry);
00049    }
00050    from.close();
00051 
00052    filename=FileName;
00053 }

gdcmDict::~gdcmDict  ) 
 

Destructor.

Definition at line 59 of file gdcmDict.cxx.

References KeyHt, and NameHt.

00059                     {
00060    for (TagKeyHT::iterator tag = KeyHt.begin(); tag != KeyHt.end(); ++tag) {
00061       gdcmDictEntry* EntryToDelete = tag->second;
00062       if ( EntryToDelete )
00063          delete EntryToDelete;
00064    }
00065 
00066    // Since AddNewEntry adds symetrical in both KeyHt and NameHT we can
00067    // assume all the pointed gdcmDictEntries are already cleaned-up when
00068    // we cleaned KeyHt.
00069    KeyHt.clear();
00070    NameHt.clear();
00071 }


Member Function Documentation

bool gdcmDict::AddNewEntry gdcmDictEntry NewEntry  ) 
 

adds a new Dicom Dictionary Entry

Parameters:
NewEntry entry to add
Returns:
false if Dicom Element already existed

Definition at line 136 of file gdcmDict.cxx.

References dbg, gdcmDictEntry::GetKey(), KeyHt, NameHt, TagKey, and gdcmDebug::Verbose().

Referenced by gdcmDict().

00137 {
00138    TagKey key;
00139    key = NewEntry->GetKey();
00140         
00141    if(KeyHt.count(key) == 1)
00142    {
00143       dbg.Verbose(1, "gdcmDict::AddNewEntry already present", key.c_str());
00144       return(false);
00145    } 
00146    else 
00147    {
00148       KeyHt[NewEntry->GetKey()] = NewEntry;
00149       NameHt[NewEntry->GetName()] = NewEntry;
00150       return(true);
00151    }
00152 }

gdcmDictEntry * gdcmDict::GetDictEntryByName TagName  name  ) 
 

Get the dictionnary entry identified by it's name.

Parameters:
name element of the ElVal to modify
Warning:
: NEVER use it ! the 'name' IS NOT an identifier within the Dicom Dicom Dictionary the name MAY CHANGE between two versions !
Returns:
the corresponding dictionnary entry when existing, NULL otherwise

Definition at line 219 of file gdcmDict.cxx.

References NameHt, and TagName.

Referenced by gdcmParser::GetDictEntryByName(), gdcmParser::GetEntryByName(), gdcmParser::GetEntryVRByName(), gdcmParser::GetHeaderEntryByName(), and gdcmParser::SetEntryByName().

00219                                                         {
00220    if ( ! NameHt.count(name))
00221       return NULL; 
00222    return NameHt.find(name)->second;
00223 }

gdcmDictEntry * gdcmDict::GetDictEntryByNumber guint16  group,
guint16  element
 

Get the dictionnary entry identified by a given tag (group,element).

Parameters:
group group of the entry to be found
element element of the entry to be found
Returns:
the corresponding dictionnary entry when existing, NULL otherwise

Definition at line 232 of file gdcmDict.cxx.

References KeyHt, TagKey, and gdcmDictEntry::TranslateToKey().

Referenced by gdcmParser::GetDictEntryByNumber(), gdcmDicomDir::SetElement(), and gdcmParser::UpdateShaEntries().

00232                                                                             {
00233    TagKey key = gdcmDictEntry::TranslateToKey(group, element);
00234    if ( ! KeyHt.count(key))
00235       return NULL; 
00236    return KeyHt.find(key)->second;
00237 }

std::list< std::string > * gdcmDict::GetDictEntryNames void   ) 
 

Consider all the entries of the public dicom dictionnary. Build all list of all the tag names of all those entries.

See also:
gdcmDictSet::GetPubDictTagNamesByCategory
Returns:
A list of all entries of the public dicom dictionnary.

Definition at line 246 of file gdcmDict.cxx.

References KeyHt.

Referenced by gdcmDictSet::GetPubDictEntryNames().

00247 {
00248    std::list<std::string> *Result = new std::list<std::string>;
00249    for (TagKeyHT::iterator tag = KeyHt.begin(); tag != KeyHt.end(); ++tag)
00250    {
00251       Result->push_back( tag->second->GetName() );
00252    }
00253    return Result;
00254 }

std::map< std::string, std::list< std::string > > * gdcmDict::GetDictEntryNamesByCategory void   ) 
 

Consider all the entries of the public dicom dictionnary. Build an hashtable whose keys are the names of the groups (fourth field in each line of dictionary) and whose corresponding values are lists of all the dictionnary entries among that group. Note that apparently the Dicom standard doesn't explicitely define a name (as a string) for each group. A typical usage of this method would be to enable a dynamic configuration of a Dicom file browser: the admin/user can select in the interface which Dicom tags should be displayed.

Warning:
Dicom *doesn't* define any name for any 'categorie' (the dictionnary fourth field was formerly NIH defined
  • and no longer he is- and will be removed when Dicom provides us a text file with the 'official' Dictionnary, that would be more friendly than asking us to perform a line by line check of the dictionnary at the beginning of each year to -try to- guess the changes) Therefore : please NEVER use that fourth field :-(
Returns:
An hashtable: whose keys are the names of the groups and whose corresponding values are lists of all the dictionnary entries among that group.

Definition at line 280 of file gdcmDict.cxx.

References KeyHt.

Referenced by gdcmDictSet::GetPubDictEntryNamesByCategory().

00281 {
00282    std::map<std::string, std::list<std::string> > *Result = new std::map<std::string, std::list<std::string> >;
00283 
00284    for (TagKeyHT::iterator tag = KeyHt.begin(); tag != KeyHt.end(); ++tag)
00285    {
00286       (*Result)[tag->second->GetFourth()].push_back(tag->second->GetName());
00287    }
00288    return Result;
00289 }

TagKeyHT& gdcmDict::GetEntries void   )  [inline]
 

returns a ref to the Dicom Dictionary H table (map) return the Dicom Dictionary H table

Definition at line 57 of file gdcmDict.h.

References KeyHt, and TagKeyHT.

00057 { return KeyHt; }

void gdcmDict::Print std::ostream &  os = std::cout  ) 
 

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.

Definition at line 80 of file gdcmDict.cxx.

References filename, and PrintByKey().

Referenced by gdcmParser::PrintPubDict(), and gdcmParser::PrintShaDict().

00080                                    {
00081    os<<"Dict file name : "<<filename<<std::endl;
00082    PrintByKey(os);
00083 }

void gdcmDict::PrintByKey std::ostream &  os = std::cout  ) 
 

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.

Definition at line 91 of file gdcmDict.cxx.

References KeyHt.

Referenced by Print().

00091                                         {
00092    std::ostringstream s;
00093 
00094    for (TagKeyHT::iterator tag = KeyHt.begin(); tag != KeyHt.end(); ++tag){
00095       s << "Entry : ";
00096       s << "(" << std::hex << std::setw(4) << tag->second->GetGroup() << ',';
00097       s << std::hex << std::setw(4) << tag->second->GetElement() << ") = " << std::dec;
00098       s << tag->second->GetVR() << ", ";
00099       s << tag->second->GetFourth() << ", ";
00100       s << tag->second->GetName() << "."  << std::endl;
00101    }
00102    os << s.str();
00103 }

void gdcmDict::PrintByName std::ostream &  os = std::cout  ) 
 

Print all the dictionary entries contained in this dictionary. Entries will be sorted by the name of the dictionary entries.

Warning:
AVOID USING IT : the name IS NOT an identifier; unpredictable result
Parameters:
os The output stream to be written to.

Definition at line 113 of file gdcmDict.cxx.

References NameHt.

00113                                          {
00114    std::ostringstream s;
00115 
00116    for (TagNameHT::iterator tag = NameHt.begin(); tag != NameHt.end(); ++tag){
00117       s << "Entry : ";
00118       s << tag->second->GetName() << ",";
00119       s << tag->second->GetVR() << ", ";
00120       s << tag->second->GetFourth() << ", ";
00121       s << "(" << std::hex << std::setw(4) << tag->second->GetGroup() << ',';
00122       s << std::hex << std::setw(4) << tag->second->GetElement() << ") = ";
00123       s << std::dec << std::endl;
00124    }
00125    os << s.str();
00126 }

bool gdcmDict::RemoveEntry guint16  group,
guint16  element
 

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

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

Definition at line 206 of file gdcmDict.cxx.

References RemoveEntry().

00206                                                           {
00207         return( RemoveEntry(gdcmDictEntry::TranslateToKey(group, element)) );
00208 }

bool gdcmDict::RemoveEntry TagKey  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 176 of file gdcmDict.cxx.

References dbg, gdcmDictEntry::GetName(), KeyHt, NameHt, TagKey, and gdcmDebug::Verbose().

Referenced by RemoveEntry(), and ReplaceEntry().

00177 {
00178    if(KeyHt.count(key) == 1) 
00179    {
00180       gdcmDictEntry* EntryToDelete = KeyHt.find(key)->second;
00181 
00182       if ( EntryToDelete )
00183       {
00184          NameHt.erase(EntryToDelete->GetName());
00185          delete EntryToDelete;
00186       }
00187 
00188       KeyHt.erase(key);
00189       return (true);
00190    } 
00191    else 
00192    {
00193       dbg.Verbose(1, "gdcmDict::RemoveEntry unfound entry", key.c_str());
00194       return (false);
00195   }
00196 }

bool gdcmDict::ReplaceEntry gdcmDictEntry 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 160 of file gdcmDict.cxx.

References gdcmDictEntry::GetKey(), KeyHt, NameHt, and RemoveEntry().

00160                                                    {
00161    if ( RemoveEntry(NewEntry->gdcmDictEntry::GetKey()) ) {
00162        KeyHt[NewEntry->GetKey()] = NewEntry;
00163        NameHt[NewEntry->GetName()] = NewEntry;
00164        return (true);
00165    } 
00166    return (false);
00167 }


Member Data Documentation

std::string gdcmDict::filename [private]
 

Definition at line 60 of file gdcmDict.h.

Referenced by gdcmDict(), and Print().

TagKeyHT gdcmDict::KeyHt [private]
 

Access through TagKey (see alternate access with NameHt).

Definition at line 63 of file gdcmDict.h.

Referenced by AddNewEntry(), GetDictEntryByNumber(), GetDictEntryNames(), GetDictEntryNamesByCategory(), GetEntries(), PrintByKey(), RemoveEntry(), ReplaceEntry(), and ~gdcmDict().

TagNameHT gdcmDict::NameHt [private]
 

Access through TagName (see alternate access with KeyHt).

Definition at line 65 of file gdcmDict.h.

Referenced by AddNewEntry(), GetDictEntryByName(), PrintByName(), RemoveEntry(), ReplaceEntry(), and ~gdcmDict().


The documentation for this class was generated from the following files:
Generated on Mon Feb 14 16:13:37 2005 for gdcm by doxygen 1.3.6