]> Creatis software - gdcm.git/blobdiff - src/gdcmDataEntry.cxx
In order to avoid confusing user with 'public' methods he is not allowed to use,
[gdcm.git] / src / gdcmDataEntry.cxx
index 11000d315ebbfc9607e52d99076e87d225a243d8..4d7b76283a5f290ed3896db61410dfd3d6a7d8a7 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDataEntry.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/10/18 10:19:27 $
-  Version:   $Revision: 1.2 $
+  Date:      $Date: 2005/10/21 15:52:13 $
+  Version:   $Revision: 1.9 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -219,6 +219,30 @@ double DataEntry::GetValue(const uint32_t &id) const
       return BinArea[id];
 }
 
+bool DataEntry::IsValueCountValid() const
+{
+  bool valid = false;
+  uint32_t vm;
+  const std::string &strVM = GetVM();
+  uint32_t vc = GetValueCount();
+  if( strVM == "1-n" )
+    {
+    // make sure it is at least one ??? FIXME
+    valid = vc >= 1 || vc == 0;
+    }
+  else
+    {
+    std::istringstream os;
+    os.str( strVM );
+    os >> vm;
+    // Two cases:
+    // vm respect the one from the dict
+    // vm is 0 (we need to check is this element is allowed to be empty) FIXME
+    valid = vc == vm || vc == 0;
+    }
+  return valid;
+}
+
 uint32_t DataEntry::GetValueCount(void) const
 {
    const VRKey &vr = GetVR();
@@ -232,6 +256,8 @@ uint32_t DataEntry::GetValueCount(void) const
       return GetLength()/sizeof(double);
    else if( Global::GetVR()->IsVROfStringRepresentable(vr) )
    {
+      // Some element in DICOM are allowed to be empty
+      if( !GetLength() ) return 0;
       // Don't use std::string to accelerate processing
       uint32_t count = 1;
       for(uint32_t i=0;i<GetLength();i++)
@@ -241,8 +267,8 @@ uint32_t DataEntry::GetValueCount(void) const
       }
       return count;
    }
-   else
-      return GetLength();
+
+   return GetLength();
 }
 
 void DataEntry::SetString(std::string const &value)
@@ -327,7 +353,7 @@ std::string const &DataEntry::GetString() const
    {
       uint16_t *data=(uint16_t *)BinArea;
 
-      for (int i=0; i < GetValueCount(); i++)
+      for (unsigned int i=0; i < GetValueCount(); i++)
       {
          if( i!=0 )
             s << '\\';
@@ -340,7 +366,7 @@ std::string const &DataEntry::GetString() const
    {
       uint32_t *data=(uint32_t *)BinArea;
 
-      for (int i=0; i < GetValueCount(); i++)
+      for (unsigned int i=0; i < GetValueCount(); i++)
       {
          if( i!=0 )
             s << '\\';
@@ -352,7 +378,7 @@ std::string const &DataEntry::GetString() const
    {
       float *data=(float *)BinArea;
 
-      for (int i=0; i < GetValueCount(); i++)
+      for (unsigned int i=0; i < GetValueCount(); i++)
       {
          if( i!=0 )
             s << '\\';
@@ -364,7 +390,7 @@ std::string const &DataEntry::GetString() const
    {
       double *data=(double *)BinArea;
 
-      for (int i=0; i < GetValueCount(); i++)
+      for (unsigned int i=0; i < GetValueCount(); i++)
       {
          if( i!=0 )
             s << '\\';
@@ -501,6 +527,12 @@ void DataEntry::Print(std::ostream &os, std::string const & )
    os << "D ";
    DocEntry::Print(os);
 
+   uint16_t g = GetGroup();
+   if (g == 0xfffe) // delimiters have NO value
+   {          
+      return; // just to avoid identing all the remaining code 
+   }
+
    std::ostringstream s;
    TSAtr v;