Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | 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:

gdcm::Base List of all members.

Public Member Functions

 Dict ()
 Constructor.

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

 ~Dict ()
 Destructor.

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 const &newEntry)
 adds a new Dicom Dictionary Entry

bool ReplaceEntry (DictEntry const &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 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 SetPrintLevel (int level)
 Sets the print level for the Dicom Header Elements.

int GetPrintLevel ()
 Gets the print level for the Dicom Entries.


Protected Attributes

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


Private Attributes

std::string Filename
 ASCII file holding the Dictionnary.

TagKeyHT KeyHt
 Access through TagKey.

TagKeyHT::iterator ItKeyHt

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 45 of file gdcmDict.h.


Constructor & Destructor Documentation

gdcm::Dict::Dict  ) 
 

Constructor.

Definition at line 37 of file gdcmDict.cxx.

References Filename.

00038 {
00039    Filename="";
00040 }

gdcm::Dict::Dict std::string const &  filename  ) 
 

Constructor.

Parameters:
filename from which to build the dictionary.

Definition at line 46 of file gdcmDict.cxx.

References AddEntry(), Filename, gdcm::FillDefaultDataDict(), gdcmWarningMacro, and gdcm::TagName.

00047 {
00048    uint16_t group;
00049    uint16_t element;
00050    TagName vr;
00051    TagName vm;
00052    TagName name;
00053 
00054    std::ifstream from( filename.c_str() );
00055    if( !from )
00056    {
00057       gdcmWarningMacro( "Can't open dictionary" << filename.c_str());
00058       // Using default embeded one:
00059       FillDefaultDataDict( this );
00060    }
00061    else
00062    {
00063       while (!from.eof())
00064       {
00065          from >> std::hex;
00066          from >> group;
00067          from >> element;
00068          from >> vr;
00069          from >> vm;
00070          from >> std::ws;  //remove white space
00071          std::getline(from, name);
00072    
00073          const DictEntry newEntry(group, element, vr, vm, name);
00074          AddEntry(newEntry);
00075       }
00076 
00077       Filename = filename;
00078       from.close();
00079    }
00080 }

gdcm::Dict::~Dict  ) 
 

Destructor.

Definition at line 85 of file gdcmDict.cxx.

References ClearEntry().

00086 {
00087    ClearEntry();
00088 }


Member Function Documentation

bool gdcm::Dict::AddEntry DictEntry const &  newEntry  ) 
 

adds a new Dicom Dictionary Entry

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

Definition at line 97 of file gdcmDict.cxx.

References gdcmWarningMacro, gdcm::DictEntry::GetKey(), KeyHt, and gdcm::TagKey.

Referenced by Dict().

00098 {
00099    const TagKey &key = newEntry.GetKey();
00100 
00101    if(KeyHt.count(key) == 1)
00102    {
00103       gdcmWarningMacro( "Already present" << key.c_str());
00104       return false;
00105    } 
00106    else 
00107    {
00108       KeyHt.insert( TagKeyHT::value_type(newEntry.GetKey(), newEntry));
00109       return true;
00110    }
00111 }

void gdcm::Dict::ClearEntry  ) 
 

Remove all Dicom Dictionary Entries.

Definition at line 165 of file gdcmDict.cxx.

References KeyHt.

Referenced by ~Dict().

00166 {
00167    // we assume all the pointed DictEntries are already cleaned-up
00168    // when we clean KeyHt.
00169    KeyHt.clear();
00170 }

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

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

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

Definition at line 178 of file gdcmDict.cxx.

References KeyHt, and gdcm::TagKey.

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

00179 {
00180    TagKey key = DictEntry::TranslateToKey(group, elem);
00181    TagKeyHT::iterator it = KeyHt.find(key);
00182    if ( it == KeyHt.end() )
00183    {
00184       return 0;
00185    }
00186    return &(it->second);
00187 }

DictEntry * gdcm::Dict::GetFirstEntry  ) 
 

Get the first entry while visiting the Dict entries.

Returns:
The first DicEntry if found, otherwhise NULL

Definition at line 193 of file gdcmDict.cxx.

References ItKeyHt, and KeyHt.

00194 {
00195    ItKeyHt = KeyHt.begin();
00196    if( ItKeyHt != KeyHt.end() )
00197       return &(ItKeyHt->second);
00198    return NULL;
00199 }

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 206 of file gdcmDict.cxx.

References gdcmAssertMacro, ItKeyHt, and KeyHt.

00207 {
00208    gdcmAssertMacro (ItKeyHt != KeyHt.end());
00209 
00210    ++ItKeyHt;
00211    if (ItKeyHt != KeyHt.end())
00212       return &(ItKeyHt->second);
00213    return NULL;
00214 }

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

Gets the print level for the Dicom Entries.

Definition at line 48 of file gdcmBase.h.

00048 { return PrintLevel; };

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 230 of file gdcmDict.cxx.

References Filename, and KeyHt.

00231 {
00232    os << "Dict file name : " << Filename << std::endl;
00233    std::ostringstream s;
00234 
00235    for (TagKeyHT::iterator tag = KeyHt.begin(); tag != KeyHt.end(); ++tag)
00236    {
00237       s << "Entry : ";
00238       s << "(" << std::hex << std::setw(4) << tag->second.GetGroup() << ',';
00239       s << std::hex << std::setw(4) << tag->second.GetElement() << ") = "
00240         << std::dec;
00241       s << tag->second.GetVR() << ", ";
00242       s << tag->second.GetVM() << ", ";
00243       s << tag->second.GetName() << "."  << std::endl;
00244    }
00245    os << s.str();
00246 }

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 157 of file gdcmDict.cxx.

References RemoveEntry().

00158 {
00159    return RemoveEntry(DictEntry::TranslateToKey(group, elem));
00160 }

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 134 of file gdcmDict.cxx.

References gdcmWarningMacro, KeyHt, and gdcm::TagKey.

Referenced by RemoveEntry(), and ReplaceEntry().

00135 {
00136    TagKeyHT::const_iterator it = KeyHt.find(key);
00137    if(it != KeyHt.end()) 
00138    {
00139       KeyHt.erase(key);
00140 
00141       return true;
00142    } 
00143    else 
00144    {
00145       gdcmWarningMacro( "Unfound entry" << key.c_str());
00146       return false;
00147   }
00148 }

bool gdcm::Dict::ReplaceEntry DictEntry const &  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 118 of file gdcmDict.cxx.

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

00119 {
00120    if ( RemoveEntry(newEntry.GetKey()) )
00121    {
00122        KeyHt.insert( TagKeyHT::value_type(newEntry.GetKey(), newEntry));
00123        return true;
00124    } 
00125    return false;
00126 }

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

Definition at line 45 of file gdcmBase.h.

Referenced by gdcm::SQItem::Print(), gdcm::SeqEntry::Print(), gdcm::FileHelper::Print(), gdcm::ElementSet::Print(), and gdcm::DicomDir::Print().

00045 { PrintLevel = level; };


Member Data Documentation

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

ASCII file holding the Dictionnary.

Definition at line 70 of file gdcmDict.h.

Referenced by Dict(), and Print().

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

Definition at line 74 of file gdcmDict.h.

Referenced by GetFirstEntry(), and GetNextEntry().

TagKeyHT gdcm::Dict::KeyHt [private]
 

Access through TagKey.

Definition at line 73 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 53 of file gdcmBase.h.

Referenced by gdcm::Base::Base().


The documentation for this class was generated from the following files:
Generated on Thu Feb 10 22:18:07 2005 for gdcm by doxygen 1.3.6