]> Creatis software - gdcm.git/blob - src/gdcmValidator.cxx
ENH: Sltightly better code
[gdcm.git] / src / gdcmValidator.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmValidator.cxx,v $
5   Language:  C++
6   Date:      $Date: 2005/06/14 20:53:19 $
7   Version:   $Revision: 1.2 $
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 "gdcmBinEntry.h"
22 #include "gdcmValEntry.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->GetValue()
38 // compare to the one from the dictionary
39 bool CheckVM(ValEntry *v)
40 {
41   const std::string &s = v->GetValue();
42   std::string::size_type n = s.find("\\");
43   if (n == s.npos) // none found
44     {
45     n = 0;
46     }
47   n++; // number of '\' + 1 == Value Multiplicity
48
49   unsigned int m;
50   std::istringstream os;
51   os.str( v->GetVM());
52   os >> m;
53
54   return n == m;
55 }
56
57 void Validator::SetInput(ElementSet *input)
58 {
59   // berk for now SetInput do two things at the same time
60   gdcm::DocEntry *d=input->GetFirstEntry();
61   while(d)
62     {
63     if ( gdcm::BinEntry *b = dynamic_cast<gdcm::BinEntry*>(d) )
64       {
65 //      copyH->InsertBinEntry( b->GetBinArea(),b->GetLength(),
66 //        b->GetGroup(),b->GetElement(),
67 //        b->GetVR() );
68         (void)b;
69       }
70     else if ( gdcm::ValEntry *v = dynamic_cast<gdcm::ValEntry*>(d) )
71       {   
72       if( !CheckVM(v))
73         {
74       std::cout << "Rah this DICOM contains one wrong tag:" << 
75         v->GetValue() << " " <<
76         v->GetGroup() << "," << v->GetElement() << "," <<
77         v->GetVR() << " " << v->GetVM() << " " << v->GetName() << std::endl;
78         }
79       }
80     else
81       {
82       // We skip pb of SQ recursive exploration
83       }
84       d=input->GetNextEntry();
85     }
86 }
87
88 } // end namespace gdcm