]> Creatis software - gdcm.git/blob - Testing/TestDict.cxx
Use new method GetFirstEntry instead of InitTraversal+GetNextEntry
[gdcm.git] / Testing / TestDict.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: TestDict.cxx,v $
5   Language:  C++
6   Date:      $Date: 2005/01/18 07:56:21 $
7   Version:   $Revision: 1.4 $
8                                                                                 
9   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10   l'Image). All rights reserved. See Doc/License.txt or
11   http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
12                                                                                 
13      This software is distributed WITHOUT ANY WARRANTY; without even
14      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15      PURPOSE.  See the above copyright notices for more information.
16                                                                                 
17 =========================================================================*/
18 #include "gdcmGlobal.h"
19 #include "gdcmDictSet.h"
20 #include "gdcmDict.h"
21 #include "gdcmDictEntry.h"
22
23 #include <iostream>
24 #include <iomanip>
25
26 int TestDict(int , char* [])
27 {  
28    // Print the DictSet
29    std::cout<<"#######################################################\n";
30    gdcm::DictSet *dicts=gdcm::Global::GetDicts();
31    if(!dicts)
32    {
33       std::cout<<"DictSet hasn't be found... Failed\n";
34       return(1);
35    }
36
37    std::cout<<"DictSet content :\n";
38
39    gdcm::Dict *d = dicts->GetFirstEntry();
40    if (!d)
41    {
42       std::cout << "Dictset is empty" << std::endl;
43       return 1;
44    }
45    while (d)
46    {
47       std::cout << "------------- a Dict is found : ----------" << std::endl;
48       d->Print();
49       d = dicts->GetNextEntry();
50    }
51
52    // Print the Dict (public)
53    std::cout<<"#######################################################\n";
54    gdcm::Dict *pubDict=dicts->GetDefaultPubDict();
55    if(!pubDict)
56    {
57       std::cout<<"The public Dict hasn't be found... Failed\n";
58       return(1);
59    }
60    std::cout<<"Public Dict content :\n";
61 //   pubDict->Print();
62
63    // Print the DictEntry (0x10,0x20)
64    std::cout<<"#######################################################\n";
65    const int ENTRY_GR = 0x10;
66    const int ENTRY_EL = 0x20;
67    std::string key=gdcm::DictEntry::TranslateToKey(ENTRY_GR,ENTRY_EL);
68    gdcm::DictEntry *entry=pubDict->GetDictEntry(ENTRY_GR,ENTRY_EL);
69    if(!entry)
70    {
71       std::cout<<"The DictEntry hasn't be found... Failed\n";
72       return(1);
73    }
74    std::cout<<"Entry "<<key<<" content :\n";
75    entry->Print();
76
77    // Print all the DictEntry
78    std::cout<<"#######################################################\n";
79    entry=pubDict->GetFirstEntry();
80    while(entry)
81    {
82       entry->Print();
83       entry=pubDict->GetNextEntry();
84    }
85
86    return(0);
87 }