]> Creatis software - gdcm.git/blob - src/gdcmValidator.cxx
> // Don't waste time checking tags where VM is OB and OW, since we know
[gdcm.git] / src / gdcmValidator.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmValidator.cxx,v $
5   Language:  C++
6   Date:      $Date: 2005/10/28 15:52:15 $
7   Version:   $Revision: 1.6 $
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   // Don't waste time checking tags where VM is OB and OW, since we know
41   // it's allways 1, whatever the actual length (found on disc)
42   
43   if ( entry->GetVR() == "OB" ||  entry->GetVR() == "OW" )
44      return true;
45      
46   const std::string &s = entry->GetString();
47   std::string::size_type n = s.find("\\");
48   if ( n == s.npos ) // none found
49   {
50     n = 0;
51   }
52   n++; // number of '\' + 1 == Value Multiplicity
53
54   unsigned int m;
55   std::istringstream os;
56   os.str( entry->GetVM());
57   os >> m;
58
59   return n == m;
60 }
61
62 void Validator::SetInput(ElementSet *input)
63 {
64   // berk for now SetInput do two things at the same time
65   DocEntry *d=input->GetFirstEntry();
66   while(d)
67   {
68     if ( DataEntry *v = dynamic_cast<DataEntry *>(d) )
69     {   
70       if ( !CheckVM(v) )
71       {
72         std::cout << "Rah this DICOM contains one wrong tag:" << 
73         v->GetString() << " " <<
74         v->GetGroup() << "," << v->GetElement() << "," <<
75         v->GetVR() << " " << v->GetVM() << " " << v->GetName() << std::endl;
76       }
77     }
78     else
79     {
80       // We skip pb of SQ recursive exploration
81     }
82       d=input->GetNextEntry();
83   }
84 }
85
86 } // end namespace gdcm