]> Creatis software - gdcm.git/blobdiff - Testing/TestAllEntryVerify.cxx
Normalization
[gdcm.git] / Testing / TestAllEntryVerify.cxx
index 3eacef55dc951b9aed0b32f81113352969ce3ec6..7f7937c52c34c5cbb2f85dce9b9001cd783ca6ef 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: TestAllEntryVerify.cxx,v $
   Language:  C++
-  Date:      $Date: 2004/12/04 08:57:20 $
-  Version:   $Revision: 1.16 $
+  Date:      $Date: 2005/02/02 10:05:26 $
+  Version:   $Revision: 1.24 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
      PURPOSE.  See the above copyright notices for more information.
                                                                                 
 =========================================================================*/
-#include "gdcmHeader.h"
+#include "gdcmFile.h"
 
 #include <map>
 #include <list>
 #include <fstream>
 #include <iostream>
+#include <sstream>
 
 //Generated file:
 #include "gdcmDataImages.h"
 
 typedef std::string EntryValueType;   // same type as ValEntry::value
 typedef std::map< gdcm::TagKey, EntryValueType > MapEntryValues;
-typedef MapEntryValuesMapEntryValuesPtr;
+typedef MapEntryValues *MapEntryValuesPtr;
 typedef std::string FileNameType;
 typedef std::map< FileNameType, MapEntryValuesPtr > MapFileValuesType;
 
@@ -51,6 +52,8 @@ class ReferenceFileParser
 {
 public:
    ReferenceFileParser();
+   ~ReferenceFileParser();
+
    bool Open( std::string& referenceFileName );
    void Print();
    void SetDataPath(std::string&);
@@ -58,22 +61,23 @@ public:
    bool Check( std::string fileName );
 
 private:
-   bool AddKeyValuePairToMap( std::string& key, std::string& value );
+   bool AddKeyValuePairToMap( std::string &key, std::string &value );
 
-   std::istream& eatwhite(std::istreamis);
-   void eatwhite(std::stringtoClean);
-   std::string ExtractFirstString(std::stringtoSplit);
-   void CleanUpLine( std::stringline );
+   std::istream& eatwhite(std::istream &is);
+   void eatwhite(std::string &toClean);
+   std::string ExtractFirstString(std::string &toSplit);
+   void CleanUpLine( std::string &line );
 
    bool Check( MapFileValuesType::iterator &fileIt );
-   std::string ExtractValue(std::stringtoSplit)  throw ( ParserException );
-   void ParseRegularLine( std::string& line ) throw ( ParserException );
-   void FirstPassReferenceFile()         throw ( ParserException );
-   bool SecondPassReferenceFile()        throw ( ParserException );
-   void HandleFileName( std::string& line )   throw ( ParserException );
-   void HandleKey( std::string& line )        throw ( ParserException );
-   bool HandleValue( std::string& line )      throw ( ParserException );
+   std::string ExtractValue(std::string &toSplit)  throw ( ParserException );
+   void ParseRegularLine( std::string &line )      throw ( ParserException );
+   void FirstPassReferenceFile()                   throw ( ParserException );
+   bool SecondPassReferenceFile()                  throw ( ParserException );
+   void HandleFileName( std::string &line )        throw ( ParserException );
+   void HandleKey( std::string &line )             throw ( ParserException );
+   bool HandleValue( std::string &line )           throw ( ParserException );
    static uint16_t axtoi( char* );
+
 private:
    /// The directory containing the images to check:
    std::string DataPath;
@@ -100,50 +104,69 @@ private:
    std::string CurrentValue;
 
    /// The current MapEntryValues pointer:
-   MapEntryValuesCurrentMapEntryValuesPtr;
+   MapEntryValues *CurrentMapEntryValuesPtr;
 };
 
+ReferenceFileParser::ReferenceFileParser()
+{
+   lineNumber = 1;
+   Indent = "      ";
+}
+
+ReferenceFileParser::~ReferenceFileParser()
+{
+   for (MapFileValuesType::iterator i  = ProducedMap.begin();
+                                    i != ProducedMap.end();
+                                    ++i)
+   {
+      delete i->second;
+   }
+}
+
 /// As gotten from:
 /// http://community.borland.com/article/0,1410,17203,0.html
