]> Creatis software - gdcm.git/blob - src/gdcmValidator.cxx
* Minor coding-style clean up
[gdcm.git] / src / gdcmValidator.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmValidator.cxx,v $
5   Language:  C++
6   Date:      $Date: 2005/10/18 08:35:51 $
7   Version:   $Revision: 1.5 $
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
19 #include "gdcmValidator.h"
20 #include "gdcmElementSet.h"
21 #include "gdcmDataEntry.h"
22
23 #include <sstream>
24
25 namespace gdcm 
26 {
27
28 Validator::Validator()
29 {
30 }
31
32 Validator::~Validator()
33 {
34 }
35
36 // Function to compare the VM found while parsing d->GetString()
37 // compare to the one from the dictionary
38 bool CheckVM(DataEntry *entry)
39 {
40   const std::string &s = entry->GetString();
41   std::string::size_type n = s.find("\\");
42   if ( n == s.npos ) // none found
43   {
44     n = 0;
45   }
46   n++; // number of '\' + 1 == Value Multiplicity
47
48   unsigned int m;
49   std::istringstream os;
50   os.str( entry->GetVM());
51   os >> m;
52
53   return n == m;
54 }
55
56 void Validator::SetInput(ElementSet *input)
57 {
58   // berk for now SetInput do two things at the same time
59   DocEntry *d=input->GetFirstEntry();
60   while(d)
61   {
62     if ( DataEntry *v = dynamic_cast<DataEntry *>(d) )
63     {   
64       if ( !CheckVM(v) )
65       {
66         std::cout << "Rah this DICOM contains one wrong tag:" << 
67         v->GetString() << " " <<
68         v->GetGroup() << "," << v->GetElement() << "," <<
69         v->GetVR() << " " << v->GetVM() << " " << v->GetName() << std::endl;
70       }
71     }
72     else
73     {
74       // We skip pb of SQ recursive exploration
75     }
76       d=input->GetNextEntry();
77   }
78 }
79
80 } // end namespace gdcm