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