-uint16_t ReferenceFileParser::axtoi(char *hexStg) {
-  int n = 0;         // position in string
-  int m = 0;         // position in digit[] to shift
-  int count;         // loop index
-  int intValue = 0;  // integer value of hex string
-  int digit[5];      // hold values to convert
-  while (n < 4) {
-     if (hexStg[n]=='\0')
-        break;
-     if (hexStg[n] > 0x29 && hexStg[n] < 0x40 ) //if 0 to 9
-        digit[n] = hexStg[n] & 0x0f;            //convert to int
-     else if (hexStg[n] >='a' && hexStg[n] <= 'f') //if a to f
-        digit[n] = (hexStg[n] & 0x0f) + 9;      //convert to int
-     else if (hexStg[n] >='A' && hexStg[n] <= 'F') //if A to F
-        digit[n] = (hexStg[n] & 0x0f) + 9;      //convert to int
-     else break;
-    n++;
-  }
-  count = n;
-  m = n - 1;
-  n = 0;
-  while(n < count) {
-     // digit[n] is value of hex digit at position n
-     // (m << 2) is the number of positions to shift
-     // OR the bits into return value
-     intValue = intValue | (digit[n] << (m << 2));
-     m--;   // adjust the position to set
-     n++;   // next digit to process
-  }
-  return intValue;
+uint16_t ReferenceFileParser::axtoi(char *hexStg) 
+{
+   int n = 0;         // position in string
+   int m = 0;         // position in digit[] to shift
+   int count;         // loop index
+   int intValue = 0;  // integer value of hex string
+   int digit[5];      // hold values to convert
+   while (n < 4) 
+   {
+      if (hexStg[n]=='\0')
+         break;
+      if (hexStg[n] > 0x29 && hexStg[n] < 0x40 )    //if 0 to 9
+         digit[n] = hexStg[n] & 0x0f;               //convert to int
+      else if (hexStg[n] >='a' && hexStg[n] <= 'f') //if a to f
+         digit[n] = (hexStg[n] & 0x0f) + 9;         //convert to int
+      else if (hexStg[n] >='A' && hexStg[n] <= 'F') //if A to F
+         digit[n] = (hexStg[n] & 0x0f) + 9;         //convert to int
+      else break;
+     n++;
+   }
+   count = n;
+   m = n - 1;
+   n = 0;
+   while(n < count) 
+   {
+      // digit[n] is value of hex digit at position n
+      // (m << 2) is the number of positions to shift
+      // OR the bits into return value
+      intValue = intValue | (digit[n] << (m << 2));
+      m--;   // adjust the position to set
+      n++;   // next digit to process
+   }
+   return intValue;
 }
 
-void ReferenceFileParser::SetDataPath( std::stringinDataPath )
+void ReferenceFileParser::SetDataPath( std::string &inDataPath )
 {
    DataPath = inDataPath;
 }
 
-bool ReferenceFileParser::AddKeyValuePairToMap( std::stringkey, 
-                                                std::stringvalue )
+bool ReferenceFileParser::AddKeyValuePairToMap( std::string &key, 
+                                                std::string &value )
 {
    if ( !CurrentMapEntryValuesPtr )
       return false;
@@ -206,7 +229,7 @@ bool ReferenceFileParser::Check( MapFileValuesType::iterator &fileIt )
 {
    std::string fileName = DataPath + fileIt->first;
    std::cout << Indent << "FileName: " << fileName << std::endl;
-   gdcm::Header* tested = new gdcm::Header( fileName.c_str() );
+   gdcm::File* tested = new gdcm::File( fileName.c_str() );
    if( !tested->IsReadable() )
    {
      std::cerr << Indent << "Failed\n"
@@ -229,7 +252,7 @@ bool ReferenceFileParser::Check( MapFileValuesType::iterator &fileIt )
       uint16_t group   = axtoi( &(groupString[0]) );
       uint16_t element = axtoi( &(groupElement[0]) );
 
-      std::string testedValue = tested->GetEntryByNumber(group, element);
+      std::string testedValue = tested->GetEntryValue(group, element);
       if ( testedValue != j->second )
       {
          // Oops make sure this is only the \0 that differ
@@ -254,7 +277,7 @@ bool ReferenceFileParser::Check( MapFileValuesType::iterator &fileIt )
    return true;
 }
 
-std::istream& ReferenceFileParser::eatwhite( std::istream& is )
+std::istream &ReferenceFileParser::eatwhite( std::istream &is )
 {
    char c;
    while (is.get(c)) {
@@ -272,7 +295,7 @@ void ReferenceFileParser::eatwhite( std::string& toClean )
       toClean.erase( 0, toClean.find_first_of( " " ) + 1 );
 }
 
-std::string ReferenceFileParser::ExtractFirstString( std::stringtoSplit )
+std::string ReferenceFileParser::ExtractFirstString( std::string &toSplit )
 {
    std::string firstString;
    eatwhite( toSplit );
@@ -287,7 +310,7 @@ std::string ReferenceFileParser::ExtractFirstString( std::string& toSplit )
    return firstString;
 }
 
-std::string ReferenceFileParser::ExtractValue( std::stringtoSplit )
+std::string ReferenceFileParser::ExtractValue( std::string &toSplit )
    throw ( ParserException )
 {
    eatwhite( toSplit );
@@ -454,13 +477,7 @@ void ReferenceFileParser::FirstPassReferenceFile() throw ( ParserException )
    from.seekg( 0, std::ios::beg );
 }
 
-ReferenceFileParser::ReferenceFileParser()
-{
-   lineNumber = 1;
-   Indent = "      ";
-}
-
-bool ReferenceFileParser::Open( std::string& referenceFileName )
+bool ReferenceFileParser::Open( std::string &referenceFileName )
 {
    from.open( referenceFileName.c_str(), std::ios::in );
    if ( !from.is_open() )
@@ -483,7 +500,7 @@ bool ReferenceFileParser::Open( std::string& referenceFileName )
    return true; //??
 }
 
-void ReferenceFileParser::CleanUpLine( std::stringline )
+void ReferenceFileParser::CleanUpLine( std::string &line )
 {
    // Cleanup from comments:
    if ( line.find_first_of( "#" ) != std::string::npos )
@@ -497,7 +514,7 @@ void ReferenceFileParser::CleanUpLine( std::string& line )
    eatwhite( line );
 }
 
-void ReferenceFileParser::HandleFileName( std::stringline )
+void ReferenceFileParser::HandleFileName( std::string &line )
    throw ( ParserException )
 {
    if ( line.length() == 0 )
@@ -509,7 +526,7 @@ void ReferenceFileParser::HandleFileName( std::string& line )
    CurrentFileName = ExtractFirstString(line);
 }
 
-void ReferenceFileParser::HandleKey( std::stringline )
+void ReferenceFileParser::HandleKey( std::string &line )
    throw ( ParserException )
 {
    if ( CurrentKey.length() != 0 )
@@ -524,7 +541,7 @@ void ReferenceFileParser::HandleKey( std::string& line )
    }
 }
 
-bool ReferenceFileParser::HandleValue( std::stringline )
+bool ReferenceFileParser::HandleValue( std::string &line )
    throw ( ParserException )
 {
    if ( line.length() == 0 )
@@ -547,7 +564,7 @@ bool ReferenceFileParser::HandleValue( std::string& line )
    return true;
 }
 
-void ReferenceFileParser::ParseRegularLine( std::stringline)
+void ReferenceFileParser::ParseRegularLine( std::string &line)
    throw ( ParserException )
 {
    if ( line.length() == 0 )
@@ -631,7 +648,7 @@ bool ReferenceFileParser::SecondPassReferenceFile()
    return true; //??
 }
 
-int TestAllEntryVerify(int argc, charargv[]) 
+int TestAllEntryVerify(int argc, char *argv[]) 
 {
    if ( argc > 2 )
    {
@@ -669,7 +686,7 @@ int TestAllEntryVerify(int argc, char* argv[])
    }
    Parser.SetDataPath(referenceDir);
    // Parser.Print();
-   std::cout << "Reference fil loaded -->\n"
+   std::cout << "Reference file loaded -->\n"
              << "Check files : \n";
 
    int ret;