# gdcmCSAElement.h

Go to the documentation of this file.

    00001 /*=========================================================================
    00002
    00003   Program: GDCM (Grassroots DICOM). A DICOM library
    00004   Module:  $URL$
    00005
    00006   Copyright (c) 2006-2010 Mathieu Malaterre
    00007   All rights reserved.
    00008   See Copyright.txt or http://gdcm.sourceforge.net/Copyright.html for details.
    00009
    00010      This software is distributed WITHOUT ANY WARRANTY; without even
    00011      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
    00012      PURPOSE.  See the above copyright notice for more information.
    00013
    00014 =========================================================================*/
    00015 #ifndef GDCMCSAELEMENT_H
    00016 #define GDCMCSAELEMENT_H
    00017
    00018 #include "gdcmTag.h"
    00019 #include "gdcmVM.h"
    00020 #include "gdcmVR.h"
    00021 #include "gdcmByteValue.h"
    00022 #include "gdcmSmartPointer.h"
    00023
    00024 namespace gdcm
    00025 {
    00030 class GDCM_EXPORT CSAElement
    00031 {
    00032 public:
    00033   CSAElement(unsigned int kf = 0):KeyField(kf) {}
    00034
    00035   friend std::ostream& operator<<(std::ostream &os, const CSAElement &val);
    00036
    00038   unsigned int GetKey() const { return KeyField; }
    00039   void SetKey(unsigned int key) { KeyField = key; }
    00040
    00042   const char *GetName() const { return NameField.c_str(); }
    00043   void SetName(const char *name) { NameField = name; }
    00044
    00046   const VM& GetVM() const { return ValueMultiplicityField; }
    00047   void SetVM(const VM &vm) { ValueMultiplicityField = vm; }
    00048
    00050   VR const &GetVR() const { return VRField; }
    00051   void SetVR(VR const &vr) { VRField = vr; }
    00052
    00054   unsigned int GetSyngoDT() const { return SyngoDTField; }
    00055   void SetSyngoDT(unsigned int syngodt) { SyngoDTField = syngodt; }
    00056
    00058   unsigned int GetNoOfItems() const { return NoOfItemsField; }
    00059   void SetNoOfItems(unsigned int items) { NoOfItemsField = items; }
    00060
    00062   Value const &GetValue() const { return *DataField; }
    00063   Value &GetValue() { return *DataField; }
    00064   void SetValue(Value const & vl) {
    00065     //assert( DataField == 0 );
    00066     DataField = vl;
    00067   }
    00069   bool IsEmpty() const { return DataField == 0; }
    00070
    00072   void SetByteValue(const char *array, VL length)
    00073     {
    00074     ByteValue *bv = new ByteValue(array,length);
    00075     SetValue( *bv );
    00076     }
    00079   const ByteValue* GetByteValue() const {
    00080     // Get the raw pointer from the gdcm::SmartPointer
    00081     const ByteValue *bv = dynamic_cast<const ByteValue*>(DataField.GetPointer());
    00082     return bv; // Will return NULL if not ByteValue
    00083   }
    00084
    00085   CSAElement(const CSAElement &_val)
    00086     {
    00087     if( this != &_val)
    00088       {
    00089       *this = _val;
    00090       }
    00091     }
    00092
    00093   bool operator<(const CSAElement &de) const
    00094     {
    00095     return GetKey() < de.GetKey();
    00096     }
    00097   CSAElement &operator=(const CSAElement &de)
    00098     {
    00099     KeyField = de.KeyField;
    00100     NameField = de.NameField;
    00101     ValueMultiplicityField = de.ValueMultiplicityField;
    00102     VRField = de.VRField;
    00103     SyngoDTField = de.SyngoDTField;
    00104     NoOfItemsField = de.NoOfItemsField;
    00105     DataField = de.DataField; // Pointer copy
    00106     return *this;
    00107     }
    00108
    00109   bool operator==(const CSAElement &de) const
    00110     {
    00111     return KeyField == de.KeyField
    00112       && NameField == de.NameField
    00113       && ValueMultiplicityField == de.ValueMultiplicityField
    00114       && VRField == de.VRField
    00115       && SyngoDTField == de.SyngoDTField
    00116       //&& ValueField == de.ValueField;
    00117       ;
    00118     }
    00119
    00120 protected:
    00121   unsigned int KeyField;
    00122   std::string NameField;
    00123   VM ValueMultiplicityField;
    00124   VR VRField;
    00125   unsigned int SyngoDTField;
    00126   unsigned int NoOfItemsField;
    00127   typedef SmartPointer<Value> DataPtr;
    00128   DataPtr DataField;
    00129 };
    00130 //-----------------------------------------------------------------------------
    00131 inline std::ostream& operator<<(std::ostream &os, const CSAElement &val)
    00132 {
    00133   os << val.KeyField;
    00134   os << " - '" << val.NameField;
    00135   os << "' VM " << val.ValueMultiplicityField;
    00136   os << ", VR " << val.VRField;
    00137   os << ", SyngoDT " << val.SyngoDTField;
    00138   os << ", NoOfItems " << val.NoOfItemsField;
    00139   os << ", Data ";
    00140   if( val.DataField )
    00141     {
    00142     //val.DataField->Print( os << "'" );
    00143     const ByteValue * bv = dynamic_cast<ByteValue*>(&*val.DataField);
    00144     assert( bv );
    00145     const char * p = bv->GetPointer();
    00146     std::string str(p, p + bv->GetLength() );
    00147     if( val.ValueMultiplicityField == VM::VM1 )
    00148       {
    00149       os << "'" << str.c_str() << "'";
    00150       }
    00151     else
    00152       {
    00153       std::istringstream is( str );
    00154       std::string s;
    00155       bool sep = false;
    00156       while( std::getline(is, s, '\\' ) )
    00157         {
    00158         if( sep )
    00159           {
    00160           os << '\\';
    00161           }
    00162         sep = true;
    00163         os << "'" << s.c_str() << "'";
    00164         }
    00165       //bv->Print( os << "'" );
    00166       //os << "'";
    00167       }
    00168     }
    00169   return os;
    00170 }
    00171
    00172 } // end namespace gdcm
    00173
    00174 #endif //GDCMCSAELEMENT_H