# gdcmPrivateTag.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 GDCMPRIVATETAG_H
    00016 #define GDCMPRIVATETAG_H
    00017
    00018 #include "gdcmTag.h"
    00019 #include "gdcmSystem.h" // FIXME
    00020
    00021 #include <iostream>
    00022 #include <iomanip>
    00023 #include <string>
    00024 #include <algorithm>
    00025
    00026 #include <string.h> // strlen
    00027 #include <ctype.h> // tolower
    00028
    00029 namespace gdcm
    00030 {
    00031
    00037 class GDCM_EXPORT PrivateTag : public Tag
    00038 {
    00039   friend std::ostream& operator<<(std::ostream &_os, const PrivateTag &_val);
    00040 public:
    00041   PrivateTag(uint16_t group = 0, uint16_t element = 0, const char *owner = ""):Tag(group,element),Owner(owner) {
    00042     std::transform(Owner.begin(), Owner.end(), Owner.begin(), ::tolower);
    00043     // truncate the high bits
    00044     SetElement( (uint8_t)element );
    00045
    00046     // TODO:
    00047     // by default the cstor create with 0x0,0x0 which is invalid...
    00048     //assert( GetElement() >= 0x0010 && GetElement() < 0x100 );
    00049   }
    00050
    00051   const char *GetOwner() const { return Owner.c_str(); }
    00052   void SetOwner(const char *owner) { Owner = owner; }
    00053
    00054   bool operator<(const PrivateTag &_val) const
    00055     {
    00056     const Tag & t1 = *this;
    00057     const Tag & t2 = _val;
    00058     if( t1 == t2 )
    00059       {
    00060       const char *s1 = Owner.c_str();
    00061       const char *s2 = _val.GetOwner();
    00062       assert( s1[strlen(s1)-1] != ' ' );
    00063       assert( s2[strlen(s2)-1] != ' ' );
    00064       bool res = strcmp(s1, s2) < 0;
    00065 #ifndef NDEBUG
    00066       if( *s1 && *s2 && gdcm::System::StrCaseCmp(s1,s2) == 0 && strcmp(s1,s2) != 0 )
    00067         {
    00068         // FIXME:
    00069         // Typically this should only happen with the "Philips MR Imaging DD 001" vs "PHILIPS MR IMAGING DD 001"
    00070         // or "Philips Imaging DD 001" vr "PHILIPS IMAGING DD 001"
    00071         //assert( strcmp(Owner.c_str(), _val.GetOwner()) == 0 );
    00072         //return true;
    00073         res = gdcm::System::StrCaseCmp(s1,s2) < 0;
    00074 assert(0);
    00075         }
    00076 #endif
    00077       return res;
    00078       }
    00079     else return t1 < t2;
    00080     }
    00081
    00082   bool ReadFromCommaSeparatedString(const char *str);
    00083
    00084 private:
    00085   // SIEMENS MED, GEMS_PETD_01 ...
    00086   std::string Owner;
    00087 };
    00088
    00089 inline std::ostream& operator<<(std::ostream &os, const PrivateTag &val)
    00090 {
    00091   //assert( !val.Owner.empty() );
    00092   os.setf( std::ios::right );
    00093   os << std::hex << '(' << std::setw( 4 ) << std::setfill( '0' )
    00094     << val[0] << ',' << std::setw( 4 ) << std::setfill( '0' )
    00095     << val[1] << ')' << std::setfill( ' ' ) << std::dec;
    00096   os << val.Owner;
    00097   return os;
    00098 }
    00099
    00100 } // end namespace gdcm
    00101
    00102 #endif //GDCMPRIVATETAG_H