4 //'identifier' : decorated name length exceeded, name was truncated
5 //#pragma warning ( disable : 4503 )
6 // 'identifier' : class 'type' needs to have dll-interface to be used by
7 // clients of class 'type2'
8 #pragma warning ( disable : 4251 )
9 // 'identifier' : identifier was truncated to 'number' characters in the
11 #pragma warning ( disable : 4786 )
15 #include <stdlib.h> // For getenv
17 #include "gdcmDictSet.h"
19 #define PUB_DICT_NAME "DicomV3Dict"
21 # define PUB_DICT_PATH "../Dicts/"
23 #define PUB_DICT_FILENAME "dicomV3.dic"
26 * \ingroup gdcmDictSet
27 * \brief Consider all the entries of the public dicom dictionnary.
28 * Build all list of all the tag names of all those entries.
29 * \sa gdcmDictSet::GetPubDictTagNamesByCategory
30 * @return A list of all entries of the public dicom dictionnary.
32 std::list<std::string> * gdcmDictSet::GetPubDictTagNames(void) {
33 std::list<std::string> * Result = new std::list<std::string>;
34 TagKeyHT entries = GetDefaultPubDict()->GetEntries();
36 for (TagKeyHT::iterator tag = entries.begin(); tag != entries.end(); ++tag){
37 Result->push_back( tag->second->GetName() );
43 * \ingroup gdcmDictSet
44 * \brief Consider all the entries of the public dicom dictionnary.
45 * Build an hashtable whose keys are the names of the groups
46 * (fourth field in each line of dictionary) and whose corresponding
47 * values are lists of all the dictionnary entries among that
48 * group. Note that apparently the Dicom standard doesn't explicitely
49 * define a name (as a string) for each group.
50 * A typical usage of this method would be to enable a dynamic
51 * configuration of a Dicom file browser: the admin/user can
52 * select in the interface which Dicom tags should be displayed.
53 * \warning Dicom *doesn't* define any name for any 'categorie'
54 * (the dictionnary fourth field was formerly NIH defined
55 * - and no longer he is-
56 * and will be removed when Dicom provides us a text file
57 * with the 'official' Dictionnary, that would be more friendly
58 * than asking us to perform a line by line check od thhe dictionnary
59 * at the beginning of each year to -try to- guess the changes)
60 * Therefore : please NEVER use that fourth field :-(
62 * @return An hashtable: whose keys are the names of the groups and whose
63 * corresponding values are lists of all the dictionnary entries
66 std::map<std::string, std::list<std::string> > * gdcmDictSet::GetPubDictTagNamesByCategory(void) {
67 std::map<std::string, std::list<std::string> > * Result = new std::map<std::string, std::list<std::string> >;
68 TagKeyHT entries = GetDefaultPubDict()->GetEntries();
70 for (TagKeyHT::iterator tag = entries.begin(); tag != entries.end(); ++tag){
71 (*Result)[tag->second->GetFourth()].push_back(tag->second->GetName());
77 * \ingroup gdcmDictSet
78 * \brief Obtain from the GDCM_DICT_PATH environnement variable the
79 * path to directory containing the dictionnaries. When
80 * the environnement variable is absent the path is defaulted
83 std::string gdcmDictSet::BuildDictPath(void) {
84 std::string ResultPath;
85 const char* EnvPath = (char*)0;
86 EnvPath = getenv("GDCM_DICT_PATH");
87 if (EnvPath && (strlen(EnvPath) != 0)) {
89 if (ResultPath[ResultPath.length() -1] != '/' )
91 dbg.Verbose(1, "gdcmDictSet::BuildDictPath:",
92 "Dictionary path set from environnement");
94 ResultPath = PUB_DICT_PATH;
99 * \ingroup gdcmDictSet
100 * \brief The Dictionnary Set obtained with this constructor simply
101 * contains the Default Public dictionnary.
103 gdcmDictSet::gdcmDictSet(void) {
104 DictPath = BuildDictPath();
105 std::string PubDictFile = DictPath + PUB_DICT_FILENAME;
106 Dicts[PUB_DICT_NAME] = new gdcmDict(PubDictFile);
109 gdcmDictSet::~gdcmDictSet() {
110 for (DictSetHT::iterator tag = Dicts.begin(); tag != Dicts.end(); ++tag) {
111 gdcmDict* EntryToDelete = tag->second;
113 delete EntryToDelete;
119 * \ingroup gdcmDictSet
120 * \brief Loads a dictionary from a specified file, and add it
121 * to already the existing ones contained in this gdcmDictSet.
122 * @param FileName Absolute or relative filename containing the
123 * dictionary to load.
124 * @param Name Symbolic name that be used as identifier of the newly
125 * created dictionary.
127 void gdcmDictSet::LoadDictFromFile(std::string FileName, DictKey Name) {
128 gdcmDict *NewDict = new gdcmDict(FileName);
129 Dicts[Name] = NewDict;
133 * \ingroup gdcmDictSet
134 * \brief Print, in an informal fashion, the list of all the dictionaries
135 * contained is this gdcmDictSet, along with their respective content.
136 * @param os Output stream used for printing.
138 void gdcmDictSet::Print(std::ostream& os) {
139 for (DictSetHT::iterator dict = Dicts.begin(); dict != Dicts.end(); ++dict){
140 os << "Printing dictionary " << dict->first << std::endl;
141 dict->second->Print(os);
146 * \ingroup gdcmDictSet
147 * \brief Retrieve the specified dictionary (when existing) from this
149 * @param DictName The synbolic name of the searched dictionary.
150 * \result The retrieved dictionary.
152 gdcmDict * gdcmDictSet::GetDict(DictKey DictName) {
153 DictSetHT::iterator dict = Dicts.find(DictName);
158 * \ingroup gdcmDictSet
159 * \brief Retrieve the default reference DICOM V3 public dictionary.
160 * \result The retrieved default dictionary.
162 gdcmDict * gdcmDictSet::GetDefaultPubDict() {
163 return GetDict(PUB_DICT_NAME);