]> Creatis software - gdcm.git/blob - src/gdcmValidator.cxx
Avoid warnings
[gdcm.git] / src / gdcmValidator.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmValidator.cxx,v $
5   Language:  C++
6   Date:      $Date: 2005/11/04 16:08:08 $
7   Version:   $Revision: 1.8 $
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 #include "gdcmUtil.h"
23
24 #include <sstream>
25
26 namespace gdcm 
27 {
28
29 Validator::Validator()
30 {
31 }
32
33 Validator::~Validator()
34 {
35 }
36
37 // Function to compare the VM found while parsing d->GetString()
38 // compare to the one from the dictionary
39 bool CheckVM(DataEntry *entry)
40 {
41   // Don't waste time checking tags where VM is OB and OW, since we know
42   // it's allways 1, whatever the actual length (found on disc)
43   
44   if ( entry->GetVR() == "OB" ||  entry->GetVR() == "OW" )
45      return true;
46      
47   const std::string &s = entry->GetString();
48
49 /*  std::string::size_type n = s.find("\\");
50   if ( n == s.npos ) // none found
51   {
52     n = 0;
53   }
54 */
55
56   unsigned int n = Util::CountSubstring( s , "\\");
57   
58   n++; // number of '\' + 1 == Value Multiplicity
59
60   std::string vmFromDict = entry->GetVM();
61   if ( vmFromDict == "1-n" || vmFromDict == "2-n" || vmFromDict == "3-n" )
62      return true;
63      
64   unsigned int m;
65   std::istringstream is;
66   is.str( vmFromDict );
67   is >> m;
68
69   return n == m;
70 }
71
72 void Validator::SetInput(ElementSet *input)
73 {
74   // berk for now SetInput do two things at the same time
75   DocEntry *d=input->GetFirstEntry();
76   if (!d)
77   {
78      std::cout << "No Entry found" << std::endl;
79      return;
80   }
81   while(d)
82   { 
83     if ( DataEntry *v = dynamic_cast<DataEntry *>(d) )
84     { 
85       if ( v->GetVM() != gdcm::GDCM_UNKNOWN )
86          if ( !CheckVM(v) )
87          {
88            std::cout << "Tag (" <<  v->GetKey() 
89                      << ")-> [" << v->GetName() << "] contains an illegal VM. "
90                      << "value [" << v->GetString() << "] VR :"
91                      << v->GetVR() << ", Expected VM :" << v->GetVM() << " " 
92                      << std::endl;
93          }
94       
95       if ( v->GetReadLength() % 2 )
96       {
97         std::cout << "Tag (" <<  v->GetKey() 
98                   << ")-> [" << v->GetName() << "] has an uneven length :"
99                   << v->GetReadLength()
100                   << " [" << v->GetString() << "] " 
101                   << std::endl;         
102       }
103     }
104     else
105     {
106       // We skip pb of SQ recursive exploration
107     }
108       d=input->GetNextEntry();
109   }
110 }
111
112 } // end namespace gdcm