4 #include <stdlib.h> // For getenv
6 #include "gdcmDictSet.h"
9 #define PUB_DICT_NAME "DicomV3Dict"
11 # define PUB_DICT_PATH "../Dicts/"
13 #define PUB_DICT_FILENAME "dicomV3.dic"
16 * \ingroup gdcmDictSet
17 * \brief Consider all the entries of the public dicom dictionnary.
18 * Build all list of all the tag names of all those entries.
19 * \sa gdcmDictSet::GetPubDictTagNamesByCategory
20 * @return A list of all entries of the public dicom dictionnary.
22 list<string> * gdcmDictSet::GetPubDictTagNames(void) {
23 list<string> * Result = new list<string>;
24 TagKeyHT entries = GetDefaultPubDict()->GetEntries();
26 for (TagKeyHT::iterator tag = entries.begin(); tag != entries.end(); ++tag){
27 Result->push_back( tag->second->GetName() );
33 * \ingroup gdcmDictSet
34 * \brief Consider all the entries of the public dicom dictionnary.
35 * Build an hashtable whose keys are the names of the groups
36 * (fourth field in each line of dictionary) and whose corresponding
37 * values are lists of all the dictionnary entries among that
38 * group. Note that apparently the Dicom standard doesn't explicitely
39 * define a name (as a string) for each group.
40 * A typical usage of this method would be to enable a dynamic
41 * configuration of a Dicom file browser: the admin/user can
42 * select in the interface which Dicom tags should be displayed.
43 * @return An hashtable: whose keys are the names of the groups and whose
44 * corresponding values are lists of all the dictionnary entries
47 map<string, list<string> > * gdcmDictSet::GetPubDictTagNamesByCategory(void) {
48 map<string, list<string> > * Result = new map<string, list<string> >;
49 TagKeyHT entries = GetDefaultPubDict()->GetEntries();
51 for (TagKeyHT::iterator tag = entries.begin(); tag != entries.end(); ++tag){
52 (*Result)[tag->second->GetFourth()].push_back(tag->second->GetName());
58 * \ingroup gdcmDictSet
59 * \brief Obtain from the GDCM_DICT_PATH environnement variable the
60 * path to directory containing the dictionnaries. When
61 * the environnement variable is absent the path is defaulted
64 string gdcmDictSet::BuildDictPath(void) {
66 const char* EnvPath = (char*)0;
67 EnvPath = getenv("GDCM_DICT_PATH");
68 if (EnvPath && (strlen(EnvPath) != 0)) {
70 if (ResultPath[ResultPath.length() -1] != '/' )
72 dbg.Verbose(1, "gdcmDictSet::BuildDictPath:",
73 "Dictionary path set from environnement");
75 ResultPath = PUB_DICT_PATH;
80 * \ingroup gdcmDictSet
81 * \brief The Dictionnary Set obtained with this constructor simply
82 * contains the Default Public dictionnary.
84 gdcmDictSet::gdcmDictSet(void) {
85 DictPath = BuildDictPath();
86 string PubDictFile = DictPath + PUB_DICT_FILENAME;
87 Dicts[PUB_DICT_NAME] = new gdcmDict(PubDictFile);
90 gdcmDictSet::~gdcmDictSet() {
91 for (DictSetHT::iterator tag = Dicts.begin(); tag != Dicts.end(); ++tag) {
92 gdcmDict* EntryToDelete = tag->second;
100 * \ingroup gdcmDictSet
101 * \brief Loads a dictionary from a specified file, and add it
102 * to allready the existing ones contained in this gdcmDictSet.
103 * @param FileName Absolute or relative filename containing the
104 * dictionary to load.
105 * @param Name Symbolic name that be used as identifier of the newly
106 * created dictionary.
108 void gdcmDictSet::LoadDictFromFile(string FileName, DictKey Name) {
109 gdcmDict *NewDict = new gdcmDict(FileName);
110 Dicts[Name] = NewDict;
114 * \ingroup gdcmDictSet
115 * \brief Print, in an informal fashion, the list of all the dictionaries
116 * contained is this gdcmDictSet, along with their respective content.
117 * @param os Output stream used for printing.
119 void gdcmDictSet::Print(ostream& os) {
120 for (DictSetHT::iterator dict = Dicts.begin(); dict != Dicts.end(); ++dict){
121 os << "Printing dictionary " << dict->first << " \n";
122 dict->second->Print(os);
127 * \ingroup gdcmDictSet
128 * \brief Retrieve the specified dictionary (when existing) from this
130 * @param DictName The synbolic name of the searched dictionary.
131 * \result The retrieved dictionary.
133 gdcmDict * gdcmDictSet::GetDict(DictKey DictName) {
134 DictSetHT::iterator dict = Dicts.find(DictName);
139 * \ingroup gdcmDictSet
140 * \brief Retrieve the default reference DICOM V3 public dictionary.
141 * \result The retrieved default dictionary.
143 gdcmDict * gdcmDictSet::GetDefaultPubDict() {
144 return GetDict(PUB_DICT_NAME);