1 /*=========================================================================
4 Module: $RCSfile: gdcmValidator.cxx,v $
6 Date: $Date: 2007/08/21 12:51:10 $
7 Version: $Revision: 1.16 $
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.
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.
17 =========================================================================*/
19 #include "gdcmValidator.h"
20 #include "gdcmElementSet.h"
21 #include "gdcmDataEntry.h"
23 #include "gdcmDebug.h" // hidden way to include sstream
27 namespace GDCM_NAME_SPACE
29 //-----------------------------------------------------------------------------
30 typedef std::map<uint16_t, int> GroupHT; // Hash Table
31 //-----------------------------------------------------------------------------
32 /// \brief Constructor
33 Validator::Validator()
36 ///\brief Canonical Destructor
37 Validator::~Validator()
41 // Function to compare the VM found while parsing d->GetString()
42 // compare to the one from the dictionary
43 bool CheckVM(DataEntry *entry)
45 // Don't waste time checking tags where VM is OB and OW, since we know
46 // it's always 1, whatever the actual length (found on disc)
48 if ( entry->GetVR() == "OB" || entry->GetVR() == "OW" )
51 const std::string &s = entry->GetString();
53 unsigned int n = Util::CountSubstring( s , "\\");
55 n++; // number of '\' + 1 == Value Multiplicity
57 std::string vmFromDict = entry->GetVM();
58 if ( vmFromDict == "1-n" || vmFromDict == "2-n" || vmFromDict == "3-n" )
62 std::istringstream is;
69 void Validator::SetInput(ElementSet *input)
74 // First stage to check group length
76 d=input->GetFirstEntry();
79 grHT[d->GetGroup()] = 0;
80 d=input->GetNextEntry();
82 for (GroupHT::iterator it = grHT.begin(); it != grHT.end(); ++it)
84 std::cout << std::hex << it->first << std::endl;
88 // berk for now SetInput do two things at the same time
89 d=input->GetFirstEntry();
92 std::cout << "No Entry found" << std::endl;
97 if ( DataEntry *v = dynamic_cast<DataEntry *>(d) )
99 if ( v->GetVM() != GDCM_NAME_SPACE::GDCM_UNKNOWN )
102 if (v->GetVM() == "FIXME" )
103 std::cout << "For Tag " << v->GetKey() << " VM = ["
104 << v->GetVM() << "]" << std::endl;
106 std::cout << "Tag (" << v->GetKey()
107 << ")-> [" << v->GetName() << "] VR :" << v->GetVR()
108 << " contains an illegal VM. Expected VM :["
109 << v->GetVM() << "], value [" << v->GetString() << "]"
113 if ( v->GetReadLength() % 2 )
115 std::cout << "Tag (" << v->GetKey()
116 << ")-> [" << v->GetName() << "] has an uneven length :"
117 << v->GetReadLength()
118 << " [" << v->GetString() << "] "
124 // We skip pb of SQ recursive exploration
126 d=input->GetNextEntry();
130 } // end namespace gdcm