]> Creatis software - gdcm.git/blob - src/gdcmValidator.cxx
ENH: proof of concept for usage of VM in gdcm. Extremely early alpha stage don't use
[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:33:54 $
7   Version:   $Revision: 1.1 $
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 namespace gdcm 
25 {
26
27 Validator::Validator()
28 {
29 }
30
31 Validator::~Validator()
32 {
33 }
34
35 // Function to compare the VM found while parsing d->GetValue()
36 // compare to the one from the dictionary
37 bool CheckVM(ValEntry *v)
38 {
39   const std::string &s = v->GetValue();
40   std::string::size_type n = s.find("\\");
41   if (n == s.npos) // none found
42     {
43     n = 0;
44     }
45   n++; //poteaux / intervalles
46
47   unsigned int m = atoi(v->GetVM().c_str());
48
49   return n == m;
50 }
51
52 void Validator::SetInput(ElementSet *input)
53 {
54   // berk for now SetInput do two things at the same time
55   gdcm::DocEntry *d=input->GetFirstEntry();
56   while(d)
57     {
58     if ( gdcm::BinEntry *b = dynamic_cast<gdcm::BinEntry*>(d) )
59       {
60 //      copyH->InsertBinEntry( b->GetBinArea(),b->GetLength(),
61 //        b->GetGroup(),b->GetElement(),
62 //        b->GetVR() );
63         (void)b;
64       }
65     else if ( gdcm::ValEntry *v = dynamic_cast<gdcm::ValEntry*>(d) )
66       {   
67       if( !CheckVM(v))
68         {
69       std::cout << "Rah this DICOM contains one wrong tag:" << 
70         v->GetValue() << " " <<
71         v->GetGroup() << "," << v->GetElement() << "," <<
72         v->GetVR() << " " << v->GetVM() << " " << v->GetName() << std::endl;
73         }
74       }
75     else
76       {
77       // We skip pb of SQ recursive exploration
78       }
79       d=input->GetNextEntry();
80     }
81 }
82
83 } // end namespace gdcm