]> Creatis software - gdcm.git/blobdiff - src/gdcmElValSet.cxx
*FIX: Use carnaught table to reduce boolean expr !
[gdcm.git] / src / gdcmElValSet.cxx
index 91045a055093f03dfd8fddcedd534fef3ca0dfb2..634237d2da097a174b036a7afeb4431165ba2c99 100644 (file)
@@ -3,7 +3,13 @@
 #include "gdcmUtil.h"
 #include "gdcmElValSet.h"
 #include "gdcmTS.h"
-#include <sstream>
+#ifdef GDCM_NO_ANSI_STRING_STREAM
+#  include <strstream>
+#  define  ostringstream ostrstream
+# else
+#  include <sstream>
+#endif
+
 
 gdcmElValSet::~gdcmElValSet() {
    for (TagElValueHT::iterator tag = tagHt.begin(); tag != tagHt.end(); ++tag) {
@@ -18,10 +24,6 @@ gdcmElValSet::~gdcmElValSet() {
    NameHt.clear();
 }
 
-TagElValueHT & gdcmElValSet::GetTagHt(void) {
-       return tagHt;
-}
-
 /**
  * \ingroup gdcmElValSet
  * \brief   
@@ -31,6 +33,11 @@ TagElValueHT & gdcmElValSet::GetTagHt(void) {
 void gdcmElValSet::Add(gdcmElValue * newElValue) {
        tagHt [newElValue->GetKey()]  = newElValue;
        NameHt[newElValue->GetName()] = newElValue;
+       
+// WARNING : push_bash in listElem ONLY during ParseHeader
+// TODO : something to allow further Elements addition 
+// position to be taken care of !      
+       listElem.push_back(newElValue); 
 }
 
 /**
@@ -53,11 +60,13 @@ int gdcmElValSet::CheckIfExistByNumber(guint16 Group, guint16 Elem ) {
 void gdcmElValSet::Print(std::ostream & os) {
 
    size_t o;
-   short int g, e;
+   unsigned short int g, e;
    TSKey v;
    std::string d2;
    gdcmTS * ts = gdcmGlobal::GetTS();
    
+   std::cout << "------------- using tagHt ---------------------" << std::endl;
+   
    for (TagElValueHT::iterator tag = tagHt.begin();
           tag != tagHt.end();
           ++tag){
@@ -87,6 +96,45 @@ void gdcmElValSet::Print(std::ostream & os) {
       }              
       os << std::endl;
    }
+   
+   std::cout << "------------ using listElem -------------------" << std::endl;
+      
+  guint32 lgth;
+  char greltag[10];  //group element tag
+   
+  for (ListTag::iterator i = listElem.begin();  
+          i != listElem.end();
+          ++i){
+      g = (*i)->GetGroup();
+      e = (*i)->GetElement();
+      v = (*i)->GetValue();
+      o = (*i)->GetOffset();
+      sprintf(greltag,"%04x|%04x",g,e);           
+      d2 = _CreateCleanString(v);  // replace non printable characters by '.'
+      os << greltag << ": lgth : ";
+      lgth = (*i)->GetReadLength();
+      if ( lgth == 0xffffffff) 
+         os << std::hex << lgth << std::dec ;
+      else
+         os << lgth;
+      os << ", Offset : " << o;
+      os << " x(" << std::hex << o << std::dec << ") ";
+      os << "\t[" << (*i)->GetVR()    << "]";
+      os << "\t[" << (*i)->GetName()  << "]";       
+      os << "\t[" << d2 << "]";
+      
+      // Display the UID value (instead of displaying the rough code)  
+      if (g == 0x0002) {  // Any more to be displayed ?
+         if ( (e == 0x0010) || (e == 0x0002) )            
+            os << "  ==>\t[" << ts->GetValue(v) << "]";   
+      } else {
+         if (g == 0x0008) {
+            if ( (e == 0x0016) || (e == 0x1150)  )        
+               os << "  ==>\t[" << ts->GetValue(v) << "]"; 
+         }
+      }              
+      os << std::endl;
+   }      
 } 
 
 /**
@@ -184,9 +232,6 @@ int gdcmElValSet::SetElValueByNumber(std::string content,
    else
       lgr = l;    
    tagHt[key]->SetLength(lgr); 
-
-       
-
    return 1;
 }
 
@@ -386,9 +431,14 @@ void gdcmElValSet::UpdateGroupLength(bool SkipSequence, FileType type) {
 
 /**
  * \ingroup gdcmElValSet
- * \brief   
- * @param   type
- * @param   _fp 
+ * \brief   writes on disc according to the requested format
+ * \        (ACR-NEMA, DICOM, RAW) the image
+ * \ warning does NOT add the missing elements in the header :
+ * \         it's up to the user doing it !
+ * \         (function CheckHeaderCoherence to be written)
+ * @param   type type of the File to be written 
+ *          (ACR-NEMA, DICOM, RAW)
+ * @param   _fp already open file pointer
  * @return  
  */
 void gdcmElValSet::WriteElements(FileType type, FILE * _fp) {
@@ -400,6 +450,10 @@ void gdcmElValSet::WriteElements(FileType type, FILE * _fp) {
    guint16 val_uint16;
    
    std::vector<std::string> tokens;
+   
+   // TODO : use listElem to iterate, not TagHt!
+   //        pb : gdcmElValSet.Add does NOT update listElem
+   //        find a trick in STL to do it, at low cost !
 
    void *ptr;